DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
F: Stroke panel — arrowheads (screen and PDF), cap/join/miter, gap colour
Brandon Thomas97b305fdcda3
diff --git a/ROADMAP.md b/ROADMAP.mdindex e14b20803..dfff83fbb 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -30,6 +30,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Edit › Paste Into (copied objects become a frame's content, clipped by it; rendered, PDF and IDML both ways — verified in InDesign 2026); Polygon Settings (sides, star inset; double-click the Polygon tool).- Color panel (fill/stroke proxy, CMYK/RGB/Lab sliders with channel ramps, tint slider for swatches, spectrum ramp, Add to Swatches) and Color Picker (double-click the proxy); mixed colours are unnamed (not listed in Swatches until added); `object.color`, `swatch.addToSwatches`, `swatch.addUnnamed`.- Place text files: Word (.docx: styles by name with their attributes, bold/italic/underline/size/font, footnotes, tables, tabs, breaks), RTF and plain text, into the insertion point, the selected frame or a new frame; autoflow adds pages and threaded frames until the text fits; Remove Styles option (`designcraft-textimport`).+- Stroke panel: cap, join, miter limit, alignment, type, Start/End arrowheads (12 kinds, drawn on screen and in PDF; the path is shortened under pointed heads) and gap colour under dashes and dots.- Preferences (⌘K: General, Type, Units & Increments) backed by `prefs.set` (application) and `document.preferences` (units, increments, grids — undoable, saved with the document); scaling applies to content and scales stroke weights (Include Stroke Weight), and X/Y/W/H measure the stroke's outer edge (Dimensions Include Stroke Weight). Quick Apply (⌘Return) finds paragraph, character and object styles as well as commands.- Parent item overrides: Cmd+Shift-click a parent item on a page (or Override All Parent Page Items, ⌥⇧⌘L) makes an editable local copy that hides the parent's; Remove All Local Overrides and Detach All Objects from Parent in the Pages panel menu.- Place PDF: placed PDF pages are sized by their crop box, drawn on screen through hayro (with mip levels) and embedded in exported PDFs as vector form XObjects (krilla), `<PDF>` in IDML.diff --git a/crates/doc/src/arrow.rs b/crates/doc/src/arrow.rsnew file mode 100644index 000000000..e3f3387fe--- /dev/null+++ b/crates/doc/src/arrow.rs@@ -0,0 +1,176 @@+//! Arrowheads at the ends of open paths (Stroke panel › Start/End). Each kind is a small shape+//! drawn in the stroke colour, sized by the stroke weight; the path is shortened under heads that+//! end in a point so the stroke doesn't show past the tip.++use designcraft_geom::kurbo::{self, ParamCurve, ParamCurveArclen, ParamCurveDeriv};+use designcraft_geom::{Affine, BezPath, PathSeg, Point, Vec2};++use crate::item::{Arrowhead, Stroke};++/// A head ready to draw: filled, or outlined with `outline` width.+#[derive(Clone, Debug)]+pub struct ArrowShape {+ pub path: BezPath,+ pub outline: Option<f64>,+}++/// Arrowhead outline in a local frame: tip at the origin, pointing along +x, for weight `w`.+/// Returns the shape, whether it is outlined, and how far to pull the path back from the tip.+fn local(kind: Arrowhead, w: f64) -> Option<(BezPath, bool, f64)> {+ // Heads stay legible on hairlines.+ let k = w.max(0.5);+ let poly = |pts: &[(f64, f64)]| {+ let mut p = BezPath::new();+ p.move_to(pts[0]);+ for q in &pts[1..] {+ p.line_to(*q);+ }+ p.close_path();+ p+ };+ let open = |pts: &[(f64, f64)]| {+ let mut p = BezPath::new();+ p.move_to(pts[0]);+ for q in &pts[1..] {+ p.line_to(*q);+ }+ p+ };+ Some(match kind {+ Arrowhead::None => return None,+ Arrowhead::Triangle => (poly(&[(0.0, 0.0), (-4.5 * k, 2.0 * k), (-4.5 * k, -2.0 * k)]), false, 4.0 * k),+ Arrowhead::TriangleWide => (poly(&[(0.0, 0.0), (-4.5 * k, 3.2 * k), (-4.5 * k, -3.2 * k)]), false, 4.0 * k),+ Arrowhead::Simple => (open(&[(-4.0 * k, 2.5 * k), (-0.5 * k, 0.0), (-4.0 * k, -2.5 * k)]), true, 0.5 * k),+ Arrowhead::SimpleWide => (open(&[(-3.0 * k, 3.6 * k), (-0.5 * k, 0.0), (-3.0 * k, -3.6 * k)]), true, 0.5 * k),+ Arrowhead::Barbed => (poly(&[(0.0, 0.0), (-5.0 * k, 2.6 * k), (-3.4 * k, 0.0), (-5.0 * k, -2.6 * k)]), false, 3.4 * k),+ Arrowhead::Curved => {+ let mut p = BezPath::new();+ p.move_to((0.0, 0.0));+ p.quad_to((-2.2 * k, 0.6 * k), (-5.0 * k, 2.8 * k));+ p.quad_to((-3.8 * k, 1.0 * k), (-3.6 * k, 0.0));+ p.quad_to((-3.8 * k, -k), (-5.0 * k, -2.8 * k));+ p.quad_to((-2.2 * k, -0.6 * k), (0.0, 0.0));+ p.close_path();+ (p, false, 3.6 * k)+ }+ // Circles and squares sit centred on the end point.+ Arrowhead::Circle | Arrowhead::CircleSolid => {+ let r = 2.2 * k;+ let p = kurbo::Shape::to_path(&kurbo::Circle::new((0.0, 0.0), r), 0.01);+ let outline = kind == Arrowhead::Circle;+ (p, outline, if outline { r } else { 0.0 })+ }+ Arrowhead::Square | Arrowhead::SquareSolid => {+ let h = 2.0 * k;+ let outline = kind == Arrowhead::Square;+ (poly(&[(-h, -h), (h, -h), (h, h), (-h, h)]), outline, if outline { h } else { 0.0 })+ }+ Arrowhead::Bar => (poly(&[(-0.5 * k, -3.0 * k), (0.5 * k, -3.0 * k), (0.5 * k, 3.0 * k), (-0.5 * k, 3.0 * k)]), false, 0.0),+ })+}++/// The path end: its point and the outward direction (unit).+fn end_of(seg: &PathSeg, at_start: bool) -> (Point, Vec2) {+ let (t, p) = if at_start { (0.0, seg.start()) } else { (1.0, seg.end()) };+ let mut d = match seg {+ PathSeg::Line(l) => l.p1 - l.p0,+ PathSeg::Quad(q) => q.deriv().eval(t).to_vec2(),+ PathSeg::Cubic(c) => c.deriv().eval(t).to_vec2(),+ };+ if d.hypot() < 1e-9 {+ d = seg.end() - seg.start();+ }+ let d = if at_start { -d } else { d };+ (p, if d.hypot() < 1e-12 { Vec2::new(1.0, 0.0) } else { d.normalize() })+}++/// Shorten a segment by `by` (arc length) at its start or end.+fn trim(seg: PathSeg, by: f64, at_start: bool) -> PathSeg {+ let len = seg.arclen(1e-3);+ if by <= 0.0 || len < 1e-9 {+ return seg;+ }+ let by = by.min(len * 0.9);+ if at_start {+ let t = seg.inv_arclen(by, 1e-3);+ seg.subsegment(t..1.0)+ } else {+ let t = seg.inv_arclen(len - by, 1e-3);+ seg.subsegment(0.0..t)+ }+}++/// The path to stroke (shortened under pointed heads) and the heads to draw, for an open path+/// with arrowheads. `None` when there is nothing to change (closed path, no heads).+pub fn apply(bp: &BezPath, st: &Stroke, closed: bool) -> Option<(BezPath, Vec<ArrowShape>)> {+ if closed || (st.start == Arrowhead::None && st.end == Arrowhead::None) {+ return None;+ }+ let mut segs: Vec<PathSeg> = bp.segments().collect();+ if segs.is_empty() {+ return None;+ }+ let mut heads = Vec::new();+ let last = segs.len() - 1;+ for (kind, at_start) in [(st.start, true), (st.end, false)] {+ let Some((shape, outlined, pull)) = local(kind, st.weight) else { continue };+ let i = if at_start { 0 } else { last };+ let (tip, dir) = end_of(&segs[i], at_start);+ let xf = Affine::translate(tip.to_vec2()) * Affine::rotate(dir.y.atan2(dir.x));+ heads.push(ArrowShape { path: xf * shape, outline: outlined.then_some(st.weight.max(0.5) * 0.9) });+ segs[i] = trim(segs[i], pull, at_start);+ }+ let mut out = BezPath::new();+ for (n, s) in segs.iter().enumerate() {+ // A new subpath wherever the original had one (gaps between consecutive segments).+ if n == 0 || (segs[n - 1].end() - s.start()).hypot() > 1e-6 {+ out.move_to(s.start());+ }+ match s {+ PathSeg::Line(l) => out.line_to(l.p1),+ PathSeg::Quad(q) => out.quad_to(q.p1, q.p2),+ PathSeg::Cubic(c) => out.curve_to(c.p1, c.p2, c.p3),+ }+ }+ Some((out, heads))+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn heads_point_along_the_path_and_trim_it() {+ let mut bp = BezPath::new();+ bp.move_to((0.0, 0.0));+ bp.line_to((100.0, 0.0));+ let st = Stroke { weight: 2.0, start: Arrowhead::Circle, end: Arrowhead::Triangle, ..Stroke::default() };+ let (line, heads) = apply(&bp, &st, false).unwrap();+ assert_eq!(heads.len(), 2);+ // The triangle's tip is the path end; its body lies before it.+ let tb = kurbo::Shape::bounding_box(&heads[1].path);+ assert!((tb.x1 - 100.0).abs() < 1e-6 && tb.x0 < 95.0, "{tb:?}");+ assert!(heads[1].outline.is_none());+ // The circle is centred on the start, outlined; the line starts at its edge.+ let cb = kurbo::Shape::bounding_box(&heads[0].path);+ assert!((cb.center().x).abs() < 1e-6, "{cb:?}");+ assert!(heads[0].outline.is_some());+ let lb = kurbo::Shape::bounding_box(&line);+ assert!((lb.x0 - 4.4).abs() < 1e-3 && (lb.x1 - 92.0).abs() < 1e-3, "{lb:?}");+ // Closed paths and plain strokes are left alone.+ assert!(apply(&bp, &st, true).is_none());+ assert!(apply(&bp, &Stroke::default(), false).is_none());+ }++ #[test]+ fn head_follows_a_curve_tangent() {+ let mut bp = BezPath::new();+ bp.move_to((0.0, 0.0));+ bp.curve_to((50.0, 0.0), (100.0, 50.0), (100.0, 100.0));+ let st = Stroke { weight: 1.0, end: Arrowhead::Bar, ..Stroke::default() };+ let (_, heads) = apply(&bp, &st, false).unwrap();+ // Ends heading straight down: the bar lies across, horizontally.+ let b = kurbo::Shape::bounding_box(&heads[0].path);+ assert!(b.width() > b.height() * 3.0, "{b:?}");+ }+}diff --git a/crates/doc/src/item.rs b/crates/doc/src/item.rsindex c39c7c9b6..ce2092ccd 100644--- a/crates/doc/src/item.rs+++ b/crates/doc/src/item.rs@@ -122,6 +122,40 @@ pub enum Arrowhead {Bar,}+impl Arrowhead {+ pub const ALL: [Arrowhead; 12] = [+ Arrowhead::None,+ Arrowhead::Simple,+ Arrowhead::SimpleWide,+ Arrowhead::Triangle,+ Arrowhead::TriangleWide,+ Arrowhead::Barbed,+ Arrowhead::Curved,+ Arrowhead::Circle,+ Arrowhead::CircleSolid,+ Arrowhead::Square,+ Arrowhead::SquareSolid,+ Arrowhead::Bar,+ ];++ pub fn label(self) -> &'static str {+ match self {+ Arrowhead::None => "None",+ Arrowhead::Simple => "Simple",+ Arrowhead::SimpleWide => "Simple - Wide",+ Arrowhead::Triangle => "Triangle",+ Arrowhead::TriangleWide => "Triangle - Wide",+ Arrowhead::Barbed => "Barbed",+ Arrowhead::Curved => "Curved",+ Arrowhead::Circle => "Circle",+ Arrowhead::CircleSolid => "Circle - Solid",+ Arrowhead::Square => "Square",+ Arrowhead::SquareSolid => "Square - Solid",+ Arrowhead::Bar => "Bar",+ }+ }+}+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase", default)]pub struct Stroke {@@ -164,6 +198,11 @@ impl Default for Stroke {}impl Stroke {+ /// How far the painted stroke can reach beyond the path (arrowheads reach further).+ pub fn extent(&self) -> f64 {+ if self.start == Arrowhead::None && self.end == Arrowhead::None { self.weight } else { self.weight.max(0.5) * 5.5 }+ }+pub fn none() -> Self {Stroke { swatch: designcraft_color::swatch::NONE.into(), ..Stroke::default() }}@@ -588,6 +627,8 @@ impl Item {StrokeAlign::Inside => 0.0,StrokeAlign::Outside => self.stroke.weight,};+ // Arrowheads on open paths.+ let w = if self.path.is_closed() { w } else { w.max(self.stroke.extent() - self.stroke.weight) };b.inflate(w, w)}diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rsindex 7282faf79..39f6c184f 100644--- a/crates/doc/src/lib.rs+++ b/crates/doc/src/lib.rs@@ -9,6 +9,7 @@#![forbid(unsafe_code)]pub mod anchored;+pub mod arrow;pub mod attrs;pub mod build;mod edit;diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rsindex b15615637..baa99fe94 100644--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@ -142,7 +142,7 @@ pub fn specs() -> Vec<CommandSpec> {"Stroke",[],None,- "{swatch?, tint?, weight?, align?: center|inside|outside, type?: {kind:…}, cap?, join?, ids?}",+ "{swatch?, tint?, weight?, align?: center|inside|outside, type?: {kind:…}, cap?: butt|round|projecting, join?: miter|round|bevel, miterLimit?, start?, end?: none|simple|simpleWide|triangle|triangleWide|barbed|curved|circle|circleSolid|square|squareSolid|bar, gapSwatch?, gapTint?, ids?}",has_selection,|s, p| {let p2 = p.clone();@@ -160,6 +160,15 @@ pub fn specs() -> Vec<CommandSpec> {if let Some(v) = p2.get("weight").and_then(Value::as_f64) {st.weight = v.max(0.0);}+ if let Some(v) = p2.get("miterLimit").and_then(Value::as_f64) {+ st.miter_limit = v.clamp(1.0, 500.0);+ }+ if let Some(v) = p2.get("gapSwatch").and_then(Value::as_str) {+ st.gap_swatch = v.into();+ }+ if let Some(v) = p2.get("gapTint").and_then(Value::as_f64) {+ st.gap_tint = v as f32;+ }for (k, apply) in [("align", 0), ("type", 1), ("cap", 2), ("join", 3), ("start", 4), ("end", 5)] {if let Some(v) = p2.get(k).cloned() {let _ = match apply {diff --git a/crates/pdf/src/export.rs b/crates/pdf/src/export.rsindex 58dead4c3..5229bb806 100644--- a/crates/pdf/src/export.rs+++ b/crates/pdf/src/export.rs@@ -411,7 +411,7 @@ impl Exporter<'_> {return;}let ds = &it.effects.drop_shadow;- let grow = it.stroke.weight + 2.0 + if ds.on { ds.distance.abs() + ds.size.abs() } else { 0.0 };+ let grow = it.stroke.extent() + 2.0 + if ds.on { ds.distance.abs() + ds.size.abs() } else { 0.0 };let vb = parent.transform_rect_bbox(it.bounds()).inflate(grow, grow);if !rects_overlap(vb, self.clip) {return;@@ -625,6 +625,9 @@ impl Exporter<'_> {None}};+ let arrows = designcraft_doc::arrow::apply(bp, st, closed);+ let trimmed = arrows.as_ref().and_then(|a| to_path(&a.0));+ let path = trimmed.as_ref().unwrap_or(path);let aligned = closed && st.align != StrokeAlign::Center;let width = if aligned { st.weight * 2.0 } else { st.weight };let mut pushes = 0;@@ -646,8 +649,16 @@ impl Exporter<'_> {_ => {}}s.set_fill(None);+ if dash.is_some()+ && pushes == 0+ && let Some(g) = self.swatch_color(&st.gap_swatch, st.gap_tint)+ {+ // Gap colour under dashes and dots.+ s.set_stroke(Some(Stroke { paint: g.into(), width: width as f32, opacity: NormalizedF32::ONE, ..Default::default() }));+ s.draw_path(path);+ }s.set_stroke(Some(Stroke {- paint: c.into(),+ paint: c.clone().into(),width: width as f32,miter_limit: st.miter_limit.max(1.0) as f32,line_cap: cap,@@ -664,6 +675,21 @@ impl Exporter<'_> {for _ in 0..pushes {s.pop();}+ for h in arrows.iter().flat_map(|a| &a.1) {+ let Some(p) = to_path(&h.path) else { continue };+ match h.outline {+ Some(w) => {+ s.set_stroke(Some(Stroke { paint: c.clone().into(), width: w as f32, opacity: NormalizedF32::ONE, ..Default::default() }));+ s.draw_path(&p);+ s.set_stroke(None);+ }+ None => {+ s.set_fill(Some(krilla::paint::Fill { paint: c.clone().into(), opacity: NormalizedF32::ONE, rule: FillRule::NonZero }));+ s.draw_path(&p);+ s.set_fill(None);+ }+ }+ }}fn load_image(&mut self, id: AssetId) -> Option<Image> {diff --git a/crates/render/src/damage.rs b/crates/render/src/damage.rsindex ccb674ae5..fb085da8e 100644--- a/crates/render/src/damage.rs+++ b/crates/render/src/damage.rs@@ -155,7 +155,7 @@ fn item_area(it: &Item) -> Option<Rect> {if !ok {return None;}- let pad = it.stroke.weight.max(0.0) + 2.0 + if it.is_text_frame() { 24.0 } else { 0.0 };+ let pad = it.stroke.extent().max(0.0) + 2.0 + if it.is_text_frame() { 24.0 } else { 0.0 };Some(it.bounds().inflate(pad, pad))}diff --git a/crates/render/src/fx.rs b/crates/render/src/fx.rsindex 2967cafed..0a9a2315c 100644--- a/crates/render/src/fx.rs+++ b/crates/render/src/fx.rs@@ -67,7 +67,7 @@ impl Renderer {pub(crate) fn draw_item_fx(&mut self, ctx: &mut RenderContext, f: &Frame, it: &Item, bp: &BezPath, xf: Affine, page_name: Option<&str>) {let doc = f.doc;let e = &it.effects;- let sw = if it.stroke.is_none() { 0.0 } else { it.stroke.weight };+ let sw = if it.stroke.is_none() { 0.0 } else { it.stroke.extent() };// Spread-space reach of what the object paints.let reach = xf.transform_rect_bbox(bp.bounding_box()).inflate(sw + 1.0, sw + 1.0);// The silhouette is the shape when the object paints its area (fill / image); text framesdiff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rsindex 03d44ec75..9c2f8bca6 100644--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@ -337,7 +337,7 @@ impl Renderer {return;}let xf = parent * it.xf;- let vb = xf.transform_rect_bbox(it.inner_bounds()).inflate(it.stroke.weight + 2.0, it.stroke.weight + 2.0);+ let vb = xf.transform_rect_bbox(it.inner_bounds()).inflate(it.stroke.extent() + 2.0, it.stroke.extent() + 2.0);if it.has_nested_items() {// A frame with items pasted into it: fill, the items clipped to the frame, stroke.if !rect_overlaps(vb, f.visible) {@@ -480,6 +480,24 @@ impl Renderer {ctx.set_transform(f.view * xf);ctx.set_paint(color_of(&c, 1.0));let closed = it.path.is_closed();+ // Arrowheads: the path is shortened under them; they're drawn after it.+ let arrows = designcraft_doc::arrow::apply(bp, st, closed);+ let bp = arrows.as_ref().map_or(bp, |a| &a.0);+ // Gap colour under dashes and dots: the whole path, undashed.+ let gap = if matches!(st.kind, StrokeType::Solid) { None } else { f.doc.resolve_color(&st.gap_swatch, st.gap_tint) };+ if let Some(g) = gap+ && !matches!(st.align, StrokeAlign::Inside | StrokeAlign::Outside if closed)+ {+ ctx.set_paint(color_of(&g, 1.0));+ ctx.set_stroke(kurbo::Stroke {+ dash_pattern: Default::default(),+ start_cap: kurbo::Cap::Butt,+ end_cap: kurbo::Cap::Butt,+ ..stroke.clone()+ });+ ctx.stroke_path(bp);+ ctx.set_paint(color_of(&c, 1.0));+ }match st.align {StrokeAlign::Inside if closed => {// Clip a double-width stroke to the path.@@ -505,6 +523,15 @@ impl Renderer {ctx.stroke_path(bp);}}+ for h in arrows.iter().flat_map(|a| &a.1) {+ match h.outline {+ Some(w) => {+ ctx.set_stroke(kurbo::Stroke::new(w).with_join(kurbo::Join::Miter));+ ctx.stroke_path(&h.path);+ }+ None => ctx.fill_path(&h.path),+ }+ }}fn draw_graphic(&mut self, ctx: &mut RenderContext, f: &Frame, g: &designcraft_doc::Graphic, xf: Affine) {@@ -735,6 +762,46 @@ mod tests {assert!(r.stats.glyphs >= 15);}+ #[test]+ fn arrowheads_draw_at_line_ends() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let id = designcraft_doc::ItemId(d.alloc());+ let path = designcraft_geom::shapes::line(designcraft_geom::Point::new(100.0, 400.0), designcraft_geom::Point::new(400.0, 400.0));+ let mut line = Item::new(id, lid, designcraft_doc::Shape::GraphicLine, path);+ line.stroke = designcraft_doc::Stroke {+ swatch: designcraft_color::swatch::BLACK.into(),+ weight: 2.0,+ end: designcraft_doc::Arrowhead::TriangleWide,+ ..Default::default()+ };+ d.insert_item(SpreadRef::Doc(0), line, None).unwrap();+ // A dashed line with a gap colour: the gaps are painted.+ let id = designcraft_doc::ItemId(d.alloc());+ let path = designcraft_geom::shapes::line(designcraft_geom::Point::new(100.0, 500.0), designcraft_geom::Point::new(400.0, 500.0));+ let mut dashed = Item::new(id, lid, designcraft_doc::Shape::GraphicLine, path);+ dashed.stroke = designcraft_doc::Stroke {+ swatch: designcraft_color::swatch::BLACK.into(),+ weight: 4.0,+ kind: designcraft_doc::StrokeType::Dashed { pattern: vec![12.0, 4.0] },+ gap_swatch: "C=100 M=0 Y=0 K=0".into(),+ ..Default::default()+ };+ d.insert_item(SpreadRef::Doc(0), dashed, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let img = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ // The head is 6.4 × weight wide: ink 4 pt above the line near the tip, none at the start.+ assert!(img.pixel(393, 396)[0] < 128, "{:?}", img.pixel(393, 396));+ assert_eq!(img.pixel(105, 396), [255, 255, 255, 255]);+ // Nothing past the tip.+ assert_eq!(img.pixel(403, 400), [255, 255, 255, 255]);+ let (dash, gap) = (img.pixel(106, 500), img.pixel(114, 500));+ assert!(dash[0] < 80 && dash[2] < 80, "dash {dash:?}");+ assert!(gap[0] < 80 && gap[2] > 150, "gap {gap:?}");+ }+#[test]fn missing_fonts_are_highlighted_on_screen_only() {let mut d = Document::new(&NewDocument::default());diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rsindex 5f5a2079f..cc3e63279 100644--- a/crates/ui-egui/src/panels/properties.rs+++ b/crates/ui-egui/src/panels/properties.rs@@ -2,7 +2,7 @@//! sections per selection state — `plan/indesign/11-observed-ui.md` §4.1) and small//! single-purpose panels (Stroke, Character, Paragraph, Text Wrap, Align, Links, Info).-use designcraft_doc::Align;+use designcraft_doc::{Align, Arrowhead, Cap, Join, StrokeAlign, StrokeType};use designcraft_geom::Unit;use designcraft_geom::corners::CornerShape;use egui::{Rect, Sense, Stroke, StrokeKind, Ui, pos2, vec2};@@ -1257,46 +1257,134 @@ pub fn paragraph_panel(app: &mut DesignApp, ui: &mut egui::Ui) {});}+/// Stroke panel: weight, cap, miter limit, join, alignment, type, arrowheads, gap colour.pub fn stroke_panel(app: &mut DesignApp, ui: &mut egui::Ui) {let Some(i) = sel_info(app) else {ui.label("Select an object.");return;};- ui.horizontal(|ui| {- caption(ui, "Weight");+ let Some(st) = app.session.active().and_then(|d| d.selection.items.first().and_then(|id| d.doc.item(*id)).map(|it| it.stroke.clone())) else {+ return;+ };+ let t = Tokens::get(ui.ctx());+ egui::Grid::new("stroke_panel").num_columns(2).spacing(vec2(8.0, 6.0)).show(ui, |ui| {+ caption(ui, "Weight:");if let Some(v) = number(ui, "sw", Some(i.stroke_weight), " pt", 60.0, 3) {let _ = app.run("object.stroke", json!({"weight": v}));}- });- ui.horizontal(|ui| {- caption(ui, "Align Stroke");- for (label, a) in [("Center", "center"), ("Inside", "inside"), ("Outside", "outside")] {- let on = serde_json::to_value(i.stroke_align).ok().and_then(|v| v.as_str().map(|s| s == a)).unwrap_or(false);- if ui.selectable_label(on, label).clicked() {- let _ = app.run("object.stroke", json!({"align": a}));+ ui.end_row();+ caption(ui, "Cap:");+ ui.horizontal(|ui| {+ for (label, v, cur) in [("Butt", "butt", Cap::Butt), ("Round", "round", Cap::Round), ("Projecting", "projecting", Cap::Projecting)] {+ if ui.selectable_label(st.cap == cur, label).clicked() {+ let _ = app.run("object.stroke", json!({"cap": v}));+ }}+ });+ ui.end_row();+ caption(ui, "Join:");+ ui.horizontal(|ui| {+ for (label, v, cur) in [("Miter", "miter", Join::Miter), ("Round", "round", Join::Round), ("Bevel", "bevel", Join::Bevel)] {+ if ui.selectable_label(st.join == cur, label).clicked() {+ let _ = app.run("object.stroke", json!({"join": v}));+ }+ }+ });+ ui.end_row();+ caption(ui, "Miter Limit:");+ if let Some(v) = number(ui, "smiter", Some(st.miter_limit), " x", 60.0, 0) {+ let _ = app.run("object.stroke", json!({"miterLimit": v}));}- });- ui.horizontal(|ui| {- caption(ui, "Type");- for (label, ty) in [- ("Solid", json!({"kind": "solid"})),- ("Dashed", json!({"kind": "dashed", "pattern": [12.0, 4.0]})),- ("Dotted", json!({"kind": "dotted"})),- ] {- if ui.small_button(label).clicked() {- let _ = app.run("object.stroke", json!({"type": ty}));+ ui.end_row();+ caption(ui, "Align Stroke:");+ ui.horizontal(|ui| {+ for (label, a, cur) in+ [("Center", "center", StrokeAlign::Center), ("Inside", "inside", StrokeAlign::Inside), ("Outside", "outside", StrokeAlign::Outside)]+ {+ if ui.selectable_label(st.align == cur, label).clicked() {+ let _ = app.run("object.stroke", json!({"align": a}));+ }+ }+ });+ ui.end_row();+ caption(ui, "Type:");+ egui::ComboBox::from_id_salt("stype").selected_text(st.kind.label()).width(140.0).show_ui(ui, |ui| {+ for ty in [json!({"kind": "solid"}), json!({"kind": "dashed", "pattern": [12.0, 4.0]}), json!({"kind": "dotted"})] {+ let label = serde_json::from_value::<StrokeType>(ty.clone()).map(|k| k.label()).unwrap_or("");+ if ui.selectable_label(st.kind.label() == label, label).clicked() {+ let _ = app.run("object.stroke", json!({"type": ty}));+ }}+ });+ ui.end_row();+ for (key, label, cur, flip) in [("start", "Start/End:", st.start, true), ("end", "", st.end, false)] {+ caption(ui, label);+ egui::ComboBox::from_id_salt(key).selected_text(cur.label()).width(140.0).show_ui(ui, |ui| {+ for a in Arrowhead::ALL {+ ui.horizontal(|ui| {+ arrow_preview(ui, a, flip, t.text_strong);+ if ui.selectable_label(a == cur, a.label()).clicked() {+ let _ = app.run("object.stroke", json!({key: a}));+ }+ });+ }+ });+ ui.end_row();}- });- ui.horizontal(|ui| {- caption(ui, "Color");+ caption(ui, "Gap Color:");+ super::swatch_picker(app, ui, "sgap", Some(st.gap_swatch.clone()), |app, n| {+ let _ = app.run("object.stroke", json!({"gapSwatch": n}));+ });+ ui.end_row();+ caption(ui, "Color:");super::swatch_picker(app, ui, "spick", Some(i.stroke.clone()), |app, n| {let _ = app.run("object.stroke", json!({"swatch": n}));});+ ui.end_row();});}+/// A short line ending in arrowhead `a` (pointing left for Start, right for End).+fn arrow_preview(ui: &mut egui::Ui, a: Arrowhead, start: bool, color: egui::Color32) {+ use designcraft_geom::kurbo;+ let (r, _) = ui.allocate_exact_size(vec2(56.0, 14.0), Sense::hover());+ let mut line = kurbo::BezPath::new();+ let (y, x0, x1) = (r.center().y as f64, r.left() as f64 + 6.0, r.right() as f64 - 6.0);+ if start {+ line.move_to((x1, y));+ line.line_to((x0, y));+ } else {+ line.move_to((x0, y));+ line.line_to((x1, y));+ }+ let st = designcraft_doc::Stroke { weight: 1.5, end: a, ..Default::default() };+ let (line, heads) = designcraft_doc::arrow::apply(&line, &st, false).unwrap_or((line, vec![]));+ let pts = |p: &kurbo::BezPath| {+ let mut v = Vec::new();+ kurbo::flatten(p.iter(), 0.1, |el| match el {+ kurbo::PathEl::MoveTo(p) | kurbo::PathEl::LineTo(p) => v.push(pos2(p.x as f32, p.y as f32)),+ _ => {}+ });+ v+ };+ let painter = ui.painter();+ painter.add(egui::Shape::line(pts(&line), Stroke::new(1.5, color)));+ for h in heads {+ let p = pts(&h.path);+ match h.outline {+ Some(w) if matches!(h.path.elements().last(), Some(kurbo::PathEl::ClosePath)) => {+ painter.add(egui::Shape::closed_line(p, Stroke::new(w as f32, color)));+ }+ Some(w) => {+ painter.add(egui::Shape::line(p, Stroke::new(w as f32, color)));+ }+ None => {+ painter.add(egui::Shape::convex_polygon(p, color, Stroke::NONE));+ }+ }+ }+}+pub fn wrap_panel(app: &mut DesignApp, ui: &mut egui::Ui) {let info = sel_info(app);ui.horizontal(|ui| {diff --git a/docs/parity.md b/docs/parity.mdindex 7333267c8..359b318fe 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -5,11 +5,11 @@ 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: 67%** over 275 features.+**Weighted breadth parity: 68%** over 275 features.| Priority | Features | Done | Partial | Missing | Parity ||---|---|---|---|---|---|-| P0 | 102 | 90 | 12 | 0 | 94% |+| P0 | 102 | 91 | 11 | 0 | 95% || P1 | 97 | 33 | 23 | 41 | 46% || P2 | 76 | 8 | 7 | 61 | 15% |@@ -20,7 +20,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Layers | 74% || Frames, shapes & paths | 74% || Transform | 78% |-| Fill, stroke, colour | 62% |+| Fill, stroke, colour | 65% || Effects & transparency | 50% || Placing & links | 57% || Type & text frames | 77% |@@ -35,7 +35,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Undo, history, saving | 100% || Accessibility | 20% |-Open P0 items: Dockable panels, Preferences, Document Setup, Pen, add/delete anchor, convert direction, Gradient panel & tool, Stroke panel, Raster formats, Vector/page formats (PDF/AI/SVG/EPS place), Display performance, OpenType features, Export to PDF (print), Display performance.+Open P0 items: Dockable panels, Preferences, Document Setup, Pen, add/delete anchor, convert direction, Gradient panel & tool, Raster formats, Vector/page formats (PDF/AI/SVG/EPS place), Display performance, OpenType features, Export to PDF (print), Display performance.## Rows@@ -151,7 +151,7 @@ Open P0 items: Dockable panels, Preferences, Document Setup, Pen, add/delete anc| Fill, stroke, colour | Load/Save Swatches (.ase) | P1 | M || Fill, stroke, colour | Color groups | P2 | M || Fill, stroke, colour | Unnamed colour to swatch | P1 | D |-| Fill, stroke, colour | Stroke panel | P0 | P |+| Fill, stroke, colour | Stroke panel | P0 | D || Fill, stroke, colour | Stroke styles | P1 | P || Fill, stroke, colour | Color management | P1 | P || Fill, stroke, colour | Overprint Preview | P1 | M |