Bug with using font family

I need to use font family in our game and found that it doesn’t display correctly on Windows (simulator and native build).
When using Regular, Bold, Italic or Bold Italic versions of the font simultaneously, the only one version of the font is displaying (the first used).
Here the example:
[lua]
– try to replace “Aver.ttf” with “AverBold.ttf”, “AverBoldItalic.ttf” or “AverItalic.ttf”
display.newText( “Hello World!”, 150, 100, “Aver.ttf”, 36 )
display.newText( “Hello World!”, 150, 200, “AverBold.ttf”, 36 )
display.newText( “Hello World!”, 150, 300, “AverBoldItalic.ttf”, 36 )
display.newText( “Hello World!”, 150, 400, “AverItalic.ttf”, 36 )
[/lua]
Replacing “Aver.ttf” with “AverBold.ttf”, “AverBoldItalic.ttf” or “AverItalic.ttf” will change the displaying of all other text lines.

Tested on Windows 7, Windows 8.1 (with latest public build and daily build 2866, no warnings or errors in console log). Tested with several font families.
Works fine on Mac OS X.
Test example is in attachment.

Hey @Andriy Pertsov I downloaded and tried to change the font names and everything but it didn’t work.

I think that the problem is that, you are trying to use a font family, when you create one text with a font that is in aver font, it will automatically use it in other fonts. But also, I might not be right. Only advice I can say is that, you should try using different fonts

Coder

Font families can be tricky because as Coder mentioned, their internal names may have some crossover:

This is especially true of free font families.  

In my experience you should either:

A. Avoid font families,

B. Edit the fonts and modify their internal names.  This can be tricky if you don’t have the right tools or knowledge

I guess there is another option:

C. Enlist the help of someone with the skills to fix the fonts.

PS - Great post and question.  You hit all the proper points:

  • Told us what you want to do.
  • Showed up what you tried.
  • Included downloadable sample.
  • Gave us details about your environment.

Awesome!

I’ve downloaded your project.  @Coder101 is correct.  It’s because all 3 of your font files have the same internal font family names (aka: typeface name).  You can see this for yourself by double clicking on each font file on Windows and look at that the “Font Name” shown in the popup for each file.  The file name means nothing to the system.  The font read from it is privately loaded/registered by its font family name internally.  Any other font file you load having the same font family name will re-use the already loaded/registered one.  I’m pretty sure Android works the same way.

@roaminggamer provides the correct solution.  Each font file you have needs to be edited to use a unique font family name.

@Mr. Coder As i write I tried different fonts families - same problem.

@roaminggamer I also think this is due to fonts’ internal names, but I expected it’s fixed after public release 2830 (https://coronalabs.com/blog/2016/02/25/important-changes-loading-fonts-just-got-easier-in-corona-sdk/)

What’s inconvenient that everything works fine on Mac OS X, so we need to modify the code and resources to support differences in Windows and Mac OS X builds.

There are some other problems with fonts on Windows (some fonts are not visible etc), but this bug is important for us now.

@JoshuaQuick I see. Will try to change typeface name. But it would be nice if Corona won’t work on Windows (and Android?) with internal name, but with file name (as it seems worked on Mac OS X).
 

The problem with loading fonts by family name instead of by font file before is that family names were proven to be not portable/cross-platform.  How the native platform loads a font by famliy name differed.  The only portable way to handle this was to load it by font filename instead.  Then it becomes nearly as simple as loading images by filename.  If anything, it becomes less convenient because now you can load all of your embedded font files the same way without if/elseif conditions.

The issue you’re running into Andriy is not technically a bug on Windows; or Android which would have the same issue.  It’s unusual to have multiple font files containing different font data like this all having the same family name.  So, native platforms that can only differentiate fonts by their family names need something to uniquely identify them with.  That’s the issue.

@JoshuaQuick Thank you for detailed explanation. Will try to edit font file to change font family name (typeface), and report if this helps.

I suppose what you’re really after is support for enabling bold and italic font styles.  Because typically a native developer would just load 1 font family and select the styles they want to render with.  Unfortunately, Corona doesn’t currently support this, but feel free to post a feature request for it via the link below.  If it gets enough votes, then that’ll increase the priority of it when we evaluate which feature to do next.

   http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback

Hey @Andriy Pertsov I downloaded and tried to change the font names and everything but it didn’t work.

I think that the problem is that, you are trying to use a font family, when you create one text with a font that is in aver font, it will automatically use it in other fonts. But also, I might not be right. Only advice I can say is that, you should try using different fonts

Coder

Font families can be tricky because as Coder mentioned, their internal names may have some crossover:

This is especially true of free font families.  

In my experience you should either:

A. Avoid font families,

B. Edit the fonts and modify their internal names.  This can be tricky if you don’t have the right tools or knowledge

I guess there is another option:

C. Enlist the help of someone with the skills to fix the fonts.

PS - Great post and question.  You hit all the proper points:

  • Told us what you want to do.
  • Showed up what you tried.
  • Included downloadable sample.
  • Gave us details about your environment.

Awesome!

I’ve downloaded your project.  @Coder101 is correct.  It’s because all 3 of your font files have the same internal font family names (aka: typeface name).  You can see this for yourself by double clicking on each font file on Windows and look at that the “Font Name” shown in the popup for each file.  The file name means nothing to the system.  The font read from it is privately loaded/registered by its font family name internally.  Any other font file you load having the same font family name will re-use the already loaded/registered one.  I’m pretty sure Android works the same way.

@roaminggamer provides the correct solution.  Each font file you have needs to be edited to use a unique font family name.

@Mr. Coder As i write I tried different fonts families - same problem.

@roaminggamer I also think this is due to fonts’ internal names, but I expected it’s fixed after public release 2830 (https://coronalabs.com/blog/2016/02/25/important-changes-loading-fonts-just-got-easier-in-corona-sdk/)

What’s inconvenient that everything works fine on Mac OS X, so we need to modify the code and resources to support differences in Windows and Mac OS X builds.

There are some other problems with fonts on Windows (some fonts are not visible etc), but this bug is important for us now.

@JoshuaQuick I see. Will try to change typeface name. But it would be nice if Corona won’t work on Windows (and Android?) with internal name, but with file name (as it seems worked on Mac OS X).
 

The problem with loading fonts by family name instead of by font file before is that family names were proven to be not portable/cross-platform.  How the native platform loads a font by famliy name differed.  The only portable way to handle this was to load it by font filename instead.  Then it becomes nearly as simple as loading images by filename.  If anything, it becomes less convenient because now you can load all of your embedded font files the same way without if/elseif conditions.

The issue you’re running into Andriy is not technically a bug on Windows; or Android which would have the same issue.  It’s unusual to have multiple font files containing different font data like this all having the same family name.  So, native platforms that can only differentiate fonts by their family names need something to uniquely identify them with.  That’s the issue.

@JoshuaQuick Thank you for detailed explanation. Will try to edit font file to change font family name (typeface), and report if this helps.

I suppose what you’re really after is support for enabling bold and italic font styles.  Because typically a native developer would just load 1 font family and select the styles they want to render with.  Unfortunately, Corona doesn’t currently support this, but feel free to post a feature request for it via the link below.  If it gets enough votes, then that’ll increase the priority of it when we evaluate which feature to do next.

   http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback