Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

AF.3: open Affinity 1 and 2 extensions everywhere and match the new fallback warning

callmeBalloch08a812e56823
diff --git a/apps/photocraft-cli/src/lib.rs b/apps/photocraft-cli/src/lib.rs
index 9fb616a4a..d5bd72fbc 100644
--- a/apps/photocraft-cli/src/lib.rs
+++ b/apps/photocraft-cli/src/lib.rs
@@ -288,7 +288,10 @@ fn same_dir(a: &Path, b: &Path) -> bool {
}
fn is_input(p: &Path) -> bool {
- let known = |e: &str| matches!(e, "pcraft" | "psd" | "psb" | "af") || photocraft_codecs::from_extension(e).is_some_and(|f| photocraft_codecs::caps(f).read);
+ let known = |e: &str| {
+ matches!(e, "pcraft" | "psd" | "psb" | "af" | "afdesign" | "afphoto" | "afpub")
+ || photocraft_codecs::from_extension(e).is_some_and(|f| photocraft_codecs::caps(f).read)
+ };
p.is_file() && p.extension().is_some_and(|e| known(&e.to_string_lossy().to_ascii_lowercase()))
}
diff --git a/apps/photocraft-web/src/web.rs b/apps/photocraft-web/src/web.rs
index a71902346..368f6edda 100644
--- a/apps/photocraft-web/src/web.rs
+++ b/apps/photocraft-web/src/web.rs
@@ -11,11 +11,11 @@ use wasm_bindgen::JsCast as _;
type Inbox = Arc<Mutex<Vec<(String, Vec<u8>)>>>;
-/// Everything File › Open reads: PhotoCraft, Photoshop and Affinity preview documents, flat images, and Photoshop
+/// Everything File › Open reads: PhotoCraft, Photoshop and Affinity documents, flat images, and Photoshop
/// brushes (.abr) and gradients (.grd), which go to the preset libraries.
const OPEN_EXTS: &[&str] = &[
"pcraft", "psd", "psb", "psdt", "png", "jpg", "jpeg", "tif", "tiff", "webp", "gif", "bmp", "tga", "ico", "qoi", "exr", "hdr", "pbm", "pgm", "ppm", "pam",
- "pfm", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "af",
+ "pfm", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "af", "afdesign", "afphoto", "afpub",
];
const CANVAS_ID: &str = "photocraft_canvas";
diff --git a/apps/photocraft/src/services.rs b/apps/photocraft/src/services.rs
index 95626922e..6189f44f0 100644
--- a/apps/photocraft/src/services.rs
+++ b/apps/photocraft/src/services.rs
@@ -11,11 +11,11 @@ use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
-/// Everything File › Open reads: PhotoCraft, Photoshop and Affinity preview documents, flat images, and Photoshop
+/// Everything File › Open reads: PhotoCraft, Photoshop and Affinity documents, flat images, and Photoshop
/// brushes (.abr) and gradients (.grd), which go to the preset libraries.
const OPEN_EXTS: &[&str] = &[
"pcraft", "psd", "psb", "psdt", "png", "jpg", "jpeg", "tif", "tiff", "webp", "gif", "bmp", "tga", "ico", "qoi", "exr", "hdr", "pbm", "pgm", "ppm", "pam",
- "pfm", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "af",
+ "pfm", "heic", "heif", "hif", "dng", "cr2", "cr3", "nef", "nrw", "arw", "pef", "orf", "rw2", "raf", "abr", "grd", "af", "afdesign", "afphoto", "afpub",
];
/// File › Save As formats: (filter name, extensions). The filter matching the suggested name's
diff --git a/crates/affinity/src/model.rs b/crates/affinity/src/model.rs
index 166cba07e..3579152ac 100644
--- a/crates/affinity/src/model.rs
+++ b/crates/affinity/src/model.rs
@@ -77,11 +77,7 @@ impl Path {
subpaths: self
.subpaths
.iter()
- .map(|s| SubPath {
- start: m.apply(s.start),
- segments: s.segments.iter().map(|seg| seg.map(|p| m.apply(p))).collect(),
- closed: s.closed,
- })
+ .map(|s| SubPath { start: m.apply(s.start), segments: s.segments.iter().map(|seg| seg.map(|p| m.apply(p))).collect(), closed: s.closed })
.collect(),
}
}
@@ -332,8 +328,7 @@ impl<'s, 'a, 'b> Reader<'s, 'a, 'b> {
continue;
}
let pages = pages(s, spread);
- let default_size =
- s.floats::<2>(doc, b"DfSz").filter(|[w, h]| *w > 0.0 && *h > 0.0).map(|[w, h]| Rect { x0: 0.0, y0: 0.0, x1: w, y1: h });
+ let default_size = s.floats::<2>(doc, b"DfSz").filter(|[w, h]| *w > 0.0 && *h > 0.0).map(|[w, h]| Rect { x0: 0.0, y0: 0.0, x1: w, y1: h });
let bounds = s.floats::<4>(spread, b"SprB").map(rect).or_else(|| pages.iter().copied().reduce(union)).or(default_size).unwrap_or(Rect {
x0: 0.0,
y0: 0.0,
@@ -524,8 +519,7 @@ impl<'s, 'a, 'b> Reader<'s, 'a, 'b> {
fn artboard(&mut self, id: ObjId, world: Affine) -> Kind {
let s = self.s;
let b = s.floats::<4>(id, b"ShpB").map(rect).unwrap_or(Rect { x0: 0.0, y0: 0.0, x1: 0.0, y1: 0.0 });
- let corners =
- [Point { x: b.x0, y: b.y0 }, Point { x: b.x1, y: b.y0 }, Point { x: b.x1, y: b.y1 }, Point { x: b.x0, y: b.y1 }].map(|p| world.apply(p));
+ let corners = [Point { x: b.x0, y: b.y0 }, Point { x: b.x1, y: b.y0 }, Point { x: b.x1, y: b.y1 }, Point { x: b.x0, y: b.y1 }].map(|p| world.apply(p));
let [a, b2, c, d, ..] = world.0;
if b2.abs() > 1e-9 || c.abs() > 1e-9 || a <= 0.0 || d <= 0.0 {
self.warn("a rotated or flipped artboard (imported at its bounding box)");
@@ -547,8 +541,7 @@ impl<'s, 'a, 'b> Reader<'s, 'a, 'b> {
/// equal pages (Publisher 1 facing spreads).
fn pages(s: &Stream, spread: ObjId) -> Vec<Rect> {
if let Some(md) = s.obj(spread, b"SpMd") {
- let v: Vec<Rect> =
- s.objs(md, b"PagR").into_iter().filter_map(|p| s.floats::<4>(p, b"rctp").map(rect)).filter(|r| r.x1 > r.x0 && r.y1 > r.y0).collect();
+ let v: Vec<Rect> = s.objs(md, b"PagR").into_iter().filter_map(|p| s.floats::<4>(p, b"rctp").map(rect)).filter(|r| r.x1 > r.x0 && r.y1 > r.y0).collect();
if !v.is_empty() {
return v;
}
diff --git a/crates/affinity/src/tests.rs b/crates/affinity/src/tests.rs
index 4c299dc3c..434edc1fe 100644
--- a/crates/affinity/src/tests.rs
+++ b/crates/affinity/src/tests.rs
@@ -201,10 +201,7 @@ mod archive {
(tag(b"Same"), F::Ref(7)),
(tag(b"Null"), F::Null),
(tag(b"Kids"), F::Shared(vec![F::Def(8, vec![tag(b"Grup"), tag(b"Node")], vec![(tag(b"Desc"), F::Str("g".into()))]), F::Ref(8)])),
- (
- tag(b"Crvs"),
- F::Obj(tag(b"PCvD"), vec![(tag(b"Data"), F::Pos(vec![F::U8(0), F::U32(1), F::Bool(true), F::Records(18, vec![vec![0; 18]; 4])]))]),
- ),
+ (tag(b"Crvs"), F::Obj(tag(b"PCvD"), vec![(tag(b"Data"), F::Pos(vec![F::U8(0), F::U32(1), F::Bool(true), F::Records(18, vec![vec![0; 18]; 4])]))])),
(tag(b"Enum"), F::Enum(2, 1)),
(tag(b"Tile"), F::Entry("d/3".into())),
(tag(b"Stat"), F::U8s(vec![4, 0, 2])),
diff --git a/crates/affinity/src/text.rs b/crates/affinity/src/text.rs
index 1b6e3dd7b..c34e4e436 100644
--- a/crates/affinity/src/text.rs
+++ b/crates/affinity/src/text.rs
@@ -54,11 +54,7 @@ pub(crate) fn read(r: &mut Reader, id: ObjId, world: Affine) -> Option<Text> {
}
}
if align.is_none() {
- align = s
- .obj(block, b"PAtt")
- .and_then(|p| s.objs(p, b"Runs").first().copied())
- .and_then(|run| s.obj(run, b"Item"))
- .map(|p| paragraph_align(r, p));
+ align = s.obj(block, b"PAtt").and_then(|p| s.objs(p, b"Runs").first().copied()).and_then(|run| s.obj(run, b"Item")).map(|p| paragraph_align(r, p));
}
}
if placeholders {
diff --git a/crates/automation/tests/mcp.rs b/crates/automation/tests/mcp.rs
index 40fb341fd..ed1e2f794 100644
--- a/crates/automation/tests/mcp.rs
+++ b/crates/automation/tests/mcp.rs
@@ -342,7 +342,7 @@ async fn affinity_preview_warns_and_requires_a_new_save_path() {
let client = connect(headless_in(&dir)).await;
for name in ["source.af", "renamed.psd"] {
let opened = json_of(&call(&client, "doc_open", json!({"path": name})).await);
- assert!(opened["warnings"].to_string().contains("Native layers"));
+ assert!(opened["warnings"].to_string().contains("only its embedded 16×8 PNG preview"));
assert_eq!(opened["width"], 16);
let refused = call(&client, "doc_save", json!({})).await;
assert_eq!(refused.is_error, Some(true), "{}", text(&refused));
diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs
index dc6d9332f..6779b6bd2 100644
--- a/crates/engine/src/file_cmds.rs
+++ b/crates/engine/src/file_cmds.rs
@@ -117,7 +117,7 @@ pub(crate) fn list_images(dir: &str) -> Result<Vec<String>> {
/// Extensions the batch commands pick up from a folder.
const OPENABLE: &[&str] = &[
"psd", "psb", "pcraft", "png", "jpg", "jpeg", "tif", "tiff", "webp", "gif", "bmp", "tga", "exr", "hdr", "qoi", "ico", "pnm", "ppm", "pgm", "heic", "heif",
- "hif", "dng", "cr2", "nef", "nrw", "arw", "pef", "af",
+ "hif", "dng", "cr2", "nef", "nrw", "arw", "pef", "af", "afdesign", "afphoto", "afpub",
];
pub(crate) fn file_name(path: &str) -> String {
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 624536dfc..2d831b5cf 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -155,7 +155,7 @@ pub struct DocState {
/// Anchor of ⇧-click range selection (the last plainly or ⌘-clicked layer).
pub layer_anchor: Option<LayerId>,
pub path: Option<String>,
- /// An Affinity preview must not acquire the native source as its Save path.
+ /// An Affinity document (or its preview) must not acquire the native source as its Save path.
pub source_read_only: bool,
/// Increments on every change; UIs re-render when it moves.
pub revision: u64,
diff --git a/crates/engine/tests/affinity.rs b/crates/engine/tests/affinity.rs
index 87108467b..2d56fbf98 100644
--- a/crates/engine/tests/affinity.rs
+++ b/crates/engine/tests/affinity.rs
@@ -98,11 +98,36 @@ fn native() -> Vec<u8> {
3,
vec![tag(b"PCrv")],
vec![
- (tag(b"Crvs"), F::Obj(tag(b"PCvD"), vec![(tag(b"Data"), F::Pos(vec![F::U8(0), F::U32(1), F::Bool(true), F::Records(18, vec![node(5.0, 5.0), node(15.0, 5.0), node(15.0, 15.0), node(5.0, 15.0), node(5.0, 5.0)])]))])),
- (tag(b"BFFl"), F::Shared(vec![F::Def(4, vec![tag(b"FDsc")], vec![(tag(b"FDeF"), F::Def(5, vec![tag(b"FilS")], vec![(tag(b"Colr"), F::Def(6, vec![tag(b"RGBA")], vec![(tag(b"_col"), red)]))]))])])),
+ (
+ tag(b"Crvs"),
+ F::Obj(
+ tag(b"PCvD"),
+ vec![(
+ tag(b"Data"),
+ F::Pos(vec![
+ F::U8(0),
+ F::U32(1),
+ F::Bool(true),
+ F::Records(18, vec![node(5.0, 5.0), node(15.0, 5.0), node(15.0, 15.0), node(5.0, 15.0), node(5.0, 5.0)]),
+ ]),
+ )],
+ ),
+ ),
+ (
+ tag(b"BFFl"),
+ F::Shared(vec![F::Def(
+ 4,
+ vec![tag(b"FDsc")],
+ vec![(tag(b"FDeF"), F::Def(5, vec![tag(b"FilS")], vec![(tag(b"Colr"), F::Def(6, vec![tag(b"RGBA")], vec![(tag(b"_col"), red)]))]))],
+ )]),
+ ),
],
);
- let spread = F::Def(2, vec![tag(b"Sprd")], vec![(tag(b"SprB"), F::F64s(vec![0.0, 0.0, 40.0, 20.0])), (tag(b"SprT"), F::Bool(true)), (tag(b"Chld"), F::Shared(vec![square]))]);
+ let spread = F::Def(
+ 2,
+ vec![tag(b"Sprd")],
+ vec![(tag(b"SprB"), F::F64s(vec![0.0, 0.0, 40.0, 20.0])), (tag(b"SprT"), F::Bool(true)), (tag(b"Chld"), F::Shared(vec![square]))],
+ );
let doc = synth::stream(&[(tag(b"DocR"), F::Def(1, vec![tag(b"DocN")], vec![(tag(b"Chld"), F::Shared(vec![spread]))]))]);
synth::container(&[("doc.dat", &doc, Method::Zstd)], None)
}
diff --git a/crates/io/src/lib.rs b/crates/io/src/lib.rs
index 42d7c8b56..399865f21 100644
--- a/crates/io/src/lib.rs
+++ b/crates/io/src/lib.rs
@@ -15,8 +15,9 @@
//! layer; unsupported raw variants fall back to the embedded JPEG preview.
//! * Layered TIFFs (Photoshop layer data in tags 37724 and 34377) open with their
//! layers through the PSD path and are written back the same way; see `tiff_layers`.
-//! * Some Affinity version-12 containers open as their indexed PNG preview, with
-//! an explicit fidelity warning and no source save path; see `affinity`.
+//! * Affinity documents (`.af`, `.afdesign`, `.afphoto`, `.afpub`) open natively
+//! with no source save path, what isn't imported listed in the warnings; a file
+//! whose native data can't be read opens as its embedded preview; see `affinity`.
//! * Every other format goes through `photocraft-codecs` as a single
//! "Background" layer (depth and Gray/RGB/CMYK model preserved).
//!
diff --git a/xtask/src/corpus_pins.rs b/xtask/src/corpus_pins.rs
index 6578a4f8a..dc0377593 100644
--- a/xtask/src/corpus_pins.rs
+++ b/xtask/src/corpus_pins.rs
@@ -151,7 +151,13 @@ pub const AFFINITY: PinnedCorpus = PinnedCorpus {
name: "affinity",
dest: "affinity",
upstreams: &[
- Upstream { prefix: "vector-art/", repo: "samuel-etver/vector-art", commit: VECTOR_ART_COMMIT, subdir: "simple", extras: &[("LICENSE", "vector-art/LICENSE")] },
+ Upstream {
+ prefix: "vector-art/",
+ repo: "samuel-etver/vector-art",
+ commit: VECTOR_ART_COMMIT,
+ subdir: "simple",
+ extras: &[("LICENSE", "vector-art/LICENSE")],
+ },
Upstream {
prefix: "afdesignload/",
repo: "NickBeeuwsaert/AFDesignLoad",