24#pragma region font loading
52#define TINYIMG_FONT_MAX_AXES 4
77#define TINYIMG_AXIS_WEIGHT 0x77676874u
79#define TINYIMG_AXIS_WIDTH 0x77647468u
81#define TINYIMG_AXIS_SLANT 0x736C6E74u
83#define TINYIMG_AXIS_ITALIC 0x6974616Cu
85#define TINYIMG_AXIS_OPTICAL_SIZE 0x6F70737Au
88#define TINYIMG_FONT_MAX_FALLBACK 4
411#pragma region text drawing
662 int32_t y, uint32_t width, uint32_t height,
const TinyTextStyle* style,
696#define TINYIMG_TEXT_MAX_RUNS 16
781 int32_t y,
const TinyTextBox* box,
const uint8_t* color
855 const TinyFont* font,
const char* text, uint32_t width,
Image processing library utilities.
Lightweight memory management implementatins in C.
One variation axis a face declares.
Definition text.h:60
float min
Definition text.h:69
float def
Definition text.h:71
float max
Definition text.h:73
uint32_t tag
The axis tag, as four packed bytes.
Definition text.h:67
What a face says about itself, in pixels at a size.
Definition text.h:259
float ascent
Definition text.h:261
uint8_t fixed_size
Definition text.h:271
float line_height
Definition text.h:265
float size
Definition text.h:267
uint32_t glyphs
Definition text.h:269
float descent
Definition text.h:263
An ordered chain of faces, tried in turn for each codepoint.
Definition text.h:218
uint32_t count
Definition text.h:222
const TinyFont * face[TINYIMG_FONT_MAX_FALLBACK]
Definition text.h:220
A loaded face.
Definition text.h:102
uint32_t hmetrics
Definition text.h:148
uint32_t gvar
Definition text.h:157
int32_t descent
Definition text.h:176
uint32_t cell_height
Definition text.h:184
uint32_t loca
Definition text.h:115
uint32_t index_count
Definition text.h:200
uint32_t glyf_size
Definition text.h:144
uint32_t kern
Definition text.h:119
uint32_t gsub_liga
Offset of the GSUB liga feature's ligature lookup, or zero.
Definition text.h:140
int32_t ascent
Definition text.h:173
uint8_t varied
Definition text.h:170
uint32_t cell_width
Definition text.h:182
uint32_t glyf
Definition text.h:113
int32_t line_gap
Definition text.h:179
uint32_t avar
Definition text.h:159
uint32_t gsub_subtables
Definition text.h:142
uint32_t units_per_em
Definition text.h:150
uint32_t * index
Codepoint and offset pairs for a BDF face, owned.
Definition text.h:198
uint32_t glyph_bytes
Definition text.h:186
uint8_t long_loca
Definition text.h:152
uint32_t bitmap
Definition text.h:188
uint32_t fvar
Definition text.h:155
size_t size
Definition text.h:106
uint32_t axes
Definition text.h:161
uint32_t gpos_subtables
Definition text.h:133
float coords[TINYIMG_FONT_MAX_AXES]
Where the face is set, one normalized coordinate per axis.
Definition text.h:168
uint32_t hmtx
Definition text.h:117
const uint8_t * data
Definition text.h:104
uint32_t glyphs
Definition text.h:146
uint32_t gpos_kern
Offset of the GPOS kern feature's pair lookup, or zero.
Definition text.h:131
uint32_t cmap
Definition text.h:111
TinyFontKind kind
Definition text.h:108
Represents an image with its width, height, and pixel data.
Definition image.h:90
The rectangle a run is set inside, and how it sits there.
Definition text.h:560
uint32_t width
Definition text.h:562
TinyTextOverflow overflow
Definition text.h:570
uint32_t height
Definition text.h:564
TinyTextVAlign valign
Definition text.h:568
TinyTextAlign align
Definition text.h:566
What one line of a run occupies, and where it sits.
Definition text.h:581
uint32_t missing
Definition text.h:597
float y
Definition text.h:591
float x
Definition text.h:589
uint8_t clipped
Definition text.h:599
uint32_t length
Definition text.h:585
uint32_t at
Definition text.h:583
float width
Definition text.h:587
float baseline
Definition text.h:593
uint32_t glyphs
Definition text.h:595
uint8_t ellipsized
Definition text.h:601
What a run of text occupies.
Definition text.h:480
uint32_t missing
Definition text.h:496
uint32_t glyphs
Definition text.h:494
float descent
Definition text.h:488
uint32_t lines
Definition text.h:492
float line_height
Definition text.h:490
float ascent
Definition text.h:486
float width
Definition text.h:482
float height
Definition text.h:484
One styled span of a rich run.
Definition text.h:705
const uint8_t * color
Definition text.h:713
const TinyFont * font
Definition text.h:707
const char * text
Definition text.h:709
const TinyTextStyle * style
Definition text.h:711
How a run of text is set.
Definition text.h:421
float shadow_y
Definition text.h:450
float shadow_x
Definition text.h:448
uint8_t kerning
Definition text.h:459
float tracking
Definition text.h:430
float size
Em size in pixels. Ignored by a bitmap face, which has one size.
Definition text.h:428
uint8_t stroke_color[4]
The outline's color, as many channels as the image has.
Definition text.h:466
float stroke
Outline width in pixels, or zero for none.
Definition text.h:446
float shadow_blur
Shadow softness in pixels, or zero for a hard offset copy.
Definition text.h:457
uint8_t shadow_color[4]
The shadow's color, as many channels as the image has.
Definition text.h:474
float line_height
Definition text.h:432
uint32_t tiny_font_axis_count(const TinyFont *font)
How many variation axes a face declares.
const TinyFont * tiny_font_set_for(const TinyFontSet *set, uint32_t codepoint)
Which face in a chain covers a codepoint.
int tiny_text_measure_wrapped(const TinyFont *font, const char *text, uint32_t width, const TinyTextStyle *style, TinyTextMetrics *out)
Measures a run of text as it would be wrapped inside a width.
TinyTextOverflow
What happens to text the box cannot hold.
Definition text.h:541
@ TINYIMG_OVERFLOW_CLIP
Definition text.h:543
@ TINYIMG_OVERFLOW_ELLIPSIS
The last line that fits ends in an ellipsis.
Definition text.h:551
int tiny_font_metrics(const TinyFont *font, float size, TinyFontMetrics *out)
Reads a face's vertical metrics at an em size.
TinyTextAlign
Where a line sits inside the width it was given.
Definition text.h:503
@ TINYIMG_ALIGN_JUSTIFY
Both edges, by widening the spaces.
Definition text.h:518
@ TINYIMG_ALIGN_RIGHT
Definition text.h:509
@ TINYIMG_ALIGN_CENTER
Definition text.h:507
@ TINYIMG_ALIGN_LEFT
Definition text.h:505
int tiny_text_measure(const TinyFont *font, const char *text, const TinyTextStyle *style, TinyTextMetrics *out)
Measures a run of text without drawing it.
int tiny_font_set_init(TinyFontSet *set)
Starts an empty chain.
int tiny_image_draw_text_set(TinyImage *image, const TinyFontSet *set, const char *text, int32_t x, int32_t y, const TinyTextBox *box, const TinyTextStyle *style, const uint8_t *color)
Draws text through a fallback chain.
int tiny_font_reset_axes(TinyFont *font)
Returns a face to its default instance.
int tiny_font_set_axis(TinyFont *font, uint32_t tag, float value)
Sets one axis, in the axis' own units.
int tiny_image_draw_text(TinyImage *image, const TinyFont *font, const char *text, int32_t x, int32_t y, const TinyTextStyle *style, const uint8_t *color)
Draws a line of text.
uint32_t tiny_text_style_sizeof(void)
Size of a TinyTextStyle, for a host allocating one across the wasm boundary.
TinyTextVAlign
Where a run sits inside the height it was given.
Definition text.h:528
@ TINYIMG_VALIGN_BOTTOM
Definition text.h:534
@ TINYIMG_VALIGN_TOP
Definition text.h:530
@ TINYIMG_VALIGN_MIDDLE
Definition text.h:532
int tiny_font_has_glyph(const TinyFont *font, uint32_t codepoint)
Reports whether a face has a glyph for a codepoint.
uint32_t tiny_text_line_sizeof(void)
Size of a TinyTextLine, for the same reason.
int tiny_font_set_add(TinyFontSet *set, const TinyFont *font)
Appends a face to the end of a chain.
void tiny_font_free(TinyFont *font)
Releases whatever a face owns.
int tiny_image_draw_text_in(TinyImage *image, const TinyFont *font, const char *text, int32_t x, int32_t y, const TinyTextBox *box, const TinyTextStyle *style, const uint8_t *color)
Draws text inside a rectangle, with the box's own settings.
TinyFontKind
Outline and bitmap face formats.
Definition text.h:35
@ TINYIMG_FONT_PSF
Definition text.h:46
@ TINYIMG_FONT_BDF
Definition text.h:48
@ TINYIMG_FONT_TRUETYPE
Quadratic outlines in a glyf table.
Definition text.h:44
int tiny_font_axis(const TinyFont *font, uint32_t index, TinyFontAxis *out)
Reads one of a face's variation axes.
int tiny_text_measure_set(const TinyFontSet *set, const char *text, const TinyTextBox *box, const TinyTextStyle *style, TinyTextMetrics *out)
Measures text as a fallback chain would set it.
uint32_t tiny_text_box_sizeof(void)
Size of a TinyTextBox, for the same reason.
int tiny_image_draw_text_runs(TinyImage *image, const TinyTextRun *runs, uint32_t count, int32_t x, int32_t y, const TinyTextBox *box, const uint8_t *color)
Draws a sequence of styled spans as one run of text.
void tiny_text_style(TinyTextStyle *style, float size)
Fills a style in with the defaults.
#define TINYIMG_FONT_MAX_AXES
Definition text.h:52
uint32_t tiny_font_sizeof(void)
Size of a TinyFont, for a host allocating one across the wasm boundary.
int tiny_font_load(TinyFont *font, const char *blob_id)
Loads a face from a resident blob.
int tiny_text_lines(const TinyFont *font, const char *text, const TinyTextBox *box, const TinyTextStyle *style, TinyTextLine *lines, uint32_t capacity, uint32_t *count)
Measures a run line by line, without drawing it.
#define TINYIMG_FONT_MAX_FALLBACK
Definition text.h:88
uint32_t tiny_text_metrics_sizeof(void)
Size of a TinyTextMetrics, for the same reason.
int tiny_font_load_bytes(TinyFont *font, const uint8_t *data, size_t size)
Loads a face from bytes the caller keeps.
int tiny_image_draw_text_box(TinyImage *image, const TinyFont *font, const char *text, int32_t x, int32_t y, uint32_t width, uint32_t height, const TinyTextStyle *style, TinyTextAlign align, const uint8_t *color)
Draws text wrapped and aligned inside a rectangle.
uint32_t tiny_font_metrics_sizeof(void)
Size of a TinyFontMetrics, for the same reason.
int tiny_text_measure_runs(const TinyTextRun *runs, uint32_t count, const TinyTextBox *box, TinyTextMetrics *out)
Measures a sequence of styled spans without drawing them.
Umbrella header, version and error codes.