Scaffolding for -elt-info

This commit is contained in:
John Whitington 2024-09-25 15:12:58 +01:00
parent 01fcd13251
commit 9e1cf6f78e
6 changed files with 40 additions and 5 deletions

View File

@ -2841,7 +2841,10 @@ let specs =
("-artifact", Arg.Unit (fun _ -> Cpdfdrawcontrol.artifact ()), " Begin an artifact");
("-end-artifact", Arg.Unit (fun _ -> Cpdfdrawcontrol.endartifact ()), "End an artifact");
("-no-auto-artifacts", Arg.Unit (fun _ -> Cpdfdrawcontrol.autoartifacts false), " Don't mark untagged content as artifacts");
("-eltinfo", Arg.String (fun s -> Cpdfdrawcontrol.eltinfo s), " Add element information");
("-end-eltinfo", Arg.String (fun s -> Cpdfdrawcontrol.endeltinfo s), " Erase element information");
("-namespace", Arg.String (fun s -> Cpdfdrawcontrol.addnamespace (expand_namespace s)), " Set the structure tree namespace");
("-rolemap", Arg.String (fun s -> Cpdfdrawcontrol.setrolemap s), " Set a role map");
("-rect", Arg.String Cpdfdrawcontrol.addrect, " Draw rectangle");
("-to", Arg.String Cpdfdrawcontrol.addto, " Move to");
("-line", Arg.String Cpdfdrawcontrol.addline, " Add line to");

View File

@ -5,6 +5,8 @@ let do_add_artifacts = ref true
let do_auto_tag = ref true
let rolemap = ref ""
type colspec =
NoCol
| RGB of float * float * float
@ -65,6 +67,8 @@ type drawops =
| BeginArtifact
| EndArtifact
| Namespace of string
| EltInfo of string * string
| EndEltInfo of string
(*let rec string_of_drawop = function
| Qq o -> "Qq (" ^ string_of_drawops o ^ ")"
@ -720,9 +724,14 @@ let write_structure_tree pdf st =
match list_of_hashtbl namespaces with
| [] -> []
| ns -> [("/Namespaces", Pdf.Array (map (function (_, objnum) -> Pdf.Indirect objnum) ns))]
in
let rolemap =
match !rolemap with
| "" -> []
| s -> [("/RoleMap", Pdfread.parse_single_object ("<<" ^ s ^ ">>"))]
in
Pdf.Dictionary
(namespaces @
(rolemap @ namespaces @
[("/Type", Pdf.Name "/StructTreeRoot");
("/ParentTree", Pdf.Indirect (Pdf.addobj pdf (Pdftree.build_name_tree true pdf parentmap)));
("/K", Pdf.Array items)])

View File

@ -60,11 +60,15 @@ type drawops =
| BeginArtifact
| EndArtifact
| Namespace of string
| EltInfo of string * string
| EndEltInfo of string
val do_add_artifacts : bool ref
val do_auto_tag : bool ref
val rolemap : string ref
(** Calling [draw fast underneath filename bates batespad range pdf drawops] draws on
top of all the pages in the range. *)
val draw : struct_tree:bool ->

View File

@ -123,6 +123,20 @@ let endartifact () =
let addnamespace s =
addop (Cpdfdraw.Namespace s)
let eltinfo s =
let k, v =
match String.split_on_char '=' s with
| [h; t] -> (h, t)
| _ -> error "Bad -eltinfo format"
in
addop (Cpdfdraw.EltInfo (k, v))
let endeltinfo s =
addop (Cpdfdraw.EndEltInfo s)
let setrolemap s =
Cpdfdraw.rolemap := s
let addrect s =
let x, y, w, h = Cpdfcoord.parse_rectangle (Pdf.empty ()) s in
addop (Cpdfdraw.Rect (x, y, w, h))

View File

@ -20,7 +20,10 @@ val addstag : string -> unit
val endtag : unit -> unit
val endstag : unit -> unit
val autotags : bool -> unit
val eltinfo : string -> unit
val endeltinfo : string -> unit
val addnamespace : string -> unit
val setrolemap : string -> unit
val artifact : unit -> unit
val endartifact : unit -> unit
val autoartifacts : bool -> unit

View File

@ -1,3 +1,5 @@
%Document -rolemap
%Document -eltinfo X=, -end-eltinfo X
%Document -stretch
%Document -redact
%Document ?x0 y0 x1 y1 rectangle specifications