Push -stag / -end-stag through to structdata

This commit is contained in:
John Whitington 2024-09-16 13:45:59 +01:00
parent c7a3babea2
commit 7d1aaec505
3 changed files with 24 additions and 8 deletions

View File

@ -54,6 +54,8 @@ type drawops =
| TextScale of float | TextScale of float
| RenderMode of int | RenderMode of int
| Rise of float | Rise of float
| STag of string
| EndSTag
(*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 ^ ")"
@ -410,7 +412,12 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num
| RenderMode i -> [Pdfops.Op_Tr i] | RenderMode i -> [Pdfops.Op_Tr i]
| Rise f -> [Pdfops.Op_Ts f] | Rise f -> [Pdfops.Op_Ts f]
| Newline -> [Pdfops.Op_T'] | Newline -> [Pdfops.Op_T']
| STag s ->
structdata =| StDataBeginTree s;
[]
| EndSTag ->
structdata =| StDataEndTree;
[]
and ops_of_drawops struct_tree dryrun pdf endpage filename bates batespad num page drawops = and ops_of_drawops struct_tree dryrun pdf endpage filename bates batespad num page drawops =
flatten (map (ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num page) drawops) flatten (map (ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num page) drawops)
@ -552,7 +559,7 @@ let dryrun ~struct_tree ~filename ~bates ~batespad range pdf chunks =
type st = type st =
StMCID of int StMCID of int
| StItem of {kind : string; pageobjnum : int; alt : string option; children : st list} | StItem of {kind : string; pageobjnum : int option; alt : string option; children : st list}
(* Build a tree from the MCIDs and structure tree instructions gathered *) (* Build a tree from the MCIDs and structure tree instructions gathered *)
let make_structure_tree pdf items = let make_structure_tree pdf items =
@ -566,7 +573,7 @@ let make_structure_tree pdf items =
(* Process the items, making the st list tree data structure *) (* Process the items, making the st list tree data structure *)
let process = function let process = function
| StDataMCID (n, mcid, alt) -> | StDataMCID (n, mcid, alt) ->
items_out =| StItem {kind = n; alt; pageobjnum = unopt (lookup !pagenum pageobjnums); children = [StMCID mcid]} items_out =| StItem {kind = n; alt; pageobjnum = lookup !pagenum pageobjnums; children = [StMCID mcid]}
| StDataPage n -> | StDataPage n ->
pagenum := n pagenum := n
| _ -> () | _ -> ()
@ -595,11 +602,16 @@ let write_structure_tree pdf st =
| Some s -> [("/Alt", Pdf.String s)] | Some s -> [("/Alt", Pdf.String s)]
| None -> [] | None -> []
in in
let page =
match pageobjnum with
| Some i -> [("/Pg", Pdf.Indirect i)]
| None -> []
in
let this_obj = let this_obj =
Pdf.Dictionary (alt @ [("/S", Pdf.Name kind); Pdf.Dictionary (alt @ page @
("/Pg", Pdf.Indirect pageobjnum); [("/S", Pdf.Name kind);
("/P", Pdf.Indirect struct_tree_root); ("/P", Pdf.Indirect struct_tree_root);
("/K", Pdf.Array (map (function StMCID x -> add_parentmap pageobjnum this_objnum; Pdf.Integer x ("/K", Pdf.Array (map (function StMCID x -> begin match pageobjnum with Some p -> add_parentmap p this_objnum | _ -> () end; Pdf.Integer x
| _ -> assert false) children))]) | _ -> assert false) children))])
in in
Pdf.addobj_given_num pdf (this_objnum, this_obj); Pdf.addobj_given_num pdf (this_objnum, this_obj);

View File

@ -53,6 +53,8 @@ type drawops =
| TextScale of float | TextScale of float
| RenderMode of int | RenderMode of int
| Rise of float | Rise of float
| STag of string
| EndSTag
(** 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. *)

View File

@ -96,9 +96,11 @@ let setfill s =
addop (Cpdfdraw.SetFill (col_of_string s)) addop (Cpdfdraw.SetFill (col_of_string s))
let addtag t = () let addtag t = ()
let addstag t = () let addstag t =
addop (Cpdfdraw.STag t)
let endtag () = () let endtag () = ()
let endstag () = () let endstag () =
addop Cpdfdraw.EndSTag
let autotags b = () let autotags b = ()
let addrect s = let addrect s =