more
This commit is contained in:
parent
a653020a5f
commit
550f809896
|
@ -3985,16 +3985,22 @@ let go () =
|
||||||
| Some TableOfContents ->
|
| Some TableOfContents ->
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
let font =
|
let font =
|
||||||
match args.font with StandardFont f -> f | _ -> error "TOC requires standard font only"
|
match args.font with
|
||||||
|
| StandardFont f -> Pdftext.StandardFont (f, Pdftext.WinAnsiEncoding)
|
||||||
|
| _ -> error "TOC requires standard font only"
|
||||||
in
|
in
|
||||||
let pdf = Cpdftoc.typeset_table_of_contents ~font ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf in
|
let pdf = Cpdftoc.typeset_table_of_contents ~font ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf in
|
||||||
write_pdf false pdf
|
write_pdf false pdf
|
||||||
| Some (Typeset filename) ->
|
| Some (Typeset filename) ->
|
||||||
let text = Pdfio.bytes_of_input_channel (open_in filename) in
|
let text = Pdfio.bytes_of_input_channel (open_in filename) in
|
||||||
let font =
|
let font =
|
||||||
match args.font with StandardFont f -> f | _ -> error "text to PDF: not a standard font"
|
match args.font with
|
||||||
|
| StandardFont f -> Pdftext.StandardFont (f, Pdftext.WinAnsiEncoding)
|
||||||
|
| _ -> error "text to PDF: not a standard font"
|
||||||
|
in
|
||||||
|
let pdf =
|
||||||
|
Cpdftexttopdf.typeset ~papersize:args.createpdf_pagesize ~font ~fontsize:args.fontsize text
|
||||||
in
|
in
|
||||||
let pdf = Cpdftexttopdf.typeset ~papersize:args.createpdf_pagesize ~font ~fontsize:args.fontsize text in
|
|
||||||
write_pdf false pdf
|
write_pdf false pdf
|
||||||
|
|
||||||
(* Advise the user if a combination of command line flags makes little sense,
|
(* Advise the user if a combination of command line flags makes little sense,
|
||||||
|
|
|
@ -103,7 +103,7 @@ let embed_truetype pdf ~fontfile ~fontname ~text ~encoding =
|
||||||
in
|
in
|
||||||
Pdf.addobj pdf font
|
Pdf.addobj pdf font
|
||||||
|
|
||||||
(* For now, to get a Pdftext.font, we build it with the function above using an empty (i.e. full) subset, put it in an empty PDF and then read it back. This will be fixed later. *)
|
(* For now, to get a Pdftext.font, put it in an empty PDF and then read it back. This will be fixed later. We just need it so that existing code which uses a charcode extractor can be reused. *)
|
||||||
let font_of_truetype ~fontfile ~fontname ~encoding =
|
let font_of_truetype ~fontfile ~fontname ~encoding =
|
||||||
let pdf = Pdf.empty () in
|
let pdf = Pdf.empty () in
|
||||||
let fontobjnum = embed_truetype pdf ~fontfile ~fontname ~text:"" ~encoding in
|
let fontobjnum = embed_truetype pdf ~fontfile ~fontname ~text:"" ~encoding in
|
||||||
|
|
|
@ -31,13 +31,14 @@ let rec of_utf8_with_newlines t =
|
||||||
let typeset ~papersize ~font ~fontsize text =
|
let typeset ~papersize ~font ~fontsize text =
|
||||||
let pdf = Pdf.empty () in
|
let pdf = Pdf.empty () in
|
||||||
let margin =
|
let margin =
|
||||||
Pdfunits.convert 72. (Pdfpaper.unit papersize) (Pdfunits.PdfPoint) (Pdfpaper.width papersize) /. 15.
|
Pdfunits.convert
|
||||||
|
72. (Pdfpaper.unit papersize) (Pdfunits.PdfPoint) (Pdfpaper.width papersize) /. 15.
|
||||||
in
|
in
|
||||||
let f = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), fontsize) in
|
|
||||||
let pages =
|
let pages =
|
||||||
Cpdftype.typeset
|
Cpdftype.typeset
|
||||||
margin margin margin margin papersize pdf
|
margin margin margin margin papersize pdf
|
||||||
([Cpdftype.Font f; Cpdftype.BeginDocument] @ of_utf8_with_newlines (Pdfio.string_of_bytes text))
|
([Cpdftype.Font (font, fontsize); Cpdftype.BeginDocument] @
|
||||||
|
of_utf8_with_newlines (Pdfio.string_of_bytes text))
|
||||||
in
|
in
|
||||||
let pdf, pageroot = Pdfpage.add_pagetree pages pdf in
|
let pdf, pageroot = Pdfpage.add_pagetree pages pdf in
|
||||||
Pdfpage.add_root pageroot [] pdf
|
Pdfpage.add_root pageroot [] pdf
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(** Text to PDF *)
|
(** Text to PDF *)
|
||||||
|
|
||||||
(** Typeset a text file as a PDF. *)
|
(** Typeset a text file as a PDF. *)
|
||||||
val typeset : papersize:Pdfpaper.t -> font:Pdftext.standard_font -> fontsize:float -> Pdfio.bytes -> Pdf.t
|
val typeset : papersize:Pdfpaper.t -> font:Pdftext.font -> fontsize:float -> Pdfio.bytes -> Pdf.t
|
||||||
|
|
|
@ -42,8 +42,8 @@ let shorten_text widths l t =
|
||||||
let typeset_table_of_contents ~font ~fontsize ~title ~bookmark pdf =
|
let typeset_table_of_contents ~font ~fontsize ~title ~bookmark pdf =
|
||||||
let marks = Pdfmarks.read_bookmarks pdf in
|
let marks = Pdfmarks.read_bookmarks pdf in
|
||||||
if marks = [] then (Printf.eprintf "No bookmarks, not making table of contents\n%!"; pdf) else
|
if marks = [] then (Printf.eprintf "No bookmarks, not making table of contents\n%!"; pdf) else
|
||||||
let f, fs = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), fontsize) in
|
let f, fs = (font, fontsize) in
|
||||||
let big = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), fontsize *. 2.) in
|
let big = (font, fontsize *. 2.) in
|
||||||
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
|
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
|
||||||
let width, firstpage_papersize, pmaxx, pmaxy, margin =
|
let width, firstpage_papersize, pmaxx, pmaxy, margin =
|
||||||
let width, height, xmax, ymax =
|
let width, height, xmax, ymax =
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(** Table of contents *)
|
(** Table of contents *)
|
||||||
|
|
||||||
(** Typeset a table of contents and prepend to the document. *)
|
(** Typeset a table of contents and prepend to the document. *)
|
||||||
val typeset_table_of_contents : font:Pdftext.standard_font -> fontsize:float -> title:string -> bookmark:bool -> Pdf.t -> Pdf.t
|
val typeset_table_of_contents : font:Pdftext.font -> fontsize:float -> title:string -> bookmark:bool -> Pdf.t -> Pdf.t
|
||||||
|
|
Loading…
Reference in New Issue