mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
Fix to text shrinking
Summary: Previously the first thing we did when calculating the size of text was to truncate it. This could lead to ASFontSizeAdjuster being sent a truncated string which, obviously, never needed to shrink. If we change the order then we first shrink, then truncate if still necessary. Reviewers: scottg, levi, garrett Differential Revision: https://phabricator.pinadmin.com/D89780
This commit is contained in:
parent
62a853b3e9
commit
082ababda6
@ -137,25 +137,30 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
|
||||
|
||||
- (void)_calculateSize
|
||||
{
|
||||
[self truncater];
|
||||
// if we have no scale factors or an unconstrained width, there is no reason to try to adjust the font size
|
||||
if (isinf(_constrainedSize.width) == NO && [_attributes.pointSizeScaleFactors count] > 0) {
|
||||
_currentScaleFactor = [[self fontSizeAdjuster] scaleFactor];
|
||||
}
|
||||
|
||||
// Force glyph generation and layout, which may not have happened yet (and isn't triggered by
|
||||
// -usedRectForTextContainer:).
|
||||
__block NSTextStorage *scaledTextStorage = nil;
|
||||
BOOL isScaled = [self isScaled];
|
||||
[[self context] performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
|
||||
if (isScaled) {
|
||||
// apply the string scale before truncating or else we may truncate the string after we've done the work to shrink it.
|
||||
[[self context] performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
|
||||
NSMutableAttributedString *scaledString = [[NSMutableAttributedString alloc] initWithAttributedString:textStorage];
|
||||
[ASTextKitFontSizeAdjuster adjustFontSizeForAttributeString:scaledString withScaleFactor:_currentScaleFactor];
|
||||
scaledTextStorage = [[NSTextStorage alloc] initWithAttributedString:scaledString];
|
||||
|
||||
[textStorage removeLayoutManager:layoutManager];
|
||||
[scaledTextStorage addLayoutManager:layoutManager];
|
||||
}];
|
||||
}
|
||||
|
||||
[self truncater];
|
||||
|
||||
// Force glyph generation and layout, which may not have happened yet (and isn't triggered by
|
||||
// -usedRectForTextContainer:).
|
||||
[[self context] performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
|
||||
[layoutManager ensureLayoutForTextContainer:textContainer];
|
||||
}];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user