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

Author Topic: Switching fonts for different character sets  (Read 2249 times)

0 Members and 1 Guest are viewing this topic.

Julian

  • Newbie
  • *
  • Posts: 2
    • View Profile
Switching fonts for different character sets
« on: September 26, 2018, 11:53:50 pm »
I'm looking into Steam integration for my game and I ran into a problem with displaying user's names. A Steam user's name can not only be in any language, but a combination of many, so I can't just pick a font for a specific language. Any ideas as to how to solve this?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Switching fonts for different character sets
« Reply #1 on: October 01, 2018, 05:31:27 am »
There is no easy out of the box solution to this problem.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Switching fonts for different character sets
« Reply #2 on: October 01, 2018, 08:02:28 am »
Quote
A Steam user's name can not only be in any language, but a combination of many, so I can't just pick a font for a specific language
And how are user names displayed in other games, or in the Steam UI or website? I don't think they use multiple fonts for the same string... they probably use a "Unicode" font.
Laurent Gomila - SFML developer

Julian

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Switching fonts for different character sets
« Reply #3 on: October 01, 2018, 03:11:43 pm »
The problem is that, from my research, you can't actually get a single font that renders every language, because the standard formats are all limited to like 65K glyphs, which is just like Japanese alone.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Switching fonts for different character sets
« Reply #4 on: October 01, 2018, 06:09:43 pm »
(I'm not a unicode/font/typography expert but I'm a 'language enthusiast' so some of the stuff here might be wrong).

Normal real life Japanese alone has nowhere near to that amount of characters. Neither do Chinese or Korean. But there are so many Chinese characters (which Korean kinda uses a bit but uses mostly it's own phonetic thing, Chinese obviously does and Japanese does too in addition to own two phonetic writings), reforms and dictionaries that no one even has a count down anymore so truly comprehensive fonts are hitting that limit (and some aren't even coded in like https://en.wikipedia.org/wiki/Taito_(kanji) and https://en.wikipedia.org/wiki/Biangbiang_noodles#Chinese_character_for_bi%C3%A1ng ).

There is a file format called ttc (True Type Collection) that can contain multiple fonts packed in one file. Freetype (which SFML uses) can open these files (I've just tested with NotoSansCJK.ttc in SFML, this is Google's comprehensive font that I once used before in XeLaTeX: https://www.google.com/get/noto/help/cjk/ ).

Supposedly that format can have up to 65536 (2^16 - 1) characters per each font it includes so there is no (practical, the number of fonts in ttc file is a 32 bit number) limit: https://graphicdesign.stackexchange.com/questions/73166/what-is-the-maximum-number-of-glyphs-an-opentype-collection-can-hold

This is the smaller problem anyway since in theory you could have rewritten sf::Text from scratch to allow many Fonts too or just ignore all these exotic characters (if someone has an obscure never used 30+ stroke Chinese character in their name for lulz they should have seriously known better).

The real problem comes from how complex Unicode is. There are two/three problems I can think of off the top of my head: combining characters (like é can be just é or the plain ASCII e followed by the acute accent, this is related to something called normalization http://unicode.org/faq/normalization.html , SFML afaik doesn't handle that, but you can also abuse combiners to create something called zalgo text: http://www.eeemo.net/ ) and 'interesting' writing systems (like Arabic and few others in which letters get dragged/changed all over the place as text grows, plus some of these, like Arabic and Hebrew, are also right to left, neither of which is a property SFML handles at all, Apple even has had few bugs related to Indian and Arabic fonts that crashed iOS and Mac apps and such in the past due to how complex these rules get).

I've seen games (Payday 1 or 2) just display boxes instead of characters it doesn't know (SFML seems to do that too for characters it can't find, or maybe the placeholder is encoded in the font itself). I've no idea what display names Steam allows (like can you get all Arabic or Hebrew name or mix combiners badly or get emojis or other non-BMP stuff?).

I think your best bet is just to get a nice BMP (https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane) font and hope for the best (that even if someone has crazy crap or emojis or something 'interesting' in their name they will have something from BMP that's left to right too so it's not all bad).
« Last Edit: October 01, 2018, 06:29:42 pm by FRex »
Back to C++ gamedev with SFML in May 2023