From bdc9d8e23997415f72893d53193a145e6a0b8d57 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Thu, 13 Jul 2023 16:22:50 +0100 Subject: [PATCH] Successful codepoint gathering --- cpdfdraw.ml | 24 +++++++++++++++++------- cpdftruetype.ml | 5 +++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cpdfdraw.ml b/cpdfdraw.ml index 96c6f23..c7d51f6 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -104,9 +104,6 @@ let empty_res () = let resstack = ref [empty_res ()] -let res () = - try hd !resstack with _ -> error "graphics stack empty" - let rescopy r = {r with images = Hashtbl.copy r.images; @@ -114,6 +111,9 @@ let rescopy r = extgstates = Hashtbl.copy r.extgstates; form_xobjects = Hashtbl.copy r.form_xobjects} +let res () = + try hd !resstack with _ -> error "graphics stack empty" + let respush () = resstack := (rescopy (res ()))::!resstack @@ -341,6 +341,12 @@ let rec contains_specials_drawop = function and contains_specials l = List.exists contains_specials_drawop l +let save_whole_stack () = + map (fun r -> rescopy r) !resstack + +let restore_whole_stack r = + resstack := r + let draw_single ~fast ~underneath ~filename ~bates ~batespad fast range pdf drawops = (res ()).num <- max (res ()).num (minimum_resource_number pdf range); let endpage = Pdfpage.endpage pdf in @@ -350,8 +356,10 @@ let draw_single ~fast ~underneath ~filename ~bates ~batespad fast range pdf draw then None else begin - ignore (ops_of_drawops true pdf endpage filename bates batespad 0 (hd pages) drawops); - Some (ops_of_drawops false pdf endpage filename bates batespad 0 (hd pages) drawops) + let r = save_whole_stack () in + ignore (ops_of_drawops true pdf endpage filename bates batespad 0 (hd pages) drawops); + restore_whole_stack r; + Some (ops_of_drawops false pdf endpage filename bates batespad 0 (hd pages) drawops) end in let ss = @@ -362,8 +370,10 @@ let draw_single ~fast ~underneath ~filename ~bates ~batespad fast range pdf draw (match ops with | Some x -> x | None -> - ignore (ops_of_drawops true pdf endpage filename bates batespad n p drawops); - ops_of_drawops false pdf endpage filename bates batespad n p drawops) + let r = save_whole_stack () in + ignore (ops_of_drawops true pdf endpage filename bates batespad n p drawops); + restore_whole_stack r; + ops_of_drawops false pdf endpage filename bates batespad n p drawops) else []) (ilist 1 endpage) pages diff --git a/cpdftruetype.ml b/cpdftruetype.ml index 2e58bbf..11d9d77 100644 --- a/cpdftruetype.ml +++ b/cpdftruetype.ml @@ -496,13 +496,14 @@ let write_font filename data = close_out fh let find_main encoding subset = - let encoding_table = Pdftext.table_of_encoding encoding in + (take subset 5, [drop subset 5]) + (*let encoding_table = Pdftext.table_of_encoding encoding in let first, rest = List.partition (fun u -> try ignore (Hashtbl.find encoding_table u); true with Not_found -> false) subset in - (first, splitinto 224 rest) + (first, splitinto 224 rest)*) let parse ~subset data encoding = let mk_b byte_offset = bitbytes_of_input (let i = input_of_bytes data in i.seek_in byte_offset; i) in