From 6589824a8f6ef65ed5d0045e3e9e5e95e525ec0d Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sat, 24 Sep 2022 17:19:05 +0100 Subject: [PATCH] more --- cpdfaddtext.ml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cpdfaddtext.ml b/cpdfaddtext.ml index 4541d31..325d443 100644 --- a/cpdfaddtext.ml +++ b/cpdfaddtext.ml @@ -2,8 +2,13 @@ open Pdfutil open Cpdferror +(* Keep a record of charcodes used for font subsetting. *) let used = null_hash () +(* If we have used a TTF font, put its name and object number here. Then we + know we put it there, and can avoid writing it anew across ANDS. *) +let glob_pdfobjnum = null_hash () + type color = Grey of float | RGB of float * float * float @@ -515,7 +520,13 @@ let | Some (StandardFont (f, encoding)) -> make_font embed encoding (Pdftext.string_of_standard_font f) | Some f -> - Pdf.Indirect (Pdftext.write_font pdf f) + begin match Hashtbl.find glob_pdfobjnum fontname with + | exception Not_found -> + let i = Pdftext.write_font pdf f in + Hashtbl.add glob_pdfobjnum fontname i; Pdf.Indirect i + | i -> + Pdf.Indirect i + end | None -> let firstpage = List.nth (Pdfpage.pages_of_pagetree pdf) (hd pages - 1)