More structure tree work

This commit is contained in:
John Whitington 2024-10-03 16:18:09 +01:00
parent 163d631dc9
commit 686318718d
2 changed files with 35 additions and 10 deletions

View File

@ -94,6 +94,30 @@ let typeset ~process_struct_tree ?subformat ?title ~papersize ~font ~fontsize te
let firstfont = hd (keep (function Cpdftype.Font _ -> true | _ -> false) tagged) in
[firstfont; Cpdftype.BeginDocument] @ tagged
in
let pages, tags = Cpdftype.typeset ~process_struct_tree margin margin margin margin papersize pdf instrs in
iter (fun x -> Printf.printf "PAGE\n"; iter (fun (_, i) -> Printf.printf "Tag number %i\n" i) x) tags;
(* We make (tag number, page number, mcid) triples *)
let tagtriples =
flatten
(map2
(fun pn tags ->
map2 (fun (_, tagnum) mcid -> (tagnum, pn, mcid)) tags (indx0 tags))
(indx0 tags)
tags)
in
Printf.printf "(tag number, page number, mcid) triples:\n";
iter (fun (tagnum, pn, mcid) -> Printf.printf "%i, %i, %i\n" tagnum pn mcid) tagtriples;
(* Now work out the nodes and what each /K and /Pg in them is *)
let pages_and_mcids =
[]
in
Printf.printf "Pages and their MCIDs\n";
iter
(fun (page, mcids) ->
Printf.printf "Page %i\n";
iter (Printf.printf "%i ") mcids;
Printf.printf "\n")
pages_and_mcids;
if subformat = Some Cpdfua.PDFUA2 then
begin
let str = Pdf.addobj pdf Pdf.Null in
@ -118,10 +142,10 @@ let typeset ~process_struct_tree ?subformat ?title ~papersize ~font ~fontsize te
Pdf.addobj_given_num pdf (str, Pdf.Dictionary [("/Type", Pdf.Name "/StructTreeRoot"); ("/K", Pdf.Array [Pdf.Indirect p]); ("/ParentTree", Pdf.Indirect parent_tree)]);
Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect str))
end;
let pages, tags = Cpdftype.typeset ~process_struct_tree margin margin margin margin papersize pdf instrs in
let pages =
map
(fun p -> if process_struct_tree then {p with Pdfpage.rest = Pdf.add_dict_entry p.Pdfpage.rest "/StructParents" (Pdf.Integer 1)} else p)
map2
(fun pn p -> if process_struct_tree then {p with Pdfpage.rest = Pdf.add_dict_entry p.Pdfpage.rest "/StructParents" (Pdf.Integer pn)} else p)
(indx0 pages)
pages
in
let pdf, pageroot = Pdfpage.add_pagetree pages pdf in

View File

@ -246,7 +246,7 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i
Hashtbl.clear width_table_cache;
let debug = false in
if debug then (print_endline "***input:\n\n"; print_endline (to_string i));
let i = number_tags 1 i in
let i = number_tags 0 i in
let i = layout lmargin rmargin papersize i in
if debug then (print_endline "***after layout:\n\n"; print_endline (to_string i));
let i = paginate tmargin bmargin papersize i in
@ -275,7 +275,8 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i
Pdfpage.rest = make_annotations pdf !thispageannotations}
in
pages := page::!pages;
tagsout := rev !tags::!tagsout
tagsout := rev !tags::!tagsout;
tags := []
in
let rec typeset_element = function
| Text cps ->