Fix up center_to_fit scaffolding
This commit is contained in:
parent
b897197443
commit
f85f2f67b0
|
@ -4223,7 +4223,7 @@ let go () =
|
||||||
warn_prerotate range pdf;
|
warn_prerotate range pdf;
|
||||||
let pdf = if args.prerotate then prerotate range pdf else pdf in
|
let pdf = if args.prerotate then prerotate range pdf else pdf in
|
||||||
let xylist = Cpdfcoord.parse_coordinates pdf args.coord in
|
let xylist = Cpdfcoord.parse_coordinates pdf args.coord in
|
||||||
write_pdf false (Cpdfpage.center_to_fit ~fast:args.fast xylist pdf range)
|
write_pdf false (Cpdfpage.center_to_fit xylist pdf range)
|
||||||
| Some (ScaleContents scale) ->
|
| Some (ScaleContents 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
|
||||||
|
|
26
cpdfpage.ml
26
cpdfpage.ml
|
@ -557,26 +557,12 @@ let stretch ?(fast=false) sxsylist pdf range =
|
||||||
process_pages stretch_page pdf range
|
process_pages stretch_page pdf range
|
||||||
|
|
||||||
(* Centre page content (crop box) on given page size, with no scaling. *)
|
(* Centre page content (crop box) on given page size, with no scaling. *)
|
||||||
let center_to_fit ?(fast=false) sxsylist pdf range =
|
let center_to_fit sxsylist pdf range =
|
||||||
let stretch_page pnum page =
|
(* Make dxdylist, suitable for shift_boxes *)
|
||||||
let sx, sy = List.nth sxsylist (pnum - 1) in
|
(* Set the new page size, as media and crop *)
|
||||||
let (minx, miny, maxx, maxy) =
|
(* Call shift_boxes to move each page. *)
|
||||||
Pdf.parse_rectangle
|
let dxdylist = sxsylist in
|
||||||
pdf
|
shift_boxes dxdylist pdf range
|
||||||
(match Pdf.lookup_direct pdf "/CropBox" page.Pdfpage.rest with
|
|
||||||
| Some r -> r
|
|
||||||
| None -> page.Pdfpage.mediabox)
|
|
||||||
in
|
|
||||||
let scale_x, scale_y = sx /. (maxx -. minx), sy /. (maxy -. miny) in
|
|
||||||
let f (xmin, ymin, xmax, ymax) = xmin *. scale_x, ymin *. scale_y, xmax *. scale_x, ymax *. scale_y in
|
|
||||||
let page = change_boxes f pdf page in
|
|
||||||
let matrix = Pdftransform.matrix_of_op (Pdftransform.Scale ((0., 0.), scale_x, scale_y)) in
|
|
||||||
let transform_op = Pdfops.Op_cm matrix in
|
|
||||||
let page = change_pattern_matrices_page pdf matrix page in
|
|
||||||
Pdfannot.transform_annotations pdf matrix page.Pdfpage.rest;
|
|
||||||
(Pdfpage.prepend_operators pdf ~fast [transform_op] page, pnum, matrix)
|
|
||||||
in
|
|
||||||
process_pages stretch_page pdf range
|
|
||||||
|
|
||||||
(* Scale to fit page of size x * y *)
|
(* Scale to fit page of size x * y *)
|
||||||
let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range =
|
let scale_to_fit_pdf ?(fast=false) position input_scale xylist op pdf range =
|
||||||
|
|
|
@ -81,7 +81,7 @@ val scale_to_fit_pdf : ?fast:bool -> Cpdfposition.position -> float -> (float *
|
||||||
|
|
||||||
val stretch : ?fast:bool -> (float * float) list -> Pdf.t -> int list -> Pdf.t
|
val stretch : ?fast:bool -> (float * float) list -> Pdf.t -> int list -> Pdf.t
|
||||||
|
|
||||||
val center_to_fit : ?fast:bool -> (float * float) list -> Pdf.t -> int list -> Pdf.t
|
val center_to_fit : (float * float) list -> Pdf.t -> int list -> Pdf.t
|
||||||
|
|
||||||
(** {2 Stamping} *)
|
(** {2 Stamping} *)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue