Skip to content

Commit 858b6a9

Browse files
committed
Handle odd line seperators in CCLabelBMFont.
The XCode plist editor and some other editors can create string data with Unicode line seperators in it, eg: \u2028. http://en.wikipedia.org/wiki/Newline#Unicode You can easily enter one using <ctrl>+<enter> in your plist or code editor. The plist editor will not let you type <enter> as it will just commit the current cell being edited. To get an actual newline you can type <option>+<enter>. Code in CCLabelBMFont correctly tests using NSCharacterSet newlineCharacterSet in most places, but in two places incorrectly tests for equality against '\n'. So strings with one of these "odd" newlines will be rendered with all the text on one line. Fix this, and make the code consistent.
1 parent 09ee27d commit 858b6a9

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

cocos2d-ui-tests/tests/CCBMFontTest.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
static NSString *TEST_STRINGS[] = {
1313
@"ABCDEFGHIJKLM\nNOPQRSTUVWXYZ",
1414
@"abcdefghijklm\nnopqrstuvwxyz",
15+
@"first line\u2028second line",
1516
@",.?!;:'\"",
1617
@"()[]{}<>\\|/\n",
1718
@"@#$%^&*+-=_",

cocos2d/CCLabelBMFont.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ -(void) createFontChars
762762
// since the Y position needs to be calcualted before hand
763763
for(NSUInteger i=0; i < stringLen-1;i++) {
764764
unichar c = [_string characterAtIndex:i];
765-
if( c=='\n')
765+
if([[NSCharacterSet newlineCharacterSet] characterIsMember:c])
766766
quantityOfLines++;
767767
}
768768

@@ -776,7 +776,7 @@ -(void) createFontChars
776776
for(NSUInteger i = 0; i<stringLen; i++) {
777777
unichar c = [_string characterAtIndex:i];
778778

779-
if (c == '\n') {
779+
if ([[NSCharacterSet newlineCharacterSet] characterIsMember:c]) {
780780
nextFontPositionX = 0;
781781
nextFontPositionY -= _configuration->_commonHeight;
782782
continue;

0 commit comments

Comments
 (0)