From 89401d7c2f48356d6bbf8694b8ef6be1f1088da5 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Fri, 16 Sep 2022 18:07:46 +0100 Subject: [PATCH] more --- cpdfaddtext.ml | 20 ++++++++++++++------ cpdfaddtext.mli | 2 +- cpdfcommand.ml | 5 +++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cpdfaddtext.ml b/cpdfaddtext.ml index 0f65ede..8ca5dc9 100644 --- a/cpdfaddtext.ml +++ b/cpdfaddtext.ml @@ -1,3 +1,9 @@ +(* Notes on ttf fonts: + + FIXME: baseline / midline adjustments need to be added for ttf fonts. + FIXME: calc_textwidth + +*) open Pdfutil open Cpdferror @@ -290,7 +296,7 @@ let pagelabel pdf num = (Pdfpagelabels.complete (Pdfpagelabels.read pdf)) let addtext - lines linewidth outline fast colour fontname embed bates batespad fontsize font + lines linewidth outline fast colour fontname embed bates batespad fontsize (font : Pdftext.font option) underneath position hoffset voffset text pages orientation cropbox opacity justification filename extract_text_font_size shift pdf = @@ -343,7 +349,7 @@ let addtext in let calc_textwidth text = match font with - | Some f -> + | Some (Pdftext.StandardFont (f, _)) -> let rawwidth = Pdfstandard14.textwidth false @@ -494,7 +500,7 @@ let unescape_string s = implode (unescape_chars [] (explode s)) let - addtexts linewidth outline fast fontname (font : Pdftext.standard_font option) embed bates batespad colour position linespacing + addtexts linewidth outline fast fontname (font : Pdftext.font option) embed bates batespad colour position linespacing fontsize underneath text pages orientation cropbox opacity justification midline topline filename extract_text_font_size shift ?(raw=false) pdf = @@ -502,8 +508,10 @@ let let realfontname = ref fontname in let fontpdfobj = match font with - | Some f -> + | Some (StandardFont (f, _)) -> make_font embed (Pdftext.string_of_standard_font f) + | Some _ -> + failwith "unknown font in addtext" | None -> let firstpage = List.nth (Pdfpage.pages_of_pagetree pdf) (hd pages - 1) @@ -545,7 +553,7 @@ let in if midline then begin match font with - | Some font -> + | Some (Pdftext.StandardFont (font, _)) -> let baseline_adjustment = (fontsize *. float (Pdfstandard14.baseline_adjustment font)) /. 1000. in @@ -555,7 +563,7 @@ let else if topline then begin match font with - | Some font -> + | Some (Pdftext.StandardFont (font, _)) -> let baseline_adjustment = (fontsize *. float (Pdfstandard14.baseline_adjustment font) *. 2.0) /. 1000. in diff --git a/cpdfaddtext.mli b/cpdfaddtext.mli index 1ebe508..827dca5 100644 --- a/cpdfaddtext.mli +++ b/cpdfaddtext.mli @@ -23,7 +23,7 @@ val addtexts : bool -> (*outline*) bool -> (*fast*) string -> (*fontname*) - Pdftext.standard_font option -> (*font*) + Pdftext.font option -> (*font*) bool -> (* embed font *) int -> (* bates number *) int option -> (* bates padding width *) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 8fb6953..d8ddc4f 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3721,9 +3721,10 @@ let go () = let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let font = match args.font with - | StandardFont f -> Some f + | StandardFont f -> Some (Pdftext.StandardFont (f, Pdftext.WinAnsiEncoding)) | OtherFont f -> None (* it's in fontname *) - | FontToEmbed (_, _) -> error "-add-text can't use TTF fonts yet" + | FontToEmbed (fontfile, encoding) -> + Some (Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~text:"" ~encoding) in warn_prerotate range pdf; let pdf =