Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How not to include dynamic font source to build

Discussion in 'UGUI & TextMesh Pro' started by Grelle, Nov 8, 2022.

  1. Grelle

    Grelle

    Joined:
    Oct 14, 2015
    Posts:
    15
    So, I found some interesting thread: https://forum.unity.com/threads/how-do-i-use-default-system-font.1262888/
    My question is not the same as TC, so I want to clear some things.

    @Stephan_B , you wrote:
    Like I explained above, when I create a build for Android for instance, the source font file will not be included. The dynamic os font asset will be included.

    I built my apk without dynamic font and with dynamic font from NotoSansSC-Regular.otf. Build with font was bigger (and bigger with size of source otf font).

    My goal is using system fonts for some symbols, which is not included to static font assets. I dont care that this symbols will not look the same as main font of application.

    Can you explain "source font file will not be included" thing? May be I do something wrong. May be I need to build aab (and it mean that source font will not include in FINAL user apk, which he will download). Or may be I use wrong font or font type for it?
     
  2. Grelle

    Grelle

    Joined:
    Oct 14, 2015
    Posts:
    15
    So I found the answer; I need to create "Dynamic OS" font asset, not just "Dynamic".

    Althrough, it doesn't work, there are squares in my build instead of chinese symbols (with fonts NotoSansSC-Regular or NotoSansCJK Regular).
    I don't understand where is problem. Font.GetPathsToOSFonts() show me that Android use "/system/fonts/NotoSansCJK-Regular.ttc", but my source font - Noto Sans CJK Regular.otf. Is this important? It doesn't seems like important; but I still get squares instead of symbols and dont's understand why o_O
     
  3. Grelle

    Grelle

    Joined:
    Oct 14, 2015
    Posts:
    15
    So... I finally get the symbols. I had to find prepared NotoSansCJK Regular ttc font, exactly the same as in android system, and it finally works.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The "Noto Sans CJK Regular.otf" file contains a single font whereas the "NotoSansCJK-Regular.ttc" contains a collection of fonts.

    The reason this matters is because in the .otf file, the font face for Regular would be at face index 0 whereas in the collection .ttc this regular face would be at some different index. As such, when trying to load this face from the OS font, the face at index 0 would not be the Regular.

    When using Dynamic OS, you have to make sure that you import and use the same font as the one found on the target plaform(s). Most of the time, if the version of the font on the device is a newer or older version that is fine provided both are of the same extension (.ttf, .otf, .ttc) and in the case of .ttc have not changed in terms of the face index layout (which should not be changing) but you never know.