Fix case where bidi detects opposite orientation from rustybuzz
This commit is contained in:
parent
9595308c25
commit
d71c142d68
2 changed files with 47 additions and 31 deletions
|
|
@ -57,33 +57,34 @@ impl<'a> FontMatches<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust end of glyphs
|
// Adjust end of glyphs
|
||||||
match direction {
|
let rtl = match direction {
|
||||||
rustybuzz::Direction::LeftToRight => {
|
rustybuzz::Direction::RightToLeft => true,
|
||||||
for i in (1..glyphs.len()).rev() {
|
//TODO: other directions?
|
||||||
let next_start = glyphs[i].start;
|
_ => false,
|
||||||
let next_end = glyphs[i].end;
|
};
|
||||||
let prev = &mut glyphs[i - 1];
|
|
||||||
if prev.start == next_start {
|
if rtl {
|
||||||
prev.end = next_end;
|
for i in 1..glyphs.len() {
|
||||||
} else {
|
let next_start = glyphs[i - 1].start;
|
||||||
prev.end = next_start;
|
let next_end = glyphs[i - 1].end;
|
||||||
}
|
let prev = &mut glyphs[i];
|
||||||
|
if prev.start == next_start {
|
||||||
|
prev.end = next_end;
|
||||||
|
} else {
|
||||||
|
prev.end = next_start;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
rustybuzz::Direction::RightToLeft => {
|
} else {
|
||||||
for i in 1..glyphs.len() {
|
for i in (1..glyphs.len()).rev() {
|
||||||
let next_start = glyphs[i - 1].start;
|
let next_start = glyphs[i].start;
|
||||||
let next_end = glyphs[i - 1].end;
|
let next_end = glyphs[i].end;
|
||||||
let prev = &mut glyphs[i];
|
let prev = &mut glyphs[i - 1];
|
||||||
if prev.start == next_start {
|
if prev.start == next_start {
|
||||||
prev.end = next_end;
|
prev.end = next_end;
|
||||||
} else {
|
} else {
|
||||||
prev.end = next_start;
|
prev.end = next_start;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
//TODO: other directions
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: improve performance!
|
//TODO: improve performance!
|
||||||
|
|
@ -114,9 +115,11 @@ impl<'a> FontMatches<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert all matching glyphs
|
// Insert all matching glyphs
|
||||||
|
// println!("Locate fallback for {},{} '{}' from font {} to font {}", start_glyph, end_glyph, &line[start_glyph..end_glyph], font_i + 1, font_i);
|
||||||
let mut j = 0;
|
let mut j = 0;
|
||||||
while j < fb_word.glyphs.len() {
|
while j < fb_word.glyphs.len() {
|
||||||
if fb_word.glyphs[j].start >= start_glyph && fb_word.glyphs[j].end <= end_glyph {
|
if fb_word.glyphs[j].start >= start_glyph && fb_word.glyphs[j].end <= end_glyph {
|
||||||
|
// println!("Copy fallback for {},{} '{}' from font {} cluster {} to font {}", start_glyph, end_glyph, &line[start_glyph..end_glyph], font_i + 1, fb_word.glyphs[j].start, font_i);
|
||||||
glyphs.insert(i, fb_word.glyphs.remove(j));
|
glyphs.insert(i, fb_word.glyphs.remove(j));
|
||||||
i += 1;
|
i += 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -132,7 +135,10 @@ impl<'a> FontMatches<'a> {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FontShapeWord { glyphs }
|
FontShapeWord {
|
||||||
|
rtl,
|
||||||
|
glyphs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shape_span(&self, line: &str, start_span: usize, end_span: usize, para_rtl: bool, span_rtl: bool) -> FontShapeSpan {
|
fn shape_span(&self, line: &str, start_span: usize, end_span: usize, para_rtl: bool, span_rtl: bool) -> FontShapeSpan {
|
||||||
|
|
@ -140,7 +146,7 @@ impl<'a> FontMatches<'a> {
|
||||||
|
|
||||||
let span = &line[start_span..end_span];
|
let span = &line[start_span..end_span];
|
||||||
|
|
||||||
//println!("Span {}: '{}'", if span_rtl { "RTL" } else { "LTR" }, span);
|
// println!("Span {}: '{}'", if span_rtl { "RTL" } else { "LTR" }, span);
|
||||||
|
|
||||||
let mut words = vec![
|
let mut words = vec![
|
||||||
self.shape_word(0, line, start_span, end_span),
|
self.shape_word(0, line, start_span, end_span),
|
||||||
|
|
@ -154,17 +160,20 @@ impl<'a> FontMatches<'a> {
|
||||||
|
|
||||||
//TODO: improve performance
|
//TODO: improve performance
|
||||||
for (linebreak, _) in unicode_linebreak::linebreaks(span) {
|
for (linebreak, _) in unicode_linebreak::linebreaks(span) {
|
||||||
let mut glyphs_opt = None;
|
let mut word_opt = None;
|
||||||
'words: for word_i in 0..words.len() {
|
'words: for word_i in 0..words.len() {
|
||||||
for glyph_i in 0..words[word_i].glyphs.len() {
|
for glyph_i in 0..words[word_i].glyphs.len() {
|
||||||
if words[word_i].glyphs[glyph_i].start == start_span + linebreak {
|
if words[word_i].glyphs[glyph_i].start == start_span + linebreak {
|
||||||
glyphs_opt = Some(words[word_i].glyphs.split_off(glyph_i));
|
word_opt = Some(FontShapeWord {
|
||||||
|
rtl: words[word_i].rtl,
|
||||||
|
glyphs: words[word_i].glyphs.split_off(glyph_i)
|
||||||
|
});
|
||||||
break 'words;
|
break 'words;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(glyphs) = glyphs_opt {
|
if let Some(word) = word_opt {
|
||||||
words.push(FontShapeWord { glyphs });
|
words.push(word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,6 +181,12 @@ impl<'a> FontMatches<'a> {
|
||||||
for word in words.iter_mut() {
|
for word in words.iter_mut() {
|
||||||
word.glyphs.reverse();
|
word.glyphs.reverse();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for word in words.iter_mut() {
|
||||||
|
if word.rtl {
|
||||||
|
word.glyphs.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if para_rtl != span_rtl {
|
if para_rtl != span_rtl {
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ impl<'a> FontShapeGlyph<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FontShapeWord<'a> {
|
pub struct FontShapeWord<'a> {
|
||||||
|
pub rtl: bool,
|
||||||
pub glyphs: Vec<FontShapeGlyph<'a>>,
|
pub glyphs: Vec<FontShapeGlyph<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue