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