Indexing by name for cpdfdraw

This commit is contained in:
John Whitington 2023-07-20 14:48:49 +01:00
parent da08260313
commit fb7ca0058c
1 changed files with 12 additions and 10 deletions

View File

@ -78,7 +78,7 @@ and string_of_drawops l =
type res = type res =
{images : (string, (string * int)) Hashtbl.t; (* (name, (pdf name, objnum)) *) {images : (string, (string * int)) Hashtbl.t; (* (name, (pdf name, objnum)) *)
extgstates : ((string * float), string) Hashtbl.t; (* (kind, value), name *) extgstates : ((string * float), string) Hashtbl.t; (* (kind, value), name *)
fonts : (Pdftext.font, (string * int)) Hashtbl.t; (* (font, (objnum, pdf name)) *) fonts : (string * int, (string * int)) Hashtbl.t; (* (font, (objnum, pdf name)) *)
form_xobjects : (string, (string * int)) Hashtbl.t; (* (name, (pdf name, objnum)) *) form_xobjects : (string, (string * int)) Hashtbl.t; (* (name, (pdf name, objnum)) *)
mutable page_names : string list; mutable page_names : string list;
mutable time : Cpdfstrftime.t; mutable time : Cpdfstrftime.t;
@ -153,8 +153,9 @@ let runs_of_utf8 s =
(map (map
(fun l -> (fun l ->
if l = [] then [] else if l = [] then [] else
let f = match l with (_, _, f)::_ -> f | _ -> assert false in let f, n = match l with (_, n, f)::_ -> f, n | _ -> assert false in
let fontname = fst (Hashtbl.find (res ()).fonts f) in (*Printf.printf "runs_of_utf8 - looking for (%s, %i) font\n" identifier n;*)
let fontname = fst (Hashtbl.find (res ()).fonts (identifier, n)) in
let charcodes = map (fun (c, _, _) -> char_of_int c) l in let charcodes = map (fun (c, _, _) -> char_of_int c) l in
[Pdfops.Op_Tf (fontname, (res ()).font_size); [Pdfops.Op_Tf (fontname, (res ()).font_size);
Pdfops.Op_Tj (implode charcodes)]) Pdfops.Op_Tj (implode charcodes)])
@ -273,16 +274,17 @@ let rec ops_of_drawop dryrun pdf endpage filename bates batespad num page = func
fontpack fontpack
in in
let ns = let ns =
map map2
(fun font -> (fun font n ->
try fst (Hashtbl.find (res ()).fonts font) with try fst (Hashtbl.find (res ()).fonts (identifier, n)) with
Not_found -> Not_found ->
let o = if dryrun then 0 else Pdftext.write_font pdf font in let o = if dryrun then 0 else Pdftext.write_font pdf font in
let n = fresh_name "/F" in let name = fresh_name "/F" in
(*Printf.printf "Adding font %s as %s\n" identifier n;*) (*Printf.printf "Adding font %s as %s\n" identifier name;*)
Hashtbl.replace (res ()).fonts font (n, o); Hashtbl.replace (res ()).fonts (identifier, n) (name, o);
n) name)
(fst fontpack) (fst fontpack)
(indx0 (fst fontpack))
in in
(res ()).page_names <- ns @ (res ()).page_names; (res ()).page_names <- ns @ (res ()).page_names;
[] []