summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAna Gelez <ana@gelez.xyz>2024-05-06 14:30:41 +0200
committerGitHub <noreply@github.com>2024-05-06 12:30:41 +0000
commit061319425b816907f4277c545d679a878b07fe3d (patch)
tree7100537c14fc075b36638c5d9302119522244371
parent69dcc89d84176838c293b2d59747cd65e28843ad (diff)
Handle RTL text correctly in TextItemView (#4060)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
-rw-r--r--crates/typst/src/text/item.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/crates/typst/src/text/item.rs b/crates/typst/src/text/item.rs
index 4bc6dd21..3ad481cf 100644
--- a/crates/typst/src/text/item.rs
+++ b/crates/typst/src/text/item.rs
@@ -89,10 +89,9 @@ impl<'a> TextItemView<'a> {
/// the original text so that it is relative to the start of the slice
pub fn glyph_at(&self, index: usize) -> Glyph {
let g = &self.item.glyphs[self.glyph_range.start + index];
- let text_range = self.text_range();
+ let base = self.text_range().start as u16;
Glyph {
- range: (g.range.start - text_range.start as u16)
- ..(g.range.end - text_range.start as u16),
+ range: g.range.start - base..g.range.end - base,
..*g
}
}
@@ -122,8 +121,8 @@ impl<'a> TextItemView<'a> {
/// The range of text in the original TextItem that this slice corresponds
/// to.
fn text_range(&self) -> Range<usize> {
- let text_start = self.item.glyphs[self.glyph_range.start].range().start;
- let text_end = self.item.glyphs[self.glyph_range.end - 1].range().end;
- text_start..text_end
+ let first = self.item.glyphs[self.glyph_range.start].range();
+ let last = self.item.glyphs[self.glyph_range.end - 1].range();
+ first.start.min(last.start)..first.end.max(last.end)
}
}