From 269936be3a35d9903dca345184ad54207e5515ee Mon Sep 17 00:00:00 2001 From: John Whitington Date: Fri, 6 Sep 2024 14:04:17 +0100 Subject: [PATCH] Add -draw-struct-tree --- Changes | 2 +- cpdfcommand.ml | 15 +++++++++++---- cpdfdraw.ml | 2 +- cpdfdraw.mli | 5 +++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Changes b/Changes index ae829f3..f560d43 100644 --- a/Changes +++ b/Changes @@ -7,7 +7,7 @@ o Removed setting of Producer field in AGPL version * New -args-json for better control files * New -replace-obj to edit dictionary entries via chain * Create structure information for files with -draw -* Create PDF/UA files from scratch with -create-pdf-ua1 +* Create PDF/UA files from scratch with -create-pdf-ua-1 * = Supported by a grant from NLnet diff --git a/cpdfcommand.ml b/cpdfcommand.ml index d92e5c0..7db3ff7 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -542,7 +542,8 @@ type args = mutable resample_interpolate : bool; mutable jbig2_lossy_threshold : float; mutable extract_stream_decompress : bool; - mutable verify_single : string option} + mutable verify_single : string option; + mutable draw_struct_tree : bool} let args = {op = None; @@ -677,7 +678,8 @@ let args = resample_interpolate = false; jbig2_lossy_threshold = 0.85; extract_stream_decompress = false; - verify_single = None} + verify_single = None; + draw_struct_tree = false} (* Do not reset original_filename or cpdflin or was_encrypted or was_decrypted_with_owner or recrypt or producer or creator or path_to_* or @@ -800,7 +802,8 @@ let reset_arguments () = args.jbig2_lossy_threshold <- 0.85; args.extract_stream_decompress <- false; clear Cpdfdrawcontrol.fontpack_initialised; - args.verify_single <- None + args.verify_single <- None; + args.draw_struct_tree <- false (* Prefer a) the one given with -cpdflin b) a local cpdflin, c) otherwise assume installed at a system place *) @@ -1801,6 +1804,9 @@ let settextwidth s = let setdraw () = args.op <- Some Draw +let setdrawstructtree () = + args.draw_struct_tree <- true + let setextractfontfile s = args.op <- Some (ExtractFontFile s) @@ -2782,6 +2788,7 @@ let specs = Arg.String settextwidth, " Find width of a line of text"); ("-draw", Arg.Unit setdraw, " Begin drawing"); + ("-draw-struct-tree", Arg.Unit setdrawstructtree, " Build structure trees when drawing."); ("-rect", Arg.String Cpdfdrawcontrol.addrect, " Draw rectangle"); ("-to", Arg.String Cpdfdrawcontrol.addto, " Move to"); ("-line", Arg.String Cpdfdrawcontrol.addline, " Add line to"); @@ -4493,7 +4500,7 @@ let go () = let ops = match !Cpdfdrawcontrol.drawops with [("_MAIN", ops)] -> rev ops | _ -> error "not enough -end-xobj or -et" in write_pdf false - (Cpdfdraw.draw ~fast:args.fast ~underneath:args.underneath ~filename:args.original_filename ~bates:args.bates ~batespad:args.batespad range pdf ops) + (Cpdfdraw.draw ~struct_tree:args.draw_struct_tree ~fast:args.fast ~underneath:args.underneath ~filename:args.original_filename ~bates:args.bates ~batespad:args.batespad range pdf ops) | Some (Composition json) -> let pdf = get_single_pdf args.op false in let filesize = diff --git a/cpdfdraw.ml b/cpdfdraw.ml index 3993064..9ec42db 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -422,7 +422,7 @@ let dryrun ~filename ~bates ~batespad range pdf chunks = restore_whole_stack r; fontpacks := saved_fontpacks -let draw ?(fast=false) ?(underneath=false) ~filename ~bates ~batespad range pdf drawops = +let draw ~struct_tree ~fast ~underneath ~filename ~bates ~batespad range pdf drawops = (*Printf.printf "%s\n" (string_of_drawops drawops);*) resstack := [empty_res ()]; Hashtbl.clear !fontpacks; diff --git a/cpdfdraw.mli b/cpdfdraw.mli index aaf0757..920044b 100644 --- a/cpdfdraw.mli +++ b/cpdfdraw.mli @@ -52,8 +52,9 @@ type drawops = (** Calling [draw fast underneath filename bates batespad range pdf drawops] draws on top of all the pages in the range. *) -val draw : ?fast:bool -> - ?underneath:bool -> +val draw : struct_tree:bool -> + fast:bool -> + underneath:bool -> filename:string -> bates:int -> batespad:int option ->