diff --git a/cpdfcommand.ml b/cpdfcommand.ml index e83dd2d..7e47e04 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1723,7 +1723,7 @@ let setnowarnrotate () = let setfontttf s = args.font <- FontToEmbed (Pdfio.bytes_of_string (contents_of_file s), Pdftext.WinAnsiEncoding); - args.fontname <- Filename.basename s + args.fontname <- Filename.remove_extension (Filename.basename s) let setfontttfmore () = args.fontttfmore <- true diff --git a/cpdfembed.ml b/cpdfembed.ml index 0152f1e..359a844 100644 --- a/cpdfembed.ml +++ b/cpdfembed.ml @@ -75,10 +75,17 @@ let embed_truetype pdf ~fontfile ~fontname ~text ~encoding = let fontfile_num = Pdf.addobj pdf fontfile in let module TT = Cpdftruetype in let open Pdftext in + let fontmetrics = + let a = Array.make 256 0. in + for x = f.TT.firstchar to f.TT.lastchar do + a.(x) <- float_of_int (f.TT.widths.(x - f.TT.firstchar)) + done; + a + in SimpleFont {fonttype = Truetype; basefont = Printf.sprintf "/%s+%s" name_1 fontname; - fontmetrics = None; + fontmetrics = Some fontmetrics; firstchar = f.TT.firstchar; lastchar = f.TT.lastchar; widths = f.TT.widths; @@ -98,27 +105,3 @@ let embed_truetype pdf ~fontfile ~fontname ~text ~encoding = charset = None; tounicode = None}; encoding} - (* - let fontdescriptor = - Pdfread.parse_single_object - (Printf.sprintf - "<>" - name_1 fontname f.TT.flags f.TT.minx f.TT.miny f.TT.maxx f.TT.maxy - f.TT.italicangle f.TT.ascent f.TT.descent f.TT.capheight f.TT.stemv - f.TT.xheight f.TT.avgwidth f.TT.maxwidth fontfile_num) - in - let fontdesc_num = Pdf.addobj pdf fontdescriptor in - let font = - Pdf.add_dict_entry - (Pdfread.parse_single_object - (Printf.sprintf - "<>" - name_1 fontname fontdesc_num (string_of_encoding encoding) - f.TT.firstchar f.TT.lastchar)) - "/Widths" - widths - in - Pdf.addobj pdf font*)