1.1.0
main.c

Complete example for the C API

#include "font-chef/font-chef.h"
#include "SDL.h"
#include "common/state.h"
#include "common/font.h"
int main(int argc, char const ** argv) {
struct state state = {};
init(&state);
struct fc_font * font = fc_construct(font_pacifico_ttf.data, fc_pt(30), fc_color_white);
fc_add(font, fc_basic_latin.first, fc_basic_latin.last);
fc_cook(font);
struct texture * font_texture = texture_make(
&state,
fc_get_pixels(font)->data,
fc_get_pixels(font)->dimensions
);
struct fc_character_mapping mapping[256];
const char text[] = "Hello, handsome! I mean... world!";
font,
(uint8_t *) text,
strlen(text),
state.bounds.right * 0.66f,
1.0f,
fc_align_left, mapping
);
fc_move(mapping, result.glyph_count, 0.0f, state.bounds.bottom / 2 - 20);
while (update(&state)) {
for (int i = 0; i < result.glyph_count; i++) {
render(font_texture, mapping[i].source, mapping[i].target);
}
}
fc_destruct(font);
texture_destroy(font_texture);
quit(&state);
return 0;
}
fc_cook
void fc_cook(struct fc_font *font)
Generates a bitmap and corresponding character information for a font.
fc_render_wrapped
struct fc_render_result fc_render_wrapped(struct fc_font const *font, unsigned char const *text, size_t byte_count, size_t line_width, float line_height_multiplier, enum fc_alignment alignment, struct fc_character_mapping *mapping)
A shortcut for rendering and then wrapping the result.
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_pt
struct fc_font_size fc_pt(float value)
Constructs and returns a fc_size value specified as points.
fc_font
A fc_font struct represents all data and metadata about a font.
fc_destruct
void fc_destruct(struct fc_font *font)
Destroys and frees all memory allocated by this library.
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_render_result
A structure holding the result of a call to fc_render or fc_render_wrapped
Definition: font.h:49
fc_color_white
struct fc_color const fc_color_white
RGBA: #FFFFFFFF
fc_unicode_block::last
uint32_t last
The last unicode point in this range (inclusive)
Definition: unicode-block.h:26
fc_render_result::glyph_count
uint32_t glyph_count
How many glphs were produced.
Definition: font.h:58
fc_unicode_block::first
uint32_t first
The first unicode point in this range.
Definition: unicode-block.h:23
fc_get_pixels
struct fc_pixels const * fc_get_pixels(struct fc_font const *font)
Returns the pixel data after for a font generated after a fc_cook was called.
fc_character_mapping
Specifies source and target rectangles to render the specified codepoint.
Definition: character-mapping.h:34
fc_move
void fc_move(struct fc_character_mapping *mapping, size_t count, float left, float baseline)
Moves all the target rectangles by left pixels horizontally and baseline pixels vertically.