Including multiple fonts of the same family in an iPad application [closed]
I have a problem using custom fonts inside my iPad application when I have to include more than one font of the same font family.
Basically some fonts get rendered like others, especially the bold ones. In my case I have these fours fonts:
Tungsten-Medium (ok)
Tungsten-Black (ok) Tungsten-Bold Tungsten-Semiboldthe system found all these in fact I have no problem with medium or black but when I choose the bold or the semibold the result is the black font!
this issue affects the native components like UILabel and UITextField but also an html documents with custom css that I'm using inside my application.
I set-up everything correctly in the in the project resources and in the Info.plist file, I even tried to convert the fonts in the ttf format but the result does not change.
I'm using the iOS sdk 4.2 for and iPad application, it's important to know that prior to this os (in 3.2) my fonts were rendered correctly!
The only working solution I found until now is to edit the fonts and set a different font family for each one but this implies a lot of work inside the code and the html so I would avoid this.
what should I try?
I found a solution reading other forums. Honestly, I think it's more a workaround than a real solution.
I used a font manager tool (Transtype pro) to edit the fonts metadata. I set a specific "OT Font family" for each font with the same value of the field "PS font name". This avoid the framework to confuse fonts of the same family without touching the code.
Ugly, but it works.
I created a method that reads descriptions of the fonts in the fontsArray of a certain family and returns appropriate font.
- (UIFont*) getFontWithFamilyName:(NSString*)familyName bold:(Boolean)bold italic:(Boolean)italic size:(uint)size {
NSArray *fonts = [UIFont fontNamesForFamilyName:familyName];
for (NSString *fname in fonts) {
UIFont *font = [UIFont fontWithName:fname size:size];
Boolean isBold = [[font description] rangeOfString:@"bold"].location != NSNotFound;
Boolean isItalic = [[font description] rangeOfString:@"italic"].location != NSNotFound;
if (isBold == bold && isItalic == italic) {
return font;
}
}
//-- font was not found, provide system font bold or normal
if (bold) {
return [UIFont boldSystemFontOfSize:size];
} else {
return [UIFont systemFontOfSize:size];
}
}
精彩评论