Search Unity

Resolved TMPro not showing simplified chinese correctly (some missing characters)

Discussion in 'UGUI & TextMesh Pro' started by GuirieSanchez, Jan 30, 2023.

  1. GuirieSanchez

    GuirieSanchez

    Joined:
    Oct 12, 2021
    Posts:
    452
    So, I'm using a main font asset for occidental languages that does not contain Chinese characters. So, in order for the asset to display Chinese characters too, you're supposed to add a fallback asset to it.

    I went on to google fonts and downloaded a bunch of different fonts just to see which style fits better. Then, I added it to the fallback and it works, as it's supposed to. Except for the fact that there are missing characters.

    upload_2023-1-30_15-54-2.png

    In blue is TMPro with some missing characters (the squared ones), and on the right side (white) is the regular text native in Unity, which displays all characters correctly.

    At first, I thought it could be a problem with the font, but apparently, every font has some missing characters, which makes me think it's totally an issue with TMPro (not that is a bug, but rather a fault in my implementation maybe).

    Any help is appreciated.
     
  2. GuirieSanchez

    GuirieSanchez

    Joined:
    Oct 12, 2021
    Posts:
    452
    Someone?
     
    Unifikation likes this.
  3. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    If the font itself doesn't have those characters, you'll get problems like this.
    A lot of Chinese fonts are not nearly complete.
     
  4. GuirieSanchez

    GuirieSanchez

    Joined:
    Oct 12, 2021
    Posts:
    452
    I found the issue:
    Those fonts are official (like Google fonts, Microsoft fonts, or Adobe fonts) and therefore they should be complete. Imagine being Chinese, texting a client for instance, and suddenly not having basic characters to communicate properly. With this in mind, I ruled out any problem regarding the font and instead I looked carefully into TMPro.

    Apparently, there's a dynamic atlas being filled with characters as soon as the Chinese characters pop up on the screen. If I'm not mistaken, the atlas size by default is either 512x512 or 1024x1024 (width and height).
    upload_2023-2-2_14-19-56.png

    With an atlas of size 1024x1024, you can fill it up to around 90-100 characters only; so, as soon as it reaches its maximum capacity, any other character that is not in the list won't be recognized and will appear as a square.

    upload_2023-2-2_14-22-50.png

    upload_2023-2-2_14-23-2.png

    One solution to this will be making the atlas bigger. I think a 4096x4096 will allow +1000 characters to be rendered (and you can use up to an 8192x8192 size Atlas), so, if your project is not too big, you can make use of it.

    But I understand this is not like a reliable fix if you happen to have a bigger project with a lot of text.

    It would be very helpful to hear about alternatives to this (that don't rely on your project not having a lot of text).
     
  5. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    this is the kind of thinking that leads to "safe and effective" being flouted as The Science™

    There's very few Chinese fonts that are character complete. None of them come from the companies you've mentioned.
     
    SF_FrankvHoof likes this.
  6. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,087
    Perhaps not carefully enough... the solution is here...



    the solution - tick "Multi Atlas Textures".

    This adds more textures after you fill each subsequent one, and is specifically for this problem. After solving this you'll find that most fonts don't have all the characters, and have to make a compromise of style versus character completeness.
     
    njellingson and Fraccas like this.
  7. GuirieSanchez

    GuirieSanchez

    Joined:
    Oct 12, 2021
    Posts:
    452
    The point I was trying to get across is about TMPro having a limited capacity rather than having an incomplete font set. I didn't try the option "Multi Atlas Textures", but if indeed it adds more textures after each subsequent one, then it looks like a perfectly suitable solution. Thanks!

    On the other hand, whether these fonts have all possible characters available or not (traditional, outdated, etc.) is up for debate. Indeed, I shouldn't have said they should be complete but rather they offer a decent amount. If they can be used to write a paper or a newspaper article with virtually no problem, it's unlikely that you may have a problem with your project. Now, if you download a font from who-knows-where then it could be possible that the font itself will have everyday-use missing characters.

    Regardless, the main issue is clear: having a small atlas that contained only 98 characters over the 6,000 - 50,000 characters that standard Chinese fonts usually offer (in my case, I chose one with 34,147 glyphs in its version). 98 over 34,147 is a tiny percentage (0.002% of the characters being displayed).

    I read some comments on TMPro (Unity Forums and Reddit) that pointed directly to the font not containing all the characters. I think it would be more useful to point towards TMPro functionality and, in this case, atlas properties first, rather than leave it out and mention other problems that are not so prominent in comparison.