mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-02-16 11:50:54 +01:00
fit working
This commit is contained in:
parent
55d18edf37
commit
a2d52196f6
45
cpdf.ml
45
cpdf.ml
@ -2767,7 +2767,7 @@ let combine_pdf_rests pdf a b =
|
||||
Pdf.Dictionary (unknown_keys_a @ unknown_keys_b @ combined_known_entries)
|
||||
|
||||
(* Calculate the transformation matrices for a single imposed output page. *)
|
||||
let impose_transforms n fx fy columns rtl btt center margin spacing linewidth mediabox len =
|
||||
let impose_transforms fx fy columns rtl btt center margin spacing linewidth mediabox len =
|
||||
let width, height =
|
||||
match Pdf.parse_rectangle mediabox with
|
||||
xmin, ymin, xmax, ymax -> xmax -. xmin, ymax -. ymin
|
||||
@ -2809,11 +2809,11 @@ let impose_transforms n fx fy columns rtl btt center margin spacing linewidth me
|
||||
|
||||
(* Combine two pages into one throughout the document. The pages have already
|
||||
had their objects renumbered so as not to clash. *)
|
||||
let impose_pages n x y columns rtl btt center margin spacing linewidth mediabox' fast pdf = function
|
||||
let impose_pages x y columns rtl btt center margin spacing linewidth mediabox' fast pdf = function
|
||||
| [] -> assert false
|
||||
| (h::_) as pages ->
|
||||
let transforms =
|
||||
impose_transforms n x y columns rtl btt center margin spacing linewidth h.Pdfpage.mediabox (length pages)
|
||||
impose_transforms x y columns rtl btt center margin spacing linewidth h.Pdfpage.mediabox (length pages)
|
||||
in
|
||||
(* Change the pattern matrices before combining resources *)
|
||||
let pages, h =
|
||||
@ -2865,38 +2865,49 @@ let impose_pages n x y columns rtl btt center margin spacing linewidth mediabox'
|
||||
Pdfpage.resources = resources';
|
||||
Pdfpage.rest = rest'}
|
||||
|
||||
(* FIXME impose to use cropbox by default? See what happens with cropbox above. Clarify? Also point to hardbox. *)
|
||||
let impose ~x ~y ~fit ~columns ~rtl ~btt ~center ~margin ~spacing ~linewidth ~fast pdf =
|
||||
(*Printf.printf
|
||||
"impose: x = %f, y = %f, fit = %b, columns = %b, rtl = %b, btt = %b, center = %b, margin = %f, spacing = %f, linewidth = %f, fast = %b\n"
|
||||
"impose: x = %f, y = %f, fit = %b, columns = %b, rtl = %b, btt = %b,
|
||||
center = %b, margin = %f, spacing = %f, linewidth = %f, fast = %b\n"
|
||||
x y fit columns rtl btt center margin spacing linewidth fast;*)
|
||||
let endpage = Pdfpage.endpage pdf in
|
||||
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
|
||||
let _, _, w, h = Pdf.parse_rectangle firstpage.Pdfpage.mediabox in
|
||||
let ix = int_of_float x in
|
||||
let iy = int_of_float y in
|
||||
let n, ix, iy =
|
||||
if ix = 0 && iy = 0 then error "impose-xy: both dimensions cannot be zero" else
|
||||
if ix = 0 then (endpage, endpage, 1)
|
||||
else if iy = 0 then (endpage, 1, endpage)
|
||||
else (ix * iy, ix, iy)
|
||||
if fit then
|
||||
(* +. 0.001 ensures a page always fits on itself, or on another page of same height or width. *)
|
||||
let across = int_of_float (floor (x /. w +. 0.001)) in
|
||||
let down = int_of_float (floor (y /. h +. 0.001)) in
|
||||
if across < 1 || down < 1 then error "Not even a single page would fit." else
|
||||
(across * down, across, down)
|
||||
else
|
||||
if ix = 0 && iy = 0 then error "impose-xy: both dimensions cannot be zero" else
|
||||
if ix = 0 then (endpage, endpage, 1)
|
||||
else if iy = 0 then (endpage, 1, endpage)
|
||||
else (ix * iy, ix, iy)
|
||||
in
|
||||
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
|
||||
let mediabox' =
|
||||
if fit then Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real x; Pdf.Real y] else
|
||||
let _, _, w, h = Pdf.parse_rectangle firstpage.Pdfpage.mediabox in
|
||||
if x = 0.0 then Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real (w *. float_of_int endpage); Pdf.Real h]
|
||||
else if y = 0.0 then Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real w; Pdf.Real (h *. float_of_int endpage)]
|
||||
else Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real (w *. x); Pdf.Real (h *. y)]
|
||||
if x = 0.0 then Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real (w *. float_of_int endpage); Pdf.Real h]
|
||||
else if y = 0.0 then Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real w; Pdf.Real (h *. float_of_int endpage)]
|
||||
else Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real (w *. x); Pdf.Real (h *. y)]
|
||||
in
|
||||
let pagenums = ilist 1 endpage in
|
||||
let pdf = upright pagenums pdf in
|
||||
let pages = Pdfpage.pages_of_pagetree pdf in
|
||||
let pagesets = splitinto n pages in
|
||||
let renumbered = map (Pdfpage.renumber_pages pdf) pagesets in
|
||||
let pages' = map (impose_pages n (float_of_int ix) (float_of_int iy) columns rtl btt center margin spacing linewidth mediabox' fast pdf) renumbered in
|
||||
let pages' =
|
||||
map
|
||||
(impose_pages (float_of_int ix) (float_of_int iy) columns rtl btt center margin spacing linewidth mediabox' fast pdf)
|
||||
renumbered
|
||||
in
|
||||
let changes = map (fun x -> (x, (x + (n - 1)) / n)) pagenums in
|
||||
Pdfpage.change_pages ~changes true pdf pages'
|
||||
|
||||
(* Legacy -twoup-stack. Imposes 2x1 on a page twice the size then rotates. *)
|
||||
(* Legacy -twoup-stack. Impose 2x1 on a page twice the size then rotate. *)
|
||||
let twoup_stack fast pdf =
|
||||
let pdf =
|
||||
impose
|
||||
@ -2906,7 +2917,7 @@ let twoup_stack fast pdf =
|
||||
let all = ilist 1 (Pdfpage.endpage pdf) in
|
||||
upright ~fast all (rotate_pdf ~-90 pdf all)
|
||||
|
||||
(* Legacy -two-up. Rotates the pages and shrinks them so as to fit 2x1 on a page the same size. *)
|
||||
(* Legacy -two-up. Rotate the pages and shrinks them so as to fit 2x1 on a page the same size. *)
|
||||
let twoup fast pdf =
|
||||
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
|
||||
let width, height =
|
||||
|
Loading…
x
Reference in New Issue
Block a user