Register
Handmade Hero»Forums»Code»Problems with loading fonts need help
Simon Anciaux
742 posts
Problems with loading fonts need help
2 weeks, 4 days ago
I haven't checked but I suppose monospaced font should not have kerning information. For example "Lucida Console" or fonts with "Mono" in the name.
51 posts
Problems with loading fonts need help
1 week ago Edited by itzjac on April 3, 2020, 4:37 p.m.
Yay!

Thanks all of you for your help, so far so good.

My font rendering with stb is close to be completed, but am really stuck trying to display some unicode characters (小耳木兎).
Regardless the font type (liberation mono, arial or times new roman), all I get are those invalid glyphs.

Is there anything in particular I need to be aware or configure when using a unicode in the range of Chinese o Japanese glyphs?




Unicode

P.S. is it only me or the img tag seems broken, it only displays an icon but I see no image
Simon Anciaux
742 posts
Problems with loading fonts need help
1 week ago Edited by Simon Anciaux on April 3, 2020, 7:15 p.m.
Most fonts support only a subset of codepoints. You need to use a font that support the codepoint range you want to display. So you will probably need to use several fonts.

For the image tag you need to put the url to the file itself, not the html page. On imgur, right click on the image and select "view image" and use that url ( https://i.imgur.com/ONqSs2q.png instead of https://imgur.com/ONqSs2q ).
Mārtiņš Možeiko
2040 posts / 1 project
Problems with loading fonts need help
6 days, 23 hours ago Edited by Mārtiņš Možeiko on April 3, 2020, 8:33 p.m.
Not a 100% accurate check (but works most of the time) is to check filesize of font. If it is around 1MB or less - it won't have asian language glyphs. Only fonts with 10MB+ size usually have those.
51 posts
Problems with loading fonts need help
6 days, 22 hours ago Edited by itzjac on April 3, 2020, 9:40 p.m.

Not a 100% accurate check (but works most of the time) is to check filesize of font. If it is around 1MB or less - it won't have asian language glyphs. Only fonts with 10MB+ size usually have those.


Oh, that might be right, but really, am using the same ttf file that's in the Windows/font path. Notepad displays those codepoints fine.
Am gonna try downloading another font that looks above 1M.

mrmixer
For the image tag you need to put the url to the file itself, not the html page

thanks that will do!
51 posts
Problems with loading fonts need help
6 days, 22 hours ago Edited by itzjac on April 3, 2020, 9:54 p.m.
@mmozeiko this is a good font (unifoundry) for testing purposes, and yes this one works!




So, how come the same arial font works in Notepad and not in my app?

Where is windows accessing the arial font with chinese characters then?


Simon Anciaux
742 posts
Problems with loading fonts need help
6 days, 21 hours ago Edited by Simon Anciaux on April 3, 2020, 10:04 p.m. Reason: fixed link
It's using a different font based on the codepoint range. https://en.wikipedia.org/wiki/Unicode#Architecture_and_terminology
Mārtiņš Možeiko
2040 posts / 1 project
Problems with loading fonts need help
6 days, 17 hours ago Edited by Mārtiņš Možeiko on April 4, 2020, 10:01 a.m.
51 posts
Problems with loading fonts need help
2 days, 22 hours ago Edited by itzjac on April 7, 2020, 9:54 p.m.
Ok, with Font Substitution that makes sense for the office Apps, maybe for Notepad too.


But! When I watched the episode of glyph extraction and unicode, I remember that Mr. Muratori tested the win32 API with the arial font ("C:\\Windows\\Fonts\\arial.ttf") and the chinese glyphs displayed nicely. Was it really arial or which one then?

Is it possible that in the arial used while streaming was different than the one in my win OS (win10 Pro)?
Mārtiņš Možeiko
2040 posts / 1 project
Problems with loading fonts need help
2 days, 19 hours ago Edited by Mārtiņš Možeiko on April 8, 2020, 12:57 a.m.
If I remember correctly he is using Windows API to get font data. Windows API does font substitution automatically. That's why it works everywhere - Word, Notepad, your custom app - everywhere.

If you use something like stb_truetype or freetype library then it is up to you to figure out if ttf file contains needed glyph, and if not then how to manually get it from different ttf file (that's where libraries like fontconfig come into play).
51 posts
Problems with loading fonts need help
2 days, 6 hours ago
Am glad I found this problem while using the stb_truetype, this is a very important feature to aware of.

I also imagined that the explanation was some "behind the scenes" for the Win32 API.

For the record, thanks all for you input.