pub fn glyph_clusters(
glyphs: &[ShapedGlyph],
text_len: usize,
) -> impl FusedIterator<Item = GlyphCluster<'_>>Expand description
Iterate over a left-to-right shaped glyph stream without allocating or copying glyphs.
Consecutive glyphs with equal cluster offsets form one group. Offsets must be
nondecreasing UTF-8 byte boundaries in the text used for shaping; text_len
must be that text’s byte length. For shape_with_fallback, use each
WordSubRun’s normalized text and local glyph stream separately.
This function only groups glyphs: it does not normalize text, validate byte
ranges, rebase offsets, or infer grapheme or line-break boundaries. Callers
accepting externally constructed glyph streams should use str::get to
validate each returned range before slicing. Descending RTL clusters are
not supported. Empty glyph streams yield no clusters, including Base-14 runs.
use mos_fonts::{EmbeddedFontId, glyph_clusters, shape};
let text = "office";
let glyphs = shape(EmbeddedFontId::Regular.data(), text);
let parts: Vec<_> = glyph_clusters(&glyphs, text.len())
.filter_map(|cluster| text.get(cluster.byte_range))
.collect();
assert_eq!(parts.concat(), text);