Place: the place cursor keeps an encrypted PDF and asks for its password

file.place.queue read each file without a password, so an encrypted
PDF, .ai or .ait file was skipped and never reached the cursor. It now
stays in the cursor at 612 x 792 pt, VectorCraft's own size, with
needsPassword: true and no thumbnail. A click or drag on it in the app
asks for its password, with the Place dialog's Show Import Options on
or off; headless, a click on it places nothing. A file that fails for
a bad option or for another reason is still refused or skipped.

File > Place of an encrypted PDF given a page and no password, with
Show Import Options on, now asks for the password too, as it does with
the option off; it used to fail for want of the password.
This commit is contained in:
dotCooCoo
2026-11-15 08:36:54 -08:00
parent bd67a010f6
commit f0ba18f793
6 changed files with 147 additions and 9 deletions
File diff suppressed because one or more lines are too long
+29
View File
@@ -1101,6 +1101,35 @@ fn the_place_queue_skips_an_image_whose_pixels_cant_be_read() {
assert_eq!(b.place_queue_read(read).unwrap(), r);
}
/// An encrypted PDF stays in the place cursor's queue, read with the session or apart from it, at
/// a letter page's size with `needsPassword`, so that a click in the app can ask for its password;
/// headless, a click on it places nothing.
#[test]
fn the_place_queue_keeps_an_encrypted_pdf() {
use vectorcraft_testkit::pdf::{PdfPage, pdf};
let locked = pdf(&[PdfPage::new(100.0, 50.0, "0 g 0 0 10 10 re f")], Some("pw"));
let p = json!({"files": [file("locked.pdf", &locked), file("a.png", &png(40, 20, [9, 9, 9, 255], None))], "thumbnail": 8});
let (mut a, mut b) = (session(), session());
let r = a.execute("file.place.queue", &p).unwrap();
assert_eq!((&r["count"], &r["skipped"]), (&json!(2), &json!([])), "{r}");
assert_eq!(r["files"][0], json!({"name": "locked.pdf", "format": "pdf", "width": 612.0, "height": 792.0, "needsPassword": true}));
assert!(r["files"][1].get("needsPassword").is_none());
let read = b.prepare_place_queue(&p).unwrap().read().unwrap();
assert_eq!(b.place_queue_read(read).unwrap(), r);
let view = ViewInfo::default();
assert_eq!(a.tool_options()["name"], "locked.pdf");
let _ = a.pointer(&PointerEvent::new(PointerKind::Down, 10.0, 10.0), view);
let _ = a.pointer(&PointerEvent::new(PointerKind::Up, 10.0, 10.0), view);
assert_eq!((top_children(&a).len(), a.doc().unwrap().history.undo.len()), (0, 0), "nothing placed without the password");
// An encrypted PDF with a bad option is refused for the option, not kept.
let e = a.execute("file.place.queue", &json!({"files": [file("locked.pdf", &locked)], "page": 0})).unwrap_err().to_string();
assert!(e.contains("page must be a whole number from 1"), "{e}");
// A PDF that can't be read for another reason is still skipped.
let broken = file("broken.pdf", b"%PDF-1.7\nnot a PDF body\n");
let r = a.execute("file.place.queue", &json!({"files": [broken, file("b.png", &png(4, 4, [0; 4], None))]})).unwrap();
assert_eq!((&r["count"], &r["skipped"][0]["name"]), (&json!(1), &json!("broken.pdf")), "{r}");
}
/// The place queue's thumbnail of an image is drawn from the pixels its check decoded, so each
/// image is decoded once.
#[test]
+28 -5
View File
@@ -74,8 +74,11 @@ pub struct PlaceState {
queue_asks: bool,
/// The loaded cursor's files by name, with the size a click places them at.
queue_sizes: Vec<(String, f64, f64)>,
/// The names of the loaded cursor's encrypted PDF files, which ask for their password.
queue_locked: Vec<String>,
/// The engine's count of cursor loads ([`vectorcraft_engine::Session::place_queue_loads`]) when
/// `queue_asks` and `queue_sizes` were set: a later load (`tool.setOption`, a script) clears them.
/// `queue_asks`, `queue_sizes` and `queue_locked` were set: a later load (`tool.setOption`, a
/// script) clears them.
queue_load: u64,
/// The import options dialog a click of the cursor opened (the token in its params'
/// [`ASKED`]), with the automation roots the cursor was loaded in: its OK, pressed outside any
@@ -202,8 +205,8 @@ fn place_file_in(app: &mut VectorcraftApp, p: &Value, read: Read) -> Result<Valu
return Ok(Value::Null);
}
// A PDF with several pages or a password asks for the page, box and password first; with
// Show Import Options off, only an encrypted one asks, for its password.
let offered = if ask { crate::dialogs::import_pdf::offer_place(app, &p) } else { crate::dialogs::import_pdf::offer_place_password(app, &p) };
// Show Import Options off, or with a `page` given, only an encrypted one asks, for its password.
let offered = (ask && crate::dialogs::import_pdf::offer_place(app, &p)) || crate::dialogs::import_pdf::offer_place_password(app, &p);
if offered {
return Ok(Value::Null);
}
@@ -463,15 +466,21 @@ fn queue_files(app: &mut VectorcraftApp, p: &Value, read: Read, asks: bool) -> R
/// The file a click or drag of the place cursor places (`file.place` with `p`, its `rect` set):
/// read off the UI thread where the files the user places are ([`crate::placing::start`]), else at
/// once. When the Place dialog loaded the cursor with Show Import Options on, a file that has
/// import options asks for them first (Cancel leaves it unplaced). An error shows in the status bar.
/// import options asks for them first (Cancel leaves it unplaced); otherwise only an encrypted PDF
/// asks, for its password. An error shows in the status bar.
pub(crate) fn place_from_cursor(app: &mut VectorcraftApp, p: &Value) {
// Read within the automation roots of whoever loaded the cursor, even on a click of the person
// at the keyboard: an agent's queue reaches no file it wasn't given.
let roots = app.session.place_queue_roots();
forget_older_queue(app);
vectorcraft_engine::file_access::confine(roots.as_ref(), || {
if app.place.queue_asks {
let locked = is_locked(app, p);
if app.place.queue_asks || locked {
let mut p = clicked_at_full_size(app, p);
if !app.place.queue_asks {
// Only its password is asked for, as File › Place with Show Import Options off.
p["showImportOptions"] = json!(false);
}
// The import options it may ask for keep the token, and their OK places within the
// same roots ([`place_file`]).
app.place.asked = roots.clone().map(|r| {
@@ -498,10 +507,17 @@ fn forget_older_queue(app: &mut VectorcraftApp) {
if app.place.queue_load != app.session.place_queue_loads() {
app.place.queue_asks = false;
app.place.queue_sizes.clear();
app.place.queue_locked.clear();
app.place.asked = None;
}
}
/// Does `p` (a cursor click's `file.place` params) name a file the cursor holds as an encrypted PDF?
fn is_locked(app: &VectorcraftApp, p: &Value) -> bool {
let name = p.get("path").or_else(|| p.get("name")).and_then(Value::as_str).map(fileio::file_name);
name.is_some_and(|n| app.place.queue_locked.contains(&n))
}
/// The params of a cursor click (`rect` at the file's queued size) on a PDF or DXF file, whose
/// import options may change its size (another page, another scale): placed as its options place
/// it at the click (`at`, the center of the box the click gave), as File › Place of that one file
@@ -538,6 +554,13 @@ pub(crate) fn show_thumbnails(app: &mut VectorcraftApp, r: &Value, asks: bool) {
.flatten()
.filter_map(|f| Some((f["name"].as_str()?.to_string(), f["width"].as_f64()?, f["height"].as_f64()?)))
.collect();
app.place.queue_locked = r["files"]
.as_array()
.into_iter()
.flatten()
.filter(|f| f["needsPassword"] == true)
.filter_map(|f| Some(f["name"].as_str()?.to_string()))
.collect();
app.place.thumbs = r["files"]
.as_array()
.into_iter()
+55
View File
@@ -1071,6 +1071,61 @@ fn the_place_cursors_files_ask_for_their_import_options_when_show_import_options
assert_eq!(dialog_kind(&app), None);
}
/// An encrypted PDF in the place cursor asks for its password when clicked, with Show Import
/// Options on or off, and the password's OK places it where the click put it.
#[test]
fn an_encrypted_pdf_in_the_place_cursor_asks_for_its_password_when_clicked() {
let mut app = app();
let dir = Folder::new("ui-place-cursor-encrypted-pdf");
let a = dir.file("a.png", &png(10, 10, 72.0));
let pages = [PdfPage::new(100.0, 100.0, "0 g 0 0 10 10 re f"), PdfPage::new(300.0, 100.0, "1 0 0 rg 0 0 30 30 re f")];
let locked = dir.file("locked.pdf", &pdf(&pages, Some("pw")));
// The click gives the box of the size the cursor holds it at, a letter page.
let click = json!({"path": locked, "link": false, "rect": [10, 10, 612, 792]});
let center = vectorcraft_geom::Point::new(316.0, 406.0);
let placed = |app: &VectorcraftApp| {
let st = app.session.active().unwrap();
let b = st.doc.node(st.selection.objects[0]).unwrap().geometric_bounds().unwrap();
(b.width().round(), b.center())
};
for show in [false, true] {
app.run("file.place", json!({"paths": [a, locked]})).unwrap();
let d = app.ui.dialog.as_mut().unwrap();
d.fields.insert("showImportOptions".into(), json!(show));
d.fields.insert("link".into(), json!(false));
crate::dialogs::confirm(&mut app).unwrap();
assert_eq!(app.session.tool_options()["count"], 2, "kept in the cursor");
crate::place::place_from_cursor(&mut app, &click);
let d = app.ui.dialog.as_mut().expect("the password dialog");
assert!(d.bool("__locked"));
assert_eq!(d.fields["__place"], json!({"link": false, "at": [316.0, 406.0]}));
d.fields.insert("password".into(), json!("pw"));
crate::dialogs::confirm(&mut app).unwrap();
if show {
// Unlocked, it asks for the page.
assert_eq!(dialog_kind(&app), Some("importPdf"));
crate::dialogs::confirm(&mut app).unwrap();
}
assert_eq!((dialog_kind(&app), placed(&app)), (None, (100.0, center)), "Show Import Options {show}");
}
// A cursor loaded by file.place.queue asks too, also with a `page`, which it then places.
app.run("file.place.queue", json!({"paths": [a, locked], "link": false, "page": 2})).unwrap();
crate::place::place_from_cursor(&mut app, &json!({"path": locked, "link": false, "page": 2, "rect": [10, 10, 612, 792]}));
let d = app.ui.dialog.as_mut().expect("the password dialog");
assert!(d.bool("__locked"));
d.fields.insert("password".into(), json!("pw"));
crate::dialogs::confirm(&mut app).unwrap();
assert_eq!((dialog_kind(&app), placed(&app).0), (None, 300.0), "page 2");
// File › Place of it with a `page` and Show Import Options on asks for the password too.
crate::place::run_for_user(&mut app, &json!({"path": locked, "link": false, "page": 1})).unwrap();
assert!(app.ui.dialog.as_ref().is_some_and(|d| d.bool("__locked")));
app.ui.dialog = None;
// An encrypted PDF whose name has no PDF extension is still left out of the cursor.
let misnamed = dir.file("locked.dat", &pdf(&pages, Some("pw")));
let r = app.run("file.place.queue", json!({"paths": [a, misnamed]})).unwrap();
assert_eq!((&r["count"], &r["skipped"][0]["name"]), (&json!(1), &json!("locked.dat")), "{r}");
}
/// A cursor loaded again after the Place dialog loaded it with Show Import Options on (a queue set
/// on the Place tool) places its files at once.
#[test]
+6 -2
View File
@@ -7183,7 +7183,10 @@ that draws the image does not decode the file again.
`file.place.info` describes a file without placing it and `image.info` reports a placed image's link, colour mode and
effective ppi. `file.place.queue` loads the place cursor (the `place` tool) with several files: headless, drive it
with `pointer_gesture` (a click places at 100% with the top-left corner there, a drag at the dragged size) and
`press_key` (Left/Right/Up/Down cycle, Escape discards the current file). `file.place`, `file.place.queue` and
`press_key` (Left/Right/Up/Down cycle, Escape discards the current file). The cursor keeps an encrypted PDF, `.ai`
or `.ait` file that it cannot read without the password, at 612 × 792 pt (VectorCraft's own size) with
`needsPassword: true` and no thumbnail; in the app a click or drag on it asks for the password, and headless it places
nothing. `file.place`, `file.place.queue` and
`file.place.info` refuse, of the keys each one takes, a `link`, `replace` or `template` that is not true or false and a `thumbnail` that is not a
number, naming the key, and place nothing; null is the same as leaving the key out.
@@ -7194,7 +7197,8 @@ slices (Place PSD). `showImportOptions: false` places such a file without asking
its dialog: the text options, the DXF fit, lineweight, centering and layer choices with the drawing at 1:1 in its own
unit, and the PSD conversion, hidden-layer and Import Slices choices. A PDF is placed on page 1 (or `page`) and its
crop box, and an encrypted PDF given no
`password` still asks for the password. A `showImportOptions` that is not true or false is refused, and nothing is placed. The
`password` still asks for the password. An encrypted PDF given a `page` and no `password` asks for the password with
Show Import Options on too, and places that page. A `showImportOptions` that is not true or false is refused, and nothing is placed. The
Place dialog (File › Place, or `file.place {paths}`) has a Show Import Options checkbox after Link, Template and
Replace ([Place multiple files in a document](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/place-multiple-files-in-a-document.html)).
It is on by default and saved with the preferences. On, each file that has import options asks for them before it is
+1
View File
@@ -1905,6 +1905,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Placed documents: File › Place of a `.vectorcraft` file links to it by default (`file.place`'s `link`): one locked object showing an artboard of the document (or its art's bounds), read the way placing it without Link reads it, its symbols, patterns and images kept apart from the document's; without Link (or from bytes, not a file) it is an editable copy as before. It stays vectors in every output (SVG, PDF, EPS, EMF, DXF), and so do placed documents inside it, read from their own files up to 8 levels deep (documents that place each other stop there). On screen they draw from bitmaps cached per file and zoom step, shared by every copy and made in the background (a placeholder until ready), so a sheet of them redraws in about a millisecond; exports and prints draw them exactly. Like linked images, a save keeps only a preview of each (JPEG when opaque) unless Include Linked Files; output, and zooming past the preview, read the file again, falling back to the preview with a warning when it is gone or changed. Saves for older versions write them as plain art. Links check, update, relink, Update Links on open, Link Info (the artboard's size), Placement Options, Break Link (also Embed, Object › Expand: the editable copy placing without Link gives, its resources joining the document), Edit Original (the document in a new tab) and the Links panel cover them; saving a document updates the open documents that place it. The native format (v4) keeps data of 8 KB or more after the JSON instead of base64 in it.
- Placed documents' bitmaps on screen: when a bitmap made in the background is ready, the desktop app renders the canvas again only where the objects that show its file are, when the frame shown was rendered on the UI thread and that part is at most half the canvas. Bitmaps drawn or made since a frame began are kept for that frame past the 512 MiB budget, up to 2 GiB, so a view showing more than the budget does not make them again in every frame. A bitmap that would take them past 2 GiB is not kept, and its file draws exactly at that zoom. A bitmap that can't be made (the file can't be read and there is no preview) shows the light placeholder and is not asked for again. Each ready bitmap used to render the whole canvas again, and bitmaps past the budget and bitmaps that could not be made were asked for again in every frame (`crates/render/src/tests/placed_document.rs`).
- Linked PDF and `.ai` pages: File › Place with Link (the default) places a page of a PDF, `.ai` or `.ait` file read as PDF pages as a placed document, as it links an image, the page and its box (`crop`) kept with the link: Links check, update and relink it, Break Link and Object › Expand give the group placing it without Link gives, every output draws the page's vectors, and Package copies the file. Without Link, or with a password or `textAs: "outlines"`, the page is embedded. EPS and PostScript `.ai` files are still embedded (`crates/engine/src/tests/placed_document.rs`).
- The place cursor keeps an encrypted PDF, `.ai` or `.ait` file, at a letter page's size (VectorCraft's own size) and without a thumbnail, and a click or drag on it asks for its password, with the Place dialog's Show Import Options on or off; such a file was left out of the cursor before (`crates/engine/src/tests/place.rs`, `crates/ui-egui/src/tests/place.rs`).
- File › Place with Bounding Box (`file.place {crop: "bounding"}`) measures the art that shows, with its strokes and effects, as an export does: hidden objects, guides and template layers do not count, a group whose only part on the page or artboard is hidden is not placed, and symbol instances are measured by their art, for `at`, `rect`, the place cursor and `file.place.info` (`crates/engine/src/tests/place.rs`).
- The Place dialog has a Show Import Options checkbox after Link, Template and Replace ([Place multiple files in a document](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/place-multiple-files-in-a-document.html)). On (VectorCraft's default, saved with the preferences), each PDF, DXF or text file asks for its import options before it is placed, also in the place cursor; off (`file.place {showImportOptions: false}`), it is placed with the options last confirmed for its format, and only an encrypted PDF asks, for its password. Text Import Options now starts from the options confirmed last (`crates/ui-egui/src/tests/place.rs`).
- Separations Preview shows placed and embedded raster images on the visible plates, as it shows vector art (#4153): an RGB image's pixels are separated into process inks with the proof setup's intent, a CMYK image shows its own inks, a hidden plate's ink leaves the image, and with one plate visible the image shows that plate's ink as a grey. Raster images carry no spot ink, so a spot plate shown alone shows them as paper; a colorized image shows its color's plates. Emoji and other bitmap glyphs follow the same rule. The plate-filtered pixels and their reduced-size copies are kept apart from the image's own pixels, for each set of visible plates, proof setup and color settings, and with the preview off nothing changes. Evidence: `tests::colorize::separations_preview_shows_an_rgb_images_process_inks`, `separations_preview_shows_a_cmyk_images_own_inks`, `separations_preview_keeps_an_images_pixels_per_plate_set`. Print preview fidelity remains the open gap, so scores and hours are unchanged.