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