Use chr_idx for ShapeGlyph range in basic shaping

We want byte indices, not code point indices. Fixes a panic when
selecting the mixed-language text at the bottom of the rich-text example
when the shaping mode is set to "Basic".
This commit is contained in:
valadaptive 2025-03-02 19:58:01 -05:00 committed by Jeremy Soller
parent db9033ba86
commit c7a426280b

View file

@ -448,31 +448,33 @@ fn shape_skip(
let ascent = metrics.ascent / f32::from(metrics.units_per_em);
let descent = metrics.descent / f32::from(metrics.units_per_em);
glyphs.extend(line[start_run..end_run].char_indices().enumerate().map(
|(i, (chr_idx, codepoint))| {
let glyph_id = charmap.map(codepoint);
let x_advance = glyph_metrics.advance_width(glyph_id);
let attrs = attrs_list.get_span(start_run + chr_idx);
glyphs.extend(
line[start_run..end_run]
.char_indices()
.map(|(chr_idx, codepoint)| {
let glyph_id = charmap.map(codepoint);
let x_advance = glyph_metrics.advance_width(glyph_id);
let attrs = attrs_list.get_span(start_run + chr_idx);
ShapeGlyph {
start: i + start_run,
end: i + start_run + 1,
x_advance,
y_advance: 0.0,
x_offset: 0.0,
y_offset: 0.0,
ascent,
descent,
font_monospace_em_width,
font_id,
glyph_id,
color_opt: attrs.color_opt,
metadata: attrs.metadata,
cache_key_flags: attrs.cache_key_flags,
metrics_opt: attrs.metrics_opt.map(|x| x.into()),
}
},
));
ShapeGlyph {
start: chr_idx + start_run,
end: chr_idx + start_run + codepoint.len_utf8(),
x_advance,
y_advance: 0.0,
x_offset: 0.0,
y_offset: 0.0,
ascent,
descent,
font_monospace_em_width,
font_id,
glyph_id,
color_opt: attrs.color_opt,
metadata: attrs.metadata,
cache_key_flags: attrs.cache_key_flags,
metrics_opt: attrs.metrics_opt.map(|x| x.into()),
}
}),
);
}
/// A shaped glyph