Skip to content

Commit

Permalink
Small fix in ASTextKitRenderer #trivial (TextureGroup#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhuy authored and mikezucc committed Nov 7, 2018
1 parent f4ec172 commit e7dce87
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit e7dce87

Please sign in to comment.