[ASTextNode] Ensure that isTruncated computes the correct value when sizing fast-path is used. (#2550) (#2763)

* Fix fast-path isTruncated.

* Clean up formatting; remove extra char.
This commit is contained in:
Adlai Holler
2016-12-13 14:01:50 -05:00
committed by GitHub
parent 8920b60dcd
commit f637392a77
3 changed files with 18 additions and 1 deletions

View File

@@ -85,6 +85,11 @@
*/
- (NSUInteger)lineCount;
/**
Whether or not the text is truncated.
*/
- (BOOL)isTruncated;
@end
@interface ASTextKitRenderer (ASTextKitRendererConvenience)

View File

@@ -261,6 +261,18 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
return lineCount;
}
- (BOOL)isTruncated
{
if (self.canUseFastPath) {
CGRect boundedRect = [_attributes.attributedString boundingRectWithSize:CGSizeMake(_constrainedSize.width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine
context:nil];
return boundedRect.size.height > _constrainedSize.height;
} else {
return self.firstVisibleRange.length < _attributes.attributedString.length;
}
}
- (std::vector<NSRange>)visibleRanges
{
return _truncater.visibleRanges;