mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-15 07:12:52 +00:00
feat(js): expose document page boxes (#5501)
* feat(js): expose document page boxes * Normalize page boxes for getPageBox * Correct page box test expectations and formatting * Use local page helper in box test --------- Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
This commit is contained in:
1 parent
1fc9501cf3
commit
3df6be4eff
9 files changed
+131
-10
No files matched your search
@@ -274,12 +274,15 @@ impl JsRunner {
|
||||
/// highlights form fields (`app.runtimeHighlight`).
|
||||
pub fn new(cos: &pdfcraft_cos::Document, file_name: &str, highlight: bool) -> JsRunner {
|
||||
let xfa = pdfcraft_xfa::xfa_shape(cos).is_some();
|
||||
let pages = pdfcraft_model::pages(cos);
|
||||
let doc = pdfcraft_js::DocInfo {
|
||||
file_name: file_name.to_string(),
|
||||
num_pages: pdfcraft_model::pages(cos).len(),
|
||||
num_pages: pages.len(),
|
||||
page: 0,
|
||||
info: info(cos),
|
||||
highlight,
|
||||
page_boxes: pdfcraft_organize::page_boxes(cos).unwrap_or_default(),
|
||||
page_rotations: pages.iter().map(|page| page.rotation(cos)).collect(),
|
||||
xfa,
|
||||
};
|
||||
// Once XFA owns the form, the PDF container's scripts belong to its fallback view.
|
||||
|
||||
@@ -6753,6 +6753,25 @@ fn inactive_xfa_and_ordinary_pdfs_keep_document_helpers_and_alerts() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn js_get_page_box_reads_effective_boxes_without_editing_the_document() {
|
||||
let (mut s, id) = session_with(1);
|
||||
let before = s.get(id).expect("opened document").can_undo().map(str::to_owned);
|
||||
let out = s
|
||||
.run_javascript(id, "JSON.stringify([this.getPageBox(), this.getPageBox('Media', 0), this.getPageBox('Trim', 0)])", None)
|
||||
.expect("script runs");
|
||||
assert_eq!(out.error, None, "{out:?}");
|
||||
assert_eq!(out.result.as_deref(), Some("[[0,300,200,0],[0,300,200,0],[0,300,200,0]]"));
|
||||
assert_eq!(s.get(id).expect("document remains open").can_undo(), before.as_deref());
|
||||
|
||||
s.apply(id, Edit::RotatePages { pages: vec![0], degrees: 90 }).expect("rotate page");
|
||||
let before = s.get(id).expect("rotated document").can_undo().map(str::to_owned);
|
||||
let out = s.run_javascript(id, "JSON.stringify(this.getPageBox('Crop', 0))", None).expect("script runs");
|
||||
assert_eq!(out.error, None, "{out:?}");
|
||||
assert_eq!(out.result.as_deref(), Some("[0,200,300,0]"));
|
||||
assert_eq!(s.get(id).expect("document remains open").can_undo(), before.as_deref());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn automatic_field_scripts_cannot_print() {
|
||||
use pdfcraft_forms::{FieldEvent, Scripts};
|
||||
|
||||
Reference in new issue
Block a user