Search Unity

TextMeshPro: How to fix the problem that chinese punctuation changes new line in TextMeshPro?

Discussion in 'UGUI & TextMesh Pro' started by kaze008, Mar 19, 2019.

  1. kaze008

    kaze008

    Joined:
    Mar 16, 2019
    Posts:
    4
    when the sentence has some chinese punctuation, it changes new line, like the picture below.
    I tried some ways to solve this problem, but failed. Could someone give some advice? Thanks a lot.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    East Asian languages which typically do not use spaces, use a list of leading and following characters which determines where line breaks should and should not occur.

    The list of leading and following characters is located in the "TextMesh Pro/Resources/..." folder.

    If you are trying to use CJK characters that are defined in the list of leading and following characters, I believe you should be able to use <nobr> tag </nobr> to prevent them from breaking the lines of text.

    For proper testing please provide an actual sentence of text.
     
    Kekaku likes this.
  3. kaze008

    kaze008

    Joined:
    Mar 16, 2019
    Posts:
    4
    Thanks a lot. It is helpful. If there are only CJK characters, the <nobr> tag solve this problem. But I still have a question. If I have to show a sentence with the western characters and CJK characters, how can I show the text right since the <nobr>tag influence the western words breaking?
    To reproduce this problem, use the characters in the CJK characters in the list of leading and following characters. The line would break incorrectly when the sentence is need to break.
    For example:
    "】】】】】】】】】】】】】】】】】】】】" ,
    “????????????????????”,
    and other combination with the CJK characters in the list of leading and following characters.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    What is the actual text you are trying to use where the line breaking is incorrect when using a combination of Latin and CJK characters?

    Using a sequence of "】" will produce strange results given this character is never supposed to be at the start of a line. This isn't a realistic example either to make sure the behavior with actual Latin and CJK text is behaving as it should.
     
  5. kaze008

    kaze008

    Joined:
    Mar 16, 2019
    Posts:
    4
    The situation is that I am writing a chat function in a online game, and the players do not always obey the rules to send message, they just send what they want. And using a sequence of "】" or other punctuation is something that may happen. So that made the weird text and I just need to avoid this situation.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This is something that I will have to take a look at when I have time.

    Until then, you can edit the list of leading and following characters to remove all characters which should then force the text to wrap as it would using Latin text.
     
  7. kaze008

    kaze008

    Joined:
    Mar 16, 2019
    Posts:
    4
    I have done this. I notice it is so late at your location. So thank you very much for your reply at night. It helps.
     
  8. xianxiaoke

    xianxiaoke

    Joined:
    Mar 5, 2021
    Posts:
    3
    Thanks for the advice! But how does unity compile these two txt files? What if I want to add ...... ? Would TMP interpret it right as ellipsis or would consider it as a single dot?