Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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-Semibold

the 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?

like image 223
nebillo Avatar asked Mar 08 '11 10:03

nebillo


People also ask

How do I add multiple fonts to my iPad?

You can download fonts from the App Store app , then use them in documents you create on iPad. After you download an app containing fonts from the App Store, open the app to install the fonts. To manage installed fonts, go to Settings > General, then tap Fonts.

How do I use AnyFont on my iPad?

Once you have the fonts downloaded to AnyFont, you can add them to iOS by creating a custom profile. To do this, tap the list icon to select the fonts you want to install. Select all the fonts you want to include in the profile and make sure they have a blue check mark next to them, then tap Install.

How do I add fonts to info plist?

To do this, add the key "Fonts provided by application" to Info. plist (the raw key name is UIAppFonts ). Xcode creates an array value for the key; add the name of the font file as an item of the array. Be sure to include the file extension as part of the name.

Is iFont app free?

I have three or more apps that are supposed to serve the whole “font managing” issue. This single app, however, combines all the useful features from them all, and puts them in one place! For free! You can't beat that.


2 Answers

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.

like image 181
nebillo Avatar answered Oct 13 '22 05:10

nebillo


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];
    }
}
like image 34
Elendurwen Avatar answered Oct 13 '22 04:10

Elendurwen