Can't render non-latin characters (ex: Korean) using ttf fonts?
I'm trying to localize some of my Kha projects, but I can't seem to get non-latin characters to ever render.
Here is a demo repository showing what I mean: https://github.com/hamaluik/kha-ko (demo at https://hamaluik.github.io/kha-ko/)
In this demo repo, I try to render "Hello World" in English, Greek, and Korean. English and Greek render just fine, but Korean doesn't display any of the Korean glyphs even though the font I'm using to render with does have those glyphs in them.
I have made sure to set kha.graphics2.Graphics.fontGlyphs to the specific glyphs I need to render (in this case, taken directly from the three strings to be [72,101,108,108,111,32,119,111,114,108,100,33,915,949,953,945,32,963,959,965,32,954,972,963,956,959,33,50504,45397,54616,49464,50836,33], you'll note the Korean codes are all very large numbers, not sure if that has anything to do with it).
I am also using haxe.Utf8 to ensure I have the proper character code values (and double checked the values against my system's character map).
I have tried this so far on the html5 and linux targets, with identical results.
Any thoughts about what I may be doing wrong? Or if Kha doesn't work with non-latin characters?
Thanks!
The truetype renderer for some reason fails to render the Korean chars. Did you try other fonts, too? I think somebody had Chinese characters render fine.
I’ve tried 3 different fonts with Korean characters, all with the same result. I thought I had tried Chinese but now I remember I only had otf fonts for those so I’ll try again with some ttf fonts there.
Alright, after much trial and error I found fonts for Korean, Chinese, and Japanese that all seem to work fine (see updated repo), so it appears it was just a font file issue? Or kravur not parsing various fonts appropriately? Several of the fonts I tried just failed silently, including the three I had originally tested. One font reported a bunch of byte encoding errors in the console.
I'm going to close this for now, since this isn't directly an issue. However it would be nice to either touch up kravur or somehow develop a method of knowing which fonts will work and which won't without trial and error.
Thanks!
The problem is somewhere deep inside the font renderer itself (which is a port of stb_truetype) it seems. Not an easy problem as that's one of the few components in Kha which I didn't write myself (the other one being the ogg decoder) but I'll give it a try eventually - and I'll keep this open for that reason.
I think maybe related to this: the character widths for Asian fonts seem to not calculate correctly (when using font.getWidth("some text")) as I've found this afternoon (the function returns 0 even though it renders correctly)
In the fontGlyphs array, the numbers must go from the smaller to the larger and do not repeat (need not forget to document it). But if the problem is not because of this, then okay.
Also having an issue with this... Is this issue also present in the original stb_truetype? In that case, someone should probably just submit an issue/PR regarding the issue to the stb repository instead of rewriting the TrueType font renderer altogether.
+ Nevermind, I am dumb, I didn't add all my glyphs to g.fontGlyphs...
So, umm, if you are looking for fonts that Kha is able to render non-ASCII characters with, Unifont is an option.
I don't know if this is useful at all, but FreeType seems to be a viable alternative for stb_truetype?
Think this is definitely a font file issue; the Hi Melody typeface doesn't work, but I can confirm that other fonts (such as 아리따-돋움 and Unifont) work. Now what the difference between those fonts is, I'm not sure. I don't have too much time on my hands ATM, but I might take a look at the font files in FontForge when I have time...
That would be very much appreciated.