This commit is contained in:
John Whitington 2021-10-19 16:56:39 +01:00
parent b1349c0b7e
commit 6d766f7b82
1 changed files with 20 additions and 6 deletions

22
cpdf.ml
View File

@ -2768,19 +2768,33 @@ 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 x y column rtl btt center margin spacing linewidth mediabox =
let impose_transforms n x y columns rtl btt center margin spacing linewidth mediabox =
let width, height =
match Pdf.parse_rectangle mediabox with
xmin, ymin, xmax, ymax -> xmax -. xmin, ymax -. ymin
in
let trs = ref [] in
let addtr px py =
trs := Pdftransform.matrix_of_transform [Pdftransform.Translate (px, py)]::!trs
in
let x = int_of_float x in
let y = int_of_float y in
let order row col =
(if btt then y - row - 1 else row),
(if rtl then x - col - 1 else col)
in
if columns then
for col = 0 to x - 1 do
for row = y - 1 downto 0 do
let row, col = order row col in
addtr (width *. float_of_int col) (height *. float_of_int row)
done
done
else
for row = y - 1 downto 0 do
for col = 0 to x - 1 do
trs :=
Pdftransform.matrix_of_transform
[Pdftransform.Translate (width *. float_of_int col, height *. float_of_int row)]::!trs;
let row, col = order row col in
addtr (width *. float_of_int col) (height *. float_of_int row)
done
done;
rev !trs