|
ginnOS
The reference: libc, the libraries and the kernel
|
bragi: fonts, faces, glyph lookup and metrics (stb_truetype). More...
#include "bragi_internal.h"#include <fcntl.h>#include <math.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <unistd.h>Macros | |
| #define | STB_TRUETYPE_IMPLEMENTATION |
| #define | FONT_MAX_SIZE (32u * 1024 * 1024) |
Functions | |
| bragi_font_t * | bragi_font_from_memory (const uint8_t *data, size_t size, bool take) |
| a font from memory. | |
| bragi_font_t * | bragi_font_open (const char *path) |
| load a TrueType file. | |
| void | bragi_font_close (bragi_font_t *font) |
| close a font. | |
| bragi_face_t * | bragi_face_new (bragi_font_t *font, float pixel_size) |
| the font at a size. | |
| void | bragi_face_set_tracking (bragi_face_t *face, float em) |
| letter spacing, as CSS letter-spacing: added after every character, so measuring, wrapping and drawing all include it. | |
| int32_t | bragi_line_baseline (const bragi_face_t *face, int32_t line_height) |
| where the baseline is in a line of text line_height pixels high, from its top: as CSS places text in a line box (the font's ascent and descent, with half of the rest above them). | |
| void | bragi_face_free (bragi_face_t *face) |
| void | bragi_face_set_fallback (bragi_face_t *face, bragi_face_t *fallback) |
| where characters the font does not have come from (NULL: none). | |
| int32_t | bragi_ascent (const bragi_face_t *face) |
| the vertical metrics in whole pixels: from the baseline up to the top of the highest letters (ascent), down to the bottom of the lowest (descent, a positive number), and the distance from one baseline to the next (line height). | |
| int32_t | bragi_descent (const bragi_face_t *face) |
| int32_t | bragi_line_height (const bragi_face_t *face) |
| bool | bragi_has_char (const bragi_face_t *face, uint32_t codepoint) |
| true if the font (not a fallback) has a glyph for the character. | |
| bragi_face_t * | bragi_find_glyph (bragi_face_t *face, uint32_t codepoint, int *glyph) |
| find the face (this one or a fallback) and the glyph for a character. | |
| int32_t | bragi_advance (const bragi_face_t *face, int glyph) |
| the advance of a glyph in 1/64 pixels. | |
| int32_t | bragi_kerning (const bragi_face_t *face, int left, int right) |
| the kerning between two glyphs of the same face, in 1/64 pixels. | |
| void | bragi_face_stats (const bragi_face_t *face, bragi_stats_t *stats) |
bragi: fonts, faces, glyph lookup and metrics (stb_truetype).
stb_truetype is compiled here, and only bragi uses it, so it can be replaced later without changing the apps.
| #define STB_TRUETYPE_IMPLEMENTATION |
| #define FONT_MAX_SIZE (32u * 1024 * 1024) |
| bragi_font_t * bragi_font_from_memory | ( | const uint8_t * | data, |
| size_t | size, | ||
| bool | take ) |
a font from memory.
with take, the font frees data when it is closed; else data must stay until then.
| bragi_font_t * bragi_font_open | ( | const char * | path | ) |
load a TrueType file.
| void bragi_font_close | ( | bragi_font_t * | font | ) |
close a font.
close its faces first.
| bragi_face_t * bragi_face_new | ( | bragi_font_t * | font, |
| float | pixel_size ) |
the font at a size.
| pixel_size | the size of the em in pixels (what "16 px text" means); 4 to 512. |
| void bragi_face_set_tracking | ( | bragi_face_t * | face, |
| float | em ) |
letter spacing, as CSS letter-spacing: added after every character, so measuring, wrapping and drawing all include it.
| em | in ems (-0.006 for Inter body text in idunn). |
| int32_t bragi_line_baseline | ( | const bragi_face_t * | face, |
| int32_t | line_height ) |
where the baseline is in a line of text line_height pixels high, from its top: as CSS places text in a line box (the font's ascent and descent, with half of the rest above them).
| void bragi_face_free | ( | bragi_face_t * | face | ) |
| void bragi_face_set_fallback | ( | bragi_face_t * | face, |
| bragi_face_t * | fallback ) |
where characters the font does not have come from (NULL: none).
| int32_t bragi_ascent | ( | const bragi_face_t * | face | ) |
the vertical metrics in whole pixels: from the baseline up to the top of the highest letters (ascent), down to the bottom of the lowest (descent, a positive number), and the distance from one baseline to the next (line height).
| int32_t bragi_descent | ( | const bragi_face_t * | face | ) |
| int32_t bragi_line_height | ( | const bragi_face_t * | face | ) |
| bool bragi_has_char | ( | const bragi_face_t * | face, |
| uint32_t | codepoint ) |
true if the font (not a fallback) has a glyph for the character.
| bragi_face_t * bragi_find_glyph | ( | bragi_face_t * | face, |
| uint32_t | codepoint, | ||
| int * | glyph ) |
find the face (this one or a fallback) and the glyph for a character.
with no face that has it, the face itself and glyph 0 (the "missing glyph" box).
| int32_t bragi_advance | ( | const bragi_face_t * | face, |
| int | glyph ) |
the advance of a glyph in 1/64 pixels.
| int32_t bragi_kerning | ( | const bragi_face_t * | face, |
| int | left, | ||
| int | right ) |
the kerning between two glyphs of the same face, in 1/64 pixels.
| void bragi_face_stats | ( | const bragi_face_t * | face, |
| bragi_stats_t * | stats ) |