- Home /
TrueTypeFontImporter.GenerateEditableFont logs strange errors
I'm working with some code to auto-generate font atlases from localisation string databases. It's code that worked fine under older versions of Unity, but at some point in the last year or so when the code was gathering dust, a Unity update changed the rules about how you manage fonts, and now you have to make sure they're "readable" before you can edit them. So, that's what I'm trying to do: Load a TTF font, then get it into an editable form so that I can generate PNGs and the like.
Unfortunately, some of the fonts I'm working with give this error:
Font Error: Cloning a dynamic font is not supported and may result in incorrect font rendering.
... And all of them give this one:
The font Assets/Foo/Bar.ttf could not be imported because the format is unsupported
The simple test code that producted these errors:
[MenuItem ("Localization/Font Test")]
static void FontTest()
{
String sSourceFontPath = "Assets/Foo/Bar.ttf";
String sTargetFontPath = "Assets/Foo/Bar_Baz.ttf";
UnityEngine.Object f = AssetDatabase.LoadMainAssetAtPath(sSourceFontPath);
string path = AssetDatabase.GetAssetPath(f);
Debug.Log("Generating copy of: " + path);
TrueTypeFontImporter fontImporter = AssetImporter.GetAtPath(path) as TrueTypeFontImporter;
Font font = fontImporter.GenerateEditableFont(sTargetFontPath);
}
What am I doing wrong?
I'm guessing Assets/Foo/Bar.ttf has been imported as a dynamic font, and, as the error says, you cannot clone dynamic fonts.