/* sketchbook's text: the faces (`abi.Face`'s ten, bundled, and a sketch's own from bytes), shaped by HarfBuzz and rasterized by pardes's font.c. One static library, `sketchbook-text`, linked by the host and by a sketch's tests, so both measure with the same code. */ #ifndef SKETCHBOOK_TEXT_H #define SKETCHBOOK_TEXT_H #include "font.h" #include #include enum { SK_TEXT_MONO, SK_TEXT_MONO_BOLD, SK_TEXT_MONO_ITALIC, SK_TEXT_SANS, SK_TEXT_SANS_MEDIUM, SK_TEXT_SANS_BOLD, SK_TEXT_CODE, SK_TEXT_CODE_BOLD, SK_TEXT_CODE_ITALIC, SK_TEXT_CODE_MEDIUM, SK_TEXT_FACES }; #define SK_TEXT_MAX_FACES 64 /* One glyph of a shaped run: `face` draws it (the run's, or its fallback), `cluster` is the byte it starts at, `x`/`y` its pen position in whole pixels from the run's start (y down). */ typedef struct { uint32_t glyph; uint32_t cluster; int32_t x; int32_t y; uint8_t face; } SkGlyph; /* `utf8` in `face` at `px` pixels, left to right: at most `max` glyphs into `out` (NULL to measure only). Returns how many there are (more than `max` when they did not fit), with the run's advance, its ascent and its line's height, all in whole pixels: each glyph's advance is rounded, and the line box is FreeType's at that size (font.h's cell metrics). Invalid UTF-8 shapes as U+FFFD; an unknown face as the mono. */ int sk_text_shape(int face, float px, const char *utf8, size_t len, SkGlyph *out, int max, int32_t *advance, int32_t *ascent, int32_t *height); /* `glyph`'s own advance in `face` at `px`, in whole pixels (what the renderer centres font.c's raster in, so the glyph lands on its origin). */ int32_t sk_text_advance(int face, float px, uint32_t glyph); /* A face for a sketch's own font, its bytes copied: the same id for the same bytes. -1 when FreeType refuses them or every face is taken. */ int sk_text_font(const uint8_t *bytes, size_t len); /* What rasterizes `face` (font.h's ui_font_raster), NULL if none. */ UIFont *sk_text_ui(int face); #endif