mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 22:19:00 +00:00
Merge pull request #10506 from dotCooCoo/fix/include-bleed-native-files
Export for Screens: Include Bleed files of an artboard hold the bleed once
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1131,23 +1131,29 @@ fn names_scripts(item: &Item, r: &Row, single: Option<&[usize]>) -> bool {
|
||||
|
||||
/// The document the file of `item` that row `r` writes carries when it carries one
|
||||
/// ([`names_scripts`]): Full Document's PDF of every artboard, the item's artboard alone for a
|
||||
/// native, `.ai` or EPS row ([`board_document`]), else the item's document.
|
||||
fn carried_document<'a>(item: &'a Item, r: &Row, single: Option<&[usize]>) -> std::borrow::Cow<'a, Document> {
|
||||
/// native, `.ai` or EPS row ([`board_document`]), else the item's document. `grown`: Include Bleed
|
||||
/// grew the artboards by the document's bleed.
|
||||
fn carried_document<'a>(item: &'a Item, r: &Row, single: Option<&[usize]>, grown: bool) -> std::borrow::Cow<'a, Document> {
|
||||
match (&item.every_artboard, r.format.id, single) {
|
||||
(Some(all), "pdf", None) => std::borrow::Cow::Borrowed(&**all),
|
||||
_ if r.whole_document() && item.artboard.is_some() => std::borrow::Cow::Owned(board_document(item)),
|
||||
_ if r.whole_document() && item.artboard.is_some() => std::borrow::Cow::Owned(board_document(item, grown)),
|
||||
_ => std::borrow::Cow::Borrowed(&*item.doc),
|
||||
}
|
||||
}
|
||||
|
||||
/// The document a native, `.ai` or EPS row writes for `item`'s artboard: that artboard alone, with
|
||||
/// its background color and the art on it, as Save's separateArtboards writes it (#3868).
|
||||
fn board_document(item: &Item) -> Document {
|
||||
/// its background color and the art on it, as Save's separateArtboards writes it (#3868). When
|
||||
/// Include Bleed grew the artboard (`grown`), the artboard already holds the bleed, so the document
|
||||
/// is written with a bleed of 0: opened again, its pages are not grown by the bleed a second time.
|
||||
fn board_document(item: &Item, grown: bool) -> Document {
|
||||
let mut d = single_artboard(&item.doc, item.region, &item.name);
|
||||
if let (Some(a), Some(from)) = (d.artboards.first_mut(), item.doc.artboards.get(item.artboard.unwrap_or(0))) {
|
||||
a.color = from.color;
|
||||
}
|
||||
super::save::keep_art_on(&mut d, item.region);
|
||||
if grown && item.every_artboard.is_none() {
|
||||
d.setup.bleed = [0.0; 4];
|
||||
}
|
||||
d
|
||||
}
|
||||
|
||||
@@ -1209,7 +1215,7 @@ pub(crate) fn export(s: &mut Session, p: &Value, asked: &Value) -> Result<Value>
|
||||
let all = item.every_artboard.is_some() && r.format.id == "pdf" && single.is_none();
|
||||
let board = item.artboard.filter(|_| !all && r.whole_document());
|
||||
if looked.insert((Arc::as_ptr(&item.doc) as usize, all, board))
|
||||
&& crate::cmd::links::names_hidden_file(&carried_document(item, r, single.as_deref()), base)
|
||||
&& crate::cmd::links::names_hidden_file(&carried_document(item, r, single.as_deref(), ungrown.is_some()), base)
|
||||
{
|
||||
return Err(bad(C, super::access::IMAGE_OUTSIDE));
|
||||
}
|
||||
@@ -1402,7 +1408,10 @@ fn encode_and_write(export: ScreenExport, writer: &mut dyn FnMut(&str, &[u8]) ->
|
||||
write(pdf_doc.unwrap_or(all), "pdf", &options)?
|
||||
} else if r.whole_document() && item.artboard.is_some() {
|
||||
let b = item.artboard.unwrap_or(0);
|
||||
let d = board_docs.entry((Arc::as_ptr(&item.doc) as usize, b)).or_insert_with(|| Arc::new(board_document(item))).clone();
|
||||
let d = board_docs
|
||||
.entry((Arc::as_ptr(&item.doc) as usize, b))
|
||||
.or_insert_with(|| Arc::new(board_document(item, pdf_doc.is_some())))
|
||||
.clone();
|
||||
let mut options = r.options_for(item.region, None)?;
|
||||
// An EPS page is the artboard, not its art's bounds: an artboard without art still writes.
|
||||
if r.format.id == "eps" {
|
||||
|
||||
@@ -1512,3 +1512,39 @@ fn each_piece_writes_its_own_native_document() {
|
||||
assert!(name.contains(&board), "{name} holds the artboard {board}");
|
||||
}
|
||||
}
|
||||
|
||||
/// With Include Bleed, a native, `.ai` or EPS file of an artboard holds the artboard grown by the
|
||||
/// bleed, and no bleed of its own: opened again, a PDF with the document's bleed has the same page
|
||||
/// as the export's own PDF row, not one grown by the bleed twice. A Full Document file keeps the
|
||||
/// document's bleed around its art's bounds, which Include Bleed doesn't grow.
|
||||
#[test]
|
||||
fn include_bleed_native_files_hold_the_bleed_once() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
|
||||
s.execute("document.setup", &json!({"bleed": 9})).unwrap();
|
||||
let r = export(&mut s, json!({"includeBleed": true, "artboard": 0, "formats": [{"format": "pdf"}]}));
|
||||
let [(_, pdf)] = &files(&r)[..] else { panic!("one PDF: {r}") };
|
||||
let [(media, bleed, ..)] = page_sizes(pdf)[..] else { panic!("one page") };
|
||||
let reopened = |name: &str, bytes: &[u8]| -> (Session, Vec<PageSizes>) {
|
||||
let mut t = Session::new();
|
||||
t.execute("document.open", &json!({"name": name, "dataBase64": vectorcraft_format::base64_encode(bytes)})).unwrap();
|
||||
let r = t.execute("document.exportPdf", &json!({"bleed": {"useDocument": true}, "preserveEditing": false})).unwrap();
|
||||
let pages = page_sizes(&b64(&r));
|
||||
(t, pages)
|
||||
};
|
||||
for format in ["vectorcraft", "ai", "eps"] {
|
||||
let r = export(&mut s, json!({"includeBleed": true, "artboard": 0, "formats": [{"format": format}]}));
|
||||
let [(name, bytes)] = &files(&r)[..] else { panic!("one {format} file: {r}") };
|
||||
let (t, pages) = reopened(name, bytes);
|
||||
let [(m, b, trim, _)] = pages[..] else { panic!("{format}: one page") };
|
||||
assert_eq!((m, b), (media, bleed), "{format}: the page of the PDF row");
|
||||
assert_eq!(trim, bleed, "{format}: the artboard holds the bleed");
|
||||
assert_eq!(t.doc().unwrap().doc.setup.bleed, [0.0; 4], "{format}: no second bleed");
|
||||
}
|
||||
// Full Document: the art's bounds, with the document's bleed around them.
|
||||
let r = export(&mut s, json!({"includeBleed": true, "fullDocument": true, "formats": [{"format": "vectorcraft"}]}));
|
||||
let [(name, bytes)] = &files(&r)[..] else { panic!("one file: {r}") };
|
||||
let (t, _) = reopened(name, bytes);
|
||||
assert_eq!(t.doc().unwrap().doc.setup.bleed, [9.0; 4]);
|
||||
}
|
||||
|
||||
+2
-1
@@ -12086,7 +12086,8 @@ height (`"100h"`) or a resolution (`"72ppi"`); raster rows name their files `@2x
|
||||
otherwise. `fullDocument` writes one file per row instead (a PDF of every artboard, other formats the bounds of all
|
||||
art), `includeBleed` grows each artboard by the document's bleed (a PDF row's page keeps the artboard as its
|
||||
TrimBox and puts the row's `bleed` around it once: the row's own values, zero included, else the document's bleed
|
||||
when the row sets none and its PDF preset gives none or a bleed of 0), `includeArtboardFill: false` (Include Artboard
|
||||
when the row sets none and its PDF preset gives none or a bleed of 0; a native, `.ai` or EPS file of an artboard
|
||||
holds the grown artboard with a bleed of 0, so the bleed is not added again when the file is opened), `includeArtboardFill: false` (Include Artboard
|
||||
Fill unchecked) leaves the artboards' background colors out of the files, `pdfs: "single"` (Export PDFs As › Single file)
|
||||
writes the artboards a PDF row exports as the pages of one PDF named after the document (it is refused with
|
||||
`assets`, `layers` or `selection: "each"`, whose files each hold one item's art), `subfolders` puts each
|
||||
|
||||
Reference in New Issue
Block a user