Skip to content

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

L: Liquid Layout — page rules, liquid guides, object pins, alternate layouts (+ panel)

Brandon Thomas6a476a28e352
diff --git a/ROADMAP.md b/ROADMAP.md
index 83070361a..bb16fb29f 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -89,6 +89,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope
- Power Zoom (Hand tool, Alt-press): zoom out to the spread, aim the red view rectangle, release to zoom back in there. InDesign triggers it by press-and-hold instead.
- Graphic cells (`table.placeGraphic`, `table.textCell`, Table › Convert Cell Type, Table panel): images in table cells, fitted or filled, clipped to the cell on screen and in PDF.
- Live Distribute (Space while dragging a selection handle; `transform.resize {distribute}`): objects keep their size and spread with the bounds.
+- Liquid Layout (`liquid.pageRule/object`, `guide.liquid`, `layout.createAlternate`, Liquid Layout panel): scale / re-center / guide-based / object-based page rules applied on page resize and Document Setup; dashed liquid guides; alternate layouts as resized page copies in a named section. Alternate layouts aren't linked to their source.
- 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/doc/src/build.rs b/crates/doc/src/build.rs
index e92b48a0e..c06d1d2ed 100644
--- a/crates/doc/src/build.rs
+++ b/crates/doc/src/build.rs
@@ -219,6 +219,7 @@ impl Document {
overridden: vec![],
guides: vec![],
show_parent_items: true,
+ liquid: Default::default(),
}
}
diff --git a/crates/doc/src/item.rs b/crates/doc/src/item.rs
index 8cd082f3e..edb88aad0 100644
--- a/crates/doc/src/item.rs
+++ b/crates/doc/src/item.rs
@@ -450,6 +450,19 @@ fn center_ref() -> u8 {
4
}
+/// Liquid Layout object rules: which edges stay at their distance from the page edge, and
+/// whether the object may stretch.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase", default)]
+pub struct ObjectLiquid {
+ pub resize_width: bool,
+ pub resize_height: bool,
+ pub pin_top: bool,
+ pub pin_bottom: bool,
+ pub pin_left: bool,
+ pub pin_right: bool,
+}
+
/// A button's On Release action.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "kind")]
@@ -728,6 +741,9 @@ pub struct Item {
/// Alternative text (Object Export Options) for tagged PDF and EPUB.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub alt_text: String,
+ /// Liquid Layout (object-based pages): pins and resize permissions.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub liquid: Option<ObjectLiquid>,
/// Buttons and Forms: what clicking this object does in an interactive PDF.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub button: Option<ButtonAction>,
@@ -780,6 +796,7 @@ impl Item {
alt_text: String::new(),
xml_tag: String::new(),
button: None,
+ liquid: None,
states: Vec::new(),
active_state: 0,
isolate: false,
diff --git a/crates/doc/src/page.rs b/crates/doc/src/page.rs
index 749d01b05..628aa6960 100644
--- a/crates/doc/src/page.rs
+++ b/crates/doc/src/page.rs
@@ -63,6 +63,9 @@ pub struct Guide {
/// The layer the guide is on: hidden with it, locked with it (`None` = always shown).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub layer: Option<crate::LayerId>,
+ /// Liquid guide: objects it crosses stretch when a guide-based page changes size.
+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]
+ pub liquid: bool,
}
impl Guide {
@@ -108,6 +111,31 @@ pub struct Page {
/// Show parent items on this page.
#[serde(default = "yes")]
pub show_parent_items: bool,
+ /// Liquid page rule: how objects follow when the page changes size.
+ #[serde(default, skip_serializing_if = "LiquidRule::is_off")]
+ pub liquid: LiquidRule,
+}
+
+/// Liquid Layout page rules.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub enum LiquidRule {
+ #[default]
+ Off,
+ /// Everything scales uniformly (letterboxed, centred).
+ Scale,
+ /// Everything keeps its size, centred on the new page.
+ ReCenter,
+ /// Objects crossed by liquid guides stretch; the rest keep their size.
+ GuideBased,
+ /// Each object's pins and resize settings decide (`Item::liquid`).
+ ObjectBased,
+}
+
+impl LiquidRule {
+ pub fn is_off(&self) -> bool {
+ *self == LiquidRule::Off
+ }
}
fn yes() -> bool {
@@ -244,6 +272,7 @@ mod tests {
overridden: vec![],
guides: vec![],
show_parent_items: true,
+ liquid: Default::default(),
}
}
diff --git a/crates/engine/src/cmd/guides.rs b/crates/engine/src/cmd/guides.rs
index d32b7d741..f3856bf08 100644
--- a/crates/engine/src/cmd/guides.rs
+++ b/crates/engine/src/cmd/guides.rs
@@ -92,7 +92,7 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
s.edit(|d, _| {
let sp = d.spread_mut(r).ok_or_else(|| bad("guide.add", "no such spread"))?;
let pg = sp.pages.get_mut(pi).ok_or_else(|| bad("guide.add", "no such page"))?;
- pg.guides.push(Guide { orientation: o, position: pos, spread: spread_guide, locked: false, layer: Some(layer) });
+ pg.guides.push(Guide { orientation: o, position: pos, spread: spread_guide, locked: false, layer: Some(layer), liquid: false });
Ok(json!({"page": pi, "index": pg.guides.len() - 1}))
})
}
@@ -171,11 +171,25 @@ fn create_guides(s: &mut Session, p: &Value) -> Result<Value> {
}
let area: Rect = if to_page { pg.bounds() } else { pg.margin_rect() };
for y in grid_positions(area.y0, area.y1, rows, rg) {
- pg.guides.push(Guide { orientation: Orientation::Horizontal, position: y, spread: false, locked: false, layer: Some(layer) });
+ pg.guides.push(Guide {
+ orientation: Orientation::Horizontal,
+ position: y,
+ spread: false,
+ locked: false,
+ layer: Some(layer),
+ liquid: false,
+ });
n += 1;
}
for x in grid_positions(area.x0, area.x1, cols, cg) {
- pg.guides.push(Guide { orientation: Orientation::Vertical, position: x, spread: false, locked: false, layer: Some(layer) });
+ pg.guides.push(Guide {
+ orientation: Orientation::Vertical,
+ position: x,
+ spread: false,
+ locked: false,
+ layer: Some(layer),
+ liquid: false,
+ });
n += 1;
}
}
diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs
index 9e7be8403..5ad49d2bd 100644
--- a/crates/engine/src/cmd/layout.rs
+++ b/crates/engine/src/cmd/layout.rs
@@ -278,6 +278,18 @@ pub fn specs() -> Vec<CommandSpec> {
}
let w = p.get("width").and_then(Value::as_f64);
let h = p.get("height").and_then(Value::as_f64);
+ // Pages with a liquid rule re-flow their objects (Adjust Layout aside).
+ let liquid_before: Vec<(usize, usize, designcraft_geom::Rect)> = if adjust {
+ vec![]
+ } else {
+ d.spreads
+ .iter()
+ .enumerate()
+ .flat_map(|(si, sp)| {
+ sp.pages.iter().enumerate().filter(|(_, pg)| !pg.liquid.is_off()).map(move |(pi, pg)| (si, pi, pg.bounds()))
+ })
+ .collect()
+ };
if w.is_some() || h.is_some() {
d.settings.page_width = w.unwrap_or(d.settings.page_width);
d.settings.page_height = h.unwrap_or(d.settings.page_height);
@@ -294,6 +306,9 @@ pub fn specs() -> Vec<CommandSpec> {
if let Some(b) = before {
adjust_layout(d, &b);
}
+ for (si, pi, old) in liquid_before {
+ super::liquid::apply(d, designcraft_doc::SpreadRef::Doc(si), pi, old);
+ }
Ok(document_setup(d))
})
}
@@ -605,10 +620,20 @@ fn page_size(s: &mut crate::Session, p: &Value) -> Result<Value> {
h = Some(pr.height);
}
s.edit(|d, _| {
- for page in &pages {
+ resize_pages(d, &pages, w, h);
+ Ok(json!({"pages": pages.len()}))
+ })
+}
+
+/// Give `pages` (1-based) their own size. Objects stay on their page; pages with a liquid rule
+/// re-flow their objects by it.
+pub(crate) fn resize_pages(d: &mut designcraft_doc::Document, pages: &[usize], w: Option<f64>, h: Option<f64>) {
+ {
+ for page in pages {
let Some((si, pi)) = d.page_loc(page - 1) else { continue };
let sp = std::sync::Arc::make_mut(&mut d.spreads[si]);
let old: Vec<f64> = sp.pages.iter().map(|x| x.x).collect();
+ let old_bounds = sp.pages[pi].bounds();
let pg = &mut sp.pages[pi];
let dw = w.map_or(0.0, |w| w.max(1.0) - pg.width);
if let Some(w) = w {
@@ -638,9 +663,20 @@ fn page_size(s: &mut crate::Session, p: &Value) -> Result<Value> {
it.xf = designcraft_geom::Affine::translate((*dx, 0.0)) * it.xf;
}
}
+ // Page guides move with their page.
+ for (k, q) in sp.pages.iter_mut().enumerate() {
+ let dx = new[k] - old[k];
+ if dx != 0.0 {
+ for g in q.guides.iter_mut().filter(|g| g.orientation == designcraft_doc::Orientation::Vertical) {
+ g.position += dx;
+ }
+ }
+ }
+ // Liquid rules: objects were carried along with the page's left edge.
+ let moved = old_bounds + designcraft_geom::Vec2::new(new[pi] - old[pi], 0.0);
+ super::liquid::apply(d, designcraft_doc::SpreadRef::Doc(si), pi, moved);
}
- Ok(json!({"pages": pages.len()}))
- })
+ }
}
/// File › Document Setup values.
diff --git a/crates/engine/src/cmd/liquid.rs b/crates/engine/src/cmd/liquid.rs
new file mode 100644
index 000000000..5cf5c2a8b
--- /dev/null
+++ b/crates/engine/src/cmd/liquid.rs
@@ -0,0 +1,311 @@
+//! Liquid Layout (Layout › Liquid Layout, the Page tool): page rules that decide how objects
+//! follow when a page changes size, liquid guides, object pins, and alternate layouts.
+
+use std::sync::Arc;
+
+use designcraft_doc::{Content, Document, Item, LiquidRule, ObjectLiquid, Orientation, SpreadRef};
+use designcraft_geom::{Affine, Rect};
+use serde_json::{Value, json};
+
+use super::{CommandSpec, bad, cmd, has_doc, has_selection, str_param, targets};
+use crate::Result;
+
+/// One axis of an object-based rule: the new (lo, hi) for an object at (lo, hi) on a page that
+/// went from (o0, o1) to (n0, n1).
+fn axis(lo: f64, hi: f64, o: (f64, f64), n: (f64, f64), pin_lo: bool, pin_hi: bool, resize: bool) -> (f64, f64) {
+ let k = (n.1 - n.0) / (o.1 - o.0).max(1e-9);
+ let w = hi - lo;
+ let nw = if resize { w * k } else { w };
+ match (pin_lo, pin_hi) {
+ (true, true) if resize => (n.0 + (lo - o.0), n.1 - (o.1 - hi)),
+ (true, true) => {
+ let c = (n.0 + (lo - o.0) + n.1 - (o.1 - hi)) / 2.0;
+ (c - w / 2.0, c + w / 2.0)
+ }
+ (true, false) => (n.0 + (lo - o.0), n.0 + (lo - o.0) + nw),
+ (false, true) => (n.1 - (o.1 - hi) - nw, n.1 - (o.1 - hi)),
+ (false, false) => {
+ let c = n.0 + ((lo + hi) / 2.0 - o.0) * k;
+ (c - nw / 2.0, c + nw / 2.0)
+ }
+ }
+}
+
+/// The new spread-space bounds of an object at `b` under `rule`.
+fn target(rule: LiquidRule, b: Rect, old: Rect, new: Rect, liquid: Option<ObjectLiquid>, vguides: &[f64], hguides: &[f64]) -> Rect {
+ let (ox, oy, nx, ny) = ((old.x0, old.x1), (old.y0, old.y1), (new.x0, new.x1), (new.y0, new.y1));
+ match rule {
+ LiquidRule::Off => b,
+ LiquidRule::ReCenter => b + (new.center() - old.center()),
+ LiquidRule::Scale => {
+ let k = (new.width() / old.width()).min(new.height() / old.height());
+ let c = new.center() + (b.center() - old.center()) * k;
+ Rect::from_center_size(c, (b.width() * k, b.height() * k))
+ }
+ LiquidRule::GuideBased => {
+ let sx = vguides.iter().any(|g| *g > b.x0 && *g < b.x1);
+ let sy = hguides.iter().any(|g| *g > b.y0 && *g < b.y1);
+ let (x0, x1) = axis(b.x0, b.x1, ox, nx, false, false, sx);
+ let (y0, y1) = axis(b.y0, b.y1, oy, ny, false, false, sy);
+ Rect::new(x0, y0, x1, y1)
+ }
+ LiquidRule::ObjectBased => {
+ let l = liquid.unwrap_or(ObjectLiquid { resize_width: true, resize_height: true, ..Default::default() });
+ let (x0, x1) = axis(b.x0, b.x1, ox, nx, l.pin_left, l.pin_right, l.resize_width);
+ let (y0, y1) = axis(b.y0, b.y1, oy, ny, l.pin_top, l.pin_bottom, l.resize_height);
+ Rect::new(x0, y0, x1, y1)
+ }
+ }
+}
+
+/// Re-flow page `pi` of spread `sr` after it went from `old` to its current bounds (objects are
+/// still placed relative to `old`). Nothing happens with the rule off.
+pub(crate) fn apply(d: &mut Document, sr: SpreadRef, pi: usize, old: Rect) {
+ let Some(sp) = d.spread(sr) else { return };
+ let Some(pg) = sp.pages.get(pi) else { return };
+ let (rule, new) = (pg.liquid, pg.bounds());
+ if rule == LiquidRule::Off || old == new || old.width() < 1e-6 || old.height() < 1e-6 {
+ return;
+ }
+ let liquid_guides = |o: Orientation| pg.guides.iter().filter(|g| g.liquid && g.orientation == o).map(|g| g.position).collect::<Vec<_>>();
+ let (vg, hg) = (liquid_guides(Orientation::Vertical), liquid_guides(Orientation::Horizontal));
+ // The page's objects: centres within its old horizontal extent (outer pages take the pasteboard).
+ let last = sp.pages.len() - 1;
+ let (lo, hi) = (if pi == 0 { f64::NEG_INFINITY } else { old.x0 }, if pi == last { f64::INFINITY } else { old.x1 });
+ let strokes = false;
+ let Some(sp) = d.spread_mut(sr) else { return };
+ for it in &mut sp.items {
+ let b = it.bounds();
+ let c = b.center().x;
+ if c < lo || c >= hi || b.width() < 1e-9 || b.height() < 1e-9 {
+ continue;
+ }
+ let to = target(rule, b, old, new, it.liquid, &vg, &hg);
+ if to == b {
+ continue;
+ }
+ let m = Affine::translate((to.x0, to.y0))
+ * Affine::scale_non_uniform(to.width() / b.width(), to.height() / b.height())
+ * Affine::translate((-b.x0, -b.y0));
+ let it: &mut Item = Arc::make_mut(it);
+ if rule == LiquidRule::Scale {
+ super::object::scale_item(it, m, (to.width() / b.width()).abs(), strokes);
+ } else if matches!(it.content, Content::Group { .. }) {
+ it.xf = m * it.xf;
+ } else {
+ // The frame stretches; content keeps its size unless the frame auto-fits it.
+ let inner = it.xf.inverse() * m * it.xf;
+ super::object::bake(it, inner);
+ let ib = it.inner_bounds();
+ if let Content::Graphic(g) = &mut it.content {
+ let o = inner * designcraft_geom::Point::ZERO;
+ g.xf = Affine::translate(o.to_vec2()) * g.xf;
+ if let Some(xf) = g.fitted(ib, g.auto_fit) {
+ g.xf = xf;
+ }
+ }
+ }
+ }
+}
+
+fn rule_param(p: &Value, id: &str) -> Result<LiquidRule> {
+ serde_json::from_value(p.get("rule").cloned().unwrap_or(json!("off"))).map_err(|_| bad(id, "`rule`: off|scale|reCenter|guideBased|objectBased"))
+}
+
+pub fn specs() -> Vec<CommandSpec> {
+ vec![
+ cmd!(
+ "liquid.pageRule",
+ "Liquid Page Rule",
+ ["Layout", "Liquid Layout"],
+ None,
+ "{rule: off|scale|reCenter|guideBased|objectBased, pages?: [1-based] (default: all)}",
+ has_doc,
+ |s, p| {
+ let rule = rule_param(p, "liquid.pageRule")?;
+ let pages: Option<Vec<usize>> =
+ p.get("pages").and_then(Value::as_array).map(|a| a.iter().filter_map(Value::as_u64).map(|n| n as usize).collect());
+ s.edit(|d, _| {
+ let n = d.page_count();
+ let list = pages.clone().unwrap_or_else(|| (1..=n).collect());
+ for page in &list {
+ let Some((si, pi)) = page.checked_sub(1).and_then(|i| d.page_loc(i)) else { continue };
+ Arc::make_mut(&mut d.spreads[si]).pages[pi].liquid = rule;
+ }
+ Ok(json!({"pages": list.len()}))
+ })
+ }
+ ),
+ cmd!(
+ "liquid.object",
+ "Object Liquid Settings",
+ [],
+ None,
+ "{ids?, resizeWidth?, resizeHeight?, pinTop?, pinBottom?, pinLeft?, pinRight?} — for object-based pages",
+ has_selection,
+ |s, p| {
+ let ids = targets(s, p)?;
+ s.edit(|d, _| {
+ for id in &ids {
+ let Some(it) = d.item_mut(*id) else { continue };
+ let mut l = it.liquid.unwrap_or(ObjectLiquid { resize_width: true, resize_height: true, ..Default::default() });
+ for (k, f) in [
+ ("resizeWidth", &mut l.resize_width),
+ ("resizeHeight", &mut l.resize_height),
+ ("pinTop", &mut l.pin_top),
+ ("pinBottom", &mut l.pin_bottom),
+ ("pinLeft", &mut l.pin_left),
+ ("pinRight", &mut l.pin_right),
+ ] {
+ if let Some(v) = p.get(k).and_then(Value::as_bool) {
+ *f = v;
+ }
+ }
+ it.liquid = Some(l);
+ }
+ Ok(json!({"objects": ids.len()}))
+ })
+ }
+ ),
+ cmd!("guide.liquid", "Convert to Liquid Guide", [], None, "{spread?, page, index, on?: bool (default true)}", has_doc, |s, p| {
+ let sr = super::spread_param(p, "spread");
+ let pi = p.get("page").and_then(Value::as_u64).unwrap_or(0) as usize;
+ let gi = p.get("index").and_then(Value::as_u64).ok_or_else(|| bad("guide.liquid", "`index` required"))? as usize;
+ let on = p.get("on").and_then(Value::as_bool).unwrap_or(true);
+ s.edit(|d, _| {
+ let sp = d.spread_mut(sr).ok_or_else(|| bad("guide.liquid", "no such spread"))?;
+ let g = sp.pages.get_mut(pi).and_then(|pg| pg.guides.get_mut(gi)).ok_or_else(|| bad("guide.liquid", "no such guide"))?;
+ g.liquid = on;
+ Ok(Value::Null)
+ })
+ }),
+ cmd!(
+ "layout.createAlternate",
+ "Create Alternate Layout…",
+ ["Layout"],
+ None,
+ "{name, width, height, rule?: page rule for the copies (default: keep each page's)} — every page copied after the last at the new size (a new section marked `name`), objects following the liquid rules",
+ has_doc,
+ create_alternate
+ ),
+ ]
+}
+
+fn create_alternate(s: &mut crate::Session, p: &Value) -> Result<Value> {
+ const ID: &str = "layout.createAlternate";
+ let name = str_param(p, "name").unwrap_or("Alternate").to_string();
+ let w = p.get("width").and_then(Value::as_f64).ok_or_else(|| bad(ID, "`width` required"))?.max(1.0);
+ let h = p.get("height").and_then(Value::as_f64).ok_or_else(|| bad(ID, "`height` required"))?.max(1.0);
+ let rule = p.get("rule").map(|_| rule_param(p, ID)).transpose()?;
+ let n = s.doc()?.doc.page_count();
+ s.edit(|d, _| {
+ let src = d.clone();
+ let parent = d.page_loc(n - 1).and_then(|(si, pi)| d.spreads[si].pages[pi].parent);
+ d.insert_pages(Some(n - 1), n, parent)?;
+ for i in 0..n {
+ let (Some((si, pi)), Some((ti, tj))) = (src.page_loc(i), d.page_loc(n + i)) else { continue };
+ let from = &src.spreads[si];
+ let pb = from.pages[pi].bounds();
+ let last = from.pages.len() - 1;
+ let ids: Vec<_> = from
+ .items
+ .iter()
+ .filter(|it| {
+ let c = it.bounds().center().x;
+ (pi == 0 || c >= pb.x0) && (pi == last || c < pb.x1)
+ })
+ .map(|it| it.id)
+ .collect();
+ // The copy keeps the page's liquid rule (or takes the one given).
+ let to = d.spreads[ti].pages[tj].bounds();
+ Arc::make_mut(&mut d.spreads[ti]).pages[tj].liquid = rule.unwrap_or(from.pages[pi].liquid);
+ Arc::make_mut(&mut d.spreads[ti]).pages[tj].guides = from.pages[pi]
+ .guides
+ .iter()
+ .cloned()
+ .map(|mut g| {
+ if g.orientation == Orientation::Vertical {
+ g.position += to.x0 - pb.x0;
+ }
+ g
+ })
+ .collect();
+ super::object::duplicate_from(d, &src, &ids, SpreadRef::Doc(ti), designcraft_geom::Vec2::new(to.x0 - pb.x0, 0.0))?;
+ }
+ let pages: Vec<usize> = (n + 1..=2 * n).collect();
+ super::layout::resize_pages(d, &pages, Some(w), Some(h));
+ d.sections.retain(|x| x.start != n);
+ d.sections.push(designcraft_doc::Section {
+ start: n,
+ start_number: Some(1),
+ style: Default::default(),
+ prefix: String::new(),
+ marker: name.clone(),
+ include_prefix: false,
+ });
+ d.sections.sort_by_key(|x| x.start);
+ Ok(json!({"firstPage": n + 1, "pages": n}))
+ })
+}
+
+#[cfg(test)]
+mod tests {
+ use serde_json::json;
+
+ use crate::Session;
+
+ fn bounds(s: &Session, id: u64) -> designcraft_geom::Rect {
+ s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds()
+ }
+
+ #[test]
+ fn liquid_rules_follow_a_page_resize() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 1, "width": 600, "height": 800})).unwrap();
+ let a = s.execute("frame.create", &json!({"rect": [100, 100, 200, 200]})).unwrap()["id"].as_u64().unwrap();
+ // Re-center: same size, shifted by half the growth.
+ s.execute("liquid.pageRule", &json!({"rule": "reCenter"})).unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 800})).unwrap();
+ let b = bounds(&s, a);
+ assert!((b.x0 - 200.0).abs() < 1e-6 && (b.width() - 100.0).abs() < 1e-6, "{b:?}");
+ // Object-based: pinned left and right, resizable → stretches with the page.
+ s.execute("liquid.pageRule", &json!({"rule": "objectBased"})).unwrap();
+ s.execute("liquid.object", &json!({"ids": [a], "pinLeft": true, "pinRight": true, "resizeWidth": true, "resizeHeight": false})).unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 900})).unwrap();
+ let b = bounds(&s, a);
+ assert!((b.x0 - 200.0).abs() < 1e-6 && (b.x1 - 400.0).abs() < 1e-6, "{b:?}");
+ // Scale: uniform, centred.
+ s.execute("liquid.pageRule", &json!({"rule": "scale"})).unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 450, "height": 400})).unwrap();
+ let b = bounds(&s, a);
+ assert!((b.width() - 100.0).abs() < 1e-6 && (b.height() - 50.0).abs() < 1e-6, "{b:?}");
+ }
+
+ #[test]
+ fn guide_based_and_alternate_layout() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"pages": 1, "width": 600, "height": 800})).unwrap();
+ let a = s.execute("frame.create", &json!({"rect": [100, 100, 300, 200]})).unwrap()["id"].as_u64().unwrap();
+ let b = s.execute("frame.create", &json!({"rect": [400, 100, 500, 200]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("guide.add", &json!({"orientation": "vertical", "position": 200, "page": 0})).unwrap();
+ s.execute("guide.liquid", &json!({"page": 0, "index": 0})).unwrap();
+ s.execute("liquid.pageRule", &json!({"rule": "guideBased"})).unwrap();
+ let r = s.execute("layout.createAlternate", &json!({"name": "Wide", "width": 1200, "height": 800})).unwrap();
+ assert_eq!(r["firstPage"], 2);
+ let d = s.doc().unwrap().doc.clone();
+ assert_eq!(d.page_count(), 2);
+ let (si, pi) = d.page_loc(1).unwrap();
+ let page = d.spreads[si].pages[pi].bounds();
+ assert!((page.width() - 1200.0).abs() < 1e-6);
+ let copies: Vec<_> = d.spreads[si].items.iter().map(|it| it.bounds()).collect();
+ assert_eq!(copies.len(), 2);
+ // The frame the liquid guide crosses doubles in width; the other keeps its size.
+ let mut widths: Vec<f64> = copies.iter().map(|r| r.width()).collect();
+ widths.sort_by(f64::total_cmp);
+ assert!((widths[0] - 100.0).abs() < 1e-6 && (widths[1] - 400.0).abs() < 1e-6, "{widths:?}");
+ // The originals are untouched, and it is one undo step.
+ assert!((bounds(&s, a).width() - 200.0).abs() < 1e-6 && (bounds(&s, b).width() - 100.0).abs() < 1e-6);
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(s.doc().unwrap().doc.page_count(), 1);
+ }
+}
diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rs
index 3729a72c1..2af86a9b6 100644
--- a/crates/engine/src/cmd/mod.rs
+++ b/crates/engine/src/cmd/mod.rs
@@ -25,6 +25,7 @@ mod layout;
pub mod library;
mod linked;
mod links;
+mod liquid;
mod lists;
mod notes;
mod object;
@@ -158,6 +159,7 @@ pub fn command_specs() -> &'static [CommandSpec] {
v.extend(library::specs());
v.extend(lists::specs());
v.extend(linked::specs());
+ v.extend(liquid::specs());
v.extend(xml::specs());
v.extend(strokes::specs());
v.extend(states::specs());
diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rs
index 6d5942deb..60fad25ff 100644
--- a/crates/engine/src/cmd/object.rs
+++ b/crates/engine/src/cmd/object.rs
@@ -860,7 +860,7 @@ fn union_bounds(d: &Document, ids: &[ItemId]) -> Rect {
}
/// Transform an item's geometry in its own space: the path and the gradient vector with it.
-fn bake(it: &mut Item, inner: Affine) {
+pub(crate) fn bake(it: &mut Item, inner: Affine) {
it.path.transform(inner);
if let Some([x0, y0, x1, y1]) = it.fill.gradient_vector {
let (a, b) = (inner * Point::new(x0, y0), inner * Point::new(x1, y1));
diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rs
index 0ae7b89d4..ea3c2b200 100644
--- a/crates/idml/src/import.rs
+++ b/crates/idml/src/import.rs
@@ -1650,6 +1650,7 @@ impl<'r> Importer<'r> {
overridden: vec![],
guides: Vec::<Guide>::new(),
show_parent_items: show,
+ liquid: Default::default(),
});
}
let overrides: Vec<Vec<String>> =
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 63587c9f4..df5221b62 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -568,7 +568,13 @@ fn draw_guides(app: &DesignApp, painter: &egui::Painter, xf: &Xf, doc: &Document
(Point::new(g.position + off.x, span.y0), Point::new(g.position + off.x, span.y1))
}
};
- painter.line_segment([xf.to_screen(a), xf.to_screen(bb)], Stroke::new(hair(painter), Color32::from_rgb(74, 227, 255)));
+ let stroke = Stroke::new(hair(painter), Color32::from_rgb(74, 227, 255));
+ if g.liquid {
+ // Liquid guides are dashed.
+ painter.extend(egui::Shape::dashed_line(&[xf.to_screen(a), xf.to_screen(bb)], stroke, 6.0, 3.0));
+ } else {
+ painter.line_segment([xf.to_screen(a), xf.to_screen(bb)], stroke);
+ }
}
}
}
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs
index ebfdea745..0d19b3078 100644
--- a/crates/ui-egui/src/dock.rs
+++ b/crates/ui-egui/src/dock.rs
@@ -40,6 +40,7 @@ pub const ICON_PANELS: &[(&str, &str, &str)] = &[
("book", "Book", "panel-library"),
("states", "Object States", "panel-articles"),
("buttons", "Buttons and Forms", "panel-articles"),
+ ("liquid", "Liquid Layout", "panel-pages"),
];
pub fn show(app: &mut DesignApp, ui: &mut egui::Ui) {
@@ -185,6 +186,7 @@ pub fn panel_body(app: &mut DesignApp, ui: &mut egui::Ui, id: &str) {
"book" => panels::library::book(app, ui),
"states" => panels::interactive::states(app, ui),
"buttons" => panels::interactive::buttons(app, ui),
+ "liquid" => panels::interactive::liquid(app, ui),
"table" => panels::table::show(app, ui),
_ => panels::properties::info_panel(app, ui),
}
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 7b525be82..39dff446e 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -525,6 +525,7 @@ pub const MENUS: &[(&str, &[&str])] = &[
"ui:window.panel|Articles|{\"panel\": \"articles\"}",
"ui:window.panel|Object States|{\"panel\": \"states\"}",
"ui:window.panel|Buttons and Forms|{\"panel\": \"buttons\"}",
+ "ui:window.panel|Liquid Layout|{\"panel\": \"liquid\"}",
"ui:window.panel|Tags|{\"panel\": \"tags\"}",
"ui:window.panel|Book|{\"panel\": \"book\"}",
"<",
diff --git a/crates/ui-egui/src/panels/interactive.rs b/crates/ui-egui/src/panels/interactive.rs
index 306c95945..a3250fc76 100644
--- a/crates/ui-egui/src/panels/interactive.rs
+++ b/crates/ui-egui/src/panels/interactive.rs
@@ -273,3 +273,73 @@ pub fn buttons(app: &mut DesignApp, ui: &mut egui::Ui) {
}
ui.label(egui::RichText::new("Buttons act in interactive PDF export.").size(10.5).color(t.text_dim));
}
+
+/// Liquid Layout panel: the current page's rule, the selection's pins (object-based), the page's
+/// liquid guides, and Create Alternate Layout.
+pub fn liquid(app: &mut DesignApp, ui: &mut egui::Ui) {
+ let t = Tokens::get(ui.ctx());
+ let Some(page) = crate::canvas::current_page(app) else {
+ ui.label(egui::RichText::new("No document.").size(11.0).color(t.text_dim));
+ return;
+ };
+ let Some(d) = app.session.active().map(|d| d.doc.clone()) else { return };
+ let Some((si, pi)) = d.page_loc(page) else { return };
+ let pg = d.spreads[si].pages[pi].clone();
+ use designcraft_doc::LiquidRule as L;
+ ui.label(egui::RichText::new(format!("Page {}", d.page_name(page))).strong());
+ let mut rule = pg.liquid;
+ egui::ComboBox::from_id_salt("liquid_rule").selected_text(format!("{rule:?}")).show_ui(ui, |ui| {
+ for (r, label) in
+ [(L::Off, "Off"), (L::Scale, "Scale"), (L::ReCenter, "Re-center"), (L::GuideBased, "Guide-based"), (L::ObjectBased, "Object-based")]
+ {
+ ui.selectable_value(&mut rule, r, label);
+ }
+ });
+ if rule != pg.liquid {
+ let _ = app.run("liquid.pageRule", json!({"rule": rule, "pages": [page + 1]}));
+ }
+ if rule == L::ObjectBased
+ && let Some(id) = app.session.active().and_then(|s| s.selection.items.first().copied())
+ && let Some(it) = d.item(id)
+ {
+ ui.separator();
+ let l = it.liquid.unwrap_or(designcraft_doc::ObjectLiquid { resize_width: true, resize_height: true, ..Default::default() });
+ let mut v = [l.resize_width, l.resize_height, l.pin_top, l.pin_bottom, l.pin_left, l.pin_right];
+ let keys = ["resizeWidth", "resizeHeight", "pinTop", "pinBottom", "pinLeft", "pinRight"];
+ let labels = ["Resize width", "Resize height", "Pin top", "Pin bottom", "Pin left", "Pin right"];
+ ui.horizontal_wrapped(|ui| {
+ for ((on, key), label) in v.iter_mut().zip(keys).zip(labels) {
+ if ui.checkbox(on, label).changed() {
+ let _ = app.run("liquid.object", json!({key: *on}));
+ }
+ }
+ });
+ }
+ if !pg.guides.is_empty() {
+ ui.separator();
+ ui.label(egui::RichText::new("Liquid guides").size(11.0).color(t.text_dim));
+ for (gi, g) in pg.guides.iter().enumerate() {
+ let mut on = g.liquid;
+ let label = format!("{:?} at {:.1}", g.orientation, g.position);
+ if ui.checkbox(&mut on, label).changed() {
+ let _ = app.run("guide.liquid", json!({"spread": si, "page": pi, "index": gi, "on": on}));
+ }
+ }
+ }
+ ui.separator();
+ let key = egui::Id::new("alt_layout");
+ let (mut name, mut w, mut h): (String, f64, f64) = ui.data(|x| x.get_temp(key)).unwrap_or(("Tablet H".into(), 1024.0, 768.0));
+ ui.label(egui::RichText::new("Create Alternate Layout").size(11.0).color(t.text_dim));
+ ui.horizontal(|ui| {
+ ui.add(egui::TextEdit::singleline(&mut name).desired_width(90.0));
+ ui.add(egui::DragValue::new(&mut w).range(1.0..=15552.0).suffix(" pt"));
+ ui.label("×");
+ ui.add(egui::DragValue::new(&mut h).range(1.0..=15552.0).suffix(" pt"));
+ });
+ if ui.button("Create").clicked()
+ && let Err(e) = app.run("layout.createAlternate", json!({"name": name, "width": w, "height": h}))
+ {
+ app.status(format!("Alternate layout: {e}"));
+ }
+ ui.data_mut(|x| x.insert_temp(key, (name, w, h)));
+}
diff --git a/docs/parity.md b/docs/parity.md
index 0a34c0ae9..ee5bac6cf 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -5,18 +5,18 @@ The summary is generated by `cargo xtask parity` from the table at the bottom of
Each 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: 93%** over 275 features.
+**Weighted breadth parity: 94%** over 275 features.
| Priority | Features | Done | Partial | Missing | Parity |
|---|---|---|---|---|---|
| P0 | 102 | 99 | 3 | 0 | 99% |
| P1 | 97 | 92 | 4 | 1 | 97% |
-| P2 | 76 | 37 | 24 | 15 | 64% |
+| P2 | 76 | 39 | 25 | 12 | 68% |
| Area | Parity |
|---|---|
| Application shell & workspace | 88% |
-| Documents, pages, spreads | 90% |
+| Documents, pages, spreads | 94% |
| Layers | 95% |
| Frames, shapes & paths | 100% |
| Transform | 100% |
@@ -78,12 +78,12 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t
| Documents, pages, spreads | Spread view rotation | P2 | M |
| Documents, pages, spreads | Layout Adjustment | P2 | D |
| Documents, pages, spreads | Adjust Layout | P2 | D |
-| Documents, pages, spreads | Liquid layout | P2 | M |
-| Documents, pages, spreads | Alternate layouts | P2 | M |
+| Documents, pages, spreads | Liquid layout | P2 | D |
+| Documents, pages, spreads | Alternate layouts | P2 | P |
| Documents, pages, spreads | Document grid & baseline grid | P0 | D |
| Documents, pages, spreads | Ruler guides | P0 | D |
| Documents, pages, spreads | Guides on layers | P1 | D |
-| Documents, pages, spreads | Liquid guides | P2 | M |
+| Documents, pages, spreads | Liquid guides | P2 | D |
| Documents, pages, spreads | Smart guides | P0 | D |
| Documents, pages, spreads | Snap to guides / grid / baseline | P0 | D |
| Layers | Layers panel | P0 | D |