Search Unity

TextMesh Pro 1.4.1 Can't create font using Editor script that has kerning information

Discussion in 'UGUI & TextMesh Pro' started by DavidZhongIGG, Aug 1, 2019.

  1. DavidZhongIGG

    DavidZhongIGG

    Joined:
    Apr 30, 2019
    Posts:
    7
    There doesn't seem to be a way to save kerning information when creating a font from script. The TMP_FontAsset.TryAddCharacters overloads doesn't include kerning.

    In TMPro.FontAssetCreatorWindow.cs, I see that you use GetKerningTable()
    to get the kerning information when saving a font. However, I can't seem to access FontEngine.GetGlyphPairAdjustmentTable() from my own editor script.

    The only way to save kerning information when creating a font from script seems to be to create an object in the scene, add a canvas and a textMeshPro component to it, assign the created font to the textmeshpro component and assign a string with all the characters that I want to render then force a mesh update:

    Code (CSharp):
    1. GameObject obj = new GameObject();
    2. obj.AddComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
    3. TextMeshProUGUI tmPro = obj.AddComponent<TextMeshProUGUI>();
    4.  
    5. TMP_FontAsset fontAsset =
    6. MP_FontAsset.CreateFontAsset(font, m_fontGenerationSettings.fontSize, m_fontGenerationSettings.characterPadding, m_fontGenerationSettings.fontRenderMode, m_fontGenerationSettings.atlasWidth, m_fontGenerationSettings.atlasHeight, AtlasPopulationMode.Dynamic);
    7. FontAssetCreationSettings settings = fontAsset.creationSettings;
    8. settings.includeFontFeatures = true;
    9. fontAsset.creationSettings = settings;
    10.  
    11. tmPro.font = fontAsset;
    12. tmPro.text = charactersToRender;
    13. EditorUtility.SetDirty(tmPro);
    14. tmPro.ForceMeshUpdate();
    However, doing it this way has some problems. The font creation was very slow when using certain fonts due to line 1626 in TMP_FontAsset.cs where it is doing FontEngine.GetGlyphPairAdjustmentTable(s_GlyphIndexArray);
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I'll take a look when I have an opportunity.

    Most likely I will add an optional overload to the TMP_FontAsset.TryAddCharacters function to determine if the Font Features for the glyphs that were successfully added to the font asset should also be included.
     
    Last edited: Aug 1, 2019