Merge branch 'main' into rtl-features

This commit is contained in:
FredApps authored and GitHub committed 2026-11-26 17:49:40 +01:00
commit 1a59e0b1e5
15 files changed
+1482 -116

No files matched your search

+1
View File
@@ -406,6 +406,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
## Progress log
- **2026-11-18** · View › Extras › Show/Hide Link Badge: frames showing a linked picture carry a link badge on their top edge, a warning when the file changed and a stop when it is missing; hidden in Preview. No readiness percentage change.
- **2026-11-16** · Fitting a bottom-aligned text frame from its top handle keeps its bottom edge and text in place (#2880): double-clicking any selection handle passes the opposite local reference point (`ref` 0..=8) to `object.fit`, menu/panel/scripting fits without `ref` anchor to vertical justification (`Bottom`/`Center`/`Top`/`Justify`), and `transform.resize` keeps unchanged edges pinned across its `1e-3` scale clamp and flips. No readiness percentage change.
- **2026-11-13** · A placed Photoshop file comes in at its own resolution (ResolutionInfo), as other rasters do since #1991: a 300 ppi PSD was placed four times too large at 72 ppi. No readiness percentage change.
- **2026-11-15** · Removed the obsolete gap saying pull requests have no test workflow: [CI](.github/workflows/ci.yml) runs the shared quality gate on every pull request and push to main (#1352). No readiness percentage change.
- **2026-11-15** · Accepting tracked deletions or rejecting insertions follows body-text selections through the removed text, including resolving all changes, and preserves independent cell and footnote insertion points. No readiness percentage change.
+3
View File
@@ -92,6 +92,9 @@ display_name = "Jonathan Cardoso"
real_name = "Adithya Shankaran"
sync_github_name = true
[people.AlPaka1234]
real_name = "Christian Holtbrügger"
[people.alejo-c]
sync_github_name = true
+1 -1
View File
@@ -336,7 +336,7 @@ impl Item {
/// How far a visible stroke reaches inside the path: half its weight centred, all of it inside,
/// none outside.
fn stroke_inside(&self) -> f64 {
pub fn stroke_inside(&self) -> f64 {
let w = self.stroke.weight;
if self.stroke.is_none() || !w.is_finite() {
return 0.0;
+117 -3
View File
@@ -502,7 +502,7 @@ fn is_origin(p: &[f64; 2]) -> bool {
p[0] == 0.0 && p[1] == 0.0
}
/// The colours of new shapes (see [`DocSettings::new_object`]).
/// The colours and stroke defaults of new shapes (see [`DocSettings::new_object`]).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default)]
pub struct NewObjectColors {
@@ -510,12 +510,126 @@ pub struct NewObjectColors {
pub fill_tint: f32,
pub stroke: String,
pub stroke_tint: f32,
#[serde(skip_serializing_if = "is_default_stroke_weight")]
pub stroke_weight: f64,
#[serde(rename = "strokeType", skip_serializing_if = "is_default_stroke_type")]
pub stroke_type: StrokeType,
#[serde(skip_serializing_if = "is_default_stroke_align")]
pub stroke_align: StrokeAlign,
#[serde(skip_serializing_if = "is_default_cap")]
pub stroke_cap: Cap,
#[serde(skip_serializing_if = "is_default_join")]
pub stroke_join: Join,
#[serde(skip_serializing_if = "is_default_miter_limit")]
pub stroke_miter_limit: f64,
#[serde(skip_serializing_if = "is_default_arrowhead")]
pub stroke_start: Arrowhead,
#[serde(skip_serializing_if = "is_default_arrowhead")]
pub stroke_end: Arrowhead,
#[serde(skip_serializing_if = "is_default_gap_swatch")]
pub gap_swatch: String,
#[serde(skip_serializing_if = "is_one_f32")]
pub gap_tint: f32,
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub gap_overprint: bool,
}
fn is_default_stroke_weight(w: &f64) -> bool {
*w == 1.0
}
fn is_default_stroke_type(t: &StrokeType) -> bool {
matches!(t, StrokeType::Solid)
}
fn is_default_stroke_align(a: &StrokeAlign) -> bool {
*a == StrokeAlign::Center
}
fn is_default_cap(c: &Cap) -> bool {
*c == Cap::Butt
}
fn is_default_join(j: &Join) -> bool {
*j == Join::Miter
}
fn is_default_miter_limit(m: &f64) -> bool {
*m == 4.0
}
fn is_default_arrowhead(a: &Arrowhead) -> bool {
*a == Arrowhead::None
}
fn is_default_gap_swatch(s: &str) -> bool {
s == designcraft_color::swatch::NONE
}
fn is_one_f32(v: &f32) -> bool {
*v == 1.0
}
impl Default for NewObjectColors {
/// No fill and a black stroke, as new documents have.
/// No fill and a 1 pt black stroke, as new documents have.
fn default() -> Self {
NewObjectColors { fill: "[None]".into(), fill_tint: 1.0, stroke: "[Black]".into(), stroke_tint: 1.0 }
let s = Stroke::default();
NewObjectColors {
fill: "[None]".into(),
fill_tint: 1.0,
stroke: s.swatch,
stroke_tint: s.tint,
stroke_weight: s.weight,
stroke_type: s.kind,
stroke_align: s.align,
stroke_cap: s.cap,
stroke_join: s.join,
stroke_miter_limit: s.miter_limit,
stroke_start: s.start,
stroke_end: s.end,
gap_swatch: s.gap_swatch,
gap_tint: s.gap_tint,
gap_overprint: s.gap_overprint,
}
}
}
impl NewObjectColors {
/// The default stroke applied to newly drawn shapes and paths.
pub fn to_stroke(&self) -> Stroke {
Stroke {
swatch: self.stroke.clone(),
tint: self.stroke_tint,
weight: self.stroke_weight,
kind: self.stroke_type.clone(),
align: self.stroke_align,
cap: self.stroke_cap,
join: self.stroke_join,
miter_limit: self.stroke_miter_limit,
start: self.stroke_start,
end: self.stroke_end,
gap_swatch: self.gap_swatch.clone(),
gap_tint: self.gap_tint,
gap_overprint: self.gap_overprint,
..Stroke::default()
}
}
/// Copy `s` into the stroke defaults for new shapes.
pub fn set_stroke(&mut self, s: &Stroke) {
self.stroke = s.swatch.clone();
self.stroke_tint = s.tint;
self.stroke_weight = s.weight;
self.stroke_type = s.kind.clone();
self.stroke_align = s.align;
self.stroke_cap = s.cap;
self.stroke_join = s.join;
self.stroke_miter_limit = s.miter_limit;
self.stroke_start = s.start;
self.stroke_end = s.end;
self.gap_swatch = s.gap_swatch.clone();
self.gap_tint = s.gap_tint;
self.gap_overprint = s.gap_overprint;
}
}
+26 -4
View File
@@ -238,10 +238,10 @@ impl Document {
}
/// Point every reference to swatch `from` at `to`: tints based on it, colour groups, inks,
/// styles, page items (fills, strokes, gaps, effects, column rules, the swatch an image is
/// coloured with), text, kenten and ruby colours, rules, shading, borders and border gaps,
/// tables (with stroke gaps, diagonal lines and cell images), footnotes, gradient stops,
/// endnotes and the footnote rule. The swatch itself is renamed by the caller.
/// styles, new-object defaults, page items (fills, strokes, gaps, effects, column rules, the
/// swatch an image is coloured with), text, kenten and ruby colours, rules, shading, borders
/// and border gaps, tables (with stroke gaps, diagonal lines and cell images), footnotes,
/// gradient stops, endnotes and the footnote rule. The swatch itself is renamed by the caller.
pub fn rename_swatch_refs(&mut self, from: &str, to: &str) {
if from == to {
return;
@@ -271,6 +271,9 @@ impl Document {
n.s(b);
}
n.s(&mut self.footnote_options.rule.color);
n.s(&mut self.settings.new_object.fill);
n.s(&mut self.settings.new_object.stroke);
n.s(&mut self.settings.new_object.gap_swatch);
n.styles(self.styles_mut());
for sp in self.spreads.iter_mut().chain(self.parents.iter_mut()) {
for it in &mut Arc::make_mut(sp).items {
@@ -287,3 +290,22 @@ impl Document {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn rename_swatch_refs_updates_new_object_defaults() {
let mut d = Document::new(&crate::build::NewDocument::default());
d.settings.new_object.fill = "Gap".into();
d.settings.new_object.stroke = "Keep".into();
d.settings.new_object.gap_swatch = "Gap".into();
d.rename_swatch_refs("Gap", "Renamed Gap");
assert_eq!(d.settings.new_object.fill, "Renamed Gap");
assert_eq!(d.settings.new_object.stroke, "Keep");
assert_eq!(d.settings.new_object.gap_swatch, "Renamed Gap");
}
}
File diff suppressed because it is too large. Load diff
+63
View File
@@ -2718,3 +2718,66 @@ fn deleting_the_active_layer_moves_to_a_usable_layer() {
s.execute("layer.delete", &json!({"id": bottom.0})).unwrap();
assert_eq!(s.doc().unwrap().active_layer, artwork);
}
#[test]
fn selection_tool_drag_and_double_click_at_top_keeps_bottom_aligned_text_in_place() {
use designcraft_doc::{ItemId, SpreadRef};
use designcraft_geom::{Point, Rect};
use designcraft_tools::{PointerEvent, PointerKind};
let mut s = session();
let r = s.execute("frame.create", &json!({"rect": [100, 100, 500, 300], "content": "text", "text": "Line one\nLine two"})).unwrap();
let id = ItemId(r["id"].as_u64().unwrap());
let sid = designcraft_doc::StoryId(r["story"].as_u64().unwrap());
s.execute("object.textFrameOptions", &json!({"ids": [id.0], "verticalJustification": "bottom"})).unwrap();
s.execute("selection.set", &json!({"ids": [id.0]})).unwrap();
s.set_tool("selection");
let baselines = |s: &Session| {
let d = &s.doc().unwrap().doc;
let cs = s.cache.get(d, sid, None);
(!cs.is_overset(), cs.frame(id).unwrap().lines.iter().map(|l| l.baseline).collect::<Vec<_>>())
};
let (ok0, lines0) = baselines(&s);
assert!(ok0 && lines0.len() == 2);
let original = Rect::new(100.0, 100.0, 500.0, 300.0);
let v = ViewInfo { snap: designcraft_tools::SnapView::OFF, ..ViewInfo::at_zoom(1.0) };
let canvas_pt = |s: &Session, x: f64, y: f64| s.layout().to_canvas(SpreadRef::Doc(0), Point::new(x, y));
// Drag the top-center handle down to y = 200: bottom edge and text stay anchored.
let top = canvas_pt(&s, 300.0, 100.0);
let mid = canvas_pt(&s, 300.0, 200.0);
s.pointer(&PointerEvent::new(PointerKind::Down, top.x, top.y), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, mid.x, mid.y), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, mid.x, mid.y), v).unwrap();
let dragged = s.doc().unwrap().doc.item(id).unwrap().bounds();
let (ok1, lines1) = baselines(&s);
assert!(ok1 && (dragged.y0 - 200.0).abs() < 1e-6 && (dragged.y1 - 300.0).abs() < 1e-9, "{dragged:?}");
assert!((lines1[0] - lines0[0]).abs() < 1e-6 && (lines1[1] - lines0[1]).abs() < 1e-6, "{lines0:?} vs {lines1:?}");
// Undo and drag near the bottom edge (triggering the 1e-3 clamp): y1 still does not drift.
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(s.doc().unwrap().doc.item(id).unwrap().bounds(), original);
let top = canvas_pt(&s, 300.0, 100.0);
let near_bottom = canvas_pt(&s, 300.0, 299.99);
s.pointer(&PointerEvent::new(PointerKind::Down, top.x, top.y), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, near_bottom.x, near_bottom.y), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, near_bottom.x, near_bottom.y), v).unwrap();
let clamped = s.doc().unwrap().doc.item(id).unwrap().bounds();
assert!((clamped.y1 - 300.0).abs() < 1e-9, "bottom edge drifted on clamped drag: {clamped:?}");
// Undo and double-click the top-center handle: aligns flush with the text while bottom stays pinned.
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(s.doc().unwrap().doc.item(id).unwrap().bounds(), original);
let top = canvas_pt(&s, 300.0, 100.0);
let undo_before = s.doc().unwrap().history.undo.len();
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, top.x, top.y), v).unwrap();
let fitted = s.doc().unwrap().doc.item(id).unwrap().bounds();
let (ok2, lines2) = baselines(&s);
assert!(ok2 && (fitted.y1 - 300.0).abs() < 1e-9 && fitted.y0 > 200.0 && fitted.x0 == 100.0 && fitted.x1 == 500.0, "{fitted:?}");
assert!((lines2[0] - lines0[0]).abs() < 1e-6 && (lines2[1] - lines0[1]).abs() < 1e-6, "{lines0:?} vs {lines2:?}");
assert_eq!(s.doc().unwrap().history.undo.len(), undo_before + 1);
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(s.doc().unwrap().doc.item(id).unwrap().bounds(), original);
}
+1 -1
View File
@@ -317,7 +317,7 @@ impl ToolContext<'_> {
/// The selected items with the transform from their own space to the canvas, found in one walk
/// of the document (a search per item made a big selection quadratic). Same first match per
/// id as `Document::find`, in selection order.
fn selected_with_canvas_xf(&self) -> Vec<(&Item, Affine)> {
pub(crate) fn selected_with_canvas_xf(&self) -> Vec<(&Item, Affine)> {
let mut want: std::collections::HashSet<ItemId> = self.selection.items.iter().copied().collect();
let mut found: std::collections::HashMap<ItemId, (&Item, Affine)> = std::collections::HashMap::new();
// Pre-order with an explicit stack: a deep group tree must not exhaust the call stack.
+102 -19
View File
@@ -539,24 +539,100 @@ fn handle_at(cx: &ToolContext, p: Point) -> Option<usize> {
handles(b).iter().position(|h| (h.x - p.x).abs() <= tol && (h.y - p.y).abs() <= tol)
}
/// Side handles are drawn on the canvas bounding box; fitting uses the frame's local axes.
fn fitting_axis(cx: &ToolContext, handle: usize) -> &'static str {
if handle.is_multiple_of(2) {
return "both";
/// Side handles are drawn on the canvas bounding box; fitting uses the frame's local axes and
/// keeps the opposite local edge/corner (`ref` 0..=8) fixed. Returns `None` when a multi-selection
/// needs different local axes for the same side handle (e.g. an unrotated frame selected alongside
/// a 90°-rotated frame). When all selected items share the same local axis but have differing
/// opposite references, `ref` is omitted so each frame keeps its own default.
fn fitting_params(cx: &ToolContext, handle: usize) -> Option<(&'static str, Option<usize>)> {
let dir = match handle {
0 => Point::new(-1.0, -1.0),
1 => Point::new(0.0, -1.0),
2 => Point::new(1.0, -1.0),
3 => Point::new(1.0, 0.0),
4 => Point::new(1.0, 1.0),
5 => Point::new(0.0, 1.0),
6 => Point::new(-1.0, 1.0),
_ => Point::new(-1.0, 0.0),
};
let corner = handle.is_multiple_of(2);
let fallback_axis = if corner {
"both"
} else if matches!(handle, 3 | 7) {
"width"
} else {
"height"
};
let mut axis: Option<&'static str> = None;
let mut ref_pt: Option<usize> = None;
let mut ref_mixed = false;
let mut seen_degenerate = false;
let selected = cx.selected_with_canvas_xf();
let count = selected.len();
for (it, spread_xf) in selected {
let Some((ax, rf)) = fitting_item_params(spread_xf * it.xf, handle, dir) else {
seen_degenerate = true;
ref_mixed = true;
continue;
};
match axis {
None => {
axis = Some(ax);
ref_pt = Some(rf);
}
Some(prev) if prev != ax => return None,
Some(_) => {
if ref_pt != Some(rf) {
ref_mixed = true;
}
}
}
}
let canvas_height = matches!(handle, 1 | 5);
let local_width_is_vertical = cx
.selection
.items
.first()
.and_then(|id| {
let it = cx.doc.item(*id)?;
let xf = cx.item_canvas_xf(*id)? * it.xf;
let [a, b, _, _, _, _] = xf.as_coeffs();
Some(b.abs() > a.abs())
})
.unwrap_or(false);
if canvas_height == local_width_is_vertical { "width" } else { "height" }
if seen_degenerate && !corner && count > 1 {
return None;
}
let axis = axis.unwrap_or(fallback_axis);
Some((axis, if ref_mixed { None } else { ref_pt }))
}
fn fitting_item_params(xf: designcraft_geom::Affine, handle: usize, dir: Point) -> Option<(&'static str, usize)> {
let [a, b, c, d, _, _] = xf.as_coeffs();
let det = a * d - b * c;
let sx = a.hypot(b);
if !(det.is_finite() && det.abs() > 1e-12 && sx.is_finite() && sx > 1e-12) {
return None;
}
// Preserve the base side-handle axis rule (local width vs height follows the local X axis
// orientation) so horizontal shear does not turn a top/bottom handle into a width fit.
let axis = if handle.is_multiple_of(2) {
"both"
} else {
let canvas_height = matches!(handle, 1 | 5);
let local_width_is_vertical = b.abs() > a.abs();
if canvas_height == local_width_is_vertical { "width" } else { "height" }
};
// Project the handle direction onto the orthonormal local-X / signed-perpendicular basis so
// shear and non-uniform scaling keep the opposite local edge/corner anchor intact.
let ux = (a * dir.x + b * dir.y) / sx;
let uy = ((-b * dir.x + a * dir.y) / sx) * det.signum();
if !(ux.is_finite() && uy.is_finite()) {
return None;
}
let anchor = |v: f64| {
if v < -1e-6 {
2
} else if v > 1e-6 {
0
} else {
1
}
};
let (rx, ry) = match axis {
"width" => (anchor(ux), 1),
"height" => (1, anchor(uy)),
_ => (anchor(ux), anchor(uy)),
};
Some((axis, ry * 3 + rx))
}
/// Just outside a corner handle of the selection → rotate.
@@ -1276,14 +1352,21 @@ impl Tool for SelectionTool {
return actions;
}
// The second press of a double click on a selection handle: Fit Frame to Content, along
// that handle's side (a corner fits both).
// that handle's side (a corner fits both), anchoring the opposite side.
if !self.direct
&& matches!(ev.kind, PointerKind::Down | PointerKind::DoubleClick)
&& ev.click_count() == 2
&& let Some(h) = handle_at(cx, p)
{
self.drag = Drag::None;
return vec![Action::Exec("object.fit".into(), json!({"mode": "fitFrameToContent", "axis": fitting_axis(cx, h)}))];
let Some((axis, rf)) = fitting_params(cx, h) else {
return vec![];
};
let params = match rf {
Some(rf) => json!({"mode": "fitFrameToContent", "axis": axis, "ref": rf}),
None => json!({"mode": "fitFrameToContent", "axis": axis}),
};
return vec![Action::Exec("object.fit".into(), params)];
}
// The second press of a double click on a text frame: edit its text.
if matches!(ev.kind, PointerKind::Down | PointerKind::DoubleClick)
+164 -5
View File
@@ -1845,9 +1845,9 @@ fn double_clicking_a_handle_fits_the_frame_to_its_content_along_that_side() {
let off = l.xf(SpreadRef::Doc(0)).translation();
let cx = ctx(&d, &s, &c, &l);
let mut t = create("selection");
for ((x, y), axis) in [((300.0, 200.0), "both"), ((200.0, 200.0), "height"), ((300.0, 150.0), "width")] {
for ((x, y), axis, rf) in [((300.0, 200.0), "both", 0), ((200.0, 200.0), "height", 1), ((300.0, 150.0), "width", 3)] {
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, x + off.x, y + off.y));
assert_eq!(a, vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis}))], "{axis}");
assert_eq!(a, vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis, "ref": rf}))], "{axis}");
}
}
@@ -1864,13 +1864,19 @@ fn fitting_handle_axes_follow_spread_and_frame_rotation() {
let cx = ctx(&d, &s, &c, &l);
let b = cx.selection_bounds().unwrap();
let mut t = create("selection");
let swapped = (spread_turn + frame_turn) % 2 == 1;
for (index, axis) in [(1, if swapped { "width" } else { "height" }), (3, if swapped { "height" } else { "width" }), (4, "both")] {
let total_turn = ((spread_turn + frame_turn) % 4) as usize;
let swapped = total_turn % 2 == 1;
let expected = [
(1, if swapped { "width" } else { "height" }, [7, 5, 1, 3][total_turn]),
(3, if swapped { "height" } else { "width" }, [3, 7, 5, 1][total_turn]),
(4, "both", [0, 6, 8, 2][total_turn]),
];
for (index, axis, rf) in expected {
let p = select::handles(b)[index];
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, p.x, p.y));
assert_eq!(
a,
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis}))],
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis, "ref": rf}))],
"spread={spread_turn}, frame={frame_turn}, handle={index}"
);
}
@@ -1878,6 +1884,159 @@ fn fitting_handle_axes_follow_spread_and_frame_rotation() {
}
}
#[test]
fn double_clicking_top_and_rotated_handles_sets_opposite_ref() {
let mut d = Document::new(&NewDocument::default());
let id = add_rect(&mut d, Rect::new(100.0, 100.0, 300.0, 200.0));
let s = Selection { items: vec![id], ..Default::default() };
let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));
let off = l.xf(SpreadRef::Doc(0)).translation();
let cx = ctx(&d, &s, &c, &l);
let mut t = create("selection");
// Handle 1 (top) fixes bottom-center (7); TL (0) fixes BR (8); L (7) fixes right-center (5).
for (handle, axis, rf) in [(1, "height", 7), (0, "both", 8), (2, "both", 6), (7, "width", 5)] {
let p = select::handles(Rect::new(100.0 + off.x, 100.0 + off.y, 300.0 + off.x, 200.0 + off.y))[handle];
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, p.x, p.y));
assert_eq!(
a,
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis, "ref": rf}))],
"handle={handle}"
);
}
// Rotating the frame 180 deg maps canvas top (1) to local bottom, so local top (1) stays fixed.
d.item_mut(id).unwrap().xf = designcraft_geom::Affine::rotate(std::f64::consts::PI);
let cx = ctx(&d, &s, &c, &l);
let b = cx.selection_bounds().unwrap();
let top = select::handles(b)[1];
assert_eq!(
t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, top.x, top.y)),
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": "height", "ref": 1}))]
);
// Mixed rotations in one selection omit `ref` so each frame uses its own default.
let other = add_rect(&mut d, Rect::new(100.0, 100.0, 300.0, 200.0));
let s2 = Selection { items: vec![id, other], ..Default::default() };
let cx2 = ctx(&d, &s2, &c, &l);
let b2 = cx2.selection_bounds().unwrap();
let top2 = select::handles(b2)[1];
assert_eq!(
t.pointer(&cx2, &PointerEvent::new(PointerKind::DoubleClick, top2.x, top2.y)),
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": "height"}))]
);
}
#[test]
fn double_clicking_handles_on_sheared_frame_keeps_axis_and_opposite_ref() {
let mut d = Document::new(&NewDocument::default());
let id = add_rect(&mut d, Rect::new(100.0, 100.0, 300.0, 200.0));
let shear = designcraft_geom::Affine::new([1.0, 0.0, 60.0_f64.to_radians().tan(), 1.0, 0.0, 0.0]);
d.item_mut(id).unwrap().xf = shear;
let s = Selection { items: vec![id], ..Default::default() };
let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));
let cx = ctx(&d, &s, &c, &l);
let b = cx.selection_bounds().unwrap();
let mut t = create("selection");
// A 60° horizontal shear keeps local X horizontal, so top/bottom still fit height and
// left/right still fit width, with each handle pinning its opposite local side.
for (handle, axis, rf) in [(1, "height", 7), (5, "height", 1), (7, "width", 5), (3, "width", 3), (0, "both", 8)] {
let p = select::handles(b)[handle];
assert_eq!(
t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, p.x, p.y)),
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis, "ref": rf}))],
"sheared handle={handle}"
);
}
// 90° clockwise rotation combined with 60° horizontal shear maps local X vertically.
d.item_mut(id).unwrap().xf = designcraft_geom::Affine::rotate(std::f64::consts::FRAC_PI_2) * shear;
let cx = ctx(&d, &s, &c, &l);
let b = cx.selection_bounds().unwrap();
for (handle, axis, rf) in [(1, "width", 5), (3, "height", 7)] {
let p = select::handles(b)[handle];
assert_eq!(
t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, p.x, p.y)),
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis, "ref": rf}))],
"rotated+sheared handle={handle}"
);
}
}
#[test]
fn double_clicking_handle_on_mixed_orientation_selection_declines_ambiguous_axes() {
let mut d = Document::new(&NewDocument::default());
let lid = d.default_layer();
let (upright, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 300.0, 200.0), lid, "A", ParaFormat::default()).unwrap();
let (upright2, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(320.0, 100.0, 520.0, 200.0), lid, "B", ParaFormat::default()).unwrap();
let (rot90, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 250.0, 300.0, 350.0), lid, "C", ParaFormat::default()).unwrap();
d.item_mut(rot90).unwrap().xf = designcraft_geom::Affine::rotate(std::f64::consts::FRAC_PI_2);
let (rot90_2, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(320.0, 250.0, 520.0, 350.0), lid, "D", ParaFormat::default()).unwrap();
d.item_mut(rot90_2).unwrap().xf = designcraft_geom::Affine::rotate(std::f64::consts::FRAC_PI_2);
let (rot180, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 400.0, 300.0, 500.0), lid, "E", ParaFormat::default()).unwrap();
d.item_mut(rot180).unwrap().xf = designcraft_geom::Affine::rotate(std::f64::consts::PI);
let singular = add_rect(&mut d, Rect::new(320.0, 400.0, 520.0, 500.0));
d.item_mut(singular).unwrap().xf = designcraft_geom::Affine::scale(0.0);
let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));
let mut t = create("selection");
// Mixed 0° + 90° selection: every side handle needs different local axes, so both selection
// orders decline the ambiguous fit (without falling through to text editing), while corners
// still share axis="both" and omit `ref`.
for items in [vec![upright, rot90], vec![rot90, upright]] {
let s = Selection { items: items.clone(), ..Default::default() };
let cx = ctx(&d, &s, &c, &l);
let b = cx.selection_bounds().unwrap();
for handle in [1, 3, 5, 7] {
let p = select::handles(b)[handle];
assert!(
t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, p.x, p.y)).is_empty(),
"expected decline for order={items:?} handle={handle}"
);
assert!(
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y).with_clicks(2)).is_empty(),
"expected decline on second press for order={items:?} handle={handle}"
);
}
let tl = select::handles(b)[0];
assert_eq!(
t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, tl.x, tl.y)),
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": "both"}))],
"corner handle for order={items:?}"
);
}
// Mixed 0° + 180° selection shares axis="height" on the top handle in both selection orders,
// omitting `ref` because opposite edges differ.
for items in [vec![upright, rot180], vec![rot180, upright]] {
let s = Selection { items: items.clone(), ..Default::default() };
let cx = ctx(&d, &s, &c, &l);
let top = select::handles(cx.selection_bounds().unwrap())[1];
assert_eq!(
t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, top.x, top.y)),
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": "height"}))],
"0+180 order={items:?}"
);
}
// Matching multi-selections keep both axis and opposite `ref`.
for (items, axis, rf) in [(vec![upright, upright2], "height", 7), (vec![rot90, rot90_2], "width", 5)] {
let s = Selection { items: items.clone(), ..Default::default() };
let cx = ctx(&d, &s, &c, &l);
let top = select::handles(cx.selection_bounds().unwrap())[1];
assert_eq!(
t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, top.x, top.y)),
vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis, "ref": rf}))],
"same-orientation multi-select {items:?}"
);
}
// A degenerate transform alongside a valid frame also declines side handles in both orders.
for items in [vec![upright, singular], vec![singular, upright]] {
let s = Selection { items: items.clone(), ..Default::default() };
let cx = ctx(&d, &s, &c, &l);
let top = select::handles(cx.selection_bounds().unwrap())[1];
assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, top.x, top.y)).is_empty(), "degenerate mixed order={items:?}");
}
}
#[test]
fn pen_continues_an_open_path_from_either_end_point() {
let mut d = Document::new(&NewDocument::default());
+29 -15
View File
@@ -160,21 +160,21 @@ pub(crate) fn show(app: &mut DesignApp, ui: &mut Ui) {
});
separator(ui);
group(ui, "appearance", 224.0, |ui, rect| {
let defaults = if info.is_none() { app.session.active().map(|d| d.doc.settings.new_object.clone()) } else { None };
let has_stroke_target = selected || defaults.is_some();
for (row, stroke) in [(0, false), (1, true)] {
// The chips open with nothing selected too, as they always have.
cell(ui, rect, 0.0, row, 30.0, true, |ui| {
let chip_resp = panels::swatch_picker(
app,
ui,
if stroke { "ctlstroke" } else { "ctlfill" },
info.as_ref().map(|i| if stroke { i.stroke.clone() } else { i.fill.clone() }),
|app, name| {
let _ = app.run(if stroke { "object.stroke" } else { "object.fill" }, json!({"swatch": name}));
},
);
let swatch = info
.as_ref()
.map(|i| if stroke { i.stroke.clone() } else { i.fill.clone() })
.or_else(|| defaults.as_ref().map(|c| if stroke { c.stroke.clone() } else { c.fill.clone() }));
let chip_resp = panels::swatch_picker(app, ui, if stroke { "ctlstroke" } else { "ctlfill" }, swatch.clone(), |app, name| {
let _ = app.run(if stroke { "object.stroke" } else { "object.fill" }, json!({"swatch": name}));
});
let chip = Rect::from_min_size(rect.min + vec2(0.0, row as f32 * ROW_PITCH + 1.5), vec2(18.0, 18.0));
if stroke && let Some(doc) = app.session.active().map(|st| &st.doc) {
let (color, gradient) = info.as_ref().map_or((Some(Color32::GRAY), None), |i| widgets::swatch_colors(doc, &i.stroke, 1.0));
let (color, gradient) = swatch.as_deref().map_or((Some(Color32::GRAY), None), |s| widgets::swatch_colors(doc, s, 1.0));
let inner = Tokens::get(ui.ctx()).panel;
if gradient.is_some() {
widgets::paint_chip(ui.painter(), chip, color, gradient);
@@ -191,14 +191,18 @@ pub(crate) fn show(app: &mut DesignApp, ui: &mut Ui) {
});
}
icon(ui, rect, 36.0, 0, "panel-stroke", &tr("Stroke Weight"));
if let Some(v) = cell(ui, rect, 56.0, 0, 74.0, selected, |ui| {
NumField::points("csw", info.as_ref().map(|i| i.stroke_weight), 3).width(74.0).spinner().range(0.0, 1000.0).show(ui)
let weight = info.as_ref().map(|i| i.stroke_weight).or_else(|| defaults.as_ref().map(|c| c.stroke_weight));
if let Some(v) = cell(ui, rect, 56.0, 0, 74.0, has_stroke_target, |ui| {
NumField::points("csw", weight, 3).width(74.0).spinner().range(0.0, 1000.0).show(ui)
}) {
let _ = app.run("object.stroke", json!({"weight": v}));
}
cell(ui, rect, 36.0, 1, 94.0, selected, |ui| {
properties::stroke_type_dropdown(app, ui, info.as_ref().map_or("solid", |i| &i.stroke_kind), 94.0)
});
let kind = info
.as_ref()
.map(|i| i.stroke_kind.clone())
.or_else(|| defaults.as_ref().map(|c| panels::stroke_kind_id(&c.stroke_type)))
.unwrap_or_else(|| "solid".into());
cell(ui, rect, 36.0, 1, 94.0, has_stroke_target, |ui| properties::stroke_type_dropdown(app, ui, &kind, 94.0));
icon(ui, rect, 138.0, 0, "opacity", &tr("Opacity"));
if let Some(v) = cell(ui, rect, 158.0, 0, 66.0, selected, |ui| {
NumField::number("cop", info.as_ref().map(|i| i.opacity * 100.0), "%", 0).width(66.0).spinner().range(0.0, 100.0).show(ui)
@@ -410,4 +414,14 @@ mod tests {
let after = ctx.read_response(id).unwrap().rect;
assert!(after.left() < before.left() && after.right() <= 900.0, "scrolling reaches the last group: {before:?} -> {after:?}");
}
#[test]
fn empty_selection_allows_editing_default_stroke_weight_in_control_bar() {
let (ctx, mut app) = fixture(false);
assert_eq!(app.session.active().unwrap().doc.settings.new_object.stroke_weight, 1.0);
let group = ctx.read_response(egui::Id::unique(("object_control", "appearance"))).unwrap().rect;
let stroke_up = group.min + vec2(56.0 + widgets::SEG_W / 2.0, FIELD_H / 4.0);
click(&ctx, &mut app, stroke_up);
assert_eq!(app.session.active().unwrap().doc.settings.new_object.stroke_weight, 2.0);
}
}
+9 -4
View File
@@ -253,10 +253,7 @@ pub fn sel_info(app: &DesignApp) -> Option<SelInfo> {
kind: first.default_label(),
is_graphic: matches!(first.content, Content::Graphic(_)),
is_text: first.is_text_frame(),
stroke_kind: serde_json::to_value(&first.stroke.kind)
.ok()
.and_then(|v| v.get("kind").and_then(Value::as_str).map(str::to_string).or_else(|| v.as_str().map(str::to_string)))
.unwrap_or_else(|| "solid".into()),
stroke_kind: stroke_kind_id(&first.stroke.kind),
corner: (first.corners.corners[0].shape, first.corners.corners[0].size),
wrap_invert: tw.invert,
wrap_side: serde_json::to_value(tw.side).ok().and_then(|v| v.as_str().map(str::to_string)).unwrap_or_default(),
@@ -267,6 +264,14 @@ pub fn sel_info(app: &DesignApp) -> Option<SelInfo> {
})
}
/// The JSON kind string for a stroke type (`solid`, `dashed`, `thickThin`, …).
pub fn stroke_kind_id(kind: &designcraft_doc::StrokeType) -> String {
serde_json::to_value(kind)
.ok()
.and_then(|v| v.get("kind").and_then(Value::as_str).map(str::to_string).or_else(|| v.as_str().map(str::to_string)))
.unwrap_or_else(|| "solid".into())
}
/// Resolved attributes at the text selection (or the selected text frames).
/// The fonts the active document sees: its own (its `Document Fonts` folder) ahead of the shared
/// ones.
@@ -16,17 +16,21 @@ pub fn stroke_panel(app: &mut DesignApp, ui: &mut egui::Ui) {
text_stroke_panel(app, ui, &a["chars"]);
return;
}
let Some(i) = sel_info(app) else {
crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Select an object."));
return;
};
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 {
let st = if sel_info(app).is_some() {
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;
};
st
} else if let Some(d) = app.session.active() {
d.doc.settings.new_object.to_stroke()
} else {
crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "No document open"));
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, crate::i18n::tr(&app.ui.language, "Weight:"));
if let Some(v) = number(ui, "sw", Some(i.stroke_weight), " pt", 60.0, 3) {
if let Some(v) = number(ui, "sw", Some(st.weight), " pt", 60.0, 3) {
let _ = app.run("object.stroke", json!({"weight": v.clamp(0.0, 1000.0)}));
}
ui.end_row();
@@ -134,7 +138,7 @@ pub fn stroke_panel(app: &mut DesignApp, ui: &mut egui::Ui) {
});
ui.end_row();
caption(ui, crate::i18n::tr(&app.ui.language, "Color:"));
crate::panels::swatch_picker(app, ui, "spick", Some(i.stroke.clone()), |app, n| {
crate::panels::swatch_picker(app, ui, "spick", Some(st.swatch.clone()), |app, n| {
let _ = app.run("object.stroke", json!({"swatch": n}));
});
ui.end_row();
@@ -135,6 +135,48 @@ fn stroke_panel_shows_the_text_stroke_options_while_text_is_selected() {
h.get_by_label("Stroke Behind Fill");
}
#[test]
fn stroke_panel_with_no_selection_edits_default_stroke_for_pencil_tool() {
use designcraft_tools::{PointerEvent, PointerKind};
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let existing = app.run("frame.create", json!({"rect": [10, 10, 50, 50], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();
app.run("selection.set", json!({"ids": []})).unwrap();
let mut ready = false;
let mut h = Harness::builder().with_size(vec2(320.0, 400.0)).build_ui_state(
move |ui, app: &mut DesignApp| {
if !ready {
crate::theme::install_fonts(ui.ctx(), "");
crate::theme::apply(ui.ctx(), &Tokens::for_brightness(Default::default()));
ready = true;
return;
}
stroke_panel(app, ui);
},
app,
);
h.run_steps(3);
assert!(h.query_by_label("Select an object.").is_none());
let field = h.get_all_by_role(egui::accesskit::Role::TextInput).next().unwrap().rect();
type_in_field(&mut h, field, "6");
let app = h.state_mut();
assert_eq!(app.session.active().unwrap().doc.settings.new_object.stroke_weight, 6.0);
assert_eq!(app.session.active().unwrap().doc.item(designcraft_doc::ItemId(existing)).unwrap().stroke.weight, 1.0);
app.session.set_tool("pencil");
let v = designcraft_engine::ViewInfo::at_zoom(1.0);
app.session.pointer(&PointerEvent::new(PointerKind::Down, 100.0, 100.0), v).unwrap();
for i in 1..=15 {
app.session.pointer(&PointerEvent::new(PointerKind::Drag, 100.0 + i as f64 * 4.0, 100.0 + i as f64 * 2.0), v).unwrap();
}
app.session.pointer(&PointerEvent::new(PointerKind::Up, 160.0, 130.0), v).unwrap();
let drawn = *app.session.active().unwrap().selection.items.first().unwrap();
assert_eq!(app.session.active().unwrap().doc.item(drawn).unwrap().stroke.weight, 6.0);
}
/// The text Stroke panel's Weight keeps a typed value inside the character stroke weight's
/// range of 0 to 800 pt, as the character style's Weight field does.
#[test]
+2 -2
View File
@@ -6,7 +6,7 @@
Canvas-painter regressions check emitted marks and hide/show transitions, including table
cells, parent editing and culled spreads (#1994).
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** patch (hidden characters follow frame, group and layer visibility (#1994); link badge on placed files; the Pen previews the curve while a smooth point is dragged and curves the rubber band after one, #1438; a Custom text variable defined with a number shows its digits, #2093; Table of Contents dialog: title field keeps its width, More Options toggles without losing hidden settings; Story panel; text Control panel Character/Paragraph modes; Properties ••• expands Character and Paragraph; live corners work; document views row: scrollbars, Alt pans while editing text; Tabs panel listed as present (#343); spring-loaded Zoom navigation; paragraph style override feedback and clearing) · **Target:** Adobe InDesign 2026 (21.6, Medium Dark, macOS)
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** patch (hidden characters follow frame, group and layer visibility (#1994); link badge on placed files; the Pen previews the curve while a smooth point is dragged and curves the rubber band after one, #1438; a Custom text variable defined with a number shows its digits, #2093; Table of Contents dialog: title field keeps its width, More Options toggles without losing hidden settings; Story panel; text Control panel Character/Paragraph modes; Properties ••• expands Character and Paragraph; live corners work; document views row: scrollbars, Alt pans while editing text; Tabs panel listed as present (#343); spring-loaded Zoom navigation; paragraph style override feedback and clearing; double-clicking a handle anchors its opposite side when fitting, #2880) · **Target:** Adobe InDesign 2026 (21.6, Medium Dark, macOS)
Tools, handles, snapping, nudging, modifiers, shortcuts, panels, menus, context menus and feel,
against InDesign 2026. The look was measured from the running app
@@ -37,7 +37,7 @@ basics of editing fail for too many users on Windows and Linux.
| Selection tool: click, marquee, move, Alt-duplicate, resize handles, rotate from corners | ✓ | ✓ | ✓ | Cmd/Ctrl held with another tool borrows the selection tool used last (Selection or Direct Selection) for one gesture, #919 |
| Direct Selection, Pen family, Pencil, Scissors | ✓ | ✓ | ~ | the Pen previews the segment while a smooth point is dragged out and curves the rubber band out of a smooth point's direction line (`pen_previews_the_curve_while_dragging_and_after_a_smooth_point`, #1438); moving reference point "0" fails (#337) |
| Live corners (yellow handle) | ✓ | ✓ widget on a selected rectangle frame; diamonds drag the corner size (Shift: one corner), Alt-click steps the shape (Shift+Alt: all) | ✓ | #186 |
| Content grabber, frame fitting by double-click | ✓ | ✓ | ✓ | |
| Content grabber, frame fitting by double-click | ✓ | ✓ double-clicking a handle anchors its opposite side (#2880) | ✓ | `object::fit_text_frame_tests::bottom_aligned_fit_keeps_bottom_edge_and_text_in_place` |
| Link badge (View › Extras): a chain on each picture placed from a file; modified and missing links marked | ✓ | ✓ chain on the frame's top edge in its layer colour, a yellow warning when the file changed, a red stop when it is missing; hidden in Preview | ✓ | Learn Skills Daily course, chapter 10 |
| Overset mark (red + at the out port) | selected frame only | every overset frame, groups included, while frame edges show | ✓ | a deliberate step past InDesign: grouped labels that overflow were invisible until Preflight |
| Smart guides, snapping to guides/grid/baseline | ✓ | ✓ (2,049-line `snap.rs`) | ~ | vertical smart spacing between two rectangles (#188) |