Use shared shaping segment boundaries

This commit is contained in:
Dylan M. Taylor
2026-11-15 16:43:08 +00:00
parent ef76a71eb6
commit 729ed8958d
3 changed files with 5 additions and 9 deletions
Generated
+1 -1
View File
@@ -1008,7 +1008,7 @@ 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=8bf20b4ba2311c1a69310fc8cba7155cf43cd42e#8bf20b4ba2311c1a69310fc8cba7155cf43cd42e"
source = "git+https://github.com/storytold/craft-libs?rev=d0a9c79933a54883cd5bc3dfe839f1dd699f2c69#d0a9c79933a54883cd5bc3dfe839f1dd699f2c69"
dependencies = [
"harfrust 0.13.3",
"kurbo 0.13.1",
+1 -1
View File
@@ -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 = "8bf20b4ba2311c1a69310fc8cba7155cf43cd42e", default-features = false }
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "d0a9c79933a54883cd5bc3dfe839f1dd699f2c69", default-features = false }
vectorcraft-geom = { workspace = true }
vectorcraft-doc = { workspace = true }
kurbo = { workspace = true }
+3 -7
View File
@@ -600,7 +600,7 @@ pub(crate) fn shape_runs(
// Split into segments by font coverage (and case, for Small Caps).
let mut seg = Segment { range: a..a, runs, source_runs, st, face: primary.clone(), small: false, level: level_at(a) };
let mut cache: std::collections::HashMap<&str, Arc<FontFace>> = std::collections::HashMap::new();
let mut script = Script::Common;
let mut boundary = craft_font_catalog::SegmentBoundary::new(primary.id(), level_at(a));
// A grapheme cluster (a letter and its marks, an emoji sequence) is set in one face.
for (i, cluster) in text[a..b].grapheme_indices(true) {
let i = a + i;
@@ -620,20 +620,16 @@ pub(crate) fn shape_runs(
};
let small = small_caps && c.is_lowercase();
let next_script = shaping_script(c);
let strong_script = !matches!(next_script, Script::Common | Script::Inherited);
let script_change = strong_script && script != Script::Common && script != next_script;
let strong_script = (!matches!(next_script, Script::Common | Script::Inherited)).then_some(next_script);
// Combining marks, zero width joiners and non-joiners, and variation selectors stay
// with the character before them.
if (face.id() != seg.face.id() || small != seg.small || level != seg.level || script_change) && !is_mark(c) {
if boundary.advance(face.id(), level, small, strong_script, is_mark(c)) {
if i > seg.range.start {
seg.range.end = i;
shape_segment(text, &range, &seg, feats, out);
}
seg = Segment { range: i..i, face, small, level, ..seg };
}
if strong_script {
script = next_script;
}
}
if b > seg.range.start {
seg.range.end = b;