From 246253107a945a5276b9aaf1c32c391fd99ae052 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sat, 8 Jun 2024 13:41:18 +0100 Subject: [PATCH] Matterhron 31_009 --- cpdffont.ml | 18 ++++++++++++------ cpdffont.mli | 4 +++- cpdfua.ml | 6 +++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cpdffont.ml b/cpdffont.ml index 67bd829..cd52e1d 100644 --- a/cpdffont.ml +++ b/cpdffont.ml @@ -97,7 +97,7 @@ let is_missing pdf dict = | Some _ -> false | None -> true -let missing_font pdf page (name, dict) = +let missing_font ?l pdf page (name, dict) = if is_missing pdf dict then let subtype = match Pdf.lookup_direct pdf "/Subtype" dict with @@ -110,12 +110,13 @@ let missing_font pdf page (name, dict) = and encoding = match Pdf.lookup_direct pdf "/Encoding" dict with | Some (Pdf.Name n) -> n - | _ -> "" + | _ -> "Built-in" in - if Pdftext.standard_font_of_name basefont <> None then () else - Printf.printf "%i, %s, %s, %s, %s\n" page name subtype basefont encoding + match l with + | None -> Printf.printf "%i, %s, %s, %s, %s\n" page name subtype basefont encoding + | Some r -> r := Printf.sprintf "%i %s %s %s %s" page name subtype basefont encoding::!r -let missing_fonts pdf range = +let missing_fonts ?l pdf range = Cpdfpage.iter_pages (fun num page -> match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with @@ -130,11 +131,16 @@ let missing_fonts pdf range = | _ -> [(name, dict)]) fontdict) in - iter (missing_font pdf num) name_dict_pairs + iter (missing_font ?l pdf num) name_dict_pairs | _ -> ()) pdf range +let missing_fonts_return pdf range = + let l = ref [] in + missing_fonts ~l pdf range; + !l + let print_font_table pdf fontname pagenumber = let page = try List.nth (Pdfpage.pages_of_pagetree pdf) (pagenumber - 1) with e -> error "page not found" in match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with diff --git a/cpdffont.mli b/cpdffont.mli index db23b3f..6ae10f9 100644 --- a/cpdffont.mli +++ b/cpdffont.mli @@ -20,7 +20,9 @@ val embed_missing_fonts : string -> bool -> string -> string -> unit val copy_font : Pdf.t -> string -> int -> int list -> Pdf.t -> Pdf.t (** Report missing fonts *) -val missing_fonts : Pdf.t -> int list -> unit +val missing_fonts : ?l:string list ref -> Pdf.t -> int list -> unit + +val missing_fonts_return : Pdf.t -> int list -> string list (** Print a font table to Standard Output. *) val print_font_table : Pdf.t -> string -> int -> unit diff --git a/cpdfua.ml b/cpdfua.ml index 59c2152..7668260 100644 --- a/cpdfua.ml +++ b/cpdfua.ml @@ -383,7 +383,11 @@ let matterhorn_31_008 pdf = (* For a font used by text intended to be rendered the font program is not embedded. *) -let matterhorn_31_009 pdf = () +(* NB This, for now, reports all unembedded fonts. *) +let matterhorn_31_009 pdf = + let l = Cpdffont.missing_fonts_return pdf (ilist 1 (Pdfpage.endpage pdf)) in + if l <> [] then + raise (MatterhornError (`List (map (fun x -> `String x) l))) (* For a font used by text the font program is embedded but it does not contain glyphs for all of the glyphs referenced by the text used for rendering. *)