diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 97d428e..4c28f80 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3047,7 +3047,7 @@ let warn_prerotate range pdf = let prerotate range pdf = Cpdfpage.upright ~fast:args.fast range pdf -let embed_font pdf = +let embed_font () = let fontpack_of_standardfont sf = let te = Pdftext.text_extractor_of_font_real sf in let table = null_hash () in @@ -3743,7 +3743,7 @@ let go () = let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in write_pdf false (Cpdfdraft.draft args.removeonly args.boxes range pdf) | Some (AddText text) -> - let pdf = get_single_pdf args.op false in + (*let pdf = get_single_pdf args.op false in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let cpdffont = embed_font pdf in warn_prerotate range pdf; @@ -3754,17 +3754,15 @@ let go () = | (InFile inname, _, _, _, _, _)::_ -> inname | _ -> "" in - let fontname = - match embedinfo with Some (_, _, fontname, _) -> fontname | None -> args.fontname - in - write_pdf false - (Cpdfaddtext.addtexts - ?embedinfo args.linewidth args.outline args.fast fontname - font args.bates args.batespad args.color args.position - args.linespacing args.fontsize args.underneath text range - args.relative_to_cropbox args.opacity - args.justification args.midline args.topline filename - args.extract_text_font_size args.coord ~raw:(args.encoding = Raw) pdf) + write_pdf false + (Cpdfaddtext.addtexts + cpdffont args.linewidth args.outline args.fast args.fontname + font args.bates args.batespad args.color args.position + args.linespacing args.fontsize args.underneath text range + args.relative_to_cropbox args.opacity + args.justification args.midline args.topline filename + args.extract_text_font_size args.coord ~raw:(args.encoding = Raw) pdf)*) + () | Some RemoveText -> let pdf = get_single_pdf args.op false in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in @@ -4009,15 +4007,18 @@ let go () = let pdf = get_single_pdf args.op true in Cpdffont.print_font_table pdf fontname args.copyfontpage | Some TableOfContents -> - let pdf = get_single_pdf args.op false in - let font, embedinfo = embed_font pdf in - let pdf = Cpdftoc.typeset_table_of_contents ?embedinfo ~font:(unopt font) ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf in - write_pdf false pdf + (*let pdf = get_single_pdf args.op false in + let cpdffont = embed_font () in + let pdf = + Cpdftoc.typeset_table_of_contents + cpdffont ~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 pdf = Pdf.empty () in - let font, embedinfo = embed_font pdf in - let pdf = Cpdftexttopdf.typeset ?embedinfo ~papersize:args.createpdf_pagesize ~font:(unopt font) ~fontsize:args.fontsize text in + let cpdffont = embed_font () in + let pdf = Cpdftexttopdf.typeset ~font:cpdffont ~papersize:args.createpdf_pagesize ~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 181a20c..6643012 100644 --- a/cpdfembed.ml +++ b/cpdfembed.ml @@ -5,7 +5,7 @@ type t = Pdftext.font list * (int, int * int) Hashtbl.t type cpdffont = PreMadeFontPack of t -| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; fontencoding : Pdftext.encoding} +| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding} | ExistingNamedFont of string let pdfcode_of_unicode_codepoint encoding_table glyphlist_table u = diff --git a/cpdfembed.mli b/cpdfembed.mli index b83fd49..5b42742 100644 --- a/cpdfembed.mli +++ b/cpdfembed.mli @@ -6,7 +6,7 @@ type t = Pdftext.font list * (int, int * int) Hashtbl.t type cpdffont = PreMadeFontPack of t -| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; fontencoding : Pdftext.encoding} +| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding} | ExistingNamedFont of string val embed_truetype : diff --git a/cpdftexttopdf.ml b/cpdftexttopdf.ml index 9bde028..e7d1894 100644 --- a/cpdftexttopdf.ml +++ b/cpdftexttopdf.ml @@ -28,11 +28,16 @@ let rec of_utf8_with_newlines used charcode_extractor t = if c <> [] then items := Text (charcodes_of_codepoints c)::!items; rev !items -(* The optional pdf argument is for providing a pre-embedded font - this will - be removed when we re-embed subsetted? *) -let typeset ?embedinfo ~papersize ~font ~fontsize text = +let typeset ~papersize ~font ~fontsize text = + let pdf = Pdf.empty () in + let font = + match font with + | Cpdfembed.PreMadeFontPack t -> hd (fst t) + | Cpdfembed.EmbedInfo {fontfile; fontname; encoding} -> + hd (fst (Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding)) + | Cpdfembed.ExistingNamedFont _ -> raise (Pdf.PDFError "Can't use existing named font for text-to-PDF") + in let charcode_extractor = Pdftext.charcode_extractor_of_font_real font in - let pdf = match embedinfo with None -> Pdf.empty () | Some (pdf, _, _, _) -> pdf in let margin = Pdfunits.convert 72. (Pdfpaper.unit papersize) (Pdfunits.PdfPoint) (Pdfpaper.width papersize) /. 15. @@ -40,12 +45,6 @@ let typeset ?embedinfo ~papersize ~font ~fontsize text = let used = null_hash () in let instrs = of_utf8_with_newlines used charcode_extractor (Pdfio.string_of_bytes text) in let codepoints = map fst (list_of_hashtbl used) in - let font = - match embedinfo with - | None -> font - | Some (pdf, fontfile, fontname, encoding) -> - hd (fst (Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding)) - in let pages = Cpdftype.typeset margin margin margin margin papersize pdf diff --git a/cpdftexttopdf.mli b/cpdftexttopdf.mli index b0855a8..44b1e0d 100644 --- a/cpdftexttopdf.mli +++ b/cpdftexttopdf.mli @@ -1,4 +1,4 @@ (** Text to PDF *) (** Typeset a text file as a PDF. *) -val typeset : ?embedinfo:(Pdf.t * Pdfio.bytes * string * Pdftext.encoding) -> papersize:Pdfpaper.t -> font:Pdftext.font -> fontsize:float -> Pdfio.bytes -> Pdf.t +val typeset : papersize:Pdfpaper.t -> font:Cpdfembed.cpdffont -> fontsize:float -> Pdfio.bytes -> Pdf.t