Improve reshape condition (#2547)
This commit is contained in:
parent
e550f0a8f7
commit
4a7d3585d9
@ -488,17 +488,35 @@ impl<'a> ShapedText<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find any glyph with the text index.
|
// Find any glyph with the text index.
|
||||||
let mut idx = self
|
let found = self.glyphs.binary_search_by(|g: &ShapedGlyph| {
|
||||||
.glyphs
|
let ordering = g.range.start.cmp(&text_index);
|
||||||
.binary_search_by(|g| {
|
if ltr {
|
||||||
let ordering = g.range.start.cmp(&text_index);
|
ordering
|
||||||
if ltr {
|
} else {
|
||||||
ordering
|
ordering.reverse()
|
||||||
} else {
|
}
|
||||||
ordering.reverse()
|
});
|
||||||
}
|
let mut idx = match found {
|
||||||
})
|
Ok(idx) => idx,
|
||||||
.ok()?;
|
Err(idx) => {
|
||||||
|
// Handle the special case where we break before a '\n'
|
||||||
|
//
|
||||||
|
// For example: (assume `a` is a CJK character with three bytes)
|
||||||
|
// text: " a \n b "
|
||||||
|
// index: 0 1 2 3 4 5
|
||||||
|
// text_index: ^
|
||||||
|
// glyphs: 0 . 1
|
||||||
|
//
|
||||||
|
// We will get found = Err(1), because '\n' does not have a glyph.
|
||||||
|
// But it's safe to break here. Thus the following condition:
|
||||||
|
// - glyphs[0].end == text_index == 3
|
||||||
|
// - text[3] == '\n'
|
||||||
|
return (idx > 0
|
||||||
|
&& self.glyphs[idx - 1].range.end == text_index
|
||||||
|
&& self.text[text_index - self.base..].starts_with('\n'))
|
||||||
|
.then_some(idx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let next = match towards {
|
let next = match towards {
|
||||||
Side::Left => usize::checked_sub,
|
Side::Left => usize::checked_sub,
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 8.2 KiB |
@ -14,3 +14,16 @@
|
|||||||
|
|
||||||
中文,中ab文a中,文ab中文
|
中文,中ab文a中,文ab中文
|
||||||
|
|
||||||
|
---
|
||||||
|
// Issue #2538
|
||||||
|
#set text(cjk-latin-spacing: auto)
|
||||||
|
|
||||||
|
abc字
|
||||||
|
|
||||||
|
abc字#linebreak()
|
||||||
|
|
||||||
|
abc字#linebreak()
|
||||||
|
母
|
||||||
|
|
||||||
|
abc字\
|
||||||
|
母
|
||||||
|
Loading…
x
Reference in New Issue
Block a user