Support for Thai text in editor

I’m currently learning UE4. And in process, I’ve run accross the issue that the editor does not support Thai text properly. It basically displays 'Tofu’s in the field.

https://forums.unrealengine.com/filedata/fetch?filedataid=162328&type=thumb

After I’ve played around a little bit, I found that the renderer does support rendering Thai text in the field, but there is no Thai font ships with the engine. I can’t find a way to add fonts to the editor, I ended up replacing DroidSansFallback.ttf with font likes DroidSansThai.ttf (which would breaks other non-latin languages). The editor then displays Thai text properly.

https://forums.unrealengine.com/filedata/fetch?filedataid=162330&type=thumb

Since this is relatively easy to fix/add (I believe), I’d like to request to add Thai font to the editor. I think DroidSans Thai (from Google) might be a good fit, as other Droid fonts are already in-use in the engine.

1 Like

After a few months, I decided to dig a little more into the UE4’s code.

Basically just adding a few fonts file into LegacySlateFontInfoCache.cpp and the editor will display some Thai text. It’s not perfect yet, but I think it looks good enough.

The font I use for this screenshot is Sarabunfrom Cadsondemak. It’s a variant of TH-Sarabun PSK, released under OFL terms.

I am actually interested to send in a PR for this change, however since font files are not parts of the source file hosted on GitHub, I can’t just send one and hope that it will work correctly. So can someone suggest how and what should I do to get this one in?

1 Like

May you share what code you add into LegacySlateFontInfoCache.cpp?

It’s been quite a while. I haven’t checked back to the forum. Sorry about that.

Here’s what I added to FLegacySlateFontInfoCache::GetDefaultFont()

        // Thai (editor-only)
		if (GIsEditor)
		{
			FCompositeSubFont& SubFont = MutableDefaultFont->SubTypefaces[MutableDefaultFont->SubTypefaces.AddDefaulted()];
			APPEND_RANGE(SubFont, Thai);
			
			APPEND_EDITOR_FONT(SubFont.Typeface, "Regular", "NotoSansThaiLooped-Regular.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "Italic", "NotoSansThaiLooped-Regular.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "Bold", "NotoSansThaiLooped-Bold.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "BoldItalic", "NotoSansThaiLooped-Bold.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "BoldCondensed", "NotoSansThaiLooped-CondensedBold.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "BoldCondensedItalic", "NotoSansThaiLooped-CondensedBold.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "Black", "NotoSansThaiLooped-Black.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "BlackItalic", "NotoSansThaiLooped-Black.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "Light", "NotoSansThaiLooped-Light.otf", EFontHinting::Default);
			APPEND_EDITOR_FONT(SubFont.Typeface, "VeryLight", "NotoSansThaiLooped-ExtraLight.otf", EFontHinting::Default);
			//*/
		}

However, it also need font files as well. Right now I’m using NotoSansThaiLooped from Google instead of Sarabun. This should be in-line with the rest of the font used by the editor (Japanese’s GenEi is a modified version of NotoSansJapanese, if I’m not mistaken, for example.).

Oh and the location of the font files is either Engine\Content\Editor\Slate\Fonts or Engine\Content\Slate\Fonts (I’m using the first one, haven’t got into why there are two separated font directories).

An update to the situation. As of UE 5.1, there’s a Thai font file bundled with the engine (NotoSansThai.ttf). However, there’s no reference to this font file at all in the engine source code (or at least as far as I can tell), so you will still get a [ท] tofu inside the editor when you type something in Thai in text control or anything.

image

So it’s safe to say we are a step closer but not there yet.

Now, with the simple code changes I made on the reply above, I can make it display Thai text (almost) properly. Given that I have the font file placed in the right place.

image

So I’d like to propose to add support for Thai text by adding Thai fonts (and the supporting code) to the UE editor.

** Choice of font **

I’m proposing to use “NotoSansThaiLooped” font, instead of “NotoSansThai”. While the name is very similar, their design are quite different. The main reason why I’d go with NotoSansThaiLooped is it has “loops”. NotoSansThai does not have loops, instead it has slant suggesting that there’s loop there.

Comparing to the non-looped version, the loop helps with legibility of the text, especially on the super small size text (like in UE’s editor). In fact, this is how the proper Thai character should looks like, not the non-looped version. I don’t know why the designer of the NotoSansThai decided not to have loops in the font.

These two fonts are part of the Google’s Noto project and there are fonts from the project that are already in-use by UE so I think it should be fine, licensing-vise.

I’d like to mention that I have talked with Chris Murphy (@HighlySpammable ) and Jack Condon a couple of times when they are here in Bangkok (the last time was the last Monday) about this. This is why I’m resurrecting this thread.

Jack did suggest that the UI font can be changed, but I can’t find where so … if anyone has an idea please let me know.

2 Likes

I prefer a loop version because it’s easy to read.

and please add to the game engine, I think we didn’t ask to much just put it in the Engine. if you want to do a marketing in SEA you have to understand we all have our own language and if you do that, it’s mean you can see us

We didn’t ask too much like making a Thai-Documentation.

I agree with the idea of being able to change the font.

In fact, the engine itself should provide a way for developers to customize this part of the engine.

In my opinion, It could be one of doable solution If we can add the font we want in DefaultEngine.ini

My quick idea is something like this

// Additional Fonts
{
	if (GConfig != nullptr)
	{
		TArray<FString> FontPaths;
		if(
			GConfig->GetArray(
				TEXT("FLegacySlateFontInfoCache"), 
				TEXT("ThaiFonts"), 
				FontPaths, 
				GEngineIni))
		{
			FCompositeSubFont& SubFont = MutableDefaultFont->SubTypefaces[MutableDefaultFont->SubTypefaces.AddDefaulted()];
			APPEND_RANGE(SubFont, Thai);
			for(const FString& FontPath : FontPaths)
			{
				SubFont.Typeface.AppendFont(
					TEXT("Regular"),
					FPaths::EngineContentDir() / TEXT("Editor") / TEXT("Slate") / TEXT("Fonts") / FontPath,
					EFontHinting::Default, EFontLoadingPolicy::LazyLoad);
			}
		}
	}
}

We can create Struct to support more data instead of String, such as being able to define the language.
In this case, we can support other languages as well.

1 Like

I agree that the engine should allow users to change font. May be it should refer to system fonts instead of having to bundle font files with the engine or have to specify the font file path in the configuration.

However, … I think having Thai fonts in the engine’s editor is more urgent and wouldn’t take as much time. Having to replace the font file manually, or have to manually compile the engine is not really healthy for us Thai. I mean if Epic really into virtual production then having more language support on the UI would bring more people into the Unreal ecosystem.

It’s kinda silly, when one engine have Thai font render in the text field but it cannot properly display it, while another one is totally capable but it does not do that. Yes the Unity 3D’s situation is much worse than Unreal, but we shouldn’t discuss that here I think

I created a PR to address this issue, see link to Github