Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a bug that when \n is used the contentWidth might be wrong

  • Loading branch information...
commit 25563a4e7d726aa7fd6a9997fead7d6d656018c3 1 parent 8ca5615
@ba01ei ba01ei authored
View
4 GSFancyText/src/GSFancyText.m
@@ -497,7 +497,9 @@ - (NSMutableArray*)generateLines {
// Regular case: if it is not the last line, it means that this line is long enough to cover a whole line
if (i != segmentLines.count -1 ) {
- contentWidth_ = width_;
+ CGFloat widthUsed = [lineText sizeWithFont:segmentFont].width;
+ CGFloat currentLineContentWidth = widthUsed + (width_ - currentLineSpaceLeft);
+ contentWidth_ = MAX(contentWidth_, currentLineContentWidth);
if (!insertLineBlock() ) {
return lines_;
}
View
38 GSFancyText/tests/GSFancyTextModelTest.m
@@ -409,6 +409,44 @@ - (void)testLineHeights {
STAssertEqualsWithAccuracy(fancyText.contentHeight, expectedHeight, 0.1, @"total height=%f, should be %f", fancyText.contentHeight, expectedHeight);
}
+- (void)testContentWidth {
+ GSFancyText* f = [[GSFancyText alloc] initWithMarkupText:@"<span id=x>1234567</span>"];
+ f.width = 1000;
+ [f generateLines];
+ STAssertTrue(f.contentWidth>0, @"no way. it's %f", f.contentWidth);
+
+ UIFont* font = [UIFont systemFontOfSize:16];
+ NSString* s1 = @"Foxtro Uniform Charlie Kilo";
+ CGFloat expectedW = [s1 sizeWithFont:font].width;
+
+ [f changeAttribute:GSFancyTextFontSizeKey to:[NSNumber numberWithFloat:16] on:GSFancyTextID withName:@"x"];
+ [f changeNodeToText:s1 forID:@"x"];
+ [f generateLines];
+
+ NSLog(@"pure text: %@", f.pureText);
+
+ STAssertTrue(f.contentWidth == expectedW, @"content width not right: %f, should be:%f", f.contentWidth, expectedW);
+
+ NSString* s2 = @"A quill pen is a writing implement made from a moulted flight feather (preferably a primary wing-feather) of a large bird. Quills were used for writing with ink before the invention of the dip pen, the metal-nibbed pen, the fountain pen, and, eventually, the ballpoint pen. The hand-cut goose quill is still used as a calligraphy tool, however rarely because many papers are now derived from wood pulp and wear down the quill very quickly. It is still the tool of choice for a few professionals and provides an unmatched sharp stroke as well as greater flexibility than a steel pen.";
+ expectedW = 1000;
+ [f changeNodeToText:s2 forID:@"x"];
+ [f generateLines];
+ STAssertTrue((expectedW - f.contentWidth)<100 && expectedW>=f.contentWidth, @"content width not right: %f, should be:%f", f.contentWidth, expectedW);
+
+ NSString* s3 = @"Short\nShorter\nShortest";
+ [f changeNodeToText:s3 forID:@"x"];
+ [f generateLines];
+ expectedW = [@"Shortest" sizeWithFont:font].width;
+ STAssertTrue(f.contentWidth == expectedW, @"content width not right: %f, should be:%f", f.contentWidth, expectedW);
+
+ NSString* s4 = @"<strong>Make You Long</strong> Short\nShorter\nShortest";
+ expectedW = [@"Make You Long Short" sizeWithFont:font].width;
+ [f changeNodeToStyledText:s4 forID:@"x"];
+ [f generateLines];
+ STAssertTrue(f.contentWidth >= expectedW, @"content width not right: %f, should be:%f", f.contentWidth, expectedW);
+
+
+}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.