Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fix in ASTextKitRenderer #trivial #1167

Merged
merged 1 commit into from
Oct 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Source/TextKit/ASTextKitRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ - (void)_calculateSize
_currentScaleFactor = [[self fontSizeAdjuster] scaleFactor];
}

const CGRect constrainedRect = {CGPointZero, _constrainedSize};

// If we do not scale, do exclusion, or do custom truncation, we should just use NSAttributedString drawing for a fast-path.
if (self.canUseFastPath) {
CGRect rect = [_attributes.attributedString boundingRectWithSize:_constrainedSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine context:self.stringDrawingContext];
// Intersect with constrained rect, in case text kit goes out-of-bounds.
rect = CGRectIntersection(rect, {CGPointZero, _constrainedSize});
rect = CGRectIntersection(rect, constrainedRect);
_calculatedSize = [self.shadower outsetSizeWithInsetSize:rect.size];
return;
}
Expand All @@ -136,7 +138,6 @@ - (void)_calculateSize

[[self truncater] truncate];

CGRect constrainedRect = {CGPointZero, _constrainedSize};
__block CGRect boundingRect;

// Force glyph generation and layout, which may not have happened yet (and isn't triggered by
Expand All @@ -153,7 +154,7 @@ - (void)_calculateSize

// TextKit often returns incorrect glyph bounding rects in the horizontal direction, so we clip to our bounding rect
// to make sure our width calculations aren't being offset by glyphs going beyond the constrained rect.
boundingRect = CGRectIntersection(boundingRect, {.size = constrainedRect.size});
boundingRect = CGRectIntersection(boundingRect, constrainedRect);
_calculatedSize = [_shadower outsetSizeWithInsetSize:boundingRect.size];
}

Expand Down