1.1.0
Welcome!

Font Chef is a cross-platform C99 and C++ library to create character atlas of pre-rasterized glyphs from a font at a specified size and color. It is mostly useful in situations where you cannot afford to rasterize a piece of text again whenever it changes.

It abstracts stb_truetype to render glyphs to a pixmap and to produce appropriate clipping rects to later display those glyphs.

Hello world in 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);
}

Hello world in 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!";
int count = fc_render(font, text, strlen(hello), output);
for (int i = 0; i < count; i++) {
render(texture, output[i].source, output[i].target
}

Features

  • Small, clean and easy-to-use API
  • Ships with C++ wrapper classes
  • Considers kerning when resolving rendering rects
  • Ships with many standard unicode blocks to choose from
  • Rendering API agnostic (it does not render anything directly, it returns pixels and clipping rects)
  • Fully documented with examples for each function
  • No external dependencies

Starting points

fc::render_result
Wraps a std::vector<fc_character_mapping>.
Definition: render-result.hpp:29
fc_color_black
struct fc_color const fc_color_black
RGBA: #000000FF
fc_cook
void fc_cook(struct fc_font *font)
Generates a bitmap and corresponding character information for a font.
fc_construct
struct fc_font * fc_construct(uint8_t const *font_data, struct fc_font_size font_size, struct fc_color font_color)
Constructs a fc_font structure with the provided font, a size (either in pixels or points) and a font...
fc::font
A wrapper class for fc_font.
Definition: font.hpp:29
fc::px
font_size px(float v)
Constructs a fc::font_size instance in pixels with specified value.
Definition: font-size.hpp:59
fc_font
A fc_font struct represents all data and metadata about a font.
fc_add
void fc_add(struct fc_font *font, uint32_t first, uint32_t last)
Adds the given unicode range to the list of blocks to be cooked. You must add blocks before calling f...
fc::font::cook
font & cook() &
Cooks all the added unicode ranges into a pixmap and clipping information.
Definition: font.hpp:142
fc::from
font from(uint8_t const *font_data, fc::font_size const &font_size, fc::color const &font_color)
A helper method to ease font cooking via method chaining.
Definition: font.hpp:238
fc::font::render
fc::render_result render(std::string const &text) const
Produces clipping and target rectangles to render specified text.
Definition: font.hpp:190
fc_render
struct fc_render_result fc_render(struct fc_font const *font, unsigned char const *text, size_t byte_count, struct fc_character_mapping *mapping)
Produces a list of source and target rectangles that can be used as clipping rects (or UV maps) for t...
fc_character_mapping
Specifies source and target rectangles to render the specified codepoint.
Definition: character-mapping.h:34
fc_px
struct fc_font_size fc_px(float value)
Constructs and returns a fc_size value specified as pixels.
fc::font::add
font & add(fc_unicode_block const &block) &
Adds a new unicode block to be cooked.
Definition: font.hpp:85