Update to Pdfunits
This commit is contained in:
parent
d7d0690546
commit
572634cd83
|
@ -15,11 +15,10 @@ let cm x = (x /. 2.54) *. 72.
|
|||
let inch x = x *. 72.
|
||||
|
||||
let points_of_papersize p =
|
||||
let unit = Pdfpaper.unit p
|
||||
and w = Pdfpaper.width p
|
||||
and h = Pdfpaper.height p in
|
||||
let c = Pdfunits.convert 0. unit Pdfunits.PdfPoint in
|
||||
c w, c h
|
||||
let u = Pdfpaper.unit p in
|
||||
let w = Pdfunits.points (Pdfpaper.width p) u in
|
||||
let h = Pdfunits.points (Pdfpaper.height p) u in
|
||||
w, h
|
||||
|
||||
let cropbox pdf page =
|
||||
match Pdf.lookup_direct pdf "/CropBox" page.Pdfpage.rest with
|
||||
|
|
|
@ -218,8 +218,8 @@ let rec image_resolution_page pdf page pagenum dpi (images : (int * string * xob
|
|||
let newpdf = Pdfpage.change_pages false pdf [page] in
|
||||
image_resolution newpdf [pagenum] dpi
|
||||
| (pagenum, name, Image (w, h)) ->
|
||||
let lx = Pdfunits.convert 0. Pdfunits.PdfPoint Pdfunits.Inch (distance_between o x)
|
||||
and ly = Pdfunits.convert 0. Pdfunits.PdfPoint Pdfunits.Inch (distance_between o y) in
|
||||
let lx = Pdfunits.points (distance_between o x) Pdfunits.Inch in
|
||||
let ly = Pdfunits.points (distance_between o y) Pdfunits.Inch in
|
||||
let wdpi = float w /. lx
|
||||
and hdpi = float h /. ly in
|
||||
add_image_result (pagenum, xobject, w, h, wdpi, hdpi)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
%Document [ ] pagespecs
|
||||
%Document extensions to -info
|
||||
%Document Topleft2 etc.
|
||||
%Test new camlpdf unit conversions
|
||||
\documentclass{book}
|
||||
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
|
||||
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.
|
||||
|
|
|
@ -61,8 +61,7 @@ let typeset ~papersize ~font ~fontsize text =
|
|||
in
|
||||
let instrs = of_utf8_with_newlines fontpack fontsize (Pdfio.string_of_bytes text) in
|
||||
let margin =
|
||||
Pdfunits.convert
|
||||
72. (Pdfpaper.unit papersize) (Pdfunits.PdfPoint) (Pdfpaper.width papersize) /. 15.
|
||||
Pdfunits.points (Pdfpaper.width papersize) (Pdfpaper.unit papersize) /. 15.
|
||||
in
|
||||
let instrs = [Cpdftype.Font (font, fontsize); Cpdftype.BeginDocument] @ instrs in
|
||||
(*Printf.printf "to_string: %s\n" (Cpdftype.to_string instrs);*)
|
||||
|
|
|
@ -106,9 +106,7 @@ let split_text space_left widths t =
|
|||
Exit -> return true
|
||||
|
||||
let layout lmargin rmargin papersize i =
|
||||
let width =
|
||||
Pdfunits.convert 72. (Pdfpaper.unit papersize) Pdfunits.PdfPoint (Pdfpaper.width papersize)
|
||||
in
|
||||
let width = Pdfunits.points (Pdfpaper.width papersize) (Pdfpaper.unit papersize) in
|
||||
let o = ref [] in
|
||||
let s = initial_state () in
|
||||
let xpos_max = width -. lmargin in
|
||||
|
@ -143,7 +141,7 @@ let layout lmargin rmargin papersize i =
|
|||
|
||||
(* Paginate, simply line-based. When ypos + lineheight exceeds max_ypos, we insert a page break. *)
|
||||
let paginate tmargin bmargin papersize i =
|
||||
let height = Pdfunits.convert 72. (Pdfpaper.unit papersize) Pdfunits.PdfPoint (Pdfpaper.height papersize) in
|
||||
let height = Pdfunits.points (Pdfpaper.height papersize) (Pdfpaper.unit papersize) in
|
||||
let o = ref [] in
|
||||
let s = initial_state () in
|
||||
s.ypos <- tmargin;
|
||||
|
@ -191,7 +189,7 @@ let typeset lmargin rmargin tmargin bmargin papersize pdf i =
|
|||
if debug then (print_endline "***after layout:\n\n"; print_endline (to_string i));
|
||||
let i = paginate tmargin bmargin papersize i in
|
||||
if debug then (print_endline "***after pagination:\n\n"; print_endline (to_string i));
|
||||
let height = Pdfunits.convert 72. (Pdfpaper.unit papersize) Pdfunits.PdfPoint (Pdfpaper.height papersize) in
|
||||
let height = Pdfunits.points (Pdfpaper.height papersize) (Pdfpaper.unit papersize) in
|
||||
let s = initial_state () in
|
||||
s.xpos <- lmargin;
|
||||
s.ypos <- tmargin;
|
||||
|
|
Loading…
Reference in New Issue