[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

@@ -1163,7 +1163,7 @@ static NSAttributedString *DefaultTruncationAttributedString()
ASDN::MutexLocker l(__instanceLock__); ASDN::MutexLocker l(__instanceLock__);
ASTextKitRenderer *renderer = [self _renderer]; ASTextKitRenderer *renderer = [self _renderer];
return renderer.firstVisibleRange.length < _attributedText.length; return renderer.isTruncated;
} }
- (void)setPointSizeScaleFactors:(NSArray *)pointSizeScaleFactors - (void)setPointSizeScaleFactors:(NSArray *)pointSizeScaleFactors

View File

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

View File

@@ -261,6 +261,18 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
return lineCount; 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 - (std::vector<NSRange>)visibleRanges
{ {
return _truncater.visibleRanges; return _truncater.visibleRanges;