From 300240446774590acf048639ebb2fe3820dfeac6 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:19:37 +0000 Subject: [PATCH] Use shared visual cluster ordering --- Cargo.lock | 3 ++- crates/text/Cargo.toml | 2 +- crates/text/src/layout/bidi.rs | 35 +++++----------------------------- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca805670fb..9441174671 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1008,12 +1008,13 @@ source = "git+https://github.com/storytold/craft-libs?rev=6d620e971e820b517b11a9 [[package]] name = "craft-font-catalog" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=d0a9c79933a54883cd5bc3dfe839f1dd699f2c69#d0a9c79933a54883cd5bc3dfe839f1dd699f2c69" +source = "git+https://github.com/storytold/craft-libs?rev=524aaa78b8a04c0497fd28b9f12438ca3711e648#524aaa78b8a04c0497fd28b9f12438ca3711e648" dependencies = [ "harfrust 0.13.3", "kurbo 0.13.1", "skrifa 0.47.0", "thiserror 2.0.21", + "unicode-bidi", "windows-registry", ] diff --git a/crates/text/Cargo.toml b/crates/text/Cargo.toml index 7feac2bc60..e308fad856 100644 --- a/crates/text/Cargo.toml +++ b/crates/text/Cargo.toml @@ -10,7 +10,7 @@ workspace = true [dependencies] # Pending shared extraction; pin the immutable official PR head until it merges. -craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "d0a9c79933a54883cd5bc3dfe839f1dd699f2c69", default-features = false } +craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "524aaa78b8a04c0497fd28b9f12438ca3711e648", default-features = false } vectorcraft-geom = { workspace = true } vectorcraft-doc = { workspace = true } kurbo = { workspace = true } diff --git a/crates/text/src/layout/bidi.rs b/crates/text/src/layout/bidi.rs index 3f9872983d..e4574c42d4 100644 --- a/crates/text/src/layout/bidi.rs +++ b/crates/text/src/layout/bidi.rs @@ -81,34 +81,9 @@ pub(super) fn visual_order(bidi: Option<&BidiInfo<'_>>, paragraph_start: usize, return vec![]; } let levels = bidi.reordered_levels(para, line.start.saturating_sub(paragraph_start)..line.end.saturating_sub(paragraph_start)); - // A list marker (length 0) is a cluster of its own. - let mut clusters: Vec> = Vec::new(); - for (i, g) in glyphs.iter().enumerate() { - if i > 0 && glyphs.get(i - 1).is_some_and(|p| p.byte == g.byte && (p.len == 0) == (g.len == 0)) { - if let Some(c) = clusters.last_mut() { - c.end = i + 1; - } - } else { - clusters.push(i..i + 1); - } - } - // A list marker is at the paragraph's level, and at a right-to-left one its tab is drawn - // before (left of) its characters. - let cluster_levels: Vec<_> = clusters - .iter() - .filter_map(|c| glyphs.get(c.start)) - .map(|g| if g.len == 0 { g.level } else { levels.get(g.byte.saturating_sub(paragraph_start)).copied().unwrap_or(g.level) }) - .collect(); - let reversed = |i: usize| glyphs.get(clusters.get(i).map_or(0, |c| c.start)).is_some_and(|g| g.len == 0 && g.level.is_rtl()); - unicode_bidi::BidiInfo::reorder_visual(&cluster_levels) - .into_iter() - .filter_map(|i| clusters.get(i).map(|c| (c.clone(), reversed(i)))) - .flat_map(|(c, rev)| { - let mut v: Vec = c.collect(); - if rev { - v.reverse(); - } - v - }) - .collect() + craft_font_catalog::visual_order( + glyphs.iter().map(|g| craft_font_catalog::VisualGlyph { byte: g.byte, len: g.len, level: g.level }), + paragraph_start, + &levels, + ) }