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

TextMesh Pro Sprite size

Discussion in 'UGUI & TextMesh Pro' started by Manufacture43, Apr 12, 2018.

  1. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    Using TextMeshPro-1.0.55.56.0b12 in Unity 2017.4.0f1



    I was fixing text baseline alignment issues we had in our game and remembered to also test sprites. As I was suspecting, they all have different sizes and positionings. In the screenshot above, all texts have a font size of 50. The japanese one (3rd line) has a scale of 1.3 but changing it to 1 also scales the sprites so that's not the issue (and is the behavior I would expect).

    Is there a way to normalize sprite size and positioning accross different fonts ?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    As you have discovered, Sprites are normalized based on the Primary Font Asset assigned to the text object.

    I can look into revising the implementation to be relative to the current font. I just need to make sure this doesn't negatively impact any other use cases.
     
  3. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    Hum, actually, what you see in the screenshot are different game objects with different main fonts. The screenshot doesn't rely on fallback fonts

    On a side note, I'm still getting baseline issues when changing fonts at runtime. Is there anything else to do besides assigning the font member? I tried calling UpdateFontAsset but my texts still are weirdly aligned vertically. But it could be unrelated, I see other weird positionning behavior in my scene.
    EDIT: Ah! Nevermind, switching to midline instead of Middle fixed all my issues.
    EDIT2: All my issues related to the sidenote. The sprites still are weird.
     
    Last edited: Apr 12, 2018
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you provide me with the raw text you are using for testing?

    The baselines should still be aligned provided the font themselves are sticking to normal design rules.
     
  5. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    http://lywenn.eu.org/bazar/FontTest.zip I extracted my test scene here, I think properly.

    I just noticed that I was in top mode in my test scene instead of middle mode. I fixed my baselines in middle mode and it looks better now even in middle mode, although it's not perfect yet. (not in the zip)
     
  6. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    I just noticed something else: the baseline changes whenever a fallback font is used:
    If I remove that A, the korean text jumps up to be properly aligned to the reference line
     
  7. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140

    Ok so, in this screenshot, you can see what I did : I scaled up/down some fonts and changed their baselines to harmonize them. If I use them separately, all goes well, which is the main case in the game so I'm mostly fine with that. But in the bottom you can see what happens when I use fallback fonts, it looks like the baseline of fallback fonts is not used and the one from the main one is instead, creating that subscript/superscript kind of look... Am I using textmeshpro wrong here is that to be expected? With how I just generated the fonts, it shouldn't be much of an issue in our game, but still...

    And we still have the uneven sprites which is my biggest problem here actually.
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I have made the change to have sprites scaled based on the current font. This also required changes to baseline positioning.

    If you can send me a Repro of your test project, I can take a look at the handling of the baseline when the fallback kicks in.
     
  9. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
  10. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    I didn't see anything related to this in the text mesh pro changelog. Any ETA on when the patch will be available?
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    New package manager version of TextMesh Pro should be available within a day or so.
     
  12. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    505
    Is this fix available for 2017.4 LTS ?
     
  13. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    We're using 2017.4 LTS too. Will TextMesh Pro be also updated in the asset store?
     
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I am working on a new major feature. Once done, I'll try to get that release available for 2017.4 as well.
     
  15. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
  16. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    We're now on Unity 2018.3.8 and the 1.3.0 TMPro package. It looks way better but it's still not there yet.

    upload_2019-4-11_11-1-8.png

    The most annoying part is not really the vertical alignment of texts in fallback mode but really the scale of the sprites that looks a bit random...

    I had tweaked the fonts to work around the issues we had. For this screenshot, I've reset all the baselines to 0 and the scales to 1. (it looks better than with the workarounds...)

    imho, for the vertical alignment issues, it seems the computations are done relative to the topmost part of the font while it should be with the bottom. So that the baselines end up aligned.
     
  17. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I'll revisit this as soon as I find the time.

    Please give this a try in version 1.4.0 which includes the new Dynamic system. Be sure to test using a backup of the project.
     
    Manufacture43 likes this.
  18. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    The sprite scale seems fixed in 1.4. It's only the vertical alignment that is still weird.

    upload_2019-4-19_10-46-16.png

    But now the behaviour is much more consistent! Modifying scales & baselines, I can get something perfect!

    upload_2019-4-19_10-45-42.png

    Thanks! :)

    Unrelated: the only thing that broke in my test project when upgrading to 1.4 is the link to the fallback fonts
     

    Attached Files:

    Last edited: Apr 19, 2019
  19. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Known issue which will be fixed in the soon to be release version 1.4.1 and 2.0.1.

    I am still planning on revisiting the vertical placement of the sprites when time permits.

    On that note, the sprites are placed based on their pivot being at Origin (which is the advanced of the previous character) and Baseline.
     
    Last edited: Apr 19, 2019
    Manufacture43 likes this.
  20. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    Sorry for not being clear, the vertical placement of sprites is fine now. I was rather talking about the vertical placement of fallback fonts, which seems to be computed from the top of the characters, rather than from the bottom.

    upload_2019-4-19_15-4-13.png
     
  21. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The fallbacks should all be at the base line unless those fonts have an altered baseline which is not uncommon with some East Asian fonts.

    Can you provide me with the sample scene you are using for testing?
     
  22. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    Here you go: http://manufacture43.com/TMProFallbackVerticalAlignBug.zip

    I've reset the scale to 1 and baseline to 0 on all fonts. To get the result from my last screenshot with matching scales and proper vertical alignment of mixed fonts, with 1.4.0, you need to change the scale and baseline to the following settings:
    - BMDOHYEON_ttf SDF: scale = 0.8 baseline = 15
    - GN-Kin-iro_SansSerif SDF: scale = 1.1 baseline = -12
    - Michroma SDF: scale = 0.9 baseline = 1.5
    - Xolonium-Regular SDF: scale = 1.05 baseline = 0
    - ZhengQingKeHuangYouTi SDF: scale = 0.8 baseline = 5
     
    Stephan_B likes this.
  23. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    I found a new sprite scale bug. The first sprite on a new line is badly scaled and/or positioned.

    upload_2019-4-24_11-16-1.png

    On this screenshot there is 8 text mesh pro ugui elements. The four on the left have the text "pouet <sprite=1> <sprite=0> <sprite=14>" while the four on the right have a newline character after "pouet". Each line uses the same font, gn-kin-iro, liberation, bmdohyeon and michroma, from the previously given unityproject (with the changed baselines and scalings)

    As you can see, the B button icon is correct on all texts on the left. But on the right, text using gn-kin-iro is vertically off and the text using bmdohyeon is too small.

    Simply adding a space after the newline works around the issue.
     

    Attached Files:

    Peter77 likes this.
  24. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Do you have that Repro project in the pre 1.3.0 of TMP?

    I am seeing some issues and would like to go back to the (pre) or even version 1.3.0 state of the project / font assets.

    If you can also throw that "pouet" example in there, that would be awesome.

    As a side note, I am assuming that each line of text should be the same in the previous example where although some of the fonts used on those individual lines have latin characters, these are excluded from those font assets where only the specific language characters are used. Correct?
     
    Last edited: Apr 25, 2019
  25. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Just like Font Assets have Face Info which define key metrics of a font, I added something similar to Sprite Assets as seen below.

    upload_2019-4-26_15-14-27.png

    Sprite Assets that do not currently have Face Info data, will continue to inherit the metrics of the current font asset that precedes the sprite and thus scaling the sprite accordingly.

    Sprite Assets with Face Info will behave independently of whatever font assets just like any other font asset would.

    upload_2019-4-26_15-24-1.png

    On the left side, you can see how the sprites are affected by the metrics / scale of the font assets. On the right side, you can see how the sprites are unaffected by font assets.

    This change will result in Sprite Assets (with defined Face Info) behaving more like font assets.

    Since Sprite Assets are created from a texture which doesn't have metrics like a font does, these Face Info values have to be defined by the user.

    As starting point when defining these values a user could use a Point Size in the ballpark of the sprite sizes. In my case, the sprites were all 128 x 128 so I set the Point Size at 128.

    The Ascent and Descent Line impact line spacing (again just like it would with font assets).

    The Baseline is where the sprite will be drawn taking into account the BearingX and BearingY. Bx and By are offsets relative to the top left corner of the sprite rectangle and where the pivot is located for the given sprite.

    Now back to your specific case in regards to the B sprite on the third right line of the pouet, the B was smaller because the linefeed character was coming from the main font asset whereas the space is coming from the fallback which is why adding a space would affect the scale of the sprite. Once you define Face Info for your sprite assets and assuming you normalize your font assets / fallbacks, you should be getting much more consistent / predictable results regardless of what font asset / fallback is used.
     
    percent004 likes this.
  26. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Here is an example using your reference scene. Notice how the size of the Sprite is consistent irrespective of the font asset.

    upload_2019-4-26_22-54-47.png
     
    Whatever560 likes this.
  27. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I would still like to get a copy of the project (pre) version 1.3.0 if possible to make sure the font asset upgrade / conversion process is behaving as expected.

    In addition, the word "Super" on the "michro" text object is rendering differently than the example image you provided. This is because in the sample project you provided, this "Michroma SDF" font asset does contain those characters whereas for the other text objects, it is using / falling back to the Xolonium font asset. Basically, I want to verify this is the expected result based on the sample project you gave me.
     
  28. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    Sorry, I don't have any repros pre-1.3.0 anymore. The "pouet" projet is using 1.4.0 and it seems I didn't even save the scene. I just reloaded that test project and ended up with the previous test.

    That face info for sprites seems like a great idea! Is it already available?
     
  29. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Do you have a backup of the project based on 1.3.0? That still would be useful for testing on my end.

    That will be available in the next release which will be 1.4.2.
     
  30. Manufacture43

    Manufacture43

    Joined:
    Apr 21, 2017
    Posts:
    140
    All the tests I've done here are in a small test project that I always use to report bugs. It's not versioned and I regularly wipe all its content to create clean repros. Sorry, I have nothing more than the zips available on this page.
     
  31. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    That's alright. Look for the new release when it becomes available and let me know how everything behave then.