summaryrefslogtreecommitdiff
path: root/src/sketch/text.zig
Commit message (Collapse)AuthorAge
* text: sk.text.places, every byte's place in one layoutGabriel Schneider6 hours
| | | | | | | | | | | | | | | | | | | | | | | An editor draws a range under its bytes, a caret on its glyph, a mark under a byte, and finds the byte under the pointer; with mixed sizes on a line a column is no longer a measure. `layout`'s `caret` gives one byte's place a layout, so a range, a caret and a hit test were a layout a byte. `sk.text.places(bytes, paragraph, out)` is the same layout with every byte's place in `out` (where a caret before that byte sits, a `Caret`: x, the line's top and height; a `\n` and the spaces a line wraps at are at its end, and one more for the end of the text). The byte at a point is then a loop over places: the last whose line holds its y and whose x is at or left of it. `lay` takes the slice to fill (empty: none), so `layout`, `places` and `f.paragraph` stay one function. Pure, as `layout`: in `update` too. The README's editor recipe and docs/text.md say so. Test: a paragraph's places are where its caret sits, byte by byte (wrapped at a space, a `\n`, a span twice the size, a two-byte codepoint, a last empty line). zig build test-text: 52 of 52 steps. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
* text: sk.text measures anywhere, Frame.paragraph wraps, aligns, spans, ↵Gabriel Schneider6 hours
reveals and finds a caret The ABI's one text entry is textRun (Host.VTable.textSize goes): a run in a face at a scale, as data, its advance and line box and each byte's x, a pure function of the font, the scale and the bytes, never of the display; and font, a face for a sketch's own TTF/OTF bytes (abi.Face is non-exhaustive: faces past the ten are a sketch's). The native host serves them from vendor/text.c (sk_text_run, sk_text_font), the web host from canvas measureText and FontFace (web/host.js), and the web draws each run in the page's monospace or sans-serif in the face's weight and style instead of 8 px a character. src/sketch/text.zig (sk.text) does the rest in plain Zig, the same on every host: size, layout and font anywhere, update included (the glue sets the host before each call into the sketch; a test binary has none and calls sketchbook-text directly, which App.addTest now links); a Paragraph is a face, scale and colour, a width to wrap at spaces, an alignment, spans (from a byte on: a colour, a face, a scale), reveal (the first N glyphs drawn, the layout the whole text's) and a caret byte, and its Layout the size, lines, glyphs and the caret's place. f.paragraph draws one, a Command.text a piece. f.text, f.textIn and f.print are a paragraph with no width when the bytes hold a \n, else the one command they were; host.textSize and textSizeIn stay, one line through textRun. Test: sk.text's own tests (a wrap, the space not counted, centred and right, a caret at a line's start and end and after a \n, a span twice the size, a word wider than the width, an empty text; reveal drawing the first glyphs of the same layout), run through sketchbook-text; and test/text.zig draws a centred paragraph with a red and a double-size span and a caret from its Layout, which test/text.script pins. zig build test-text runs these and the atlas's comparison with pardes's raster. Every other pinned pixel of test/text.script holds: the lines it pins are the same pixels Pango drew. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T