Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

AR1.1: verify Kashida fallback without Tatweel fonts

Shao Wenbin02c5f6117367
diff --git a/ROADMAP.md b/ROADMAP.md
index 4757199ed..805a7966c 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -1,5 +1,7 @@
# DesignCraft roadmap
+- AR1.1: Kashida justification tests verify space fallback without Tatweel fonts using an isolated font database, while retaining elongation assertions when fonts support it.
+
- AR1: Arabic IDML controls now retain character direction, kashida switches, diacritic offsets/forms, paragraph policy values and independent story/table directions. Shaping preserves joining context and script/language selection; paragraph-level bidi, contextual digit conversion, mark-safe elongation, RTL columns/tables and physical column insertion have regression coverage. Vendor-specific justification and diacritic presets remain explicit preflight warnings; see docs/arabic-typography.md.
- CJK1: IDML composite fonts now retain character mappings and metrics; explicit aki, tsume, jidori, em alignment/leading, named/custom kinsoku boundaries, hanging punctuation, tate-chu-yoko offsets and kenten symbols flow through composition and IDML export. Automatic kerning no longer imports inactive numeric values as enormous manual spacing. Composite definitions are editable through commands with undo/cache invalidation. Mojikumi definitions are retained and unsupported spacing-table / push-in-push-out policies are reported by preflight. Full InDesign CJK composition parity, frame-grid layout and detailed ruby/warichu remain unfinished.
diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rs
index 72df2bbb3..10f293c36 100644
--- a/crates/compose/src/lib.rs
+++ b/crates/compose/src/lib.rs
@@ -420,7 +420,10 @@ const DEFAULT_TAB: f64 = 36.0;
/// Compose `story` into `frames`.
pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &ComposeOptions) -> ComposedStory {
- let db = FontDb::global();
+ compose_with_db(doc, story, frames, opts, FontDb::global())
+}
+
+fn compose_with_db(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &ComposeOptions, db: &FontDb) -> ComposedStory {
let mut out = ComposedStory { story: story.id, rev: story.rev, text_len: story.text.len(), ..Default::default() };
let mut styles_tab: Vec<RunStyle> = Vec::new();
let mut missing_fonts: HashMap<String, bool> = HashMap::new();
diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rs
index 74d4c7dc5..a168c1508 100644
--- a/crates/compose/src/tests.rs
+++ b/crates/compose/src/tests.rs
@@ -871,6 +871,19 @@ fn carets_in_right_to_left_text_follow_the_drawing() {
#[test]
fn kashidas_stretch_justified_arabic_before_spaces() {
+ check_kashida_justification(FontDb::global(), false);
+}
+
+#[test]
+fn kashidas_without_tatweel_fall_back_to_spaces() {
+ // A private database excludes host fonts without mutating the global database
+ // used by parallel tests. Bundled Latin/Japanese fonts have no tatweel.
+ let db = FontDb::with_font_dirs(Vec::new());
+ db.set_system_fallback(false);
+ check_kashida_justification(&db, true);
+}
+
+fn check_kashida_justification(db: &FontDb, require_fallback: bool) {
let mut d = Document::new(&designcraft_doc::build::NewDocument::default());
let lid = d.default_layer();
let text = "بسم الله الرحمن الرحيم الحمد لله رب العالمين الرحمن الرحيم مالك يوم الدين اياك نعبد واياك نستعين";
@@ -879,14 +892,28 @@ fn kashidas_stretch_justified_arabic_before_spaces() {
..Default::default()
};
let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 260.0, 400.0), lid, text, pf).unwrap();
- let first = |d: &Document| compose_story(d, sid, &ComposeOptions::default()).frames[0].lines[0].clone();
+ let composed = |d: &Document| compose_with_db(d, d.story(sid).unwrap(), &frame_specs(d, sid), &ComposeOptions::default(), db);
+ let first = |d: &Document| composed(d).frames[0].lines[0].clone();
let with = first(&d);
- assert!(compose_story(&d, sid, &ComposeOptions::default()).frames[0].lines.len() > 1);
+ assert!(composed(&d).frames[0].lines.len() > 1);
+ let lacks_tatweel = with.glyphs.iter().all(|g| g.face.glyph_for('\u{0640}') == 0);
+ if require_fallback {
+ assert!(lacks_tatweel);
+ }
// Spaces keep (about) their natural width; the joins took the extra length.
let space_w = |l: &Line| l.glyphs.iter().filter(|g| g.len > 0 && text[g.byte..].starts_with(' ')).map(|g| g.adv).fold(0.0, f64::max);
d.story_mut(sid).unwrap().paras[0].para.kashidas = Some(false);
let without = first(&d);
- assert!(space_w(&with) < space_w(&without) - 0.5, "{} {}", space_w(&with), space_w(&without));
+ if lacks_tatweel {
+ // No legal elongation can be drawn: enabling kashidas must preserve
+ // the same space justification as disabling them.
+ assert_eq!(with.glyphs.len(), without.glyphs.len());
+ for (a, b) in with.glyphs.iter().zip(&without.glyphs) {
+ assert_eq!((a.byte, a.gid, a.x, a.adv), (b.byte, b.gid, b.x, b.adv));
+ }
+ } else {
+ assert!(space_w(&with) < space_w(&without) - 0.5, "{} {}", space_w(&with), space_w(&without));
+ }
// Both fill the measure: the line's (visually last) glyph reaches the left edge either way.
let left = |l: &Line| l.glyphs.iter().filter(|g| g.len > 0).map(|g| g.x).fold(f64::MAX, f64::min);
assert!((left(&with) - left(&without)).abs() < 1.0, "{} {}", left(&with), left(&without));