Merge pull request #1343 from rcancro/cacheFontScale

[ASTextNode] Improvements to the implementation of the font scale adjuster.
This commit is contained in:
appleguy
2016-03-09 02:41:13 -08:00
3 changed files with 26 additions and 11 deletions

View File

@@ -337,7 +337,18 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
[self setNeedsDisplay];
return [[self _renderer] size];
CGSize size = [[self _renderer] size];
if (self.attributedString.length > 0) {
CGFloat screenScale = ASScreenScale();
self.ascender = round([[_attributedString attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL] ascender] * screenScale)/screenScale;
self.descender = round([[_attributedString attribute:NSFontAttributeName atIndex:_attributedString.length - 1 effectiveRange:NULL] descender] * screenScale)/screenScale;
if (_renderer.currentScaleFactor > 0 && _renderer.currentScaleFactor < 1.0) {
// while not perfect, this is a good estimate of what the ascender of the scaled font will be.
self.ascender *= _renderer.currentScaleFactor;
self.descender *= _renderer.currentScaleFactor;
}
}
return size;
}
#pragma mark - Modifying User Text
@@ -375,12 +386,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
} else {
self.isAccessibilityElement = YES;
}
if (attributedString.length > 0) {
CGFloat screenScale = ASScreenScale();
self.ascender = round([[attributedString attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL] ascender] * screenScale)/screenScale;
self.descender = round([[attributedString attribute:NSFontAttributeName atIndex:attributedString.length - 1 effectiveRange:NULL] descender] * screenScale)/screenScale;
}
}
#pragma mark - Text Layout