diff options
| author | eunhhu <[email protected]> | 2026-09-28 13:03:50 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-28 13:03:50 +0100 |
| commit | 202e6bf4677565c0cfbef5340119d0f9674bf17d (patch) | |
| tree | de23a6974e74784813556e51b52c0719b699b220 /text/layout.h | |
| parent | 0d2e04f1c9d05a598deb443ba067ef61e0b9cab3 (diff) | |
| download | vega-202e6bf4677565c0cfbef5340119d0f9674bf17d.tar.gz vega-202e6bf4677565c0cfbef5340119d0f9674bf17d.zip | |
Set paragraphs into lines: bidi, script runs, shaping, line breaking, visual order
text/layout.c puts the checked parts together: a paragraph's levels,
scripts resolved for Common and Inherited characters, break
opportunities, one shaping to measure, lines broken at the last
opportunity that fits (trailing spaces hang, and a line that shapes
wider than measured backs off), then per line L1, runs of one level and
one script shaped again, the runs in L2's order and their glyphs placed.
test-layout checks 30,000 random mixed-script paragraphs: lines cover
the text, mandatory breaks end lines, lines fit when they can, and
glyphs come in the order UAX #9 gives the characters. vega-symbols
paragraph draws a layout through the symbol file's glyphs.
Diffstat (limited to 'text/layout.h')
| -rw-r--r-- | text/layout.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/text/layout.h b/text/layout.h new file mode 100644 index 0000000..9282536 --- /dev/null +++ b/text/layout.h @@ -0,0 +1,38 @@ +#ifndef VEGA_LAYOUT_H +#define VEGA_LAYOUT_H +#include "shape.h" + +/* A paragraph set into lines (docs/design/004-text.md): its bidi levels + * (UAX #9), lines broken where UAX #14 allows and they fit (spaces at a + * line's end hang past it), and each line's runs (one level, one script) + * shaped and put in visual order. Positions are in the font's units: x + * from the paragraph's left edge, y up from the line's baseline. */ +typedef struct { + uint32_t glyph; /* the font's: its symbol is VEGA_GLYPH_SYMBOLS + glyph */ + uint32_t cluster; /* the paragraph index of the first character it came from */ + int32_t x, y, advance; +} VegaPlaced; +typedef struct { + size_t first, count; /* its glyphs, left to right */ + size_t start, end; /* the characters it holds, [start, end) */ + int32_t left, width; /* where it starts and how far what shows goes */ +} VegaLine; +typedef struct { + VegaLine *lines; + size_t line_count; + VegaPlaced *glyphs; + size_t glyph_count; + int level; /* the paragraph's: odd is right to left, and its lines align right */ + int32_t width; /* the widest line's */ + /* what setting the paragraph works in, kept for the next */ + void *work; + size_t work_size, lines_allocated, glyphs_allocated; +} VegaLayout; + +/* Set count characters in lines of at most width (0: no limit) with the + * font's shaping; direction is VEGA_BIDI_AUTO, _LTR or _RTL. The layout + * holds the result until it is set again; false without memory. */ +bool vega_layout(VegaLayout *, VegaShaper *, const VegaShaping *, const uint32_t *codes, size_t count, int direction, + int32_t width); +void vega_layout_free(VegaLayout *); +#endif |
