Wrap: word wrap and ellipsis over a measure function

Crafter.Graphics shapes one line at a time and drops newlines, so the app
breaks text itself: a greedy wrap with breaks after spaces and hyphens
(a space that itself overflows ends the line after the words that fit,
and opens no line of its own when it ends the text or a newline
follows; one at a line's start is no break at all, nor is a run of
them: a break is recorded only once the line holds a word, and a run of
spaces wider than the line splits like a word, with the same rule at the
text's end and before a newline), hard breaks at
newlines, over-long words split between code points, and
the run of spaces where a line wraps left out of both lines. Results are
cached per (text, width, size). The measure is a function, so the caller
supplies the advances; the tests use a constant ten-pixel advance.

Tested: tests/Wrap on a ten-pixel monospace measure, a leading run of
spaces among the cases.
This commit is contained in:
Jorijn van der Graaf 2026-10-17 23:25:41 +02:00
commit 335b27b72d
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
3 changed files with 288 additions and 0 deletions

View file

@ -135,6 +135,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
cfg.AddTest("Number").Dependencies({ Core.get() });
cfg.AddTest("Time").Dependencies({ Core.get() });
cfg.AddTest("Wrap").Dependencies({ Core.get() });
LintRules::AddRules(cfg);
return cfg;