Skip to content

Commit

Permalink
Merge pull request cocos2d#16659 from zilongshanren/fix-mac-font-name
Browse files Browse the repository at this point in the history
fix mac system font creation with NSFont
  • Loading branch information
zilongshanren committed Oct 10, 2016
2 parents 56e0e6f + 5b10985 commit eeab15b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 9 additions & 0 deletions cocos/platform/ios/CCDevice-ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ static CGSize _calculateShrinkedSizeForString(NSAttributedString **str, id font,
actualSize.size.height > constrainSize.height) {
fontSize = fontSize - 1;

if(fontSize < 0) {
actualSize = CGRectMake(0, 0, 0, 0);
break;
}

NSMutableAttributedString *mutableString = [[*str mutableCopy] autorelease];
*str = __attributedStringWithFontSize(mutableString, fontSize);

Expand Down Expand Up @@ -122,6 +127,10 @@ static CGSize _calculateShrinkedSizeForString(NSAttributedString **str, id font,
while (actualSize.size.height > constrainSize.height ||
actualSize.size.width > constrainSize.width) {
fontSize = fontSize - 1;
if(fontSize < 0) {
actualSize = CGRectMake(0, 0, 0, 0);
break;
}

NSMutableAttributedString *mutableString = [[*str mutableCopy] autorelease];
*str = __attributedStringWithFontSize(mutableString, fontSize);
Expand Down
12 changes: 2 additions & 10 deletions cocos/platform/mac/CCDevice-mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,10 @@ static NSSize _calculateRealSizeForString(NSAttributedString **str, id font, NSS
fntName = [[fntName lastPathComponent] stringByDeletingPathExtension];

// font
NSFont *font = [[NSFontManager sharedFontManager]
fontWithFamily:fntName
traits:NSUnboldFontMask | NSUnitalicFontMask
weight:0
size:size];
NSFont *font = [NSFont fontWithName:fntName size:size];

if (font == nil) {
font = [[NSFontManager sharedFontManager]
fontWithFamily:@"Arial"
traits:NSUnboldFontMask | NSUnitalicFontMask
weight:0
size:size];
font = [NSFont systemFontOfSize:size];
}
return font;
}
Expand Down

0 comments on commit eeab15b

Please sign in to comment.