Skip to main content

Module measure

Module measure 

Source
Expand description

Text measurement, abstracted.

This trait is the reason the rest of the crate has no dependencies. Shaping text genuinely needs a font stack, but everything around shaping — wrapping, height indexing, scroll anchoring, the message model — does not, and keeping the font stack behind a trait is what lets the whole engine run under cargo test on display-less CI.

The view supplies a Pango-backed implementation. The tests here supply FixedMeasure, where every character is exactly N pixels wide, which makes wrap assertions exact and readable instead of font-dependent and brittle.

It is also a hedge against xtext’s worst performance bug. Its find_next_wrap (xtext.c:3685) called backend_get_text_width_emph per character, and that did a pango_layout_set_text + pango_layout_get_pixel_size round trip each time. The trait’s unit of work is a run, never a character, so an implementation physically cannot repeat that mistake.

Structs§

FixedMeasure
Deterministic measurer for tests: every character is char_width pixels wide regardless of style.
FontMetrics
Font metrics the layout engine needs before it measures anything.

Traits§

TextMeasure
Measures runs of styled text.