From 550f809896a7fe36d3b014a5753fd13884628d8f Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 13 Sep 2022 17:59:13 +0100 Subject: [PATCH] more --- cpdfcommand.ml | 12 +++++++++--- cpdfembed.ml | 2 +- cpdftexttopdf.ml | 7 ++++--- cpdftexttopdf.mli | 2 +- cpdftoc.ml | 4 ++-- cpdftoc.mli | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index a72fc93..060c227 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3985,16 +3985,22 @@ let go () = | Some TableOfContents -> let pdf = get_single_pdf args.op false in 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 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 | Some (Typeset filename) -> let text = Pdfio.bytes_of_input_channel (open_in filename) in 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 - let pdf = Cpdftexttopdf.typeset ~papersize:args.createpdf_pagesize ~font ~fontsize:args.fontsize text in write_pdf false pdf (* Advise the user if a combination of command line flags makes little sense, diff --git a/cpdfembed.ml b/cpdfembed.ml index c95051e..d107ef9 100644 --- a/cpdfembed.ml +++ b/cpdfembed.ml @@ -103,7 +103,7 @@ let embed_truetype pdf ~fontfile ~fontname ~text ~encoding = in 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 pdf = Pdf.empty () in let fontobjnum = embed_truetype pdf ~fontfile ~fontname ~text:"" ~encoding in diff --git a/cpdftexttopdf.ml b/cpdftexttopdf.ml index 0d19755..a7371b6 100644 --- a/cpdftexttopdf.ml +++ b/cpdftexttopdf.ml @@ -31,13 +31,14 @@ let rec of_utf8_with_newlines t = let typeset ~papersize ~font ~fontsize text = let pdf = Pdf.empty () in 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 - let f = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), fontsize) in let pages = Cpdftype.typeset 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 let pdf, pageroot = Pdfpage.add_pagetree pages pdf in Pdfpage.add_root pageroot [] pdf diff --git a/cpdftexttopdf.mli b/cpdftexttopdf.mli index eb4c3a9..31c047d 100644 --- a/cpdftexttopdf.mli +++ b/cpdftexttopdf.mli @@ -1,4 +1,4 @@ (** Text to 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 diff --git a/cpdftoc.ml b/cpdftoc.ml index a0f6745..63d7665 100644 --- a/cpdftoc.ml +++ b/cpdftoc.ml @@ -42,8 +42,8 @@ let shorten_text widths l t = let typeset_table_of_contents ~font ~fontsize ~title ~bookmark pdf = let marks = Pdfmarks.read_bookmarks pdf in 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 big = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), fontsize *. 2.) in + let f, fs = (font, fontsize) in + let big = (font, fontsize *. 2.) in let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in let width, firstpage_papersize, pmaxx, pmaxy, margin = let width, height, xmax, ymax = diff --git a/cpdftoc.mli b/cpdftoc.mli index 9f749a5..f549ccb 100644 --- a/cpdftoc.mli +++ b/cpdftoc.mli @@ -1,4 +1,4 @@ (** Table of contents *) (** 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