Adds -stretch implmentation

This commit is contained in:
John Whitington 2024-09-21 18:02:28 +01:00
parent b5a71b2504
commit 4e9bae2596
1 changed files with 21 additions and 2 deletions

View File

@ -534,8 +534,27 @@ let scale_pdf ?(fast=false) sxsylist pdf range =
in in
process_pages scale_page pdf range process_pages scale_page pdf range
let stretch ?(fast=false) xylist pdf range = (* Scale without regard to aspect ratio. *)
let stretch ?(fast=false) sxsylist pdf range =
let stretch_page pnum page =
let sx, sy = List.nth sxsylist (pnum - 1) in
let (minx, miny, maxx, maxy) =
Pdf.parse_rectangle
pdf pdf
(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 =