Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
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
Binary file modified AsyncDisplayKit-Prefix.gcda
Binary file not shown.
19 changes: 19 additions & 0 deletions AsyncDisplayKit/TextKit/ASTextKitRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ - (void)_calculateSize
__block CGRect boundingRect;
[_context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
boundingRect = [layoutManager usedRectForTextContainer:textContainer];

// Work around line spacing of the last line not getting taken into account
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is this a TextKit bug? Were you able to find any other reports of it online? Ideally we should file a Radar for this and reference the number here...almost certainly this code will break in a future version of iOS (if it is a workaround), and thus a future version of ourselves will be puzzling over the intent and context here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find anything on google. Logged a bug rdar://23885167.

// (rdar://23885167)
NSRange visibleGlyphRange = [layoutManager glyphRangeForBoundingRect:constrainedRect
inTextContainer:textContainer];
NSInteger lastVisibleGlyphIndex = (NSMaxRange(visibleGlyphRange) - 1);
NSInteger lastVisibleGlyphAttributeIndex = [layoutManager characterIndexForGlyphAtIndex:lastVisibleGlyphIndex];

NSParagraphStyle *paragraphStyle = [textStorage attributesAtIndex:lastVisibleGlyphAttributeIndex
effectiveRange:NULL][NSParagraphStyleAttributeName];

if (paragraphStyle.lineSpacing > 0) {
CGSize boundingSize = boundingRect.size;
CGSize sizeWithLineSpacing = CGSizeMake(boundingSize.width,
boundingSize.height + paragraphStyle.lineSpacing);
boundingRect = (CGRect){ .origin = boundingRect.origin,
.size = sizeWithLineSpacing };
}

}];

// TextKit often returns incorrect glyph bounding rects in the horizontal direction, so we clip to our bounding rect
Expand Down
12 changes: 11 additions & 1 deletion AsyncDisplayKitTests/ASTextNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ - (void)setUp
[[NSMutableAttributedString alloc] initWithString:@"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." attributes:d];
NSMutableParagraphStyle *para = [NSMutableParagraphStyle new];
para.alignment = NSTextAlignmentCenter;
[mas addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0,mas.length)];
para.lineSpacing = 1.0;
[mas addAttribute:NSParagraphStyleAttributeName value:para
range:NSMakeRange(0, mas.length - 1)];

// Vary the linespacing on the last line
NSMutableParagraphStyle *lastLinePara = [NSMutableParagraphStyle new];
lastLinePara.alignment = para.alignment;
lastLinePara.lineSpacing = 5.0;
[mas addAttribute:NSParagraphStyleAttributeName value:lastLinePara
range:NSMakeRange(mas.length - 1, 1)];

_attributedString = mas;
_textNode.attributedString = _attributedString;
}
Expand Down