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"); ("-artifact", Arg.Unit (fun _ -> Cpdfdrawcontrol.artifact ()), " Begin an artifact");
("-end-artifact", Arg.Unit (fun _ -> Cpdfdrawcontrol.endartifact ()), "End 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"); ("-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"); ("-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"); ("-rect", Arg.String Cpdfdrawcontrol.addrect, " Draw rectangle");
("-to", Arg.String Cpdfdrawcontrol.addto, " Move to"); ("-to", Arg.String Cpdfdrawcontrol.addto, " Move to");
("-line", Arg.String Cpdfdrawcontrol.addline, " Add line 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 do_auto_tag = ref true
let rolemap = ref ""
type colspec = type colspec =
NoCol NoCol
| RGB of float * float * float | RGB of float * float * float
@ -65,6 +67,8 @@ type drawops =
| BeginArtifact | BeginArtifact
| EndArtifact | EndArtifact
| Namespace of string | Namespace of string
| EltInfo of string * string
| EndEltInfo of string
(*let rec string_of_drawop = function (*let rec string_of_drawop = function
| Qq o -> "Qq (" ^ string_of_drawops o ^ ")" | Qq o -> "Qq (" ^ string_of_drawops o ^ ")"
@ -721,11 +725,16 @@ let write_structure_tree pdf st =
| [] -> [] | [] -> []
| ns -> [("/Namespaces", Pdf.Array (map (function (_, objnum) -> Pdf.Indirect objnum) ns))] | ns -> [("/Namespaces", Pdf.Array (map (function (_, objnum) -> Pdf.Indirect objnum) ns))]
in in
Pdf.Dictionary let rolemap =
(namespaces @ match !rolemap with
[("/Type", Pdf.Name "/StructTreeRoot"); | "" -> []
("/ParentTree", Pdf.Indirect (Pdf.addobj pdf (Pdftree.build_name_tree true pdf parentmap))); | s -> [("/RoleMap", Pdfread.parse_single_object ("<<" ^ s ^ ">>"))]
("/K", Pdf.Array items)]) in
Pdf.Dictionary
(rolemap @ namespaces @
[("/Type", Pdf.Name "/StructTreeRoot");
("/ParentTree", Pdf.Indirect (Pdf.addobj pdf (Pdftree.build_name_tree true pdf parentmap)));
("/K", Pdf.Array items)])
in in
Pdf.addobj_given_num pdf (struct_tree_root, st); Pdf.addobj_given_num pdf (struct_tree_root, st);
Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect struct_tree_root)) Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect struct_tree_root))

View File

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

View File

@ -123,6 +123,20 @@ let endartifact () =
let addnamespace s = let addnamespace s =
addop (Cpdfdraw.Namespace 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 addrect s =
let x, y, w, h = Cpdfcoord.parse_rectangle (Pdf.empty ()) s in let x, y, w, h = Cpdfcoord.parse_rectangle (Pdf.empty ()) s in
addop (Cpdfdraw.Rect (x, y, w, h)) addop (Cpdfdraw.Rect (x, y, w, h))

View File

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

View File

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