PDF/UA preservation for more operations

This commit is contained in:
John Whitington
2025-02-26 14:36:21 +00:00
parent 477fd7e550
commit d4563d2efc
3 changed files with 13 additions and 3 deletions

View File

@@ -10,6 +10,9 @@ can follow a chain from each found dictionary entry
* More of the PDF/UA Matterhorn verification suite implemented * More of the PDF/UA Matterhorn verification suite implemented
* Font lister now returns the font itself * Font lister now returns the font itself
o Allow %objnum in output name for -extract-images o Allow %objnum in output name for -extract-images
* -show-boxes, -trim-marks, -table-of-contents, -add-text
-add-rectangle, -impose, -twoup, -twoup-stack now preserve
PDF/UA compatibility
Fixes: Fixes:

View File

@@ -63,7 +63,8 @@ let ops font fontpack fontpackpdfobjs fontname longest_w x y rotate hoffset voff
| Some font -> [Pdfops.Op_Tf (unique_fontname, fontsize); Pdfops.Op_Tj (charcodes_of_utf8 font text)] | Some font -> [Pdfops.Op_Tf (unique_fontname, fontsize); Pdfops.Op_Tj (charcodes_of_utf8 font text)]
| None -> [Pdfops.Op_Tf (unique_fontname, fontsize); Pdfops.Op_Tj text] | None -> [Pdfops.Op_Tf (unique_fontname, fontsize); Pdfops.Op_Tj text]
in in
[Pdfops.Op_q; [Pdfops.begin_artifact;
Pdfops.Op_q;
Pdfops.Op_BMC "/CPDFSTAMP"; Pdfops.Op_BMC "/CPDFSTAMP";
Pdfops.Op_cm Pdfops.Op_cm
(Pdftransform.matrix_of_transform (Pdftransform.matrix_of_transform
@@ -74,7 +75,7 @@ let ops font fontpack fontpackpdfobjs fontname longest_w x y rotate hoffset voff
@ [colour_op colour; colour_op_stroke colour] @ [colour_op colour; colour_op_stroke colour]
@ (match unique_extgstatename with None -> [] | Some n -> [Pdfops.Op_gs n]) @ (match unique_extgstatename with None -> [] | Some n -> [Pdfops.Op_gs n])
@ textops @ textops
@ [Pdfops.Op_ET; Pdfops.Op_EMC; Pdfops.Op_Q] @ [Pdfops.Op_ET; Pdfops.Op_EMC; Pdfops.Op_Q; Pdfops.end_artifact]
type justification = LeftJustify | CentreJustify | RightJustify type justification = LeftJustify | CentreJustify | RightJustify
@@ -616,6 +617,7 @@ let addrectangle
| _ -> (x, y) | _ -> (x, y)
in in
let ops = let ops =
Pdfops.begin_artifact::
[ [
Pdfops.Op_q; Pdfops.Op_q;
Pdfops.Op_BMC "/CPDFSTAMP"; Pdfops.Op_BMC "/CPDFSTAMP";
@@ -633,6 +635,7 @@ let addrectangle
Pdfops.Op_EMC; Pdfops.Op_EMC;
Pdfops.Op_Q Pdfops.Op_Q
] ]
@ [Pdfops.end_artifact]
in in
let page = {page with Pdfpage.resources = resources'} in let page = {page with Pdfpage.resources = resources'} in
if underneath if underneath

View File

@@ -963,11 +963,13 @@ let show_boxes_page fast pdf _ page =
| None -> [] | None -> []
in in
let ops = let ops =
make_ops (255., 0., 0.) 0. 0. "/MediaBox" [Pdfops.begin_artifact]
@ make_ops (255., 0., 0.) 0. 0. "/MediaBox"
@ make_ops (0., 255., 0.) 7. 7. "/CropBox" @ make_ops (0., 255., 0.) 7. 7. "/CropBox"
@ make_ops (0., 0., 255.) 5. 5. "/ArtBox" @ make_ops (0., 0., 255.) 5. 5. "/ArtBox"
@ make_ops (255.,150.,0.) 3. 3. "/TrimBox" @ make_ops (255.,150.,0.) 3. 3. "/TrimBox"
@ make_ops (255.,9.,147.) 2. 2. "/BleedBox" @ make_ops (255.,9.,147.) 2. 2. "/BleedBox"
@ [Pdfops.end_artifact]
in in
Pdfpage.postpend_operators pdf ops ~fast page Pdfpage.postpend_operators pdf ops ~fast page
@@ -988,6 +990,7 @@ let trim_marks_page fast pdf n page =
[Pdfops.Op_q; [Pdfops.Op_q;
Pdfops.Op_K (1., 1., 1., 1.); Pdfops.Op_K (1., 1., 1., 1.);
Pdfops.Op_w 1.] Pdfops.Op_w 1.]
@ [Pdfops.begin_artifact]
@ line (minx, tmaxy, tminy -. allowance, tmaxy) (* top left *) @ line (minx, tmaxy, tminy -. allowance, tmaxy) (* top left *)
@ line (tminx, tmaxy +. allowance, tminx, maxy) @ line (tminx, tmaxy +. allowance, tminx, maxy)
@ line (tmaxx +. allowance, tmaxy, maxx, tmaxy) (* top right *) @ line (tmaxx +. allowance, tmaxy, maxx, tmaxy) (* top right *)
@@ -996,6 +999,7 @@ let trim_marks_page fast pdf n page =
@ line (tmaxx, tminy -. allowance, tmaxx, miny) @ line (tmaxx, tminy -. allowance, tmaxx, miny)
@ line (tminx -. allowance, tminy, minx, tminy) (* bottom left *) @ line (tminx -. allowance, tminy, minx, tminy) (* bottom left *)
@ line (tminx, tminy -. allowance, tminx, miny) @ line (tminx, tminy -. allowance, tminx, miny)
@ [Pdfops.end_artifact]
@ [Pdfops.Op_Q] @ [Pdfops.Op_Q]
in in
Pdfpage.postpend_operators pdf ops ~fast page Pdfpage.postpend_operators pdf ops ~fast page