use f_office_paint::GlyphRun;
pub(crate) fn positioned_groups(run: &GlyphRun) -> Vec<std::ops::Range<usize>> {
let mut groups = Vec::new();
let mut start = 0;
let mut text: Option<(u32, u32)> = None;
for (index, glyph) in run.glyphs.iter().enumerate() {
let (from, to) = (glyph.text_start, glyph.text_end);
let joins = match text {
None => true,
Some((low, high)) => from == to || (from < high && low < to),
};
if joins {
text = Some(text.map_or((from, to), |(low, high)| (low.min(from), high.max(to))));
} else {
groups.push(start..index);
start = index;
text = Some((from, to));
}
}
if start < run.glyphs.len() {
groups.push(start..run.glyphs.len());
}
groups
}