Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Fallback fonts for multiple languages and characters.  (Read 2110 times)

0 Members and 1 Guest are viewing this topic.

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Fallback fonts for multiple languages and characters.
« on: November 10, 2014, 04:39:25 am »
Hi all.

I was wondering if it was at all possible to implement a feature into sf::Font to check if the font has a certain character. A usage example would be to use the arial font with asian characters with correct use of wide strings. The result is that the characters are displayed as boxes. While I dont have a problem with this, I do have a problem that I cant tell if a font has these characters or not, so being able to check would be helpful since I could swap to another font to display these foreign characters.

This isnt COMPLETELY relevant, but I noticed that Steam does this seamlessly but that might be a feature in SDL I'm not sure.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Fallback fonts for multiple languages and characters.
« Reply #1 on: November 10, 2014, 08:49:07 am »
It seems strange to check this on the fly, usually you choose your font file according to the language that you intend to display. And if you don't know in advance, you can still choose a font per supported language, and load the one that matches the user's language.
Laurent Gomila - SFML developer

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Fallback fonts for multiple languages and characters.
« Reply #2 on: November 10, 2014, 08:55:32 am »
The thing is that i want to display a font for english and another for asian characters. The main thing is that arial doesnt support asian characters and I either have to display everything with super spacing (for some reason MS Gothic does that with english) or deal with boxes for unsupported characters.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Fallback fonts for multiple languages and characters.
« Reply #3 on: November 10, 2014, 09:00:47 am »
Currently, SFML loads glyphs "directly" without translating a unicode codepoint to a glyph index first. If SFML would do that, it would realize that a glyph isn't available since FreeType maps unavailable glyphs to a special "unavailable glyph" index, 0. If you try to load the glyph at index 0 you will get the famous box texture everybody knows.

What this means is that no matter whether you load 1 character that isn't available or another, they will all map to the same texture data, the box. It is unfortunate that SFML doesn't make use of this fact because glyph texture data is mapped with the codepoint as the key and not the glyph index. Maybe this will change in the future ;).

For now, a nice "workaround" you could use is to simply compare the texture data of a glyph you want to try loading to a glyph that is known not to exist e.g. the NUL character with codepoint 0. If they compare equal, you know that that glyph isn't available and you can take the corrective measures you mentioned. Obviously doing this a lot could lead to performance issues, so caching the result would be recommended.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Fallback fonts for multiple languages and characters.
« Reply #4 on: November 11, 2014, 02:45:46 am »
The scenario I'm using is to display player names, so if someone chooses an asian name and someone else chooses say arabic or something, I dont want an english players UI to be set to arabic or asian just because there are foreign characters if that makes sense. I'm not overly fond of workarounds that impeded performance so I think ill just have to deal with the boxes for now. Perhaps SDL might have some mechanic for this.

 

anything