thing2(text): inspect all scalars in is_ri_cluster and pin cluster slices
This commit is contained in:
parent
07aa8d9b00
commit
b0f2751471
2 changed files with 29 additions and 1 deletions
|
|
@ -105,7 +105,7 @@ struct Cleaned {
|
|||
/// extended grapheme cluster (e.g. a modifier or ZWJ sequence across a dropped bidi control), never
|
||||
/// pairing Regional Indicators across a dropped boundary.
|
||||
fn is_ri_cluster(s: &str) -> bool {
|
||||
s.chars().next().is_some_and(|c| ('\u{1f1e6}'..='\u{1f1ff}').contains(&c))
|
||||
s.chars().any(|c| ('\u{1f1e6}'..='\u{1f1ff}').contains(&c))
|
||||
}
|
||||
|
||||
fn clean(paragraph: &str) -> Cleaned {
|
||||
|
|
|
|||
|
|
@ -508,6 +508,7 @@ fn ri_does_not_re_pair_across_dropped_cluster() {
|
|||
}
|
||||
let Run::Cells { text: full, .. } = &unwrapped.lines[0].run else { panic!() };
|
||||
assert_eq!(full.width(), 3);
|
||||
assert_eq!(full.clusters().collect::<Vec<_>>(), [("\u{1f1ef}", 1), ("\u{1f1f5}\u{1f1f5}", 2)]);
|
||||
assert_eq!(CellText::new(text).width(), 3);
|
||||
|
||||
let no_break = CellMeasure.text(&TextRequest { node: &node, text: "\u{1f1ef}\u{202c}\u{1f1f5}\u{1f1f5}", style_token: "body", wrap: true, max_lines: None, geometry: true }, 2.0);
|
||||
|
|
@ -525,10 +526,37 @@ fn ri_does_not_re_pair_across_dropped_cluster() {
|
|||
assert_eq!(pair_wrapped.lines[1].source, (7, 11));
|
||||
assert_eq!(pair_wrapped.lines[1].stops, [Stop { byte: 7, x: 0.0 }, Stop { byte: 11, x: 1.0 }]);
|
||||
|
||||
let pair_unwrapped = CellMeasure.text(&TextRequest { node: &node, text: pair, style_token: "body", wrap: false, max_lines: None, geometry: true }, 80.0);
|
||||
assert_eq!(pair_unwrapped.lines.len(), 1);
|
||||
let Run::Cells { text: pair_full, .. } = &pair_unwrapped.lines[0].run else { panic!() };
|
||||
assert_eq!(pair_full.clusters().collect::<Vec<_>>(), [("\u{1f1ef}", 1), ("\u{1f1f5}", 1)]);
|
||||
assert_eq!(&CellText::new(pair), pair_full);
|
||||
|
||||
assert_eq!(&CellText::new(text), full);
|
||||
// An RI followed by a non-RI extension across a dropped cluster still coalesces (only RI+RI is blocked).
|
||||
assert_eq!(CellText::new("\u{1f1ef}\u{200b}\u{1f3fd}").clusters().count(), 1);
|
||||
check_geometry("\u{1f1ef}\u{200b}\u{1f3fd}", false, None, 80.0);
|
||||
assert_eq!(CellText::new("\u{0600}\u{001b}").clusters().collect::<Vec<_>>(), [("\u{0600}", 1), ("\u{fffd}", 1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepend_ri_does_not_re_pair_across_dropped_cluster() {
|
||||
let node = NodeId::new("n");
|
||||
let text = "\u{0600}\u{1f1ef}\u{200b}\u{1f1f5}";
|
||||
assert_eq!(
|
||||
CellText::new(text).clusters().collect::<Vec<_>>(),
|
||||
[("\u{0600}\u{1f1ef}", 2), ("\u{1f1f5}", 1)]
|
||||
);
|
||||
check_geometry(text, false, None, 80.0);
|
||||
check_geometry(text, true, None, 2.0);
|
||||
|
||||
let unwrapped = CellMeasure.text(&TextRequest { node: &node, text, style_token: "body", wrap: false, max_lines: None, geometry: true }, 80.0);
|
||||
assert_eq!(unwrapped.lines.len(), 1);
|
||||
let Run::Cells { text: full, .. } = &unwrapped.lines[0].run else { panic!() };
|
||||
assert_eq!(full.clusters().collect::<Vec<_>>(), [("\u{0600}\u{1f1ef}", 2), ("\u{1f1f5}", 1)]);
|
||||
let stop6 = unwrapped.lines[0].stops.iter().find(|s| s.byte == 6).expect("stop at byte 6");
|
||||
assert_eq!(stop6.x, 2.0);
|
||||
assert_eq!(stop6.x, CellText::new(&text[..6]).width() as f32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue