Files
pdfcraft/crates/edit/tests/printer_marks_bleed_reach.rs
T
Osvaldo DuranandClaude Opus 5.5 8c6c5a261b Print production: Add printer marks (dialog, edit, tool)
Trim marks at the trim box's corners, dashed bleed marks at the bleed box,
registration targets, a colour bar and a page-information line, drawn outside
the trim box as a removable page mark (MarkKind::PrinterMarks); the page is
widened to make room when asked and the trim box stays, so the printed page
cuts the same. Edit::AddPrinterMarks (scope Full, undoable) and Remove printer
marks through Edit::RemoveMarks; Dialog::PrinterMarks reachable from the
catalog, the palette and --view printer-marks; tools doc_printer_marks and
doc_remove_marks kind printer_marks; rows in every language; parity
print.printer-marks shipped.

Carries the review fixes:
- ATTRIBUTION.toml: the language files' checksums after the new rows
- Printer marks: drop the unreachable AddPrinterMarks pattern in scope_of
- Tests: printer marks read the document's marks through upstream's marks() (#1434)
- Printer marks: make room inside the crop box and keep the trim box on rerun
- Format with rustfmt
- Printer marks: keep accented labels and make room for the bleed marks
- Printer marks test: the page is letter size, so the bleed marks (33 pt beyond the trim box) fit
- i18n(ui): carry this PR's new wordings in the catalogues that must cover them
- Parity: evidence paths follow the tests moved into tests/it
- Fix the build after merging upstream/main
- fix(printer-marks): refuse numbers out of range, print on every plate

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 18:53:50 -05:00

51 lines
1.9 KiB
Rust

//! Bleed marks start at the bleed box, so the room made for the marks counts the bleed too.
use pdfcraft_cos::{Dict, Document, Object};
use pdfcraft_edit::{PrinterMarks, add_printer_marks};
fn rect(r: [f64; 4]) -> Object {
Object::Array(r.iter().map(|v| Object::Real(*v)).collect())
}
fn page_with(boxes: &[(&[u8], [f64; 4])]) -> Document {
let mut doc = Document::new_empty();
let pages = doc.get(doc.root().unwrap()).as_dict().unwrap().reference(b"Pages").unwrap();
let mut page = Dict::new();
page.set(b"Type".to_vec(), Object::name("Page"));
page.set(b"Parent".to_vec(), Object::Ref(pages));
for (key, r) in boxes {
page.set(key.to_vec(), rect(*r));
}
let page = doc.add(page);
doc.update_dict(pages, |d| {
d.set(b"Kids".to_vec(), Object::Array(vec![Object::Ref(page)]));
d.set(b"Count".to_vec(), Object::Int(1));
})
.unwrap();
doc
}
fn page_box(doc: &Document, key: &[u8]) -> Option<Vec<f64>> {
let page = pdfcraft_model::pages(doc).first().cloned()?;
let a = page.dict.get(key).map(|o| doc.resolve(o))?;
Some(a.as_array()?.iter().filter_map(|v| doc.resolve(v).as_f64()).collect())
}
/// A 9 pt bleed: the bleed marks run out to 9 + 6 + 18 = 33 pt from the trim box, further than the
/// usual 24, so the crop box grows by that much.
#[test]
fn crop_box_grows_to_hold_the_bleed_marks() {
let mut doc = page_with(&[
(b"MediaBox", [0.0, 0.0, 1000.0, 1000.0]),
(b"CropBox", [200.0, 200.0, 800.0, 800.0]),
(b"TrimBox", [200.0, 200.0, 800.0, 800.0]),
(b"BleedBox", [191.0, 191.0, 809.0, 809.0]),
]);
let marks = PrinterMarks::default();
assert_eq!(marks.reach(), 24.0);
let widened = add_printer_marks(&mut doc, &[0], &marks, false).unwrap();
assert_eq!(widened, vec![0]);
assert_eq!(page_box(&doc, b"CropBox"), Some(vec![167.0, 167.0, 833.0, 833.0]));
assert_eq!(page_box(&doc, b"TrimBox"), Some(vec![200.0, 200.0, 800.0, 800.0]));
}