Search Unity

Bug TMP Input field placeholder text clipped

Discussion in 'UGUI & TextMesh Pro' started by andyz, Aug 26, 2020.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,279
    Just place a TMP Input field and the placeholder text is immediately clipped slightly on the left, worse if bitmap font.
    2019 LTS, TMP 2.1.1:

    tmp3.png

    There is a general issue with the default mask being too tight to the text - even the typed text can be cropped by a pixel so the component needs a little adjusting. The placeholder could be on top
     
    Last edited: Aug 26, 2020
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    In Unity 2020.x, control over padding was added as seen in the image below.

    upload_2020-8-27_11-54-15.png

    Let me inquire about the possibility of back porting this to 2019.4.
     
  3. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,279
    Ok, I mean you can manually fix it by padding the text inside the mask or not using a mask, but isn't the real issue the italic rendering - seems like TMP italic is perhaps shifting the bottom of the text left while Unity shifts the top right, at least that is the way it looks on the surface?
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The text in white is the true italic version of Roboto whereas the red text is the simulated italic using a slant angle of 35 deg.

    upload_2020-8-27_16-17-19.png

    Adjusting the italic slant to 17 deg. on the simulated italic, we get the following which closely mirrors the true italic type.

    The horizontal shifting of the simulated italic vs. italic typeface is simple the result of the x bearing of the italic typeface being adjust specifically for this typeface.

    upload_2020-8-27_16-18-27.png

    The issue with the input field is two fold. The first is the fact that even normal type characters can exceed the bounds of the text container / margin.

    Here is an example that is common with most fonts where for instance the letter `i` and `j` are correctly aligned vertically. This is achieved by the font designer adjusting the x bearing of each individual glyphs.

    Unfortunately and in most fonts, this requires a large negative adjustment of the x bearing of the glyph for the `j` which results in the vertical stem / descender of the `j` pretty much always going outside of the bound of the text as seen below.

    upload_2020-8-27_16-25-51.png

    Italic typeface, (not the simulated version) results in an even greater portion of the letter `j` exceeding the bound of the text container as seen below.

    upload_2020-8-27_16-29-49.png

    In these cases, the `j` would get clipped by the RectMask2D which is why I requested that we add padding to the RectMask2D component.

    We could also adjust the margins of the text as seen below to compensate for this but depending on the use case, that might not be the best option where adding padding to the mask / clipping region is much easier.

    upload_2020-8-27_16-32-26.png

    Back to the topic of the simulated italic, the default slant angle of 35 deg. is clearly too much in this case and reducing it to 17 deg, closely mirrors the true italic tyepface.
     
    andyz likes this.