Matterhron 31_009

This commit is contained in:
John Whitington 2024-06-08 13:41:18 +01:00
parent 5fc006cdc1
commit 246253107a
3 changed files with 20 additions and 8 deletions

View File

@ -97,7 +97,7 @@ let is_missing pdf dict =
| Some _ -> false | Some _ -> false
| None -> true | None -> true
let missing_font pdf page (name, dict) = let missing_font ?l pdf page (name, dict) =
if is_missing pdf dict then if is_missing pdf dict then
let subtype = let subtype =
match Pdf.lookup_direct pdf "/Subtype" dict with match Pdf.lookup_direct pdf "/Subtype" dict with
@ -110,12 +110,13 @@ let missing_font pdf page (name, dict) =
and encoding = and encoding =
match Pdf.lookup_direct pdf "/Encoding" dict with match Pdf.lookup_direct pdf "/Encoding" dict with
| Some (Pdf.Name n) -> n | Some (Pdf.Name n) -> n
| _ -> "" | _ -> "Built-in"
in in
if Pdftext.standard_font_of_name basefont <> None then () else match l with
Printf.printf "%i, %s, %s, %s, %s\n" page name subtype basefont encoding | 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 Cpdfpage.iter_pages
(fun num page -> (fun num page ->
match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with
@ -130,11 +131,16 @@ let missing_fonts pdf range =
| _ -> [(name, dict)]) | _ -> [(name, dict)])
fontdict) fontdict)
in in
iter (missing_font pdf num) name_dict_pairs iter (missing_font ?l pdf num) name_dict_pairs
| _ -> ()) | _ -> ())
pdf pdf
range 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 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 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 match Pdf.lookup_direct pdf "/Font" page.Pdfpage.resources with

View File

@ -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 val copy_font : Pdf.t -> string -> int -> int list -> Pdf.t -> Pdf.t
(** Report missing fonts *) (** 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. *) (** Print a font table to Standard Output. *)
val print_font_table : Pdf.t -> string -> int -> unit val print_font_table : Pdf.t -> string -> int -> unit

View File

@ -383,7 +383,11 @@ let matterhorn_31_008 pdf =
(* For a font used by text intended to be rendered the font program is not (* For a font used by text intended to be rendered the font program is not
embedded. *) 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 (* 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. *) glyphs for all of the glyphs referenced by the text used for rendering. *)