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:
GameObject obj = new GameObject();
obj.AddComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
TextMeshProUGUI tmPro = obj.AddComponent<TextMeshProUGUI>();
TMP_FontAsset fontAsset =
MP_FontAsset.CreateFontAsset(font, m_fontGenerationSettings.fontSize, m_fontGenerationSettings.characterPadding, m_fontGenerationSettings.fontRenderMode, m_fontGenerationSettings.atlasWidth, m_fontGenerationSettings.atlasHeight, AtlasPopulationMode.Dynamic);
FontAssetCreationSettings settings = fontAsset.creationSettings;
settings.includeFontFeatures = true;
fontAsset.creationSettings = settings;
tmPro.font = fontAsset;
tmPro.text = charactersToRender;
EditorUtility.SetDirty(tmPro);
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);