mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Made a few changes to font scale adjustment
1) cache the scale in the font adjuster. The adjuster will be dealloc'ed when the renderer that owns it is dealloc'ed (or invalidated). Until that time we can trust the scale that the adjuster has computed. 2) When measuring line count, make sure that we are not bounding the height of the container's size. This will cause the wrong number of lines to be returned. 3) Instead of setting the ascender/descender on an ASTextNode when an attributed string is added, wait until after the renderer calculates size. This way, if there is any need to scale the font to fit we can apply that scale to the ascender/descender.
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
__weak ASTextKitContext *_context;
|
||||
ASTextKitAttributes _attributes;
|
||||
std::mutex _textKitMutex;
|
||||
BOOL _measured;
|
||||
CGFloat _scaleFactor;
|
||||
}
|
||||
|
||||
- (instancetype)initWithContext:(ASTextKitContext *)context
|
||||
@@ -85,7 +87,7 @@
|
||||
NSLayoutManager *layoutManager = _attributes.layoutManagerCreationBlock ? _attributes.layoutManagerCreationBlock() : [[ASLayoutManager alloc] init];
|
||||
layoutManager.usesFontLeading = NO;
|
||||
[textStorage addLayoutManager:layoutManager];
|
||||
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:_constrainedSize];
|
||||
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:CGSizeMake(_constrainedSize.width, FLT_MAX)];
|
||||
|
||||
textContainer.lineFragmentPadding = 0;
|
||||
textContainer.lineBreakMode = _attributes.lineBreakMode;
|
||||
@@ -104,8 +106,14 @@
|
||||
|
||||
- (CGFloat)scaleFactor
|
||||
{
|
||||
if (_measured) {
|
||||
return _scaleFactor;
|
||||
}
|
||||
|
||||
if ([_attributes.pointSizeScaleFactors count] == 0 || isinf(_constrainedSize.width)) {
|
||||
return 1.0;
|
||||
_measured = YES;
|
||||
_scaleFactor = 1.0;
|
||||
return _scaleFactor;
|
||||
}
|
||||
|
||||
__block CGFloat adjustedScale = 1.0;
|
||||
@@ -177,7 +185,9 @@
|
||||
}
|
||||
|
||||
}];
|
||||
return adjustedScale;
|
||||
_measured = YES;
|
||||
_scaleFactor = adjustedScale;
|
||||
return _scaleFactor;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user