@@ -971,9 +971,19 @@ - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
971
971
aWidth = CGFLOAT_MAX;
972
972
}
973
973
aWidth = [attributedStringCpy boundingRectWithSize: CGSizeMake (aWidth, CGFLOAT_MAX) options: NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context: nil ].size .width ;
974
+
975
+ /* Must get ceil of aWidth. Or core text may not return correct bounds.
976
+ Maybe aWidth without ceiling triggered some critical conditions. */
977
+ aWidth = ceil (aWidth);
974
978
CTFramesetterRef ctframesetterRef = CTFramesetterCreateWithAttributedString ((__bridge CFAttributedStringRef )(attributedStringCpy));
975
979
suggestSize = CTFramesetterSuggestFrameSizeWithConstraints (ctframesetterRef, CFRangeMake (0 , 0 ), NULL , CGSizeMake (aWidth, MAXFLOAT), NULL );
976
980
981
+ if (_lines == 0 ) {
982
+ // If not line limit use suggestSize directly.
983
+ CFRelease (ctframesetterRef);
984
+ return CGSizeMake (aWidth, suggestSize.height );
985
+ }
986
+
977
987
CGMutablePathRef path = NULL ;
978
988
path = CGPathCreateMutable ();
979
989
// sufficient height to draw text
@@ -982,15 +992,14 @@ - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
982
992
CTFrameRef frameRef = NULL ;
983
993
frameRef = CTFramesetterCreateFrame (ctframesetterRef, CFRangeMake (0 , attributedStringCpy.length ), path, NULL );
984
994
CGPathRelease (path);
995
+ CFRelease (ctframesetterRef);
985
996
986
- CFArrayRef lines = NULL ;
987
997
if (NULL == frameRef) {
988
998
// try to protect unexpected crash.
989
999
return suggestSize;
990
1000
}
991
- CFRelease (ctframesetterRef);
992
- ctframesetterRef = NULL ;
993
- lines = CTFrameGetLines (frameRef);
1001
+
1002
+ CFArrayRef lines = CTFrameGetLines (frameRef);
994
1003
CFIndex lineCount = CFArrayGetCount (lines);
995
1004
CGFloat ascent = 0 ;
996
1005
CGFloat descent = 0 ;
@@ -1010,7 +1019,6 @@ - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
1010
1019
1011
1020
totalHeight = totalHeight + actualLineCount * leading;
1012
1021
CFRelease (frameRef);
1013
- frameRef = NULL ;
1014
1022
1015
1023
if (WX_SYS_VERSION_LESS_THAN (@" 10.0" )) {
1016
1024
// there is something wrong with coreText drawing text height, trying to fix this with more efficent way.
0 commit comments