@@ -44,6 +44,9 @@ of this software and associated documentation files (the "Software"), to deal
44
44
// Vibrate
45
45
#import < AudioToolbox/AudioToolbox.h>
46
46
47
+ const float MAX_MEASURE_HEIGHT = 10000 ;
48
+
49
+
47
50
static NSAttributedString * __attributedStringWithFontSize (NSMutableAttributedString * attributedString, CGFloat fontSize)
48
51
{
49
52
{
@@ -82,7 +85,11 @@ static CGFloat _calculateTextDrawStartHeight(cocos2d::Device::TextAlign align, C
82
85
return startH;
83
86
}
84
87
85
- static CGSize _calculateShrinkedSizeForString (NSAttributedString **str, id font, CGSize constrainSize, bool enableWrap, int & newFontSize)
88
+ static CGSize _calculateShrinkedSizeForString (NSAttributedString **str,
89
+ id font,
90
+ CGSize constrainSize,
91
+ bool enableWrap,
92
+ int & newFontSize)
86
93
{
87
94
CGRect actualSize = CGRectMake (0 , 0 , constrainSize.width + 1 , constrainSize.height + 1 );
88
95
int fontSize = [font pointSize ];
@@ -102,7 +109,7 @@ static CGSize _calculateShrinkedSizeForString(NSAttributedString **str, id font,
102
109
*str = __attributedStringWithFontSize (mutableString, fontSize);
103
110
104
111
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString ((__bridge CFAttributedStringRef)*str);
105
- CGSize targetSize = CGSizeMake (CGFLOAT_MAX, CGFLOAT_MAX );
112
+ CGSize targetSize = CGSizeMake (MAX_MEASURE_HEIGHT, MAX_MEASURE_HEIGHT );
106
113
CGSize fitSize = CTFramesetterSuggestFrameSizeWithConstraints (framesetter, CFRangeMake (0 , [(*str) length ]), NULL , targetSize, NULL );
107
114
CFRelease (framesetter);
108
115
if (fitSize.width == 0 || fitSize.height == 0 ) {
@@ -135,10 +142,10 @@ static CGSize _calculateShrinkedSizeForString(NSAttributedString **str, id font,
135
142
NSMutableAttributedString *mutableString = [[*str mutableCopy ] autorelease ];
136
143
*str = __attributedStringWithFontSize (mutableString, fontSize);
137
144
138
- CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString ((__bridge CFAttributedStringRef)*str);
139
- CGSize targetSize = CGSizeMake (constrainSize. width , CGFLOAT_MAX);
140
- CGSize fitSize = CTFramesetterSuggestFrameSizeWithConstraints (framesetter, CFRangeMake ( 0 , [(*str) length ]), NULL , targetSize, NULL ) ;
141
- CFRelease (framesetter);
145
+ CGSize fitSize = [*str boundingRectWithSize: CGSizeMake (constrainSize.width, MAX_MEASURE_HEIGHT)
146
+ options: (NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
147
+ context: nil ]. size ;
148
+
142
149
if (fitSize.width == 0 || fitSize.height == 0 ) {
143
150
continue ;
144
151
}
@@ -160,7 +167,7 @@ static CGSize _calculateShrinkedSizeForString(NSAttributedString **str, id font,
160
167
161
168
newFontSize = fontSize;
162
169
163
- return CGSizeMake (actualSize.size .width , actualSize.size .height );
170
+ return CGSizeMake (ceilf ( actualSize.size .width ), ceilf ( actualSize.size .height ) );
164
171
}
165
172
166
173
#define SENSOR_DELAY_GAME 0.02
@@ -339,16 +346,16 @@ static CGSize _calculateStringSize(NSAttributedString *str, id font, CGSize *con
339
346
{
340
347
CGSize textRect = CGSizeZero;
341
348
textRect.width = constrainSize->width > 0 ? constrainSize->width
342
- : CGFLOAT_MAX ;
349
+ : MAX_MEASURE_HEIGHT ;
343
350
textRect.height = constrainSize->height > 0 ? constrainSize->height
344
- : CGFLOAT_MAX ;
351
+ : MAX_MEASURE_HEIGHT ;
345
352
346
353
if (overflow == 1 ) {
347
354
if (!enableWrap) {
348
- textRect.width = CGFLOAT_MAX ;
349
- textRect.height = CGFLOAT_MAX ;
355
+ textRect.width = MAX_MEASURE_HEIGHT ;
356
+ textRect.height = MAX_MEASURE_HEIGHT ;
350
357
} else {
351
- textRect.height = CGFLOAT_MAX ;
358
+ textRect.height = MAX_MEASURE_HEIGHT ;
352
359
}
353
360
}
354
361
0 commit comments