DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
T: paragraph borders and shading offsets, per column part (+ panel, IDML)
Brandon Thomas79c73c815d63
diff --git a/ROADMAP.md b/ROADMAP.mdindex 43780150b..8fbcd8c49 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -59,6 +59,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Nested line styles (`nestedLineStyles` paragraph attribute, Paragraph Style Options › Drop Caps and Nested Styles, IDML AllNestedLineStyles): the first lines restyle until the line breaks settle.- User dictionary hyphenation exceptions (`hyphenation.addException/removeException/list`, Edit ▸ Spelling ▸ User Dictionary): `ex~am~ple` breaks only at `~`, a plain word never hyphenates.- Frame Fitting Options (`object.fittingOptions`, Object ▸ Fitting ▸ Frame Fitting Options…): Auto-Fit refits on resize, fitting, Align From reference point, crop amounts; IDML FrameFittingOption.+- Paragraph borders (per-side weights, colour, tint, offsets) and shading offsets, drawn per column part of split paragraphs (also when overset); Paragraph panel controls; IDML ParagraphBorder*/ParagraphShading*Offset.- Drag and drop text editing: drag selected text to move it (Alt copies) with its formatting (`text.release`).- Image Import Options: place any page of a multi-page PDF (`file.place {pdfPage}`; the app asks which page), shown on screen and embedded as that page in PDF export.- Define Lists: named numbered lists that continue across stories in page order (`list.define`, paragraph `listName` / `startAt`), round-tripped through IDML; `null` in `type.para` / `type.char` now removes an override.diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex a1f9a7ed5..56e1b4063 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -614,6 +614,8 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compoloop {if cur.fi >= frames.len() {out.overset_at = Some(glyphs.get(g0).map(|g| g.byte).unwrap_or(prange.start));+ // The part of the paragraph that fits keeps its shading and border.+ para_box_decos(&mut out, pi, &pp);break 'paras;}let f = &frames[cur.fi];@@ -831,20 +833,8 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compotint: r.tint,});}- if pp.shading_on {- let lines: Vec<&Line> = ft.lines.iter().filter(|l| l.para == pi).collect();- if let (Some(a), Some(z)) = (lines.first(), lines.last()) {- ft.decos.insert(- 0,- Deco {- rect: Rect::new(a.x0, a.baseline - a.ascent, a.x1, z.baseline + z.descent),- color: pp.shading_color.clone(),- tint: pp.shading_tint,- },- );- }- }}+ para_box_decos(&mut out, pi, &pp);if pp.rule_below.on&& let Some(ft) = out.frames.get_mut(cur.fi.min(frames.len().saturating_sub(1)))&& let Some(l) = ft.lines.iter().rev().find(|l| l.para == pi)@@ -954,6 +944,52 @@ fn mark_keep_violations(doc: &Document, story: &Story, out: &mut ComposedStory)}}+/// Paragraph shading and border, per column the paragraph sits in (a split paragraph gets one box+/// per part; the border's top edge on the first part, its bottom edge on the last).+fn para_box_decos(out: &mut ComposedStory, pi: usize, pp: &ParaProps) {+ if !pp.shading_on && !pp.border_on {+ return;+ }+ let mut parts: Vec<(usize, Rect)> = Vec::new();+ for (fi, ft) in out.frames.iter().enumerate() {+ let mut cols_seen: Vec<u32> = ft.lines.iter().filter(|l| l.para == pi).map(|l| l.column).collect();+ cols_seen.dedup();+ for c in cols_seen {+ let lines: Vec<&Line> = ft.lines.iter().filter(|l| l.para == pi && l.column == c).collect();+ if let (Some(a), Some(z)) = (lines.first(), lines.last()) {+ parts.push((fi, Rect::new(a.x0, a.baseline - a.ascent, a.x1, z.baseline + z.descent)));+ }+ }+ }+ let n = parts.len();+ for (k, (fi, r)) in parts.into_iter().enumerate() {+ let ft = &mut out.frames[fi];+ if pp.shading_on {+ let [t, l, b, rr] = pp.shading_offsets;+ ft.decos+ .insert(0, Deco { rect: Rect::new(r.x0 - l, r.y0 - t, r.x1 + rr, r.y1 + b), color: pp.shading_color.clone(), tint: pp.shading_tint });+ }+ if pp.border_on {+ let [t, l, b, rr] = pp.border_offsets;+ let o = Rect::new(r.x0 - l, r.y0 - t, r.x1 + rr, r.y1 + b);+ let [wt, wl, wb, wr] = pp.border_weights.map(|w| w.max(0.0));+ let mut edge = |rect: Rect| ft.decos.push(Deco { rect, color: pp.border_color.clone(), tint: pp.border_tint });+ if k == 0 && wt > 0.0 {+ edge(Rect::new(o.x0 - wl, o.y0 - wt, o.x1 + wr, o.y0));+ }+ if k + 1 == n && wb > 0.0 {+ edge(Rect::new(o.x0 - wl, o.y1, o.x1 + wr, o.y1 + wb));+ }+ if wl > 0.0 {+ edge(Rect::new(o.x0 - wl, o.y0, o.x0, o.y1));+ }+ if wr > 0.0 {+ edge(Rect::new(o.x1, o.y0, o.x1 + wr, o.y1));+ }+ }+ }+}+/// Breaker parameters from the paragraph's settings.fn spacing_for(pp: &ParaProps, base_size: f64) -> Spacing {Spacing {diff --git a/crates/doc/src/attrs.rs b/crates/doc/src/attrs.rsindex e9392eea4..8a956e9af 100644--- a/crates/doc/src/attrs.rs+++ b/crates/doc/src/attrs.rs@@ -534,10 +534,18 @@ attr_set! {list_separator: String = "\t".into(),balance_ragged: bool = false,optical_margin: bool = false,- /// Paragraph shading.+ /// Paragraph shading, and how far it reaches past the text: top, left, bottom, right.shading_on: bool = false,shading_color: String = "[Black]".into(),shading_tint: f32 = 0.2,+ shading_offsets: [f64; 4] = [0.0; 4],+ /// Paragraph border: stroke weights (top, left, bottom, right), colour, and offsets past the+ /// text (top, left, bottom, right).+ border_on: bool = false,+ border_weights: [f64; 4] = [1.0; 4],+ border_color: String = "[Black]".into(),+ border_tint: f32 = 1.0,+ border_offsets: [f64; 4] = [0.0; 4],}}diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rsindex 91d559577..43101f162 100644--- a/crates/engine/src/cmd/text.rs+++ b/crates/engine/src/cmd/text.rs@@ -977,3 +977,38 @@ mod nested_line_style_tests {assert_eq!(nl[0].style, "Lead");}}++#[cfg(test)]+mod border_tests {+ use serde_json::json;++ use crate::Session;++ #[test]+ fn paragraph_border_and_shading_follow_each_column() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let text = "word ".repeat(80);+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 400, 160], "content": "text", "text": text, "caret": false})).unwrap();+ s.execute("object.textFrameOptions", &json!({"ids": [r["id"]], "columns": 2})).unwrap();+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 0})).unwrap();+ s.execute("type.para", &json!({"borderOn": true, "borderWeights": [2, 1, 2, 1], "borderOffsets": [4, 4, 4, 4], "borderColor": "[Black]", "shadingOn": true, "shadingOffsets": [4, 4, 4, 4]})).unwrap();+ let sid = designcraft_doc::StoryId(r["story"].as_u64().unwrap());+ let cs = s.cache.get(&s.doc().unwrap().doc, sid, None);+ let decos = &cs.frames[0].decos;+ let shading: Vec<_> = decos.iter().filter(|d| d.tint < 0.5).collect();+ assert_eq!(shading.len(), 2, "one shaded box per column");+ let edges = decos.len() - shading.len();+ assert_eq!(edges, 6, "top on the first part, bottom on the last, sides on both");+ let top = decos.iter().filter(|d| d.tint >= 0.5).map(|d| d.rect).fold(f64::MAX, |a, r| a.min(r.y0));+ let first_line = &cs.frames[0].lines[0];+ assert!((top - (first_line.baseline - first_line.ascent - 4.0 - 2.0)).abs() < 1e-6, "offset 4 + weight 2 above the text");+ let back = designcraft_idml::import_idml(&designcraft_idml::export_idml(&s.doc().unwrap().doc)).unwrap();+ let p = &back.stories.values().find(|st| st.text.starts_with("word")).unwrap().paras[0].para;+ assert_eq!(+ (p.border_on, p.border_weights, p.shading_offsets),+ (Some(true), Some([2.0, 1.0, 2.0, 1.0]), Some([4.0; 4])),+ "IDML paragraph border"+ );+ }+}diff --git a/crates/idml/src/export.rs b/crates/idml/src/export.rsindex b581a308d..6305d459c 100644--- a/crates/idml/src/export.rs+++ b/crates/idml/src/export.rs@@ -1219,6 +1219,27 @@ impl<'a> Ex<'a> {props.push(p("ParagraphShadingColor", "object", self.sw(c)));}n!(shading_tint, "ParagraphShadingTint", pct);+ const SIDES: [&str; 4] = ["Top", "Left", "Bottom", "Right"];+ if let Some(o) = a.shading_offsets {+ for (i, side) in SIDES.iter().enumerate() {+ el.set(&format!("ParagraphShading{side}Offset"), num(o[i]));+ }+ }+ b!(border_on, "ParagraphBorderOn");+ if let Some(c) = &a.border_color {+ props.push(p("ParagraphBorderColor", "object", self.sw(c)));+ }+ n!(border_tint, "ParagraphBorderTint", pct);+ if let Some(w) = a.border_weights {+ for (i, side) in SIDES.iter().enumerate() {+ el.set(&format!("ParagraphBorder{side}LineWeight"), num(w[i]));+ }+ }+ if let Some(o) = a.border_offsets {+ for (i, side) in SIDES.iter().enumerate() {+ el.set(&format!("ParagraphBorder{side}Offset"), num(o[i]));+ }+ }}fn rule(&mut self, el: &mut El, props: &mut Vec<El>, k: &str, r: &Rule) {diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rsindex 0fbaff509..9766b1a70 100644--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@ -1192,6 +1192,18 @@ impl<'r> Importer<'r> {a.shading_color = Some(self.swatch_ref(c.trim()));}a.shading_tint = tint(e.num("ParagraphShadingTint"));+ let sides = |f: &dyn Fn(&str) -> String| -> Option<[f64; 4]> {+ let v = ["Top", "Left", "Bottom", "Right"].map(|s| e.num(&f(s)));+ v.iter().any(Option::is_some).then(|| v.map(|x| x.unwrap_or(0.0)))+ };+ a.shading_offsets = sides(&|s| format!("ParagraphShading{s}Offset"));+ a.border_on = e.boolean("ParagraphBorderOn");+ if let Some(c) = e.prop("ParagraphBorderColor") {+ a.border_color = Some(self.swatch_ref(c.trim()));+ }+ a.border_tint = tint(e.num("ParagraphBorderTint"));+ a.border_weights = sides(&|s| format!("ParagraphBorder{s}LineWeight"));+ a.border_offsets = sides(&|s| format!("ParagraphBorder{s}Offset"));a}diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rsindex 4f2697b0a..8837b77e0 100644--- a/crates/ui-egui/src/panels/properties.rs+++ b/crates/ui-egui/src/panels/properties.rs@@ -1327,6 +1327,45 @@ pub fn paragraph_panel(app: &mut DesignApp, ui: &mut egui::Ui) {let _ = app.run("type.para", json!({"attrs": {"composer": "singleLine"}}));}});+ // Paragraph Border and Shading.+ let swatches: Vec<String> =+ app.session.active().map(|d| d.doc.swatches.iter().filter(|w| !w.hidden).map(|w| w.name.clone()).collect()).unwrap_or_default();+ for (on_key, color_key, label) in [("shadingOn", "shadingColor", "Shading"), ("borderOn", "borderColor", "Border")] {+ ui.horizontal(|ui| {+ let mut on = p[on_key].as_bool().unwrap_or(false);+ if ui.checkbox(&mut on, label).changed() {+ let _ = app.run("type.para", json!({ on_key: on }));+ }+ if on {+ let cur = p[color_key].as_str().unwrap_or("[Black]").to_string();+ egui::ComboBox::from_id_salt(("pbs", label)).selected_text(&cur).width(110.0).show_ui(ui, |ui| {+ for w in &swatches {+ if ui.selectable_label(*w == cur, w).clicked() {+ let _ = app.run("type.para", json!({ color_key: w }));+ }+ }+ });+ if label == "Shading" {+ if let Some(v) = number(ui, "pshtint", p["shadingTint"].as_f64().map(|t| t * 100.0), "%", 46.0, 0) {+ let _ = app.run("type.para", json!({"shadingTint": (v / 100.0).clamp(0.0, 1.0)}));+ }+ } else if let Some(v) = number(ui, "pbw", p["borderWeights"][0].as_f64(), " pt", 50.0, 2) {+ let w = [v.max(0.0); 4];+ let _ = app.run("type.para", json!({ "borderWeights": w }));+ }+ }+ });+ }+ if p["shadingOn"].as_bool().unwrap_or(false) || p["borderOn"].as_bool().unwrap_or(false) {+ ui.horizontal(|ui| {+ caption(ui, "Offsets");+ let o = p["borderOffsets"][0].as_f64().or(p["shadingOffsets"][0].as_f64());+ if let Some(v) = number(ui, "pbo", o, " pt", 50.0, 2) {+ let o = [v; 4];+ let _ = app.run("type.para", json!({ "borderOffsets": o, "shadingOffsets": o }));+ }+ });+ }let ps = a["paragraphStyle"].as_str().unwrap_or("").to_string();let ov = a["paraOverrides"].as_u64().unwrap_or(0) + a["charOverrides"].as_u64().unwrap_or(0);ui.horizontal(|ui| {diff --git a/docs/parity.md b/docs/parity.mdindex 4a398ea8f..66a9b2978 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -5,12 +5,12 @@ The summary is generated by `cargo xtask parity` from the table at the bottom ofEach row of the InDesign feature catalogue is scored **D** (done), **P** (partial: works but lacks options or UI) or **M** (missing), weighted by priority (**P0** core = 3, **P1** = 2, **P2** = 1). Out-of-scope rows (Adobe cloud services, plug-ins, Typekit, Flash) are excluded.<!-- SUMMARY -->-**Weighted breadth parity: 88%** over 275 features.+**Weighted breadth parity: 89%** over 275 features.| Priority | Features | Done | Partial | Missing | Parity ||---|---|---|---|---|---|| P0 | 102 | 99 | 3 | 0 | 99% |-| P1 | 97 | 82 | 14 | 1 | 92% |+| P1 | 97 | 83 | 13 | 1 | 92% || P2 | 76 | 23 | 13 | 40 | 39% || Area | Parity |@@ -24,7 +24,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Effects & transparency | 71% || Placing & links | 82% || Type & text frames | 92% |-| Typography | 92% |+| Typography | 94% || Styles | 92% || Tables | 92% || Long documents | 88% |@@ -225,7 +225,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t| Typography | Tabs, leaders, right-indent tab | P0 | D || Typography | Nested / line / GREP styles | P1 | D || Typography | Paragraph rules | P1 | D |-| Typography | Paragraph borders & shading | P1 | P |+| Typography | Paragraph borders & shading | P1 | D || Typography | Balance ragged lines | P1 | D || Typography | Optical margin alignment | P1 | D || Typography | Baseline grid | P0 | D |