Search Unity

TextMesh Pro Set the Glyph Table parameters from the script

Discussion in 'UGUI & TextMesh Pro' started by ysalpha, Aug 23, 2022.

  1. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    Is it possible to adjust the Glyph Table from the script after generating the SDF?
    When we re-generate the SDF, the Glyph Table parameters that we have adjusted will be reset.
    Every time I generate an SDF, I have to re-set the Glyph Table values from Inspector, which is very difficult.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The ability to preserve "edits" to the various font asset tables has been requested in the past. This makes a lot of sense to me so definitely something to add at some point.

    In terms of making those adjustments in code, the TMP_FontAsset.glyphTable property is public where as such, you should be able to modify individual glyphs to reapply your custom changes. Be mindful these values are relative to the sampling point size.
     
  3. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    I was able to change the glyphTable parameter with the following code.

    Code (CSharp):
    1. char chr = 'A';
    2. uint unicodeNumber = System.Convert.ToUInt32( chr );
    3. var character = tmpFontAsset.characterTable.Find( x => x.unicode == unicodeNumber );
    4. if( character != null )
    5. {
    6.     var glyph = tmpFontAsset.glyphTable.Find( x => x.index == character.glyphIndex );
    7.     if( glyph != null )
    8.     {
    9.         glyph.scale = 10.0f;
    10.     }
    11. }