Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

TextMesh Pro Chinese punctuation placement problem

Discussion in 'UGUI & TextMesh Pro' started by abcjjy, Sep 25, 2020.

  1. abcjjy

    abcjjy

    Joined:
    Mar 6, 2015
    Posts:
    13
    Here is my code

    Code (CSharp):
    1.  
    2. public class TestTMP : MonoBehaviour
    3. {
    4.     public TextMeshProUGUI text;
    5.  
    6.     void Start()
    7.     {
    8.         var f2 = new Font("/System/Library/Fonts/PingFang.ttc");
    9.         var tmf = TMP_FontAsset.CreateFontAsset(f2);
    10.         text.font = tmf;
    11.         text.text = "\u6587\u5b57\uff0c\u6807\u70b9\u3002";
    12.     }
    13. }
    14.  
    Unity 2018.4.27
    Mac 10.15
    TextMeshPro 1.5.1

    Output: 截屏2020-09-25 15.25.26.png

    Period and comma are expected to be placed at bottom like this 截屏2020-09-25 15.27.38.png
     
    MrLucid72 likes this.
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    4,974
    Looking at the font in a font editing tool, both of those glyphs are placed in the middle of the line as seen below.

    upload_2020-9-25_1-25-33.png

    This appears to be a design choice on the part of the font designer.

    You can always edit individual glyphs in the font asset glyph table inspector. In this case, you would adjust the ybearing of this particular glyph as seen below.

    upload_2020-9-25_1-31-35.png

    Image showing "." and "," along with \u3002 and \uFF0C unmodified metrics.

    Default values for \u3002
    upload_2020-9-25_1-33-35.png

    Edited values to adjust the Y Bearing (BY) to place it on the baseline.
    upload_2020-9-25_1-34-33.png

    These values are relative to the sampling point size so this is just to show what values you would adjust.

    Note the Character Table would include \U3002 which then references a glyph index which is this 29264.

    To visualize these font metrics, you can add the TMP_TextInfoDebugTool.cs to any TMP text object. This script is located in the TMP Examples & Extras.
     
  3. abcjjy

    abcjjy

    Joined:
    Mar 6, 2015
    Posts:
    13
    Thanks for your quick response. I tried BY and BX. It works. But there still must be something wrong. Here is the sample text displayed with the same font in Mac Font Book app.
    截屏2020-09-25 17.29.05.png

    And this is rendered with legacy Text component: 截屏2020-09-25 17.38.58.png

    I'm not familiar with font metrics. But I am a Chinese native speaker. I do know which one is correct. Font Book sample is the standard form. Legacy Text component result is not very ideal but acceptable.

    Please help.
     
    Last edited: Sep 25, 2020
  4. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    798
    I feel like my font does this too. Self reminder (not at home) to check!
     
  5. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    798
    Seems like false positive: Indeed, many fonts prefer this. Eg, Discord prefers the v-centered Asian period.
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    4,974
    Here is a comparison with NotoSansCJK where in this case the full stop is baseline aligned.

    upload_2020-9-25_12-9-59.png

    Whereas for PingFang.ttc, the full stop is in the middle vertically. This is by design from whoever designed this font.
     
    MrLucid72 likes this.
  7. abcjjy

    abcjjy

    Joined:
    Mar 6, 2015
    Posts:
    13
    How does legacy text component render it aligned the baseline? @Stephan_B
     
unityunity