Font Issue on Windows

system: Chinese windows 10
haxe: [4.3.3]
openfl: [9.3.2]
haxeui-core: [1.6.0]
haxeui-openfl: [1.6.0]
lime: [8.1.1]

By default, apps using haxeui-openfl backend cannot display Chinese characters unless I embed Chinese font files into assets.
But the same code can display Chinese characters correctly using the haxeui-nme backend.

I’m not sure if this is also the case on other non-English Windows systems
Is it possible to display Chinese characters correctly without using embedded fonts on Windows?

Hi there (and welcome!),

I saw your github issue, im not 100% sure what the issue is, but my guess is its a difference in the way openfl and nme handle fonts. HaxeUI “piggy backs” off of its “host” frameworks in order to handle its text display (and text input). One thing i am fairly sure of is that nme uses “system fonts” if possible, which is why text display is generally crisper on it. I wonder if that has something to do with it?

I would guess that if you remove haxeui from the equation you will have the same results (as haxeui isnt doing anything particularly special here i dont think). Is there a problem using embedded fonts? I dont really know enough about fonts (especially not with non-utf8 charsets) to really know what is a good solution here.

Cheers,
Ian

PS: its almost certainly not going to fix your font / text issue, but you should use the git version of haxeui-core and haxeui-openfl (or any haxeui backend). 1.6.0 is months and months out of date at this point.

First of all thank you for your help. I think I may have found the cause of the problem, but it’s hard to find a general solution.

openfl provides three sets of default fonts, namely “_sans”, “_serif” and “_typewriter”, and haxeui-openfl uses the “_sans” font

haxeui-openfl/haxe/ui/backend/openfl/_module/styles/main.css at master · haxeui/haxeui-openfl (github.com)

.label, .textfield, .textarea {
    font-size: 13px;
    __font-name: "_sans";
}

However, the default font of openfl only has English characters.

openfl/src/openfl/text/_internal/TextEngine.hx at develop · openfl/openfl (github.com)

#if windows
			__defaultFonts.set("_sans",
				new DefaultFontSet(findFont(systemFontDirectory + "/arial.ttf"), findFont(systemFontDirectory + "/arialbd.ttf"),
					findFont(systemFontDirectory + "/ariali.ttf"), findFont(systemFontDirectory + "/arialbi.ttf")));

			__defaultFonts.set("_serif",
				new DefaultFontSet(findFont(systemFontDirectory + "/times.ttf"), findFont(systemFontDirectory + "/timesbd.ttf"),
					findFont(systemFontDirectory + "/timesi.ttf"), findFont(systemFontDirectory + "/timesbi.ttf")));

			__defaultFonts.set("_typewriter",
				new DefaultFontSet(findFont(systemFontDirectory + "/cour.ttf"), findFont(systemFontDirectory + "/courbd.ttf"),
					findFont(systemFontDirectory + "/couri.ttf"), findFont(systemFontDirectory + "/courbi.ttf")));

I can use the Windows system Chinese font in the code, but I cannot override the default “_sans” font of openfl.

openfl.text.Font.registerFont(openfl.text.Font.fromFile(lime.system.System.fontsDirectory + "\\simhei.ttf"));
<style>
.button { font-name: SimHei; }
</style>

Unfortunately, the default Chinese font on Windows is msyh.ttc, and openfl does not support the *.ttc format. Therefore, I cannot make the haxeui-openfl application display the same font as other windows applications.

Interesting, i wonder how nme does it? Maybe the same thing (or something similar) could be done in openfl? :thinking:

Maybe not.
I read a little bit about NME’s source code. It seems to use native C++ code for font rendering

nme/project/src/windows/GDIFont.cpp

Maybe I made a mistake

================

The code for openfl glyph rendering is in the lime project, I have to read the code again

================

Then I found out that lime’s backend is SDL? So should I go to the SDL project to find the answer? emmmmmm…

================

Maybe the backend is Cairo
I’m already confused