Skip to main content

shape_text

Function shape_text 

Source
pub fn shape_text(font: Font, size: f32, text: &str) -> ShapedRun
Expand description

Shape text against font and return both the glyph stream and the advance widths in user-space points. Callers that need only the width can use text_width; callers that will also emit glyphs downstream should use this to avoid shaping twice.

Input is normalized through crate::nfc_text before shaping, so decomposed sequences are precomposed to Unicode NFC. Returned glyph cluster offsets are byte offsets into that normalized text, not necessarily the caller’s original string.

For Base14 faces, glyphs is empty (Base14 runs go out as WinAnsi-byte strings, not glyph IDs); only the width is computed.

§Examples

use mos_fonts::{Base14Font, Font, shape_text};

let run = shape_text(Font::Base14(Base14Font::Helvetica), 10.0, "A");

assert!(run.glyphs.is_empty());
assert_eq!(run.advance_pt, 6.67);