2

I am using different fonts in my Codename One app. If I include and use Roboto-Bold.ttf or Oswald font from Google fonts or Keep Calm Medium from dafont.com the text is displayed on Android and Codename One Simulator (as reported on this SO question) but NOT on iOS (neither on the device nor on XCode device) although the fonts are packaged in the .ipa generated by Codename One.

I tried with style = PLAIN or BOLD with the same results.

I used font = Font.createTrueTypeFont(fontName, fontFilename ).derive(fontSize, style);

Why are some fonts working while other aren't? Is there any way to know before compilation which fonts are more likely to work on iOS?

Community
  • 1
  • 1
HelloWorld
  • 2,275
  • 18
  • 29

1 Answers1

2

iOS and Android use very different approaches to dealing with fonts which we try to simplify with a simple method.

If you define the font in the designer with a UIID we can hide most of that complexity for you but when you load the font dynamically you are exposed to some of that.

Android just loads font files so the file is used and this should work easily like the simulator. iOS needs the fonts to be installed and then loaded by font name (which isn't the file name and isn't very intuitive). This stack overflow question discusses the method of getting the font name on a Mac: How do I get the font name from an otf or ttf file?

Community
  • 1
  • 1
Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thanks Shai! I tried to define the font in the designer and use it and it worked. Then I opened the font in OSX ([as showed here](http://stackoverflow.com/questions/4143908/name-of-non-system-font-in-iphone)) and noted the name displayed in the window title bar (Keep Calm for Keep Calm Medium). I then used Keep Calm as fontName in CN1 and it worked! In fontForge this name is the "Prefered OFT family" field. – HelloWorld Jul 08 '16 at 13:26
  • 2
    FYI you can also just define all the fonts you want (and their sizes) in the theme and then use `Font fnt = UIManager.getInstance().getComponentStyle("MyUIID").getFont();` – Shai Almog Jul 09 '16 at 04:42
  • Thanks Shai I tried this before trying the solution I voted for since you suggested it in your answer. It works as expected but it's just I did not want to make a different case for these 2 fonts compared to the 10 other fonts my app is using (to make the maintenance work easier). But you are right and it works ;-) – HelloWorld Jul 17 '16 at 20:09