diff --git a/Changes b/Changes index ac8efea..83f5eec 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ o New -decompress-just-content for easier content stream debugging Fixes: * Sanitizes inputs to prevent command injection attacks +o Fix PMAXX et al. w.r.t -add-rectangle * = Supported by a grant from NLnet diff --git a/cpdfaddtext.ml b/cpdfaddtext.ml index 2137683..6b61c90 100644 --- a/cpdfaddtext.ml +++ b/cpdfaddtext.ml @@ -579,7 +579,7 @@ let !pdf let addrectangle - fast (w, h) colour outline linewidth opacity position relative_to_cropbox + fast coord colour outline linewidth opacity position relative_to_cropbox underneath range pdf = let addrectangle_page _ page = @@ -607,6 +607,11 @@ let addrectangle else Pdf.parse_rectangle pdf page.Pdfpage.mediabox in + let w, h = + match Cpdfcoord.parse_units_string pdf page coord with + | [w; h] -> w, h + | _ -> error "bad coordinate specification" + in let x, y, _ = Cpdfposition.calculate_position false w mediabox position in diff --git a/cpdfaddtext.mli b/cpdfaddtext.mli index 8992d50..421ac54 100644 --- a/cpdfaddtext.mli +++ b/cpdfaddtext.mli @@ -48,10 +48,10 @@ val addtexts : Pdf.t ->(*pdf*) Pdf.t -(** Add a rectangle to the given pages. [addrectangle fast (w, h) colour outline linewidth opacity position relative_to_cropbox underneath range pdf]. *) +(** Add a rectangle to the given pages. [addrectangle fast coordinate colour outline linewidth opacity position relative_to_cropbox underneath range pdf]. *) val addrectangle : bool -> - float * float -> + string -> colour -> bool -> float -> diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 3b26c71..6403686 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -4590,7 +4590,7 @@ let go () = let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in write_pdf false (Cpdfaddtext.addrectangle - args.fast (Cpdfcoord.parse_coordinate pdf args.coord) + args.fast args.coord args.color args.outline args.linewidth args.opacity args.position args.relative_to_cropbox args.underneath range pdf) | Some (AddBookmarks file) -> diff --git a/cpdfcoord.mli b/cpdfcoord.mli index 5e75334..95234d2 100644 --- a/cpdfcoord.mli +++ b/cpdfcoord.mli @@ -14,5 +14,7 @@ val parse_coordinate : Pdf.t -> string -> float * float (** Read a list of coordinates from a string *) val parse_coordinates : Pdf.t -> string -> (float * float) list +val parse_units_string : Pdf.t -> Pdfpage.t -> string -> float list + (** Read a single number from a string *) val parse_single_number : Pdf.t -> string -> float diff --git a/cpdfimpose.ml b/cpdfimpose.ml index fcc7a15..82e594b 100644 --- a/cpdfimpose.ml +++ b/cpdfimpose.ml @@ -188,7 +188,7 @@ let add_border linewidth ~fast pdf = let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in let _, _, w, h = Pdf.parse_rectangle pdf firstpage.Pdfpage.mediabox in Cpdfaddtext.addrectangle - fast (w -. linewidth, h -. linewidth) (RGB (0., 0., 0.)) true linewidth 1. (Cpdfposition.BottomLeft (linewidth /. 2., linewidth /. 2.)) + fast (string_of_float (w -. linewidth) ^ " " ^ string_of_float (h -. linewidth)) (RGB (0., 0., 0.)) true linewidth 1. (Cpdfposition.BottomLeft (linewidth /. 2., linewidth /. 2.)) false false (ilist 1 (Pdfpage.endpage pdf)) pdf let impose ~process_struct_tree ~x ~y ~fit ~columns ~rtl ~btt ~center ~margin ~spacing ~linewidth ~fast pdf =