mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 05:58:06 +00:00
Merge pull request #8362 from dotCooCoo/feat/place-pdf-link-default
Import PDF: All checks Import PDF pages as links and Range clears it
This commit is contained in:
@@ -95,7 +95,7 @@ pub use naming::{NameParts as FileNameParts, parse_date as parse_file_date, rend
|
||||
pub(crate) use native::preview_png;
|
||||
pub use native::with_compression_pref;
|
||||
pub(crate) use pdfimport::opened_page_document;
|
||||
pub use pdfimport::{LoadOptions, page_document};
|
||||
pub use pdfimport::{LoadOptions, page_document, pages_can_link};
|
||||
pub(crate) use psdlayers::import_active as psd_layers;
|
||||
pub use psdlayers::{PsdInfo, info as psd_info};
|
||||
pub(crate) use psdslices::over as psd_slices;
|
||||
|
||||
@@ -222,6 +222,13 @@ fn page_options(page: usize, o: &LoadOptions) -> ImportOptions {
|
||||
ImportOptions { pages: Some(vec![page]), crop: o.crop, password: o.password.clone(), text_as: o.text_as, layers: false, ..Default::default() }
|
||||
}
|
||||
|
||||
/// Whether `document.open`'s `linkPages` takes the file `name` holding `bytes`: a PDF or a
|
||||
/// PDF-compatible `.ai` or `.ait` of at most [`document::MAX_FILE`] bytes. Its path, a password
|
||||
/// and `textAs` are checked apart ([`linked_pages`]).
|
||||
pub fn pages_can_link(name: &str, bytes: &[u8]) -> bool {
|
||||
bytes.len() <= document::MAX_FILE && document::is_pdf(name, bytes)
|
||||
}
|
||||
|
||||
/// `document.open` with `linkPages`: the pages `o` picks of the PDF (or PDF-compatible `.ai` or
|
||||
/// `.ait`) `name`, read from `path`, as a document holding one placed document per page, linked to
|
||||
/// that page of the file as File › Place with Link places one ([`document::source`]). Each page
|
||||
|
||||
@@ -410,3 +410,16 @@ fn a_placeholder_only_pdf_part_is_detected() {
|
||||
assert!(open(&mut s, &two, json!({"pages": "1"})).is_err());
|
||||
open(&mut s, &two, json!({})).unwrap();
|
||||
}
|
||||
|
||||
/// `linkPages` takes a PDF up to the largest file placed, and nothing else.
|
||||
#[test]
|
||||
fn pages_can_link_a_pdf_up_to_the_largest_file_placed() {
|
||||
let small = three_pages();
|
||||
assert!(pages_can_link("pages.pdf", &small));
|
||||
assert!(!pages_can_link("pages.svg", b"<svg xmlns=\"http://www.w3.org/2000/svg\"/>"));
|
||||
let mut big = vec![0u8; crate::cmd::place::document::MAX_FILE + 1];
|
||||
big[..small.len()].copy_from_slice(&small);
|
||||
assert!(!pages_can_link("pages.pdf", &big), "over the limit");
|
||||
big.pop();
|
||||
assert!(pages_can_link("pages.pdf", &big), "at the limit");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user