diff --git a/Cargo.lock b/Cargo.lock index 5483806..bce13c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -602,7 +602,7 @@ dependencies = [ [[package]] name = "canvas-pilot" -version = "0.10.0-rc.5" +version = "0.10.0-rc.6" dependencies = [ "base64 0.22.1", "craft-dwg", diff --git a/Cargo.toml b/Cargo.toml index dbf5580..d0c4977 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"] resolver = "3" [workspace.package] -version = "0.10.0-rc.5" +version = "0.10.0-rc.6" edition = "2024" license = "MIT" repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot" diff --git a/crates/canvas-pilot/locales/en.json b/crates/canvas-pilot/locales/en.json index 98d898a..2c1fcd9 100644 --- a/crates/canvas-pilot/locales/en.json +++ b/crates/canvas-pilot/locales/en.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "Review pasted values", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "Choose a destination for each item below. Other layers stay unchanged.", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Use supplied source names. Unnamed items and destination folders stay unchanged.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Copy exact crop edges, offsets and fit mode. Source dimensions after input crop must match; source assignments remain unchanged.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Scale crop edges proportionally to the destination input. Keep this layer’s Advanced fit; default to Centered (fit). Source assignments stay unchanged.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Copy the four proportional mask edges without resizing the layer.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Unchecked values keep the destination settings. Format changes may adjust existing crops to fit.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "Outline adjustment requires Format. Position uses the source top-left when enabled.", diff --git a/crates/canvas-pilot/locales/eo.json b/crates/canvas-pilot/locales/eo.json index 99f8003..a4d54c1 100644 --- a/crates/canvas-pilot/locales/eo.json +++ b/crates/canvas-pilot/locales/eo.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "Kontroli algluitajn valorojn", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "Elektu celon por ĉiu suba ero. Aliaj tavoloj restas senŝanĝaj.", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Uzu liveritajn fontajn nomojn. Sennomaj eroj kaj celaj dosierujoj restas senŝanĝaj.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Kopiu precizajn tondajn randojn, deŝovojn kaj adaptan reĝimon. Fontaj dimensioj post enira tondo devas kongrui; fontaj atribuoj restas senŝanĝaj.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Scale crop edges proportionally to the destination input. Keep this layer’s Advanced fit; default to Centered (fit). Source assignments stay unchanged.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Kopiu la kvar proporciajn maskajn randojn sen regrandigi la tavolon.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Nemarkitaj valoroj konservas la celajn agordojn. Formataj ŝanĝoj povas adapti ekzistantajn tondojn.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "Kontura adapto bezonas Formaton. Pozicio uzas la supran maldekstran fontan angulon kiam ŝaltita.", diff --git a/crates/canvas-pilot/locales/es.json b/crates/canvas-pilot/locales/es.json index e89b376..be773be 100644 --- a/crates/canvas-pilot/locales/es.json +++ b/crates/canvas-pilot/locales/es.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "Revisar valores pegados", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "Elija un destino para cada elemento. Las otras capas no cambian.", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Usa los nombres de origen proporcionados. Los elementos sin nombre y las carpetas de destino no cambian.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Copia bordes, desplazamientos y modo de ajuste exactos. Las dimensiones tras el recorte de entrada deben coincidir; las asignaciones de fuentes no cambian.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Adaptar los bordes de recorte proporcionalmente a la entrada de destino. Mantener Advanced fit de esta capa; por defecto, Centered (fit). Las asignaciones de fuentes no cambian.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Copia los cuatro bordes proporcionales de máscara sin redimensionar la capa.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Los valores desmarcados conservan el destino. Cambiar el formato puede ajustar los recortes existentes.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "El ajuste de contorno requiere Formato. Posición usa la esquina superior izquierda de origen cuando está activada.", diff --git a/crates/canvas-pilot/locales/fr.json b/crates/canvas-pilot/locales/fr.json index 9245ff3..db4f2a2 100644 --- a/crates/canvas-pilot/locales/fr.json +++ b/crates/canvas-pilot/locales/fr.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "Vérifier les valeurs collées", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "Choisissez une destination pour chaque élément. Les autres calques restent inchangés.", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Utiliser les noms fournis. Les éléments sans nom et les dossiers de destination restent inchangés.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Copier les bords de recadrage, décalages et mode d’ajustement exacts. Les dimensions après recadrage d’entrée doivent correspondre ; les affectations de sources restent inchangées.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Adapter les bords de recadrage proportionnellement à l’entrée de destination. Conserver le mode Advanced fit de ce calque ; par défaut, Centered (fit). Les affectations de sources restent inchangées.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Copier les quatre bords proportionnels du masque sans redimensionner le calque.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Les valeurs décochées conservent les réglages de destination. Les changements de format peuvent adapter les recadrages existants.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "L’ajustement des contours nécessite Format. Position utilise le coin supérieur gauche de la source quand cette option est active.", diff --git a/crates/canvas-pilot/locales/grc.json b/crates/canvas-pilot/locales/grc.json index 6ca6f01..d5e8fb7 100644 --- a/crates/canvas-pilot/locales/grc.json +++ b/crates/canvas-pilot/locales/grc.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "Σκέψαι τὰς ἐπικολληθείσας τιμάς", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "Ἕλου προορισμὸν ἑκάστῳ τῶν κάτω. Τὰ ἄλλα στρώματα μένει.", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Χρῶ τοῖς δοθεῖσιν ὀνόμασι πηγῆς. Ἀνώνυμα καὶ φάκελοι προορισμοῦ μένουσιν.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Ἀντίγραψον ἀκριβῆ ὅρια, μετατοπίσεις καὶ τρόπον προσαρμογῆς. Αἱ διαστάσεις μετὰ τὴν ἀποτομὴν εἰσόδου δεῖ συμφωνεῖν· αἱ ἀναθέσεις πηγῶν μένουσιν.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Τὰ ὅρια τῆς ἀποτομῆς κατὰ λόγον τῆς εἰσόδου προσαρμόζεται. Ὁ τρόπος Advanced fit τοῦ στρώματος μένει· ὁ συνήθης Centered (fit). Αἱ ἀναθέσεις πηγῶν μένουσιν.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Ἀντίγραψον τὰ τέσσαρα ἀνάλογα ὅρια καλύμματος ἄνευ μεταβολῆς μεγέθους στρώματος.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Αἱ μὴ ἐκλελεγμέναι τιμαὶ τηροῦσι τὰ τοῦ προορισμοῦ. Μεταβολαὶ μορφῆς δύνανται προσαρμόζειν ὑπαρχούσας ἀποτομάς.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "Ἡ διόρθωσις περιγράμματος δεῖται Μορφῆς. Ἡ Θέσις τῇ ἄνω ἀριστερᾷ γωνίᾳ τῆς πηγῆς χρῆται ἐνεργοῦσα.", diff --git a/crates/canvas-pilot/locales/hi.json b/crates/canvas-pilot/locales/hi.json index 13ebece..70a5312 100644 --- a/crates/canvas-pilot/locales/hi.json +++ b/crates/canvas-pilot/locales/hi.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "चिपकाए गए मान जाँचें", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "नीचे हर वस्तु का गंतव्य चुनें। अन्य परतें बनी रहती हैं।", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Use supplied source names. Unnamed items and destination folders stay unchanged.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Copy exact crop edges, offsets and fit mode. Source dimensions after input crop must match; source assignments remain unchanged.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Scale crop edges proportionally to the destination input. Keep this layer’s Advanced fit; default to Centered (fit). Source assignments stay unchanged.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Copy the four proportional mask edges without resizing the layer.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Unchecked values keep the destination settings. Format changes may adjust existing crops to fit.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "Outline adjustment requires Format. Position uses the source top-left when enabled.", diff --git a/crates/canvas-pilot/locales/ja.json b/crates/canvas-pilot/locales/ja.json index 544ea78..1107114 100644 --- a/crates/canvas-pilot/locales/ja.json +++ b/crates/canvas-pilot/locales/ja.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "貼り付けた値を確認", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "下の各項目の宛先を選んでください。他のレイヤーは変更されません。", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "提供されたソース名を使用します。名前のない項目と宛先フォルダーは変更されません。", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "クロップの端、オフセット、fit モードを正確にコピーします。入力クロップ後のソース寸法は一致する必要があります。ソースの割り当ては変わりません。", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "クロップの各辺を宛先入力の寸法に比例して調整します。このレイヤーの Advanced fit を維持し、既定は Centered (fit) です。ソースの割り当ては変更しません。", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "レイヤーのサイズを変えず、マスクの四辺の比率をコピーします。", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "未選択の値は宛先の設定を保持します。フォーマットを変更すると既存クロップが調整される場合があります。", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "輪郭調整にはフォーマットが必要です。位置を有効にするとソースの左上を使用します。", diff --git a/crates/canvas-pilot/locales/ne.json b/crates/canvas-pilot/locales/ne.json index 8df79e3..ae4a97a 100644 --- a/crates/canvas-pilot/locales/ne.json +++ b/crates/canvas-pilot/locales/ne.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "टाँसिएका मानहरू समीक्षा गर्नुहोस्", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "तलका हरेक वस्तुको गन्तव्य छान्नुहोस्। अरू तह उही रहन्छन्।", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Use supplied source names. Unnamed items and destination folders stay unchanged.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Copy exact crop edges, offsets and fit mode. Source dimensions after input crop must match; source assignments remain unchanged.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Scale crop edges proportionally to the destination input. Keep this layer’s Advanced fit; default to Centered (fit). Source assignments stay unchanged.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Copy the four proportional mask edges without resizing the layer.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Unchecked values keep the destination settings. Format changes may adjust existing crops to fit.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "Outline adjustment requires Format. Position uses the source top-left when enabled.", diff --git a/crates/canvas-pilot/locales/pt-PT.json b/crates/canvas-pilot/locales/pt-PT.json index eeefdde..2a4ac2f 100644 --- a/crates/canvas-pilot/locales/pt-PT.json +++ b/crates/canvas-pilot/locales/pt-PT.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "Rever valores colados", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "Escolha um destino para cada elemento. As outras camadas mantêm-se.", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Use supplied source names. Unnamed items and destination folders stay unchanged.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Copy exact crop edges, offsets and fit mode. Source dimensions after input crop must match; source assignments remain unchanged.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Scale crop edges proportionally to the destination input. Keep this layer’s Advanced fit; default to Centered (fit). Source assignments stay unchanged.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Copy the four proportional mask edges without resizing the layer.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Unchecked values keep the destination settings. Format changes may adjust existing crops to fit.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "Outline adjustment requires Format. Position uses the source top-left when enabled.", diff --git a/crates/canvas-pilot/locales/th.json b/crates/canvas-pilot/locales/th.json index f2c9c66..ca7d775 100644 --- a/crates/canvas-pilot/locales/th.json +++ b/crates/canvas-pilot/locales/th.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "ตรวจสอบค่าที่วาง", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "เลือกปลายทางสำหรับแต่ละรายการด้านล่าง เลเยอร์อื่นคงเดิม", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Use supplied source names. Unnamed items and destination folders stay unchanged.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Copy exact crop edges, offsets and fit mode. Source dimensions after input crop must match; source assignments remain unchanged.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Scale crop edges proportionally to the destination input. Keep this layer’s Advanced fit; default to Centered (fit). Source assignments stay unchanged.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Copy the four proportional mask edges without resizing the layer.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Unchecked values keep the destination settings. Format changes may adjust existing crops to fit.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "Outline adjustment requires Format. Position uses the source top-left when enabled.", diff --git a/crates/canvas-pilot/locales/tok.json b/crates/canvas-pilot/locales/tok.json index fb2b3d2..de0587c 100644 --- a/crates/canvas-pilot/locales/tok.json +++ b/crates/canvas-pilot/locales/tok.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "o lukin e nanpa kama", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "o anu e tawa pi ijo ale ni. lipu ante li awen.", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "Use supplied source names. Unnamed items and destination folders stay unchanged.", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Copy exact crop edges, offsets and fit mode. Source dimensions after input crop must match; source assignments remain unchanged.", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "Scale crop edges proportionally to the destination input. Keep this layer’s Advanced fit; default to Centered (fit). Source assignments stay unchanged.", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "Copy the four proportional mask edges without resizing the layer.", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "Unchecked values keep the destination settings. Format changes may adjust existing crops to fit.", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "Outline adjustment requires Format. Position uses the source top-left when enabled.", diff --git a/crates/canvas-pilot/locales/zh-CN.json b/crates/canvas-pilot/locales/zh-CN.json index b9a5e69..e84aed7 100644 --- a/crates/canvas-pilot/locales/zh-CN.json +++ b/crates/canvas-pilot/locales/zh-CN.json @@ -256,7 +256,7 @@ "ui.review-pasted-values": "检查粘贴数值", "ui.choose-a-destination-for-each-item-below-other-layers-stay-unchanged": "为以下各项选择目标。其他图层保持不变。", "ui.use-supplied-source-names-unnamed-items-and-destination-folders-stay-unchanged": "使用提供的源名称。无名称项目和目标文件夹保持不变。", - "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "精确复制裁剪边缘、偏移和适配模式。输入裁剪后的源尺寸必须匹配;源分配保持不变。", + "ui.copy-exact-crop-edges-offsets-and-fit-mode-source-dimensions-after-input-crop-must-ma": "按目标输入尺寸等比例调整各轴的裁剪边缘。保留此图层的 Advanced fit,默认使用 Centered (fit)。不改变源分配。", "ui.copy-the-four-proportional-mask-edges-without-resizing-the-layer": "复制遮罩四边比例,不改变图层尺寸。", "ui.unchecked-values-keep-the-destination-settings-format-changes-may-adjust-existing-cro": "未勾选的值保留目标设置。格式更改可能调整现有裁剪。", "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled": "轮廓调整需要启用格式。启用位置时使用源左上角。", diff --git a/crates/canvas-pilot/src/clipboard.rs b/crates/canvas-pilot/src/clipboard.rs index 3f5da43..642793b 100644 --- a/crates/canvas-pilot/src/clipboard.rs +++ b/crates/canvas-pilot/src/clipboard.rs @@ -167,7 +167,7 @@ impl Layout { } } let mut seen = std::collections::BTreeSet::new(); - for &(i, a) in appearances { + for &(i, _) in appearances { if i >= self.layers.len() || !self.selectable(i) { return Err("Clipboard destination must be an editable layer.".into()); } @@ -177,28 +177,39 @@ impl Layout { if zooms.iter().any(|(target, _)| *target == i) { return Err("Choose full crop and fit or legacy zoom, not both.".into()); } - if crop_fit { - let input = self.formats.input(i)?; - if input - .iter() - .zip(a.input_size) - .any(|(v, expected)| (v - expected).abs() > 1e-8) - { - return Err("Crop & fit requires matching source dimensions after input crop. Match the destination source or uncheck Crop & fit.".into()); - } - } } let mut draft = self.clone(); draft.apply_mapped_import_with_zoom(values, zooms)?; for &(i, appearance) in appearances { if crop_fit { - appearance.validate(draft.layers[i]).map_err(|error| { - format!( - "Cannot paste Crop & fit: {error} Include Format or uncheck Crop & fit." - ) - })?; - draft.formats.advanced[i] = appearance.crop; - draft.formats.layer_fit[i] = appearance.fit; + formats::validate_size(appearance.input_size)?; + appearance.crop.remaining(appearance.input_size)?; + let input = draft.formats.input(i)?; + let scale = [ + input[0] / appearance.input_size[0], + input[1] / appearance.input_size[1], + ]; + let crop = Crop { + left: appearance.crop.left * scale[0], + right: appearance.crop.right * scale[0], + top: appearance.crop.top * scale[1], + bottom: appearance.crop.bottom * scale[1], + }; + let g = draft.layers[i]; + let fit = draft.formats.layer_fit[i].or_else(|| { + formats::mapping(input, [g.width, g.height], crop) + .is_err() + .then_some(LayerFit::Centered) + }); + let adapted = Appearance { + input_size: input, + crop, + fit, + mask: appearance.mask, + }; + adapted.validate(g)?; + draft.formats.advanced[i] = crop; + draft.formats.layer_fit[i] = fit; } if masks { draft.formats.masks[i] = appearance.mask.validate()?; diff --git a/crates/canvas-pilot/src/gui.rs b/crates/canvas-pilot/src/gui.rs index a0e24dd..f699df2 100644 --- a/crates/canvas-pilot/src/gui.rs +++ b/crates/canvas-pilot/src/gui.rs @@ -1477,7 +1477,7 @@ impl Editor { } egui::CollapsingHeader::new(tr(ui.ctx(), "ui.import-details")).id_salt("Import details").show(ui, |ui| { ui.label(&p.note); - ui.small(if p.appearance_available() { "Source assignments, device links and input proposals are not imported. Crop & fit requires matching source dimensions." } else { "Source format, crop offsets, colors and outline appearance are not imported." }); + ui.small(if p.appearance_available() { "Source assignments, device links and input settings stay unchanged. Crop edges adapt proportionally using the destination’s Advanced fit; the default is Centered (fit)." } else { "Source format, crop offsets, colors and outline appearance are not imported." }); }); if !p.include_size {ui.small(tr(ui.ctx(), "ui.outline-adjustment-requires-format-position-uses-the-source-top-left-when-enabled"));} ui.separator(); @@ -7802,6 +7802,9 @@ mod tests { _ => None, }) .unwrap(); + app.layout + .set_layer_fit(1, fit, Default::default()) + .unwrap(); app.layout.select(Some(1)); app.open_paste(text.clone()); let p = app.paste.take().unwrap(); diff --git a/crates/canvas-pilot/tests/clipboard.rs b/crates/canvas-pilot/tests/clipboard.rs index b6399ef..26d084b 100644 --- a/crates/canvas-pilot/tests/clipboard.rs +++ b/crates/canvas-pilot/tests/clipboard.rs @@ -65,6 +65,7 @@ fn every_fit_roundtrips_exact_crop_mask_and_offset_with_atomic_undo() { layout.set_mask(0, mask).unwrap(); let text = clipboard::encode(&layout, &[0], "Readable values").unwrap(); let shape = parse_values(&text).unwrap().shapes.remove(0); + layout.set_layer_fit(1, fit, Crop::default()).unwrap(); let before = Project::from_layout(&layout); let a = shape.appearance.unwrap(); assert_eq!(a.fit, fit); @@ -96,8 +97,11 @@ fn every_fit_roundtrips_exact_crop_mask_and_offset_with_atomic_undo() { } } #[test] -fn appearance_can_be_applied_independently_and_source_mismatch_is_atomic() { +fn appearance_adapts_source_sizes_independently_and_invalid_batches_are_atomic() { let (mut layout, text) = copied(Some(LayerFit::Fullscreen)); + layout + .set_layer_fit(1, Some(LayerFit::Fullscreen), Crop::default()) + .unwrap(); let a = parse_values(&text).unwrap().shapes[0].appearance.unwrap(); let before = Project::from_layout(&layout); let g = layout.layers()[1]; @@ -105,12 +109,15 @@ fn appearance_can_be_applied_independently_and_source_mismatch_is_atomic() { input_size: [1000., 500.], ..a }; - assert!( - layout - .apply_mapped_clipboard(&[(1, g)], &[], &[(1, incompatible)], true, true) - .unwrap_err() - .contains("matching source dimensions") - ); + let input = layout.formats().input(1).unwrap(); + layout + .apply_mapped_clipboard(&[(1, g)], &[], &[(1, incompatible)], true, true) + .unwrap(); + assert_eq!(layout.formats().input(1).unwrap(), input); + assert!((layout.formats().advanced[1].left - a.crop.left * input[0] / 1000.).abs() < 1e-9); + assert!((layout.formats().advanced[1].top - a.crop.top * input[1] / 500.).abs() < 1e-9); + assert_eq!(layout.formats().layer_fit[1], a.fit); + layout.undo(); assert_eq!(Project::from_layout(&layout), before); layout .apply_mapped_clipboard(&[(1, g)], &[], &[(1, incompatible)], false, true) @@ -156,20 +163,64 @@ fn appearance_can_be_applied_independently_and_source_mismatch_is_atomic() { ); } #[test] -fn normal_crop_requires_matching_aspect_and_does_not_silently_reframe() { +fn normal_crop_falls_back_to_centered_fit_for_a_different_box() { let (mut layout, text) = copied(None); let a = parse_values(&text).unwrap().shapes[0].appearance.unwrap(); let before = Project::from_layout(&layout); let mut g = layout.layers()[1]; g.width = g.height; - assert!( - layout - .apply_mapped_clipboard(&[(1, g)], &[], &[(1, a)], true, true) - .unwrap_err() - .contains("Include Format") - ); + layout + .apply_mapped_clipboard(&[(1, g)], &[], &[(1, a)], true, true) + .unwrap(); + assert_eq!(layout.formats().layer_fit[1], Some(LayerFit::Centered)); + assert_eq!(layout.formats().advanced[1], a.crop); + let retained = a.crop.remaining(a.input_size).unwrap(); + let fitted = LayerFit::Centered.image(retained, g).unwrap(); + assert!((fitted.width / fitted.height - retained[0] / retained[1]).abs() < 1e-9); + layout.undo(); assert_eq!(Project::from_layout(&layout), before); } + +#[test] +fn all_explicit_modes_paste_across_input_ratios_without_changing_sources() { + for fit in LayerFit::ALL { + let (mut layout, text) = copied(Some(if fit == LayerFit::Fullscreen { + LayerFit::Centered + } else { + LayerFit::Fullscreen + })); + layout.set_layer_fit(1, Some(fit), Crop::default()).unwrap(); + let a = parse_values(&text).unwrap().shapes[0].appearance.unwrap(); + layout.set_layer_source_resolution(1, [942, 1029]).unwrap(); + let before = Project::from_layout(&layout); + let sources = layout.formats().sources.clone(); + let g = layout.layers()[1]; + layout + .apply_mapped_clipboard(&[(1, g)], &[], &[(1, a)], true, true) + .unwrap(); + assert_eq!(layout.formats().sources, sources); + assert_eq!(layout.formats().layer_fit[1], Some(fit)); + let crop = layout.formats().advanced[1]; + for (actual, expected) in [ + (crop.left / 942., a.crop.left / a.input_size[0]), + (crop.right / 942., a.crop.right / a.input_size[0]), + (crop.top / 1029., a.crop.top / a.input_size[1]), + (crop.bottom / 1029., a.crop.bottom / a.input_size[1]), + ] { + assert!((actual - expected).abs() < 1e-9); + } + assert_eq!(layout.formats().masks[1], a.mask); + let copied_again = clipboard::encode(&layout, &[1], "").unwrap(); + let restored = parse_values(&copied_again).unwrap().shapes[0] + .appearance + .unwrap(); + assert_eq!(restored.crop, crop); + assert_eq!(restored.fit, Some(fit)); + layout.undo(); + assert_eq!(Project::from_layout(&layout), before); + } +} + #[test] fn clipboard_schema_is_bounded_versioned_and_never_falls_back_on_invalid_payload() { let (layout, text) = copied(None); diff --git a/docs/canvas-pilot/changelog.md b/docs/canvas-pilot/changelog.md index 3d9a0b8..e740710 100644 --- a/docs/canvas-pilot/changelog.md +++ b/docs/canvas-pilot/changelog.md @@ -4,6 +4,13 @@ ## Unreleased +### v0.10.0-rc.6 + +- Allow Crop & fit paste across different input dimensions. Crop edges transfer + proportionally without changing source assignments or input preprocessing. + The destination’s Advanced fit is preserved; normal crops that no longer match the box + use Centered (fit), retaining ratio rather than stretching or refusing paste. + ### v0.10.0-rc.5 - Adapt a layer to the selected input resolution instead of requiring a manual diff --git a/docs/canvas-pilot/guide/advanced-exchange.md b/docs/canvas-pilot/guide/advanced-exchange.md index e1a97fd..c8f9733 100644 --- a/docs/canvas-pilot/guide/advanced-exchange.md +++ b/docs/canvas-pilot/guide/advanced-exchange.md @@ -52,7 +52,9 @@ For a complete editable backup, **Save project** remains the recommended choice. Canvas Pilot’s **Copy layer values** also preserves exact geometry, crop edges, offsets, fit and blanking through the clipboard. Its mapping review offers an -optional **Appearance** group; source assignments and device links remain unchanged. +optional **Appearance** group. Pasted crop edges adapt proportionally to the +destination input and use its selected **Advanced fit**; the copied fit does not +replace that choice. Source assignments and device links remain unchanged. The separate **Rename destination layers** option applies supplied source names. See [clipboard preservation and limits](files.md#canvas-pilot-layer-clipboard). This is separate from plain geometry import and export snapshot restoration. diff --git a/docs/canvas-pilot/guide/files.md b/docs/canvas-pilot/guide/files.md index 95131bd..e1aaf68 100644 --- a/docs/canvas-pilot/guide/files.md +++ b/docs/canvas-pilot/guide/files.md @@ -168,10 +168,12 @@ does not change what Canvas Pilot pastes. To copy only appearance, uncheck Position and Format. Expand **Appearance** to choose Crop & fit, Blanking, or both. Source assignments, device mappings and -input settings stay unchanged. Crop & fit requires matching source dimensions -after device preprocessing; normal crop also needs compatible box proportions. The -review explains mismatches before allowing import. Match the source dimensions, -include Format, or uncheck Crop & fit as appropriate. Blanking works independently +input settings stay unchanged. Crop edges adapt proportionally to the destination +input dimensions. The destination layer’s **Advanced fit** stays selected; the +copied fit mode does not replace it. A normal crop that does not +match the destination box uses **Centered (fit)**, preserving ratio without +stretching. You do not need to match source dimensions or include Format. +Blanking works independently of source dimensions. A failed batch changes nothing; a successful paste undoes in one step. diff --git a/docs/interfaces/canvas-pilot-clipboard.md b/docs/interfaces/canvas-pilot-clipboard.md index 41c0086..7e5313e 100644 --- a/docs/interfaces/canvas-pilot-clipboard.md +++ b/docs/interfaces/canvas-pilot-clipboard.md @@ -59,11 +59,14 @@ off by default, copies v2/v3 names only, and leaves folders/IDs unchanged. Exter formats have no such payload; older normal-crop summaries offer their legacy zoom control instead. Ignored items do not affect availability or mapped values. -Crop & fit requires the destination's effective source dimensions to match the -recorded dimensions within 1e-8 pixels per axis. It copies exact crop and mode; -it does not adapt different inputs silently. Normal-crop aspect must also match -the resulting box. Mismatches block the batch with guidance to include Format, -match the local source dimensions, or disable Crop & fit. Blanking can be applied +Crop & fit scales each crop edge by the destination/source input dimension on +its axis, preserving proportions independently of input preprocessing. It leaves +destination source dimensions and assignments unchanged. The destination layer’s selected Advanced fit remains authoritative; the copied +fit mode does not replace it. A normal crop retains normal mode when its ratio matches the resulting +box; otherwise it becomes Centered (fit), preserving ratio inside that box. +Matching input dimensions retain exact crop values. The payload schema is unchanged; +input_size provides the reference units for this conversion. +Blanking can be applied independently across different input sizes as proportions of the selected layer/source reference; source mode follows the destination’s source and crop/fit, rather than copying source pixel distances. Unchecked appearance fields remain unchanged, except that a selected Format change @@ -92,8 +95,8 @@ versions do not support the appended payload; remove the payload only when intentionally exchanging the legacy normal-crop geometry/zoom subset. Regression tests cover every mode, crop offsets, fractional values, masks, -independent appearance controls, legacy summaries, invalid schemas, source/aspect -mismatches, locked destinations, whole-batch rollback and undo/redo. +independent appearance controls, legacy summaries, invalid schemas, proportional source-size +adaptation and centered aspect fallback, locked destinations, whole-batch rollback and undo/redo. ## External text detection and fallback