memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.15k stars 771 forks source link

Support for loading a certain font face from a font file. #559

Closed olliwang closed 4 years ago

olliwang commented 4 years ago

This commit allows loading a certain font face from a font collection file such as TTC.

TTC file is very important for CJK fonts. For example, Android includes .ttc font files for CJK characters due to the fact that Chinese/Japanese/Korean share a lot of characters. Without a .ttc file, we need four files (each file takes at least 15 MB) to support all of Japanese/Chinese/Korean characters. The Noto-CJK TTC font file included in Android only takes ~25 MB.

Currently, the stb implementation in NanoVG does not support TTC at all as mentioned in #554. And the FreeType implementation only loads the first font face in the TTC. This isn't ideal as the same character may look different in different languages.

cjk

Without TTC support, we need to bundle 4 font files to cover all CJK characters, and we can't use the .ttc file included in Android system already. That would make the app super heavy.

olliwang commented 4 years ago

@memononen Thanks. I just updated the code. 👍

memononen commented 4 years ago

Thanks or the improvement!

olliwang commented 4 years ago

Thanks for merging. Cheers! :)