Hey all!
I'm releasing a new library, called Font Chef, to assist in text rendering. Its purpose is to create an atlas of selected glyphs from unicode blocks and produce source and target rectangles to clip and render the atlas into the screen. It is basically an abstraction of the great stb_truetype
It handles kerning, wrapping (line breaking) and alignment. It is also fully documented with examples and a manual.
Example for C:
fc_font * font = fc_construct(font_data, fc_px(30), fc_color_black);
fc_add(fc_basic_latin.start, fc_basic_latin.end);
fc_cook(font);
// use fc_get_pixels(font) to make a texture
const char hello[] = "Hello, world!";
fc_character_mapping output[32];
int count = fc_render(font, text, strlen(hello), &output);
for (int i = 0; i < count; i++) {
render(texture, output[i].source, output[i].target
}
It comes with a C++ wrapper. Example for C++:
fc::font font = fc
::from(font_data, fc::px(30), fc_color_black)
.add(fc_basic_latin)
.cook();
// use font.pixels() to make a texture
fc::render_result result = font.render("Hello, world!");
for (auto & map : result) {
render(texture, map.source, map.target);
}
I believe this is mostly useful to those handling directly with graphics rendering (aka game developers with their own engine) but I hope it is useful to you if you're not in that group.
Opinions and constructive criticism are very much welcome.
Links
- Source code: https://github.com/mobius3/font-chef
- Documentation: https://mobius3.github.io/font-chef
- Manual: https://mobius3.github.io/font-chef/manual.html