Search Unity

Question How to load TMP emoji sprite assets from android and iOS native fonts?

Discussion in 'UGUI & TextMesh Pro' started by itsnottme, Jul 18, 2021.

  1. itsnottme

    itsnottme

    Joined:
    Mar 8, 2017
    Posts:
    129
    Hello, how can I load the emoji sprite assets from phone (android and iOS)?

    Currently I am loading all OS fonts on the start of the app, but now emojis don't work at all.
    Not loading any OS fonts will use the default sprite asset which is missing many emojis.

    Code (CSharp):
    1. string[] fontPaths = Font.GetPathsToOSFonts();
    2.  
    3.         for (int i = 0; i < fontPaths.Length; i++)
    4.         {
    5.             Font osFont = new Font(fontPaths[i]);
    6.  
    7.             TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(osFont);
    8.  
    9.             TMP_Settings.fallbackFontAssets.Add(fontAsset);
    10.         }
     
  2. itsnottme

    itsnottme

    Joined:
    Mar 8, 2017
    Posts:
    129
    Any help would be great here, thanks.
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    In your example above, you appear to be creating a font asset for every font file available on the device? Is that intended?

    I presume that your expectation is that one of those font files would contain Emojis?
     
  4. itsnottme

    itsnottme

    Joined:
    Mar 8, 2017
    Posts:
    129
    I am trying to add all languages, but I am not sure how to find them all without creating a font asset for all fonts on the device.
    Creating a font asset for all actually completely messed up emojis.

    I did try to create font files for Noto fonts before building, but the build size was much bigger so I had to scrap that idea.

    It would be great if there is a way to find all languages without needing to create a font asset for all.
     
  5. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    297
    What? As far as I know, TMP does not support full emojis. You need this to make it work. It's completely unrelated to font asset
     
  6. itsnottme

    itsnottme

    Joined:
    Mar 8, 2017
    Posts:
    129
    Yes I know. I already use this extension for emojis.
    By messing up emojis I meant nothing shows up after clicking on any of the emojis, not even missing characters.
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    That is not really possible given fonts come in all shapes and sizes and also overlap in terms of their Unicode code point coverage.

    For example, if your primary font for Latin languages was fairly thin, you would want to fallback to a similar font in terms of design, style and weight for CJK. However, if your primary font was more stylish and heavier weight, you would choose to fallback to some other font for CJK.

    Also noteworthy, there are many Unicode code points that are common for Chinese and Japanese but with different glyph designs. As such, If the local was Chinese, you would select the NotoSans-SC (Simplified Chinese) or TC (Traditional Chinese) instead of the NotoSans-JP (Japanese) as you want to display the appropriate glyph for the user selected language.

    As such, searching through fonts looking for a specific Unicode code point isn't going to work which is why most applications like Microsoft Word, Google Docs and browsers like Chrome, etc. have lists of predefined fonts to search / use for various languages. Local and user language selection typically determines which lists of fonts will be used. These lists are essentially a list of fallbacks.

    Since font availability varies per platform and devices, it is important to know what is available on these various platforms so you can define / setup your fallback list based on platform and potentially language selection.

    Today, you will need to continue to create your font asset at runtime as you have been but should create them based on some predefined list for the given platform and then assign those to the appropriate font asset as fallbacks, etc.

    In the next release of the TMP package, I will be introducing Dynamic OS Font Assets which will enable you to leverage fonts available on the various platforms / operating systems. In the Editor, they will work just like Dynamic Font Assets but when creating a build, their source font file will not be included since we will be using the font available on the platforms.

    Can you provide more information on the Emoji issue? It is possible that you end up creating some font asset that contains color glyphs so something could be happening related to this. I just need more information to figure out what is going on.
     
  8. itsnottme

    itsnottme

    Joined:
    Mar 8, 2017
    Posts:
    129
    That sounds great, do you mind letting me know when it will be available?

    After adding all the OS fonts. Clicking on emojis creates an invisible character (placeholder is no longer active). I was testing on a Samsung S9+ (if that helps).
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Currently in the process of finalizing this next release. I would really like to have it available sometime next week.

    Can you check if this is caused by adding a specific font to your list? or perhaps it only happens after a certain number is added?
     
  10. itsnottme

    itsnottme

    Joined:
    Mar 8, 2017
    Posts:
    129
    I did some testing, the problem comes from loading "NotoColorEmoji" as a font.

    By the way, how can I load emojis from OS similar to fonts?
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The reason why your sprite asset stop working is simply due to the fact that the "NotoColorEmoji" font contains characters mapped at the same Unicode code point as the sprites in your sprite asset.

    When searching for any given character, TMP will first check the primary font asset and then go through all of it local fallbacks recursively, it then looks at the local sprite asset, then global fallbacks listed in the TMP Setting and then the sprite asset.

    Since this NotoColorEmoji is searched before the sprite asset based on the search order described above and given it contains the requested characters / unicode code points, it is used instead of the sprite asset. Since this font file contains "Color" glyphs, they likely don't render which is something I need to look at in the sense that since we can't render those, we should not be using them but that is a different issue which I will investigate.

    Now in terms of Font Asset supporting "Color" glyph / Emoji support that is something that I will be adding in this next preview release cycled. Once support for color glyph is available in font assets, you will then be able to use font files that contains color glyphs / emojis and those will work just like any other font asset / font file.

    When creating a new font asset for these color glyphs, you will be using a new Atlas Render Mode which will be something like "Smooth - Color" which will be a new bitmap mode but color as oppose to 8 bit alpha.
     
    itsnottme likes this.
  12. RahmatAli_Noob

    RahmatAli_Noob

    Joined:
    Sep 13, 2022
    Posts:
    74
    Hi there,
    I am using the Emoji's with the Sprite asset and I can use the Emoji's with single Unicode Like "U+1F600" , but there is the Issue that how can I use the Emoji's with the long Unicode Like" u1f3c3_1f3fb_200d_2640" the Running Girl Emoji.
    I try to write it and it shows the Girl but with the Emoji it shows the Boxes.
    Will you please let me know How I can Do it.
    Thanks in Advance.
    @Stephan_B
    @HugoBD-Unity