Skip to content

Commit

Permalink
fix(text): 🐛 fix glyphs shaped with partiall success
Browse files Browse the repository at this point in the history
  • Loading branch information
wjian23 committed Jun 20, 2023
1 parent 745f2d0 commit 6b38a40
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions text/src/shaper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
cell::RefCell,
collections::HashSet,
hash::{Hash, Hasher},
rc::Rc,
};
Expand Down Expand Up @@ -158,7 +157,7 @@ fn collect_miss_part<'a>(
let mut miss_parts = vec![];
for (start, end, helper) in new_part {
let mut miss_start = None;
let mut miss_cluster = HashSet::new();
let mut last_miss_cluster = None;
glyphs[*start..*end]
.iter()
.enumerate()
Expand All @@ -167,9 +166,13 @@ fn collect_miss_part<'a>(
if glyph.is_miss() {
if miss_start.is_none() {
miss_start = Some(idx);
miss_cluster.insert(glyph.cluster);
}
} else if !miss_cluster.contains(&glyph.cluster) && miss_start.is_some() {
last_miss_cluster = Some(glyph.cluster);
} else if last_miss_cluster
.as_ref()
.map_or(true, |cluster| *cluster != glyph.cluster)
&& miss_start.is_some()
{
miss_parts.push((miss_start.take().unwrap(), idx, helper.clone()));
}
});
Expand All @@ -178,14 +181,12 @@ fn collect_miss_part<'a>(
}
}

miss_parts.iter_mut().for_each(|(start, end, _)| {
miss_parts.iter_mut().for_each(|(start, _, _)| {
while 0 < *start && glyphs[*start - 1].cluster == glyphs[*start].cluster {
*start -= 1;
}
while *end < glyphs.len() && glyphs[*end - 1].cluster == glyphs[*end].cluster {
*end += 1;
}
});

miss_parts
}

Expand Down

0 comments on commit 6b38a40

Please sign in to comment.