Search Unity

TextMesh Pro A better line breaking algorithm?

Discussion in 'UGUI & TextMesh Pro' started by MadWatch, Feb 2, 2020.

  1. MadWatch

    MadWatch

    Joined:
    May 26, 2016
    Posts:
    112
    Hello everyone.

    The sticky announcement post is mentioning some upcoming improvements to the way TMP is handling line breaking. I searched but I haven't been able to find the relevant forum posts about it. Does anyone knows what improvements are expected and when?

    Right now, TMP doesn't handle line breaking very well. For example, with French language, it sends the exclamation and interrogation marks to the next line even thought this is not typographically correct.

    This is what TMP does:
    Screenshot 2020-02-02 at 19.19.18.png

    This is what it should do:
    Screenshot 2020-02-02 at 19.19.49.png

    The Unicode Line Breaking Algorithm handles these cases pretty well for most languages. Would it be feasible to integrate it to TMP?

    Best Regards.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    What version of Unity and the TMP package are you using?

    This should be handled correctly as seen below.

    upload_2020-2-3_13-50-23.png

    The above example is using the following text "Toto veut-il du gateau?"

    It is possible that you are using some alternative form of ? which is handled differently for CJK. Can you copy paste the exact text that you are using?
     
  3. MadWatch

    MadWatch

    Joined:
    May 26, 2016
    Posts:
    112
    I'm writing French. The typographic rules aren't the same as English. In French, spaces are required before interrogation and exclamation marks. So TMP is breaking on the space before the '?'.

    For information I tested both TMP 2.0.1 with Unity 2019.2.19 and TMP 2.1.0 preview with Unity 2019.3, but the behaviour is the same.

    As I said, the Unicode Line Breaking Algorithm works fine for this. I'm currently working on using it to wrap my text before feeding it to TMP, but I think it would be much simpler and more efficient if it was implemented inside TMP.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    I am french and we do not use / add a space before ".", "?" or "!" at the end of a line just like English. Pretty much all Latin based language use the same rules for line breaking. For testing, Microsoft Word or Outlook or Google Docs behave the same way.

    Having said the above ... you can add a non-breaking space \u00A0 between the last character and "?" this will prevent line breaking at "?".
     
  5. MadWatch

    MadWatch

    Joined:
    May 26, 2016
    Posts:
    112
    I'm pretty sure we do.

    For reference:
    http://www.guide-typographie.com/ponctuation_Espaces.htm
    https://fr.wikipedia.org/wiki/Wikipédia:Conventions_typographiques#Signes_de_ponctuation

    For comparison with English:
    http://www.guide-typographie.com/anglais.htm

    You're right that it should be a non breakable space instead of a normal space (actually it should be a thin space). But I would rather let the algorithm handle that kind of stuff for me rather than checking the spaces in every sentences of my game. Also, I have no idea what the rules are for other languages. Judging by how insanely long the list of rules regarding line breaking is in Unicode (see here), I would guess different languages must have many different rules.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    I will take a look at improving the line breaking handling of some of those special characters. No ETA on that but I'll see what I can do.

    Until then, I suggest using a non-breaking space in the text. I did add in the previous release support for <NBSP> which is easier to read / less error prone in the text. Internally, this <NBSP> tag gets replaced by \u00A0.
     
  7. DrSkipper7

    DrSkipper7

    Joined:
    Apr 18, 2017
    Posts:
    13
    Hey there! I am trying to solve this exact problem while adding French localization to our game. I tried the <NBSP> tag but it wasn't recognized... do I have to set a flag for it somewhere? Tags like <color> work fine.
     
  8. DrSkipper7

    DrSkipper7

    Joined:
    Apr 18, 2017
    Posts:
    13
    Ah I suppose it may be because we are on Unity 2018.4.26f, so we are limited to TMP 1.4.1 (I believe?), and maybe that tag was added in a later version?
     
  9. DrSkipper7

    DrSkipper7

    Joined:
    Apr 18, 2017
    Posts:
    13
    Huh I just updated TMP to 1.5.6, even though the package manager said we were already "up to date"... and it worked! the tag is recognized now. I'm a little worried we're gonna run into problems though since the package manager was telling us we were already up to date though?
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The latest release of the TMP package for Unity 2018.4 is version 1.5.6.
     
  11. DrSkipper7

    DrSkipper7

    Joined:
    Apr 18, 2017
    Posts:
    13
    Ok perfect thank you! I wonder why the package manager said it was up to date.
     
  12. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Are you using the latest version of Unity 2018.4?

    I know that when I open the latest Unity 2018.4 or close to the latest, it will show me that a new package is available. Now perhaps if I was to open a version of Unity that predates this release, it might not show the latest package but I am speculating here as this is package manager stuff.