Adds processing of /L in line annotations when transformed

This commit is contained in:
John Whitington 2022-07-15 16:47:28 +01:00
parent 755a4352b5
commit a6edb47d69
1 changed files with 15 additions and 2 deletions

View File

@ -1,5 +1,7 @@
open Pdfutil open Pdfutil
(* FIXME: All of this should probably be pushed down into CamlPDF *)
(* For uses of process_pages which don't need to deal with matrices, this (* For uses of process_pages which don't need to deal with matrices, this
function transforms into one which returns the identity matrix *) function transforms into one which returns the identity matrix *)
let ppstub f n p = (f n p, n, Pdftransform.i_matrix) let ppstub f n p = (f n p, n, Pdftransform.i_matrix)
@ -169,7 +171,9 @@ let transform_quadpoints pdf transform = function
Printf.eprintf "Unknown or malformed /QuadPoints format %s\n" (Pdfwrite.string_of_pdf qp); Printf.eprintf "Unknown or malformed /QuadPoints format %s\n" (Pdfwrite.string_of_pdf qp);
qp qp
(* Apply transformations to any annotations in /Annots (i.e their /Rect and /QuadPoints entries) *) (* Apply transformations to any annotations in /Annots (i.e their /Rect and
/QuadPoints entries). Also as a best-effort service, altering other
coordinates, like the endpoints /L in a line annotation. *)
let transform_annotations pdf transform rest = let transform_annotations pdf transform rest =
match Pdf.lookup_direct pdf "/Annots" rest with match Pdf.lookup_direct pdf "/Annots" rest with
| Some (Pdf.Array annots) -> | Some (Pdf.Array annots) ->
@ -188,14 +192,23 @@ let transform_annotations pdf transform rest =
| Some qp -> Some (transform_quadpoints pdf transform qp) | Some qp -> Some (transform_quadpoints pdf transform qp)
| None -> None | None -> None
in in
let line' =
match Pdf.lookup_direct pdf "/L" annot with
| Some rect -> Some (transform_rect pdf transform rect)
| _ -> None
in
let annot = Pdf.add_dict_entry annot "/Rect" rect' in let annot = Pdf.add_dict_entry annot "/Rect" rect' in
let annot = let annot =
match quadpoints' with match quadpoints' with
| Some qp -> Pdf.add_dict_entry annot "/QuadPoints" qp | Some qp -> Pdf.add_dict_entry annot "/QuadPoints" qp
| None -> annot | None -> annot
in
let annot =
match line' with
| Some l -> Pdf.add_dict_entry annot "/L" l
| None -> annot
in in
Pdf.addobj_given_num pdf (i, annot) Pdf.addobj_given_num pdf (i, annot)
| _ -> Printf.eprintf "transform_annotations: not indirect\n%!") | _ -> Printf.eprintf "transform_annotations: not indirect\n%!")
annots annots
| _ -> () | _ -> ()