fix: use dynamic font probing to preserve ligatures across break opportunities
This commit is contained in:
parent
5d1db4992a
commit
c6ce5e69e5
2 changed files with 68 additions and 23 deletions
|
|
@ -78,7 +78,8 @@ fn test_english_mixed_with_arabic_paragraph_rendering() {
|
|||
fn test_ligature_segmentation() {
|
||||
use cosmic_text::{Buffer, FontSystem, Metrics, Shaping};
|
||||
|
||||
let mut font_system = FontSystem::new_with_locale_and_db("en-US".into(), fontdb::Database::new());
|
||||
let mut font_system =
|
||||
FontSystem::new_with_locale_and_db("en-US".into(), fontdb::Database::new());
|
||||
let font = std::fs::read("fonts/Inter-Regular.ttf").unwrap();
|
||||
font_system.db_mut().load_font_data(font);
|
||||
let metrics = Metrics::new(14.0, 20.0);
|
||||
|
|
@ -93,25 +94,38 @@ fn test_ligature_segmentation() {
|
|||
let shape = line.shape_opt().expect("ShapeLine not found");
|
||||
let span = &shape.spans[0];
|
||||
|
||||
// The pipe character | is typically a line break opportunity.
|
||||
// This test ensures that our patch prevents splitting |> into separate words,
|
||||
// which would break ligature formation in fonts that support it.
|
||||
// Inter-Regular does NOT have a ligature for |>, so we expect it to be split.
|
||||
// This confirms that we didn't break valid wrapping for non-ligatures.
|
||||
assert_eq!(
|
||||
span.words.len(),
|
||||
1,
|
||||
"Expected '|>' to be a single word (preserved for ligature), but found {} words.",
|
||||
2,
|
||||
"Expected '|>' to be 2 words (no ligature in Inter), but found {} words.",
|
||||
span.words.len()
|
||||
);
|
||||
|
||||
// Test -> (Arrow), which is a common ligature.
|
||||
buffer.set_text("->", &Attrs::new(), Shaping::Advanced, None);
|
||||
buffer.shape_until_scroll(false);
|
||||
let line = &buffer.lines[0];
|
||||
let shape = line.shape_opt().expect("ShapeLine not found");
|
||||
|
||||
assert_eq!(
|
||||
shape.spans[0].words.len(),
|
||||
1,
|
||||
"Expected '->' to be a single word (ligature), but found {} words.",
|
||||
shape.spans[0].words.len()
|
||||
);
|
||||
|
||||
// Test !=
|
||||
buffer.set_text("!=", &Attrs::new(), Shaping::Advanced, None);
|
||||
buffer.shape_until_scroll(false);
|
||||
let line = &buffer.lines[0];
|
||||
let shape = line.shape_opt().expect("ShapeLine not found");
|
||||
// Inter-Regular does not have a != ligature.
|
||||
assert_eq!(
|
||||
shape.spans[0].words.len(),
|
||||
1,
|
||||
"Expected '!=' to be a single word, but found {} words.",
|
||||
2,
|
||||
"Expected '!=' to be 2 words (no ligature), but found {} words.",
|
||||
shape.spans[0].words.len()
|
||||
);
|
||||
|
||||
|
|
@ -120,10 +134,11 @@ fn test_ligature_segmentation() {
|
|||
buffer.shape_until_scroll(false);
|
||||
let line = &buffer.lines[0];
|
||||
let shape = line.shape_opt().expect("ShapeLine not found");
|
||||
// Inter does not have a ++ ligature.
|
||||
assert_eq!(
|
||||
shape.spans[0].words.len(),
|
||||
1,
|
||||
"Expected '++' to be a single word, but found {} words.",
|
||||
2,
|
||||
"Expected '++' to be 2 words, but found {} words.",
|
||||
shape.spans[0].words.len()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue