Move Standard 14 substitute loading into Cpdfembed

This commit is contained in:
John Whitington 2024-04-01 19:03:31 +01:00
parent 718d93713a
commit ea0e29d802
3 changed files with 30 additions and 25 deletions

View File

@ -24,21 +24,6 @@ let initial_file_size = ref 0
let empty = Pdf.empty ()
let fontnames =
[(Pdftext.TimesRoman, ["NimbusRoman-Regular.ttf"]);
(Pdftext.TimesBold, ["NimbusRoman-Bold.ttf"]);
(Pdftext.TimesItalic, ["NimbusRoman-Italic.ttf"]);
(Pdftext.TimesBoldItalic, ["NimbusRoman-BoldItalic.ttf"]);
(Pdftext.Helvetica, ["NimbusSans-Regular.ttf"]);
(Pdftext.HelveticaBold, ["NimbusSans-Bold.ttf"]);
(Pdftext.HelveticaOblique, ["NimbusSans-Italic.ttf"]);
(Pdftext.HelveticaBoldOblique, ["NimbusSans-BoldItalic.ttf"]);
(Pdftext.Courier, ["NimbusMonoPS-Regular.ttf"]);
(Pdftext.CourierBold, ["NimbusMonoPS-Bold.ttf"]);
(Pdftext.CourierOblique, ["NimbusMonoPS-Italic.ttf"]);
(Pdftext.CourierBoldOblique, ["NimbusMonoPS-BoldItalic.ttf"]);
(Pdftext.Symbol, ["StandardSymbolsPS.ttf"]);
(Pdftext.ZapfDingbats, ["D050000L.ttf"])]
(* Wrap up the file reading functions to exit with code 1 when an encryption
problem occurs. This happens when object streams are in an encrypted document
@ -1707,11 +1692,7 @@ let embed_font_inner font =
begin match args.embedstd14 with
| Some dirname ->
begin try
let fontfile, fontname =
let filename = hd (List.assoc f fontnames) in
Pdfio.bytes_of_string (contents_of_file (Filename.concat dirname filename)),
Filename.remove_extension filename
in
let fontfile, fontname = Cpdfembed.load_substitute dirname f in
Cpdfembed.EmbedInfo {fontfile; fontname; encoding = args.fontencoding}
with
e -> error (Printf.sprintf "Can't load font for embedding: %s\n" (Printexc.to_string e))

View File

@ -106,3 +106,24 @@ let rec collate_runs cfn a = function
let collate_runs = function
| [] -> []
| (_, fontnum, _)::_ as l -> collate_runs fontnum [] l
let fontnames =
[(Pdftext.TimesRoman, ["NimbusRoman-Regular.ttf"]);
(Pdftext.TimesBold, ["NimbusRoman-Bold.ttf"]);
(Pdftext.TimesItalic, ["NimbusRoman-Italic.ttf"]);
(Pdftext.TimesBoldItalic, ["NimbusRoman-BoldItalic.ttf"]);
(Pdftext.Helvetica, ["NimbusSans-Regular.ttf"]);
(Pdftext.HelveticaBold, ["NimbusSans-Bold.ttf"]);
(Pdftext.HelveticaOblique, ["NimbusSans-Italic.ttf"]);
(Pdftext.HelveticaBoldOblique, ["NimbusSans-BoldItalic.ttf"]);
(Pdftext.Courier, ["NimbusMonoPS-Regular.ttf"]);
(Pdftext.CourierBold, ["NimbusMonoPS-Bold.ttf"]);
(Pdftext.CourierOblique, ["NimbusMonoPS-Italic.ttf"]);
(Pdftext.CourierBoldOblique, ["NimbusMonoPS-BoldItalic.ttf"]);
(Pdftext.Symbol, ["StandardSymbolsPS.ttf"]);
(Pdftext.ZapfDingbats, ["D050000L.ttf"])]
let load_substitute dirname f =
let filename = hd (List.assoc f fontnames) in
(Pdfio.bytes_of_string (contents_of_file (Filename.concat dirname filename)),
Filename.remove_extension filename)

View File

@ -24,3 +24,6 @@ val embed_truetype :
(** Collate outputs of [get_char] with like font *)
val collate_runs : ('a * 'b * 'c) list -> ('a * 'b * 'c) list list
(** Load substitute Standard 14 font *)
val load_substitute : string -> Pdftext.standard_font -> Pdfio.bytes * string