Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Horizontal wrap causing text size of Chinese characters to shrink

Discussion in 'UGUI & TextMesh Pro' started by fractal_sounds, Apr 7, 2018.

  1. fractal_sounds

    fractal_sounds

    Joined:
    Apr 7, 2018
    Posts:
    1
    Hello. I am working on an application built by someone else previously, and I have been asked to make some changes. One of these was adding Chinese translations of the content (provided to us by translators, I don't know the language myself). I am having a problem with horizontal wrapping causing the text size to become much smaller when working with the Chinese text.

    I have attached screenshots to illustrate the issue. As you can see from the first image, when inputting English characters, the text size remains consistent regardless of whether the sentence runs over one or multiple lines. The text card element simply grows in height, as expected.

    01.jpg

    Note that each sentence in the "multiple sentences" example is separated by a blank space. I have not entered any manual line breaks.

    The second screenshot shows the problem I am having with Chinese test. As soon as the sentence runs over one line, it gets shrunk significantly.

    02.jpg

    I realise that part of the problem is that the Chinese character used for a period at the end of a sentence is the following "。" which is a single character that has a small amount of horizontal space built into it. In other words, unlike in English, there actually aren't any physical blank space characters in between sentences to help the wrapping functionality break up the words accordingly.

    This was confirmed when I manually inserted blank spaces after the "。" period character which resulted in normal rendering of the text size. However, this isn't a suitable solution. Firstly, it is unfeasible for me to go through the application and manually insert spaces into the numerous text boxes that exist. Secondly, even if I could, it still doesn't entirely fix the problem when there is actually a long sentence without any punctuation characters. It helps a bit, but the text size still gets shrunk, as shown in the final screenshot.

    03.jpg

    And not knowing the language, I can't go around placing random blank spaces in between charcters, as I don't know if it would change the meaning of the words.

    I have attempted to play around with the minimum, preferred, and flexible height values of the Layout Element attached to the text card objects, but nothing seems to help.

    If anyone has any suggestions for how I could resolve this, it would be greatly appreciated.

    Thank you.
     
  2. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    bump!

    I have the similar problem using "Best Fit", Unity resized all Chinese character to smaller font size without wrapping them... English is alright and kept the optimal size coz it's wrapped.

    The only way to fix is disable "Best Fit" for Chinese (and all languages not using white spaces)
     
  3. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Just ran into this implementing multi-lingual support. As long as best fit is enabled (which I have enabled on pretty much everything in case something overflows) it will just shrink the text without trying to word wrap because Japanese doesn't use spaces. =[

    I wonder if there's a way to check if vertical overflow has kicked in and lower the font size in real time...
     
  4. Ukounu

    Ukounu

    Joined:
    Nov 2, 2019
    Posts:
    209
    Bumping, since this thread shows up on Google when searching solution for the issue described above.

    https://gist.github.com/stakira/63ecbcc0134d3cbc90392f1daf5dd0df

    This custom replacement for Unity's default "text" component fixes the bug. Text without spaces is downsized correctly when "best fit" is enabled.

    The only problem with this solution is that it requires replacing Unity's default text component with a new custom text component.
     
    Last edited: Sep 25, 2023
  5. Ukounu

    Ukounu

    Joined:
    Nov 2, 2019
    Posts:
    209
  6. Ukounu

    Ukounu

    Joined:
    Nov 2, 2019
    Posts:
    209
    In the end I copy-pasted com.unity.ugui package into "Packages" project folder (thus creating a custom package override), and edited Text.cs by inserting the fix mentioned above. This allows to resolve the issue and keep using the default Text component without any additional setup.