tinyimg 1.1.1
Lightweight image manipulation library for WebAssembly
Loading...
Searching...
No Matches
text.h File Reference

Font loading, text measurement and text drawing. More...

#include <stddef.h>
#include <stdint.h>
#include "tinyimg/image.h"
#include "tinyimg/memory.h"
#include "tinyimg/tinyimg.h"

Go to the source code of this file.

Classes

struct  TinyFontAxis
 One variation axis a face declares. More...
struct  TinyFont
 A loaded face. More...
struct  TinyFontSet
 An ordered chain of faces, tried in turn for each codepoint. More...
struct  TinyFontMetrics
 What a face says about itself, in pixels at a size. More...
struct  TinyTextStyle
 How a run of text is set. More...
struct  TinyTextMetrics
 What a run of text occupies. More...
struct  TinyTextBox
 The rectangle a run is set inside, and how it sits there. More...
struct  TinyTextLine
 What one line of a run occupies, and where it sits. More...
struct  TinyTextRun
 One styled span of a rich run. More...

Macros

#define TINYIMG_FONT_MAX_AXES   4
#define TINYIMG_AXIS_WEIGHT   0x77676874u
#define TINYIMG_AXIS_WIDTH   0x77647468u
#define TINYIMG_AXIS_SLANT   0x736C6E74u
#define TINYIMG_AXIS_ITALIC   0x6974616Cu
#define TINYIMG_AXIS_OPTICAL_SIZE   0x6F70737Au
#define TINYIMG_FONT_MAX_FALLBACK   4
#define TINYIMG_TEXT_MAX_RUNS   16

Typedefs

typedef enum TinyFontKind TinyFontKind
 Outline and bitmap face formats.
typedef enum TinyTextAlign TinyTextAlign
 Where a line sits inside the width it was given.
typedef enum TinyTextVAlign TinyTextVAlign
 Where a run sits inside the height it was given.
typedef enum TinyTextOverflow TinyTextOverflow
 What happens to text the box cannot hold.

Enumerations

enum  TinyFontKind { TINYIMG_FONT_TRUETYPE = 0 , TINYIMG_FONT_PSF = 1 , TINYIMG_FONT_BDF = 2 }
 Outline and bitmap face formats. More...
enum  TinyTextAlign { TINYIMG_ALIGN_LEFT = 0 , TINYIMG_ALIGN_CENTER = 1 , TINYIMG_ALIGN_RIGHT = 2 , TINYIMG_ALIGN_JUSTIFY = 3 }
 Where a line sits inside the width it was given. More...
enum  TinyTextVAlign { TINYIMG_VALIGN_TOP = 0 , TINYIMG_VALIGN_MIDDLE = 1 , TINYIMG_VALIGN_BOTTOM = 2 }
 Where a run sits inside the height it was given. More...
enum  TinyTextOverflow { TINYIMG_OVERFLOW_CLIP = 0 , TINYIMG_OVERFLOW_ELLIPSIS = 1 }
 What happens to text the box cannot hold. More...

Functions

int tiny_font_set_init (TinyFontSet *set)
 Starts an empty chain.
int tiny_font_set_add (TinyFontSet *set, const TinyFont *font)
 Appends a face to the end of a chain.
const TinyFont * tiny_font_set_for (const TinyFontSet *set, uint32_t codepoint)
 Which face in a chain covers a codepoint.
uint32_t tiny_font_axis_count (const TinyFont *font)
 How many variation axes a face declares.
int tiny_font_axis (const TinyFont *font, uint32_t index, TinyFontAxis *out)
 Reads one of a face's variation axes.
int tiny_font_set_axis (TinyFont *font, uint32_t tag, float value)
 Sets one axis, in the axis' own units.
int tiny_font_reset_axes (TinyFont *font)
 Returns a face to its default instance.
int tiny_font_load (TinyFont *font, const char *blob_id)
 Loads a face from a resident blob.
int tiny_font_load_bytes (TinyFont *font, const uint8_t *data, size_t size)
 Loads a face from bytes the caller keeps.
void tiny_font_free (TinyFont *font)
 Releases whatever a face owns.
int tiny_font_metrics (const TinyFont *font, float size, TinyFontMetrics *out)
 Reads a face's vertical metrics at an em size.
int tiny_font_has_glyph (const TinyFont *font, uint32_t codepoint)
 Reports whether a face has a glyph for a codepoint.
uint32_t tiny_font_sizeof (void)
 Size of a TinyFont, for a host allocating one across the wasm boundary.
uint32_t tiny_font_metrics_sizeof (void)
 Size of a TinyFontMetrics, for the same reason.
void tiny_text_style (TinyTextStyle *style, float size)
 Fills a style in with the defaults.
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.
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.
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.
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_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.
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.
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.
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.
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_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.
uint32_t tiny_text_style_sizeof (void)
 Size of a TinyTextStyle, for a host allocating one across the wasm boundary.
uint32_t tiny_text_box_sizeof (void)
 Size of a TinyTextBox, for the same reason.
uint32_t tiny_text_line_sizeof (void)
 Size of a TinyTextLine, for the same reason.
uint32_t tiny_text_metrics_sizeof (void)
 Size of a TinyTextMetrics, for the same reason.

Detailed Description

Font loading, text measurement and text drawing.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
1.0.0
Date
2026-09-03

Macro Definition Documentation

◆ TINYIMG_AXIS_ITALIC

#define TINYIMG_AXIS_ITALIC   0x6974616Cu

The ital axis, 0 or 1.

◆ TINYIMG_AXIS_OPTICAL_SIZE

#define TINYIMG_AXIS_OPTICAL_SIZE   0x6F70737Au

The opsz axis, the size the design is optimized for.

◆ TINYIMG_AXIS_SLANT

#define TINYIMG_AXIS_SLANT   0x736C6E74u

The slnt axis, degrees clockwise from upright.

◆ TINYIMG_AXIS_WEIGHT

#define TINYIMG_AXIS_WEIGHT   0x77676874u

The wght axis, 1 to 1000 by convention.

◆ TINYIMG_AXIS_WIDTH

#define TINYIMG_AXIS_WIDTH   0x77647468u

The wdth axis, a percentage.

◆ TINYIMG_FONT_MAX_AXES

#define TINYIMG_FONT_MAX_AXES   4

How many variation axes one face may be set on at once.

◆ TINYIMG_FONT_MAX_FALLBACK

#define TINYIMG_FONT_MAX_FALLBACK   4

How many faces one fallback chain holds.

◆ TINYIMG_TEXT_MAX_RUNS

#define TINYIMG_TEXT_MAX_RUNS   16

How many styled spans one rich run holds.

Typedef Documentation

◆ TinyFontKind

typedef enum TinyFontKind TinyFontKind

Outline and bitmap face formats.

Dispatched from the first four bytes, so a caller never says which one they have. The three are genuinely different shapes rather than variants of one: an outline face has a curve per glyph and scales to any size, and a bitmap face has a fixed grid and one size.

◆ TinyTextVAlign

Where a run sits inside the height it was given.

Needs a box height to mean anything; with none, every value is the same as TINYIMG_VALIGN_TOP.

Enumeration Type Documentation

◆ TinyFontKind

Outline and bitmap face formats.

Dispatched from the first four bytes, so a caller never says which one they have. The three are genuinely different shapes rather than variants of one: an outline face has a curve per glyph and scales to any size, and a bitmap face has a fixed grid and one size.

Enumerator
TINYIMG_FONT_TRUETYPE 

Quadratic outlines in a glyf table.

Both the .ttf and the .otf wrappers of it. An OpenType file whose outlines are CFF charstrings rather than glyf is a different format behind the same extension, and loading one reports TINYIMG_ERR_UNSUPPORTED_VARIANT.

TINYIMG_FONT_PSF 

A PC screen font: one fixed cell, one bit per pixel.

TINYIMG_FONT_BDF 

Glyph Bitmap Distribution Format, one bitmap per glyph.

◆ TinyTextAlign

Where a line sits inside the width it was given.

Enumerator
TINYIMG_ALIGN_LEFT 

Against the left edge.

TINYIMG_ALIGN_CENTER 

Centered in the width.

TINYIMG_ALIGN_RIGHT 

Against the right edge.

TINYIMG_ALIGN_JUSTIFY 

Both edges, by widening the spaces.

The last line of a paragraph is set left, which is what every typesetter does: stretching four words across a full measure is worse than the ragged edge it was avoiding. A line with no space to widen is also set left rather than having its letters spaced.

◆ TinyTextOverflow

What happens to text the box cannot hold.

Enumerator
TINYIMG_OVERFLOW_CLIP 

Lines past the box are not drawn.

TINYIMG_OVERFLOW_ELLIPSIS 

The last line that fits ends in an ellipsis.

A single U+2026, and a face without that glyph gets three full stops instead, so a subset face that never included the character still produces something a reader recognizes rather than a missing glyph box.

◆ TinyTextVAlign

Where a run sits inside the height it was given.

Needs a box height to mean anything; with none, every value is the same as TINYIMG_VALIGN_TOP.

Enumerator
TINYIMG_VALIGN_TOP 

First line box against the top edge.

TINYIMG_VALIGN_MIDDLE 

The run centered in the height.

TINYIMG_VALIGN_BOTTOM 

Last line box against the bottom edge.

Function Documentation

◆ tiny_font_axis()

int tiny_font_axis ( const TinyFont * font,
uint32_t index,
TinyFontAxis * out )

Reads one of a face's variation axes.

Parameters
fontThe face.
indexZero based, below tiny_font_axis_count.
outReceives the axis.
Returns
int TINYIMG_OK, TINYIMG_ERR_NULL, or TINYIMG_ERR_BOUNDS.

◆ tiny_font_axis_count()

uint32_t tiny_font_axis_count ( const TinyFont * font)

How many variation axes a face declares.

Zero for a static face, which is every face that carries no fvar table.

Parameters
fontThe face.
Returns
uint32_t The count, capped at TINYIMG_FONT_MAX_AXES.

◆ tiny_font_free()

void tiny_font_free ( TinyFont * font)

Releases whatever a face owns.

Never the bytes, which belong to the blob table or to the caller. Only a BDF face owns anything, so this is a no-op for the other two; calling it always is still the right habit and costs a branch.

Parameters
fontThe face, left safe to load into again.

◆ tiny_font_has_glyph()

int tiny_font_has_glyph ( const TinyFont * font,
uint32_t codepoint )

Reports whether a face has a glyph for a codepoint.

Parameters
fontThe face.
codepointThe Unicode codepoint.
Returns
int Non-zero when it does. A codepoint it does not have still draws: it maps to glyph zero, which is what a text renderer does with one.

◆ tiny_font_load()

int tiny_font_load ( TinyFont * font,
const char * blob_id )

Loads a face from a resident blob.

The blob is what a Worker has: imported as a wrangler Data module, or fetched from a bucket and handed to tiny_blob_load. Its bytes stay owned by the blob table, so the face borrows them and tiny_blob_free invalidates it.

Parameters
fontReceives the face.
blob_idThe id it was loaded under, or NULL for the first font blob.
Returns
int TINYIMG_OK, TINYIMG_ERR_BLOB_MISSING when no such blob is resident, TINYIMG_ERR_UNKNOWN_FORMAT when the bytes match no face format, TINYIMG_ERR_UNSUPPORTED_VARIANT for a CFF-outlined OpenType file, or TINYIMG_ERR_CORRUPT.

◆ tiny_font_load_bytes()

int tiny_font_load_bytes ( TinyFont * font,
const uint8_t * data,
size_t size )

Loads a face from bytes the caller keeps.

The escape hatch from the blob table, and the difference is ownership: tiny_blob_load takes the bytes and frees them, this borrows them and frees nothing. Use it when the bytes are already somewhere convenient, or when a face is wanted for one call and should not occupy a blob slot.

Parameters
fontReceives the face.
dataThe face's bytes, which must outlive the face.
sizeHow many.
Returns
int TINYIMG_OK or a negative TinyImageError; see tiny_font_load.

◆ tiny_font_metrics()

int tiny_font_metrics ( const TinyFont * font,
float size,
TinyFontMetrics * out )

Reads a face's vertical metrics at an em size.

Parameters
fontThe face.
sizeEm size in pixels. Zero, or any size for a bitmap face, reports the face's own.
outReceives the metrics.
Returns
int TINYIMG_OK or a negative TinyImageError.

◆ tiny_font_metrics_sizeof()

uint32_t tiny_font_metrics_sizeof ( void )

Size of a TinyFontMetrics, for the same reason.

Returns
uint32_t sizeof(TinyFontMetrics).

◆ tiny_font_reset_axes()

int tiny_font_reset_axes ( TinyFont * font)

Returns a face to its default instance.

Parameters
fontThe face.
Returns
int TINYIMG_OK or TINYIMG_ERR_NULL.

◆ tiny_font_set_add()

int tiny_font_set_add ( TinyFontSet * set,
const TinyFont * font )

Appends a face to the end of a chain.

Parameters
setThe chain.
fontThe face, which the chain borrows.
Returns
int TINYIMG_OK, TINYIMG_ERR_NULL, or TINYIMG_ERR_RANGE past TINYIMG_FONT_MAX_FALLBACK.

◆ tiny_font_set_axis()

int tiny_font_set_axis ( TinyFont * font,
uint32_t tag,
float value )

Sets one axis, in the axis' own units.

tiny_font_set_axis(&font, TINYIMG_AXIS_WEIGHT, 700.0f) is a bold instance of one variable file, drawn from the same bytes as the regular one. The value is clamped to the axis' range, so 900 on an axis that stops at 800 is 800 rather than an error.

The outlines are interpolated from the face's gvar deltas, which is what the format defines rather than an approximation of it: the deltas of every region the coordinate falls in are scaled and summed, and points no region mentions are inferred from their neighbors along the contour. Advances vary too, from the same deltas' phantom points, so a bolder instance is spaced as its designer set it.

A face with no fvar reports TINYIMG_ERR_UNSUPPORTED_VARIANT, and a tag it does not declare reports TINYIMG_ERR_NOT_FOUND. Neither is a failure a caller has to prevent: ask the face what it has with tiny_font_axis first, or ignore the result and get the default instance.

Parameters
fontThe face, whose variation state this changes.
tagThe axis tag.
valueThe value, in the axis' units.
Returns
int TINYIMG_OK, TINYIMG_ERR_NULL, TINYIMG_ERR_UNSUPPORTED_VARIANT for a static face, or TINYIMG_ERR_NOT_FOUND for an axis the face does not declare.

◆ tiny_font_set_for()

const TinyFont * tiny_font_set_for ( const TinyFontSet * set,
uint32_t codepoint )

Which face in a chain covers a codepoint.

Parameters
setThe chain.
codepointThe character.
Returns
const TinyFont* The first face with a glyph for it, or the first face in the chain when none has one, so a caller always has something to draw.

◆ tiny_font_set_init()

int tiny_font_set_init ( TinyFontSet * set)

Starts an empty chain.

Parameters
setThe chain to initialize.
Returns
int TINYIMG_OK or TINYIMG_ERR_NULL.

◆ tiny_font_sizeof()

uint32_t tiny_font_sizeof ( void )

Size of a TinyFont, for a host allocating one across the wasm boundary.

Returns
uint32_t sizeof(TinyFont).

◆ tiny_image_draw_text()

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.

x and y are the top left of the line box, not the baseline, which is what every other drawing entry point in this library takes and what a caller placing a label wants. The baseline is y + metrics.ascent, so a caller who wants to sit text on a baseline subtracts that.

A newline in text starts a new line at x, so a short multi-line string needs no box.

Parameters
imageThe image to draw on.
fontThe face.
textUTF-8, NUL terminated. A malformed sequence draws the replacement glyph rather than failing.
xLeft edge of the line box; may be negative.
yTop edge of the line box; may be negative.
styleHow to set it, or NULL for the defaults at the face's own size.
colorThe color, as many channels as the image has.
Returns
int TINYIMG_OK, TINYIMG_ERR_BLOB_MISSING for an unloaded face, or a negative TinyImageError.

◆ tiny_image_draw_text_box()

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.

Wraps on spaces where it can and mid-word where a single word is wider than the box, so a long unbroken string is clipped by the box rather than running out of it. A line whose box has run out of height is not drawn, and the metrics still report every line the text would have taken, so a caller can tell that it overflowed.

Parameters
imageThe image to draw on.
fontThe face.
textUTF-8, NUL terminated.
xLeft edge of the box.
yTop edge of the box.
widthWidth to wrap inside. Zero draws nothing.
heightHeight to fill. Zero means no limit.
styleHow to set it, or NULL for the defaults.
alignWhere each line sits inside width.
colorThe color, as many channels as the image has.
Returns
int TINYIMG_OK or a negative TinyImageError.

◆ tiny_image_draw_text_in()

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.

What tiny_image_draw_text_box does, plus vertical alignment, justification and an ellipsis. The two share every line of layout, so a caller who measures with tiny_text_lines and then draws gets the lines the measurement described.

A stroke or a shadow makes this three passes over the run rather than one: every shadow, then every outline, then every fill. Drawing each glyph's three layers together would let one glyph's outline print over the previous glyph's fill, which is visible wherever two letters touch.

Parameters
imageThe image to draw on.
fontThe face.
textUTF-8, NUL terminated.
xLeft edge of the box.
yTop edge of the box.
boxThe rectangle and how the run sits in it, or NULL for none.
styleHow to set it, or NULL for the defaults.
colorThe fill color, as many channels as the image has.
Returns
int TINYIMG_OK or a negative TinyImageError.

◆ tiny_image_draw_text_runs()

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.

The spans flow into each other rather than being drawn one after another: a wrap can land in the middle of a span, and a line that mixes sizes sits on one baseline, which is the largest ascent on that line. Two spans of different sizes therefore share a baseline rather than each having their own, which is what makes a superscript or a larger first letter look right.

Every span carries its own face, size, tracking, kerning, outline and shadow. Kerning does not cross a span boundary, because a kern pair is a property of one face and the two glyphs either side of the boundary may be in different ones.

Parameters
imageThe image to draw on.
runsThe spans, in order.
countHow many, up to TINYIMG_TEXT_MAX_RUNS.
xLeft edge of the box.
yTop edge of the box.
boxThe rectangle and how the run sits in it, or NULL for none.
colorThe fill color for any span that does not name one.
Returns
int TINYIMG_OK, TINYIMG_ERR_RANGE past TINYIMG_TEXT_MAX_RUNS, or a negative TinyImageError.

◆ tiny_image_draw_text_set()

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.

The same layout as tiny_image_draw_text_in, with the face chosen per codepoint instead of once for the run. A chain of one face is exactly the single-face path, so nothing about a caller who does not need this changes.

Parameters
imageThe image to draw on.
setThe chain.
textUTF-8, NUL terminated.
xLeft edge of the box.
yTop edge of the box.
boxThe rectangle and how the run sits in it, or NULL for none.
styleHow to set it, or NULL for the defaults.
colorThe fill color, as many channels as the image has.
Returns
int TINYIMG_OK or a negative TinyImageError.

◆ tiny_text_box_sizeof()

uint32_t tiny_text_box_sizeof ( void )

Size of a TinyTextBox, for the same reason.

Returns
uint32_t sizeof(TinyTextBox).

◆ tiny_text_line_sizeof()

uint32_t tiny_text_line_sizeof ( void )

Size of a TinyTextLine, for the same reason.

Returns
uint32_t sizeof(TinyTextLine).

◆ tiny_text_lines()

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.

The layout a draw would produce, one entry per line, including the lines the box's height leaves out and which line an ellipsis lands on. What a caller needs to place a badge beside the second line, or to tell that a headline was truncated and pick a smaller size.

Parameters
fontThe face.
textUTF-8, NUL terminated.
boxThe rectangle it would be set in, or NULL for none.
styleHow it would be set, or NULL for the defaults.
linesReceives up to capacity entries. May be NULL to count only.
capacityHow many entries lines holds.
countReceives the number of lines the run takes, which may be more than capacity.
Returns
int TINYIMG_OK or a negative TinyImageError.

◆ tiny_text_measure()

int tiny_text_measure ( const TinyFont * font,
const char * text,
const TinyTextStyle * style,
TinyTextMetrics * out )

Measures a run of text without drawing it.

Named for the text rather than for an image because it takes none: the size of a string is a property of the face and the style. It is the same layout the drawing entry points use, so measuring and then drawing at the measured position lands where the measurement said.

Parameters
fontThe face.
textUTF-8, NUL terminated. Newlines count as line breaks.
styleHow it would be set, or NULL for the defaults.
outReceives the metrics.
Returns
int TINYIMG_OK or a negative TinyImageError.

◆ tiny_text_measure_runs()

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.

The same layout the draw uses. ascent and line_height are the largest of the spans on the first line, which is what the run actually occupies.

Parameters
runsThe spans, in order.
countHow many, up to TINYIMG_TEXT_MAX_RUNS.
boxThe rectangle they would be set in, or NULL for none.
outReceives the metrics.
Returns
int TINYIMG_OK, TINYIMG_ERR_RANGE, or a negative TinyImageError.

◆ tiny_text_measure_set()

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.

Parameters
setThe chain.
textUTF-8, NUL terminated.
boxThe rectangle it would be set in, or NULL for none.
styleHow it would be set, or NULL for the defaults.
outReceives the metrics. missing counts the codepoints no face in the chain had a glyph for.
Returns
int TINYIMG_OK or a negative TinyImageError.

◆ tiny_text_measure_wrapped()

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.

Parameters
fontThe face.
textUTF-8, NUL terminated.
widthWidth to wrap inside. Zero measures without wrapping.
styleHow it would be set, or NULL for the defaults.
outReceives the metrics, whose lines is what the wrap produced.
Returns
int TINYIMG_OK or a negative TinyImageError.

◆ tiny_text_metrics_sizeof()

uint32_t tiny_text_metrics_sizeof ( void )

Size of a TinyTextMetrics, for the same reason.

Returns
uint32_t sizeof(TinyTextMetrics).

◆ tiny_text_style()

void tiny_text_style ( TinyTextStyle * style,
float size )

Fills a style in with the defaults.

Parameters
styleReceives them.
sizeEm size in pixels.

◆ tiny_text_style_sizeof()

uint32_t tiny_text_style_sizeof ( void )

Size of a TinyTextStyle, for a host allocating one across the wasm boundary.

Returns
uint32_t sizeof(TinyTextStyle).