measure_text_block
Mojo function 🡭
measure_text_block
fn def measure_text_block(text: String, size: Float64, family: String = "Sans", slant: FontSlant = FontSlant.NORMAL, weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT, kerning: Bool = True, ligatures: Bool = True) -> TextBlockBoundsThe bounding box draw_text(canvas, x, y, text, …, rotation= rotation, align=align) would render into, anchor-relative and without drawing – see TextBlockBounds.
A string with no ink (empty, or every line whitespace-only) returns a zero-sized box at the anchor, matching draw_text’s no-op.
Builds a FontCache per call. Use the cache= overload when
measuring multiple blocks.
Args:
- text (
String): Text to lay out, “\n”-separated lines. - size (
Float64): Font size in points. - family (
String): Font family name or generic alias. - slant (
FontSlant): Requested upright/italic/oblique style. - weight (
FontWeight): Requested normal/bold weight. - rotation (
Float64): Radians, rotating the whole block around the anchor. - align (
TextAlign): Horizontal alignment of each line. - kerning (
Bool): Apply the font’s pair kerning between adjacent glyphs. - ligatures (
Bool): Apply the font’sGSUBshaping – ligatures and Arabic contextual forms. False lays out one glyph per character.
Returns:
TextBlockBounds: The block’s anchor-relative bounding box.
Raises:
fn def measure_text_block(text: String, size: Float64, family: String = "Sans", slant: FontSlant = FontSlant.NORMAL, weight: FontWeight = FontWeight.NORMAL, rotation: Float64 = 0, align: TextAlign = TextAlign.LEFT, kerning: Bool = True, ligatures: Bool = True, *, mut cache: FontCache) -> TextBlockBoundsLike measure_text_block above, but resolving fonts through cache rather than fresh every call.
Args:
- text (
String): Text to lay out, “\n”-separated lines. - size (
Float64): Font size in points. - family (
String): Font family name or generic alias. - slant (
FontSlant): Requested upright/italic/oblique style. - weight (
FontWeight): Requested normal/bold weight. - rotation (
Float64): Radians, rotating the whole block around the anchor. - align (
TextAlign): Horizontal alignment of each line. - kerning (
Bool): Apply the font’s pair kerning between adjacent glyphs. - ligatures (
Bool): Apply the font’sGSUBshaping – ligatures and Arabic contextual forms. False lays out one glyph per character. - cache (
FontCache): Shared cache for font resolution and parsed faces.
Returns:
TextBlockBounds: The block’s anchor-relative bounding box.
Raises: