DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Column rules: tint, horizontal offset and top/bottom insets; IDML import and export
aiongg7d0bdbc916a1
diff --git a/ROADMAP.md b/ROADMAP.mdindex 48eeaff17..81fb7f370 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -76,7 +76,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Image Import Options › Crop to for placed PDFs (`file.place {pdfCrop: crop|trim|bleed|art|media}`, Place PDF dialog): the frame shows that page box.- Stroke styles: striped (thick-thin… and custom bands), wavy and straight-hash strokes now draw on screen and in PDF; named custom stripe/dash/dot styles (`strokeStyle.new/delete/list`, Stroke panel Type list; IDML Striped/Dashed/DottedStrokeStyle).- Object ▸ Primary Text Frame (`object.primaryTextFrame`): any text frame's story can become (or stop being) the primary story Smart Text Reflow follows.-- Column rules (Text Frame Options › Column Rules, `object.textFrameOptions {columnRule, columnRuleWeight, columnRuleColor}`, reported by `document.inspect`): a bar centred in each gutter of a multi-column frame, inside the insets and between the columns of right-to-left and vertical frames too, broken around paragraphs that span columns; on screen and in PDF (tagged as an artifact). The dialog shows the frame's options and changes only the fields edited. Rule offsets, stroke type, tint and IDML aren't there yet.+- Column rules (Text Frame Options › Column Rules, `object.textFrameOptions {columnRule, columnRuleWeight, columnRuleColor, columnRuleTint, columnRuleOffset, columnRuleTopInset, columnRuleBottomInset}`, reported by `document.inspect`): a bar centred in each gutter of a multi-column frame, inside the insets and between the columns of right-to-left and vertical frames too, broken around paragraphs that span columns, with weight, colour, tint, horizontal offset and top/bottom insets; on screen, in PDF (tagged as an artifact) and in IDML (`ColumnRule…` attributes of `TextFramePreference`, also in object styles). The dialog shows the frame's options and changes only the fields edited. Rule stroke types and overprint aren't there yet.- Place a page of an IDML or DesignCraft document (`file.place {layoutPage}`): its objects, stories, styles and swatches as one group (INDD files are not readable).- Articles panel (`article.new/add/remove/options/delete/list`): reading order and content of EPUB and HTML exports.- Object ▸ Clipping Path (`object.clippingPath {type: alpha|edges, threshold, tolerance}`): traces the placed image and makes the outline the frame.diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex a0815d2af..51687f92f 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -1039,8 +1039,9 @@ fn compose_with_db(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &C// Column rules, once vertical justification has put the lines in place.for (ft, f) in out.frames.iter_mut().zip(frames) {if f.opts.column_rule {- let rects = column_rule_rects(&ft.columns, &ft.lines, f.opts.column_rule_weight);- ft.decos.extend(rects.into_iter().map(|rect| Deco { rect, color: f.opts.column_rule_color.clone(), tint: 1.0 }));+ let rects = column_rule_rects(&ft.columns, &ft.lines, &f.opts);+ let tint = if f.opts.column_rule_tint.is_finite() { f.opts.column_rule_tint.clamp(0.0, 1.0) } else { 1.0 };+ ft.decos.extend(rects.into_iter().map(|rect| Deco { rect, color: f.opts.column_rule_color.clone(), tint }));}}out.styles = styles_tab;@@ -1142,18 +1143,23 @@ fn para_box_decos(out: &mut ComposedStory, pi: usize, pp: &ParaProps) {/// Thickest column rule drawn (points).const MAX_COLUMN_RULE_WEIGHT: f64 = 1000.0;-/// Text Frame Options › Column Rules: one bar per gutter, `weight` wide and centred between the-/// facing edges of the two columns, from the columns' top to their bottom (the text area, inside-/// the insets). Works in the composed space, so right-to-left and vertical frames (whose columns-/// are laid out in the turned box) get their rules between the columns too.+/// Text Frame Options › Column Rules: one bar per gutter, `column_rule_weight` wide, centred+/// between the facing edges of the two columns and moved by `column_rule_offset`, from the+/// columns' top to their bottom (the text area, inside the insets) shortened by the rule's top+/// and bottom insets. Works in the composed space, so right-to-left and vertical frames (whose+/// columns are laid out in the turned box) get their rules between the columns too.////// A paragraph that spans columns interrupts the rule: the bar stops at the top of its first line/// and resumes below its last line. Nothing is drawn for a single column or a weight that is not a/// positive finite number.-pub fn column_rule_rects(columns: &[Rect], lines: &[Line], weight: f64) -> Vec<Rect> {+pub fn column_rule_rects(columns: &[Rect], lines: &[Line], opts: &TextFrameOptions) -> Vec<Rect> {+ let weight = opts.column_rule_weight;if !weight.is_finite() || weight <= 0.0 || columns.len() < 2 {return Vec::new();}+ let finite = |v: f64| if v.is_finite() { v } else { 0.0 };+ let (offset, top_inset, bottom_inset) =+ (finite(opts.column_rule_offset), finite(opts.column_rule_top_inset), finite(opts.column_rule_bottom_inset));let half = weight.min(MAX_COLUMN_RULE_WEIGHT) / 2.0;let mut cols: Vec<Rect> =columns.iter().copied().filter(|c| c.x0.is_finite() && c.x1.is_finite() && c.y0.is_finite() && c.y1.is_finite()).collect();@@ -1162,7 +1168,7 @@ pub fn column_rule_rects(columns: &[Rect], lines: &[Line], weight: f64) -> Vec<Rfor pair in cols.windows(2) {let [a, b] = [pair[0], pair[1]];let cx = (a.x1 + b.x0) / 2.0;- let (top, bottom) = (a.y0.max(b.y0), a.y1.min(b.y1));+ let (top, bottom) = (a.y0.max(b.y0) + top_inset, a.y1.min(b.y1) - bottom_inset);if bottom <= top {continue;}@@ -1179,10 +1185,11 @@ pub fn column_rule_rects(columns: &[Rect], lines: &[Line], weight: f64) -> Vec<R}}spans.sort_by(|p, q| p.1.total_cmp(&q.1));+ let x = cx + offset;let mut y = top;for (_, t, z) in spans {if t > y {- out.push(Rect::new(cx - half, y, cx + half, t.min(bottom)));+ out.push(Rect::new(x - half, y, x + half, t.min(bottom)));}y = y.max(z);if y >= bottom {@@ -1190,7 +1197,7 @@ pub fn column_rule_rects(columns: &[Rect], lines: &[Line], weight: f64) -> Vec<R}}if y < bottom {- out.push(Rect::new(cx - half, y, cx + half, bottom));+ out.push(Rect::new(x - half, y, x + half, bottom));}}outdiff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rsindex e73ec69a6..67f5541f6 100644--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@ -1924,12 +1924,13 @@ fn column_rules_sit_in_the_gutters_inside_the_insets() {#[test]fn column_rules_centre_on_unequal_gutters_and_ignore_bad_weights() {let cols = [Rect::new(200.0, 0.0, 300.0, 50.0), Rect::new(0.0, 0.0, 100.0, 50.0), Rect::new(110.0, 0.0, 180.0, 50.0)];- let rules = column_rule_rects(&cols, &[], 1.0);+ let weight = |w: f64| TextFrameOptions { column_rule_weight: w, ..Default::default() };+ let rules = column_rule_rects(&cols, &[], &weight(1.0));let centres: Vec<f64> = rules.iter().map(|r| r.center().x).collect();assert_eq!(centres, [105.0, 190.0]);- assert!(column_rule_rects(&cols, &[], f64::NAN).is_empty());- assert!(column_rule_rects(&cols, &[], -1.0).is_empty());- assert!((column_rule_rects(&cols, &[], 1e12)[0].width() - 1000.0).abs() < 1e-9);+ assert!(column_rule_rects(&cols, &[], &weight(f64::NAN)).is_empty());+ assert!(column_rule_rects(&cols, &[], &weight(-1.0)).is_empty());+ assert!((column_rule_rects(&cols, &[], &weight(1e12))[0].width() - 1000.0).abs() < 1e-9);}#[test]@@ -1966,3 +1967,30 @@ fn column_rules_break_around_paragraphs_that_span_columns() {// The rule resumes below the span and runs to the bottom of the columns.assert!(rules.iter().any(|r| (r.y0 - bottom).abs() < 1e-9 && (r.y1 - 380.0).abs() < 1e-9), "{rules:?}");}++#[test]+fn column_rules_take_their_offset_insets_and_tint() {+ let (d, fid, rules) = ruled("Text", Rect::new(0.0, 0.0, 300.0, 200.0), 2, |d, sid| {+ let fid = d.story(sid).unwrap().frames[0];+ let o = &mut d.item_mut(fid).unwrap().text_frame_mut().unwrap().options;+ o.column_rule_offset = 3.0;+ o.column_rule_top_inset = 15.0;+ o.column_rule_bottom_inset = 25.0;+ o.column_rule_tint = 0.4;+ });+ // Gutter centre 150 moved 3 pt; columns 10..180 shortened to 25..155.+ assert_eq!(rules.len(), 1, "{rules:?}");+ let r = rules[0];+ assert!((r.center().x - 153.0).abs() < 1e-9 && (r.y0 - 25.0).abs() < 1e-9 && (r.y1 - 155.0).abs() < 1e-9, "{r:?}");+ let sid = d.item(fid).unwrap().text_frame().unwrap().story;+ let cs = compose_story(&d, sid, &ComposeOptions::default());+ assert!(cs.frames[0].decos.iter().any(|dc| dc.rect == r && (dc.tint - 0.4).abs() < 1e-6));+ // Insets that meet leave no rule.+ let (_, _, rules) = ruled("Text", Rect::new(0.0, 0.0, 300.0, 200.0), 2, |d, sid| {+ let fid = d.story(sid).unwrap().frames[0];+ let o = &mut d.item_mut(fid).unwrap().text_frame_mut().unwrap().options;+ o.column_rule_top_inset = 100.0;+ o.column_rule_bottom_inset = 100.0;+ });+ assert!(rules.is_empty(), "{rules:?}");+}diff --git a/crates/doc/src/item.rs b/crates/doc/src/item.rsindex 549219601..5cfe05fe2 100644--- a/crates/doc/src/item.rs+++ b/crates/doc/src/item.rs@@ -326,6 +326,13 @@ pub struct TextFrameOptions {pub column_rule: bool,pub column_rule_weight: f64,pub column_rule_color: String,+ /// 0..1.+ pub column_rule_tint: f32,+ /// Horizontal offset of each rule from the middle of its gutter.+ pub column_rule_offset: f64,+ /// The rule starts this far below the column top and ends this far above its bottom.+ pub column_rule_top_inset: f64,+ pub column_rule_bottom_inset: f64,/// Use a custom baseline grid for this frame.#[serde(skip_serializing_if = "Option::is_none")]pub baseline_grid: Option<(f64, f64)>,@@ -375,6 +382,10 @@ impl Default for TextFrameOptions {column_rule: false,column_rule_weight: 1.0,column_rule_color: designcraft_color::swatch::BLACK.into(),+ column_rule_tint: 1.0,+ column_rule_offset: 0.0,+ column_rule_top_inset: 0.0,+ column_rule_bottom_inset: 0.0,baseline_grid: None,path: None,}diff --git a/crates/engine/src/cmd/inspect.rs b/crates/engine/src/cmd/inspect.rsindex 200ce1d63..f3c273368 100644--- a/crates/engine/src/cmd/inspect.rs+++ b/crates/engine/src/cmd/inspect.rs@@ -45,6 +45,10 @@ fn item_json(it: &Item) -> Value {if t.options.column_rule {v["columnRuleWeight"] = json!(t.options.column_rule_weight);v["columnRuleColor"] = json!(t.options.column_rule_color);+ v["columnRuleTint"] = json!(t.options.column_rule_tint);+ v["columnRuleOffset"] = json!(t.options.column_rule_offset);+ v["columnRuleTopInset"] = json!(t.options.column_rule_top_inset);+ v["columnRuleBottomInset"] = json!(t.options.column_rule_bottom_inset);}}Content::Graphic(g) => v["asset"] = json!(g.asset.0),diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rsindex ccc6acaf3..9fd05771d 100644--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@ -479,7 +479,7 @@ pub fn specs() -> Vec<CommandSpec> {"Text Frame Options…",["Object"],Some("Cmd+B"),- "{columns?, gutter?, inset?: number|[t,l,b,r] (null keeps that side), verticalJustification?: top|center|bottom|justify, firstBaseline?, autoSize?, ignoreWrap?, balanceColumns?, columnRule?: bool, columnRuleWeight? (pt), columnRuleColor? (swatch name), vertical?: bool (sets the story direction of the frames' stories, as Type ▸ Story Direction), ids?}",+ "{columns?, gutter?, inset?: number|[t,l,b,r] (null keeps that side), verticalJustification?: top|center|bottom|justify, firstBaseline?, autoSize?, ignoreWrap?, balanceColumns?, columnRule?: bool, columnRuleWeight? (pt), columnRuleColor? (swatch name), columnRuleTint? (0..1), columnRuleOffset? (pt, horizontal), columnRuleTopInset? (pt), columnRuleBottomInset? (pt), vertical?: bool (sets the story direction of the frames' stories, as Type ▸ Story Direction), ids?}",has_selection,text_frame_options),@@ -1418,13 +1418,18 @@ fn text_frame_options(s: &mut Session, p: &Value) -> Result<Value> {{ids = st.doc.story(t.story).map(|s| s.frames.clone()).unwrap_or_default();}- let rule_weight = match p.get("columnRuleWeight") {- None | Some(Value::Null) => None,+ let ranged = |key: &str, lo: f64, hi: f64, what: &str| match p.get(key) {+ None | Some(Value::Null) => Ok(None),Some(v) => match v.as_f64() {- Some(w) if w.is_finite() && (0.0..=1000.0).contains(&w) => Some(w),- _ => return Err(bad(ID, format!("columnRuleWeight must be a number of points from 0 to 1000, not {v}"))),+ Some(x) if x.is_finite() && (lo..=hi).contains(&x) => Ok(Some(x)),+ _ => Err(bad(ID, format!("{key} must be {what} from {lo} to {hi}, not {v}"))),},};+ let rule_weight = ranged("columnRuleWeight", 0.0, 1000.0, "a number of points")?;+ let rule_tint = ranged("columnRuleTint", 0.0, 1.0, "a tint")?;+ let rule_offset = ranged("columnRuleOffset", -1440.0, 1440.0, "a number of points")?;+ let rule_top = ranged("columnRuleTopInset", -1440.0, 1440.0, "a number of points")?;+ let rule_bottom = ranged("columnRuleBottomInset", -1440.0, 1440.0, "a number of points")?;let rule_color = match p.get("columnRuleColor") {None | Some(Value::Null) => None,Some(Value::String(c)) if st.doc.swatch(c).is_some() => Some(c.clone()),@@ -1479,6 +1484,18 @@ fn text_frame_options(s: &mut Session, p: &Value) -> Result<Value> {if let Some(c) = &rule_color {o.column_rule_color = c.clone();}+ if let Some(t) = rule_tint {+ o.column_rule_tint = t as f32;+ }+ if let Some(v) = rule_offset {+ o.column_rule_offset = v;+ }+ if let Some(v) = rule_top {+ o.column_rule_top_inset = v;+ }+ if let Some(v) = rule_bottom {+ o.column_rule_bottom_inset = v;+ }}// Story direction belongs to the story: every frame of the thread turns.if let Some(v) = p.get("vertical").and_then(Value::as_bool) {@@ -2462,15 +2479,19 @@ mod column_rule_tests {let e = s.execute("object.textFrameOptions", &json!({"ids": [id.0], "columnRule": true, "columnRuleColor": "Mauve"})).unwrap_err();assert!(e.to_string().contains("Mauve"), "{e}");assert!(s.execute("object.textFrameOptions", &json!({"ids": [id.0], "columnRuleWeight": -1})).is_err());+ assert!(s.execute("object.textFrameOptions", &json!({"ids": [id.0], "columnRuleTint": 2})).is_err());+ assert!(s.execute("object.textFrameOptions", &json!({"ids": [id.0], "columnRuleTopInset": "x"})).is_err());assert_eq!(opts(&s), before);s.execute("object.textFrameOptions",- &json!({"ids": [id.0], "columnRule": true, "columnRuleWeight": 0.5, "columnRuleColor": "C=100 M=0 Y=0 K=0"}),+ &json!({"ids": [id.0], "columnRule": true, "columnRuleWeight": 0.5, "columnRuleColor": "C=100 M=0 Y=0 K=0", "columnRuleTint": 0.5,+ "columnRuleOffset": -2, "columnRuleTopInset": 4, "columnRuleBottomInset": 6}),).unwrap();let o = opts(&s);assert!(o.column_rule && o.column_rule_weight == 0.5 && o.column_rule_color == "C=100 M=0 Y=0 K=0");assert_eq!(o.inset, [1.0, 2.0, 3.0, 4.0], "untouched options stay");+ assert_eq!((o.column_rule_tint, o.column_rule_offset, o.column_rule_top_inset, o.column_rule_bottom_inset), (0.5, -2.0, 4.0, 6.0));let item = s.execute("document.inspect", &json!({})).unwrap()["spreads"][0]["items"].as_array().unwrap()@@ -2482,6 +2503,10 @@ mod column_rule_tests {(&item["columnRule"], &item["columnRuleWeight"], &item["columnRuleColor"]),(&json!(true), &json!(0.5), &json!("C=100 M=0 Y=0 K=0")));+ assert_eq!(+ (&item["columnRuleTint"], &item["columnRuleOffset"], &item["columnRuleTopInset"], &item["columnRuleBottomInset"]),+ (&json!(0.5), &json!(-2.0), &json!(4.0), &json!(6.0))+ );// One undo step.s.execute("edit.undo", &json!({})).unwrap();assert_eq!(opts(&s), before);diff --git a/crates/idml/src/export.rs b/crates/idml/src/export.rsindex 919991eb0..a275f8e12 100644--- a/crates/idml/src/export.rs+++ b/crates/idml/src/export.rs@@ -991,7 +991,7 @@ impl<'a> Ex<'a> {}let mut el = with_props(el, props);if let Some(tf) = &os.text_frame {- el.push(text_frame_pref(tf));+ el.push(text_frame_pref(tf, &self.sw(&tf.column_rule_color)));}og.insert(&os.name, el);}@@ -1626,7 +1626,7 @@ impl<'a> Ex<'a> {el.push(t);}if let Content::Text(t) = &it.content {- el.push(text_frame_pref(&t.options));+ el.push(text_frame_pref(&t.options, &self.sw(&t.options.column_rule_color)));if let Some((start, inc)) = t.options.baseline_grid {el.push(El::new("BaselineFrameGridOption")@@ -2286,7 +2286,8 @@ fn margin_el(pg: &designcraft_doc::Page) -> El {.attr("ColumnsPositions", pos.join(" "))}-fn text_frame_pref(o: &TextFrameOptions) -> El {+/// `rule_color` is the IDML reference of the column rule's swatch.+fn text_frame_pref(o: &TextFrameOptions, rule_color: &str) -> El {let mut inset = El::new("InsetSpacing").attr("type", "list");for v in o.inset {inset.push(p("ListItem", "unit", num(v)));@@ -2305,6 +2306,26 @@ fn text_frame_pref(o: &TextFrameOptions) -> El {.attr("AutoSizingType", names::auto_size_out(o.auto_size)).attr("AutoSizingReferencePoint", names::REF_POINTS[(o.auto_size_ref as usize).min(8)]);let el = if o.column_width > 0.0 { el.attr("TextColumnFixedWidth", num(o.column_width)) } else { el };+ let d = TextFrameOptions::default();+ let rule_set = o.column_rule+ || o.column_rule_weight != d.column_rule_weight+ || o.column_rule_color != d.column_rule_color+ || o.column_rule_tint != d.column_rule_tint+ || o.column_rule_offset != d.column_rule_offset+ || o.column_rule_top_inset != d.column_rule_top_inset+ || o.column_rule_bottom_inset != d.column_rule_bottom_inset;+ let el = if rule_set {+ el.attr("ColumnRuleOverride", bool_s(o.column_rule))+ .attr("ColumnRuleStrokeWidth", num(o.column_rule_weight))+ .attr("ColumnRuleStrokeColor", rule_color)+ .attr("ColumnRuleStrokeTint", num(f64::from(o.column_rule_tint) * 100.0))+ .attr("ColumnRuleOffset", num(o.column_rule_offset))+ .attr("ColumnRuleTopInset", num(o.column_rule_top_inset))+ .attr("ColumnRuleBottomInset", num(o.column_rule_bottom_inset))+ .attr("ColumnRuleInsetChainOverride", bool_s(o.column_rule_top_inset == o.column_rule_bottom_inset))+ } else {+ el+ };with_props(el, vec![inset])}diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rsindex 3e1c17e28..600acf2f7 100644--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@ -686,6 +686,15 @@ impl<'r> Importer<'r> {}/// A swatch reference (Self id) → our swatch name; unnamed colours become value-named swatches.+ /// A `TextFramePreference`, with its column rule colour resolved to a swatch.+ fn frame_options(&mut self, e: &El) -> TextFrameOptions {+ let mut o = text_frame_options(e);+ if let Some(r) = e.get("ColumnRuleStrokeColor") {+ o.column_rule_color = self.swatch_ref(r);+ }+ o+ }+fn swatch_ref(&mut self, r: &str) -> String {if let Some(n) = self.swatch_names.get(r) {return n.clone();@@ -896,8 +905,11 @@ impl<'r> Importer<'r> {let paragraph_style = enabled("EnableParagraphStyle", "AppliedParagraphStyle").then(|| e.get("AppliedParagraphStyle").map(|r| self.para_style_ref(r))).flatten();- let text_frame =- if e.get("EnableTextFrameGeneralOptions") == Some("true") { e.find("TextFramePreference").map(text_frame_options) } else { None };+ let text_frame = if e.get("EnableTextFrameGeneralOptions") == Some("true") {+ e.find("TextFramePreference").map(|t| self.frame_options(t))+ } else {+ None+ };let s = ObjectStyle { name: name.clone(), based_on, fill, stroke, paragraph_style, text_frame };match self.styles.object.iter_mut().find(|o| o.name == name) {Some(slot) => *slot = s,@@ -2042,7 +2054,7 @@ impl<'r> Importer<'r> {sid}};- let mut options = e.find("TextFramePreference").map(text_frame_options).unwrap_or_default();+ let mut options = e.find("TextFramePreference").map(|t| self.frame_options(t)).unwrap_or_default();if let Some(g) = e.find("BaselineFrameGridOption")&& g.get("UseCustomBaselineFrameGrid") == Some("true"){@@ -2376,6 +2388,24 @@ fn text_frame_options(e: &El) -> TextFrameOptions {if let Some(v) = e.get("AutoSizingReferencePoint") {o.auto_size_ref = names::REF_POINTS.iter().position(|p| *p == v).unwrap_or(1) as u8;}+ // Column rules (the colour is a swatch reference: see `Importer::frame_options`).+ o.column_rule = e.get("ColumnRuleOverride") == Some("true");+ let finite = |k: &str| e.num(k).filter(|v| v.is_finite());+ if let Some(v) = finite("ColumnRuleStrokeWidth") {+ o.column_rule_weight = v.clamp(0.0, 1000.0);+ }+ if let Some(t) = tint(finite("ColumnRuleStrokeTint")) {+ o.column_rule_tint = t.clamp(0.0, 1.0);+ }+ for (k, v) in [+ ("ColumnRuleOffset", &mut o.column_rule_offset),+ ("ColumnRuleTopInset", &mut o.column_rule_top_inset),+ ("ColumnRuleBottomInset", &mut o.column_rule_bottom_inset),+ ] {+ if let Some(x) = finite(k) {+ *v = x.clamp(-1440.0, 1440.0);+ }+ }o}diff --git a/crates/idml/src/lib.rs b/crates/idml/src/lib.rsindex c82f0c74d..71d688255 100644--- a/crates/idml/src/lib.rs+++ b/crates/idml/src/lib.rs@@ -20,8 +20,8 @@//! (page size, facing pages, bleed/slug, margins and columns, units, grids), layers, sections,//! parent (master) spreads and applied parents, spreads and pages, page items (`TextFrame`,//! `Rectangle`, `Oval`, `Polygon`, `GraphicLine`, `Group`) with fill/stroke, corner options, text-//! wrap, transparency (opacity, blend mode, drop shadow, feather), images (embedded `Contents` or-//! linked), stories with paragraph/character style ranges and local overrides, special+//! frame options (with column rules), text wrap, transparency (opacity, blend mode, drop shadow,+//! feather), images (embedded `Contents` or linked), stories with paragraph/character style ranges and local overrides, special//! characters and breaks, and text threading.//!//! ## TODO (ignored on import / not written on export)@@ -30,7 +30,8 @@//! - Guides, page-item overrides of parent items (only the page's `OverrideList` is read),//! parent-of-parent page mapping beyond `AppliedMaster`, alternate layouts, liquid layout.//! - Nested/GREP/line styles, bullets & numbering details (bullet glyph, number format), OpenType-//! feature flags, paragraph borders, grid alignment, column rules, custom dashed stroke styles.+//! feature flags, paragraph borders, grid alignment, custom dashed stroke styles; column rule+//! stroke type and overprint.//! - Mixed inks, gradient stop opacity and gradient feathers, effects other than drop shadow and//! basic feather, EPS/PDF/AI placed graphics (imported as images when the data is available),//! clipping paths, compound-path fill rules.diff --git a/crates/idml/src/tests.rs b/crates/idml/src/tests.rsindex b636a2ac1..398fbf7b6 100644--- a/crates/idml/src/tests.rs+++ b/crates/idml/src/tests.rs@@ -857,3 +857,49 @@ fn arabic_story_and_table_directions_survive_idml_export() {assert_eq!(st.direction, designcraft_doc::TextDirection::RightToLeft);assert_eq!(st.tables.values().next().unwrap().options.direction, designcraft_doc::TextDirection::RightToLeft);}++#[test]+fn imports_column_rules_from_frames_and_object_styles() {+ let rule = r#"ColumnRuleOverride="true" ColumnRuleStrokeWidth="2.5" ColumnRuleStrokeColor="Color/Black" ColumnRuleStrokeTint="40"+ ColumnRuleStrokeType="StrokeStyle/$ID/Solid" ColumnRuleOverprintOverride="false" ColumnRuleOffset="-3" ColumnRuleTopInset="6"+ ColumnRuleBottomInset="9" ColumnRuleInsetChainOverride="false""#;+ let styles = format!(+ r#"<ObjectStyle Self="ObjectStyle/Padded" Name="Padded" EnableTextFrameGeneralOptions="true"><TextFramePreference TextColumnCount="2" {rule}/></ObjectStyle>"#+ );+ let d = inset_fixture(&format!(r#"<TextFramePreference TextColumnCount="3" {rule}/>"#), &styles);+ let style = d.styles.object.iter().find(|s| s.name == "Padded").unwrap().text_frame.clone().unwrap();+ for o in [d.spreads[0].items[0].text_frame().unwrap().options.clone(), style] {+ assert!(o.column_rule, "{o:?}");+ assert_eq!(o.column_rule_weight, 2.5);+ assert_eq!(o.column_rule_color, designcraft_color::swatch::BLACK);+ assert!((o.column_rule_tint - 0.4).abs() < 1e-6);+ assert_eq!((o.column_rule_offset, o.column_rule_top_inset, o.column_rule_bottom_inset), (-3.0, 6.0, 9.0));+ }+ // Absent attributes: no rule, InDesign's defaults.+ let d = inset_fixture(r#"<TextFramePreference TextColumnCount="3"/>"#, "");+ assert_eq!(d.spreads[0].items[0].text_frame().unwrap().options, designcraft_doc::TextFrameOptions { columns: 3, ..Default::default() });+}++#[test]+fn column_rules_round_trip() {+ let mut d = small_doc();+ let fid = d.spreads[0].items[0].id;+ let o = &mut d.item_mut(fid).unwrap().text_frame_mut().unwrap().options;+ o.columns = 2;+ o.column_rule = true;+ o.column_rule_weight = 0.75;+ o.column_rule_color = "Brand".into();+ o.column_rule_tint = 0.5;+ o.column_rule_offset = 1.5;+ o.column_rule_top_inset = 4.0;+ o.column_rule_bottom_inset = 2.0;+ let want = o.clone();+ let bytes = export_idml(&d);+ let back = import_idml(&bytes).unwrap();+ let got = back.spreads[0].items.iter().find_map(|i| i.text_frame().filter(|t| t.options.column_rule)).unwrap().options.clone();+ assert_eq!(got, want);+ // Frames without a rule stay without one.+ let plain = export_idml(&small_doc());+ let back = import_idml(&plain).unwrap();+ assert!(back.spreads.iter().flat_map(|s| &s.items).filter_map(|i| i.text_frame()).all(|t| !t.options.column_rule));+}diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 0b7205ecc..5955f960f 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -300,6 +300,8 @@ fn seed_text_frame_options(app: &DesignApp, d: &mut Dialog) {"insetTop": fm(o.inset[0]), "insetLeft": fm(o.inset[1]), "insetBottom": fm(o.inset[2]), "insetRight": fm(o.inset[3]),"verticalJustification": serde_json::to_value(o.vertical_justification).unwrap_or(Value::Null),"columnRule": o.column_rule, "columnRuleWeight": format_measure(o.column_rule_weight, Unit::Points), "columnRuleColor": o.column_rule_color,+ "columnRuleTint": percent(o.column_rule_tint), "columnRuleTopInset": fm(o.column_rule_top_inset),+ "columnRuleBottomInset": fm(o.column_rule_bottom_inset), "columnRuleOffset": fm(o.column_rule_offset),});if let Value::Object(m) = &shown {for (k, v) in m {@@ -309,6 +311,12 @@ fn seed_text_frame_options(app: &DesignApp, d: &mut Dialog) {d.fields.insert("_shown".into(), shown);}+/// A 0..1 tint as a percentage ("40", "12.5").+fn percent(t: f32) -> String {+ let s = format!("{:.2}", f64::from(t) * 100.0);+ s.trim_end_matches('0').trim_end_matches('.').to_string()+}+fn text_frame_options_dialog(app: &DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {let lang = app.ui.language.clone();let tr = |s: &'static str| crate::i18n::tr(&lang, s);@@ -365,6 +373,16 @@ fn text_frame_options_dialog(app: &DesignApp, ui: &mut egui::Ui, d: &mut Dialog)crate::rtl::label(ui, tr("Color"));combo(ui, d, "columnRuleColor", &opts);ui.end_row();+ for (label, key) in [+ ("Tint %", "columnRuleTint"),+ ("Top Inset", "columnRuleTopInset"),+ ("Bottom Inset", "columnRuleBottomInset"),+ ("Horizontal Offset", "columnRuleOffset"),+ ] {+ crate::rtl::label(ui, tr(label));+ text_field(ui, d, key, 70.0);+ ui.end_row();+ }});}@@ -414,6 +432,18 @@ fn confirm_text_frame_options(app: &mut DesignApp, d: &mut Dialog) -> Result<Valif edited(d, "columnRuleColor") {p.insert("columnRuleColor".into(), json!(d.s("columnRuleColor")));}+ if edited(d, "columnRuleTint") {+ p.insert("columnRuleTint".into(), json!(d.n("columnRuleTint").ok_or_else(|| bad("the column rule tint is not a number"))? / 100.0));+ }+ for (key, what) in [+ ("columnRuleTopInset", "the column rule top inset is not a measure"),+ ("columnRuleBottomInset", "the column rule bottom inset is not a measure"),+ ("columnRuleOffset", "the column rule offset is not a measure"),+ ] {+ if edited(d, key) {+ p.insert(key.into(), json!(d.m(key).ok_or_else(|| bad(what))?));+ }+ }if p.is_empty() {return Ok(Value::Null);}@@ -2816,6 +2846,11 @@ mod tests {let o = opts(&app);assert!(o.column_rule && o.column_rule_weight == 6.0, "{o:?}");assert_eq!((o.inset, o.columns, o.gutter), (before.inset, before.columns, before.gutter));+ // One of the rule's insets edited: the other rule settings stay.+ open(&mut app, &[("columnRuleBottomInset", json!("0p9")), ("columnRuleTint", json!("40"))]).unwrap();+ let o = opts(&app);+ assert_eq!((o.column_rule_bottom_inset, o.column_rule_top_inset, o.column_rule_offset, o.column_rule_weight), (9.0, 0.0, 0.0, 6.0));+ assert!((o.column_rule_tint - 0.4).abs() < 1e-6 && o.column_rule);// One inset side edited: the others keep their values.open(&mut app, &[("insetLeft", json!("1p0"))]).unwrap();assert_eq!(opts(&app).inset, [1.0, 12.0, 3.0, 4.0]);@@ -2824,8 +2859,9 @@ mod tests {assert!(e.contains("Mauve") && app.ui.dialog.is_some(), "{e}");assert_eq!(opts(&app).column_rule_color, designcraft_color::swatch::BLACK);// Each OK is one undo step.- app.run("edit.undo", json!({})).unwrap();- app.run("edit.undo", json!({})).unwrap();+ for _ in 0..3 {+ app.run("edit.undo", json!({})).unwrap();+ }assert_eq!(opts(&app), before);}diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rsindex 3b32a5ecb..dfe3e93cf 100644--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@ -1239,6 +1239,10 @@ const TABLE: &[(&str, [&str; 5])] = &[("Column Width", ["Column Width", "Column Width", "Column Width", "Column Width", "列宽"]),("Column Rules", ["Spaltenlinien", "Filets de colonne", "Filetes de columna", "段間罫線", "栏间线"]),("Insert Column Rule", ["Spaltenlinie einfügen", "Insérer un filet de colonne", "Insertar filete de columna", "段間罫線を挿入", "插入栏间线"]),+ ("Tint %", ["Farbton %", "Teinte %", "Matiz %", "濃淡 %", "色调 %"]),+ ("Top Inset", ["Oberer Einzug", "Retrait supérieur", "Sangría superior", "上インセット", "顶部内边距"]),+ ("Bottom Inset", ["Unterer Einzug", "Retrait inférieur", "Sangría inferior", "下インセット", "底部内边距"]),+ ("Horizontal Offset", ["Horizontaler Versatz", "Décalage horizontal", "Desplazamiento horizontal", "水平オフセット", "水平偏移"]),("Condition Options…", ["Condition Options…", "Condition Options…", "Condition Options…", "Condition Options…", "条件选项…"]),("Convert to Liquid Guide",diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rsindex c6114d055..9f6065983 100644--- a/crates/ui-egui/src/i18n/ar.rs+++ b/crates/ui-egui/src/i18n/ar.rs@@ -442,6 +442,10 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Column Width", "عرض العمود"),("Column Rules", "خطوط الأعمدة"),("Insert Column Rule", "إدراج خط بين الأعمدة"),+ ("Tint %", "درجة اللون %"),+ ("Top Inset", "الإزاحة العلوية"),+ ("Bottom Inset", "الإزاحة السفلية"),+ ("Horizontal Offset", "الإزاحة الأفقية"),("Composer", "منضّد النص"),("Convert Selection to Multi-State Object", "تحويل التحديد إلى كائن متعدد الحالات"),("Convert to Text", "تحويل إلى نص"),diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rsindex 8b028b0cb..b995bd2b9 100644--- a/crates/ui-egui/src/i18n/pt_br.rs+++ b/crates/ui-egui/src/i18n/pt_br.rs@@ -443,6 +443,10 @@ pub(super) const TABLE: &[(&str, &str)] = &[("Column Width", "Largura da coluna"),("Column Rules", "Fios de coluna"),("Insert Column Rule", "Inserir fio de coluna"),+ ("Tint %", "Matiz %"),+ ("Top Inset", "Recuo superior"),+ ("Bottom Inset", "Recuo inferior"),+ ("Horizontal Offset", "Deslocamento horizontal"),("Composer", "Compositor"),("Convert Selection to Multi-State Object", "Converter seleção em objeto de vários estados"),("Convert to Text", "Converter em texto"),