Changes for shift_boxes in cpdflib

This commit is contained in:
John Whitington 2024-02-07 16:55:10 +00:00
parent 8684ec3092
commit 17c8e1ae1a
3 changed files with 14 additions and 10 deletions

View File

@ -4034,22 +4034,19 @@ let go () =
Cpdfannot.list_annotations range args.encoding pdf Cpdfannot.list_annotations range args.encoding pdf
| Some Shift -> | Some Shift ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
let dxdylist = Cpdfcoord.parse_coordinates pdf args.coord in let dxdylist = Cpdfcoord.parse_coordinates pdf args.coord in
write_pdf false (Cpdfpage.shift_pdf ~fast:args.fast dxdylist pdf range) write_pdf false (Cpdfpage.shift_pdf ~fast:args.fast dxdylist pdf range)
| Some ShiftBoxes -> | Some ShiftBoxes ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
let dxdylist = Cpdfcoord.parse_coordinates pdf args.coord in let dxdylist = Cpdfcoord.parse_coordinates pdf args.coord in
let dx, dy = match dxdylist with (a, b)::_ -> a, b | _ -> 0.0, 0.0 in write_pdf false (Cpdfpage.shift_boxes dxdylist pdf range)
let f (xmin, ymin, xmax, ymax) = (xmin +. dx, ymin +. dy, xmax +. dx, ymax +. dy) in
let fpage _ p = Cpdfpage.change_boxes f pdf p in
write_pdf false (Cpdfpage.process_pages (Pdfpage.ppstub fpage) pdf range)
| Some Scale -> | Some Scale ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
let sxsylist = Cpdfcoord.parse_coordinates pdf args.coord in let sxsylist = Cpdfcoord.parse_coordinates pdf args.coord in
write_pdf false (Cpdfpage.scale_pdf ~fast:args.fast sxsylist pdf range) write_pdf false (Cpdfpage.scale_pdf ~fast:args.fast sxsylist pdf range)
| Some ScaleToFit -> | Some ScaleToFit ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in

View File

@ -310,6 +310,11 @@ let change_boxes f pdf page =
make_mediabox (f (Pdf.parse_rectangle pdf page.Pdfpage.mediabox)); make_mediabox (f (Pdf.parse_rectangle pdf page.Pdfpage.mediabox));
Pdfpage.rest = rest'} Pdfpage.rest = rest'}
let shift_boxes dxdylist pdf range =
let dx, dy = match dxdylist with (a, b)::_ -> a, b | _ -> 0.0, 0.0 in
let f (xmin, ymin, xmax, ymax) = (xmin +. dx, ymin +. dy, xmax +. dx, ymax +. dy) in
let fpage _ p = change_boxes f pdf p in
process_pages (Pdfpage.ppstub fpage) pdf range
(* Scale contents *) (* Scale contents *)
let scale_page_contents ?(fast=false) scale position pdf pnum page = let scale_page_contents ?(fast=false) scale position pdf pnum page =

View File

@ -23,6 +23,8 @@ val hard_box : Pdf.t -> int list -> string -> bool -> bool -> Pdf.t
for all pages in pdf. *) for all pages in pdf. *)
val shift_pdf : ?fast:bool -> (float * float) list -> Pdf.t -> int list -> Pdf.t val shift_pdf : ?fast:bool -> (float * float) list -> Pdf.t -> int list -> Pdf.t
val shift_boxes : (float * float) list -> Pdf.t -> int list -> Pdf.t
(** Change a page's media box so its minimum x and y are 0, making other (** Change a page's media box so its minimum x and y are 0, making other
operations simpler to think about. Any shift that is done is reflected in operations simpler to think about. Any shift that is done is reflected in
other boxes (clip etc.) *) other boxes (clip etc.) *)