STB Font library with chinese characters

Been playing around with this… But I am not getting anywhere. The most obvious problem is that I wont have a large enough texture… Chinese isn’t written like english, where you have 26 letters and from that can construct any word; each word has its own Character. So if I were to write:
你好啊,今天吃饭了吗?昨天老师给我们贴别多的作业!我很晚去睡觉哈哈。
All of these characters have their own respective meaning. But since it isn’t a letter-based system there are THOUSANDS of characters to choose from; i.e. how can I fit them all onto a texture?

The second problem I run into, which is where this is an issue with the STB library. The chinese characters stored in unicode are ALL OVER THE PLACE. Which is annoying because with STB you just declare a start and an end, and it fills the middle in with letters. But I need to define a lot of ranges spanning thousands of numbers to store them. I am not quite sure what to do.

Well If I create a 4k texture I can populate it with what seems like most Simplified Chinese Characters spanning from the unicode range: 19850 - 41000

Looks like this:

However, then I can’t fit punctuation because Chinese punctuation is stored in the 60000’s (even though it looks just like English punctuation)

An idea I had was to create a sort of “wrapper”, where I create a font object and attach charsets to it. Each charset defines a min, max, material, and stb-backed image. So, I can attach multiple font textures to a single font object, and mix the letters while drawing.

End result:

I am not sure if this is the best way to go about it though…

[quote=“orange451,post:1,topic:58693”]
Storing every chinese character is generally a waste of memory. The usual approach is to have a caching scheme, i.e. a texture + associated stb packing that gets updated on the fly as new glyphs are required.

[quote=“orange451,post:1,topic:58693”]
Have you tried stbtt_PackFontRanges?

I will look into it, Thanks Spasi :slight_smile: