Skip to main content

text_layout_json

Function text_layout_json 

Source
pub fn text_layout_json(
    rasterizer: &TextRasterizer,
    generator_json: &str,
    width: u32,
    height: u32,
    unit: StringUnit,
) -> Result<String, MeasureError>
Expand description

Reports where each line, word and cluster of the text generator generator_json lies on a width by height canvas (crate::text_layout), ranges in unit.

Returns JSON { fontSize, layout, lines, words, clusters }: lines as { clusters: [first, end], box, em, baseline }, words as { clusters, boxes, ink }, clusters as { range: [start, end], run, word, line, space, ellipsis, fontSize, baseline, box, ink }. Rectangles are { left, top, right, bottom } in fractions of the canvas, baselines fractions of its height, font sizes fractions of its shorter side; run, word and ink may be null.

§Errors

Returns MeasureError::Input for invalid generator JSON or an empty canvas, and MeasureError::Text for the text host’s refusal.