Return tags from typesetter

This commit is contained in:
John Whitington 2024-10-03 12:32:26 +01:00
parent 6bb3e55de6
commit 4cb6fca6af
4 changed files with 11 additions and 6 deletions

View File

@ -92,6 +92,6 @@ let typeset ~process_struct_tree ?subformat ?title ~papersize ~font ~fontsize te
let firstfont = hd (keep (function Cpdftype.Font _ -> true | _ -> false) tagged) in let firstfont = hd (keep (function Cpdftype.Font _ -> true | _ -> false) tagged) in
[firstfont; Cpdftype.BeginDocument] @ tagged [firstfont; Cpdftype.BeginDocument] @ tagged
in in
let pages = Cpdftype.typeset ~process_struct_tree margin margin margin margin papersize pdf instrs in let pages, tags = Cpdftype.typeset ~process_struct_tree margin margin margin margin papersize pdf instrs in
let pdf, pageroot = Pdfpage.add_pagetree pages pdf in let pdf, pageroot = Pdfpage.add_pagetree pages pdf in
Pdfpage.add_root pageroot [] pdf Pdfpage.add_root pageroot [] pdf

View File

@ -156,7 +156,7 @@ let typeset_table_of_contents ~font ~fontsize ~title ~bookmark pdf =
Cpdftype.NewLine]) Cpdftype.NewLine])
(Pdfmarks.read_bookmarks pdf) (Pdfmarks.read_bookmarks pdf)
in in
let toc_pages = let toc_pages, _ =
let title = let title =
let glue = Cpdftype.VGlue (fontsize *. 2.) in let glue = Cpdftype.VGlue (fontsize *. 2.) in
if title = "" then [] else if title = "" then [] else

View File

@ -263,6 +263,8 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i
let thispageannotations = ref [] in let thispageannotations = ref [] in
let thisdestrectangles = ref [] in let thisdestrectangles = ref [] in
let pages = ref [] in let pages = ref [] in
let tags = ref [] in
let tagsout = ref [] in
let write_page () = let write_page () =
let ops = if process_struct_tree then add_artifacts (rev !ops) else rev !ops in let ops = if process_struct_tree then add_artifacts (rev !ops) else rev !ops in
let page = let page =
@ -272,7 +274,8 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i
Pdfpage.rotate = Pdfpage.Rotate0; Pdfpage.rotate = Pdfpage.Rotate0;
Pdfpage.rest = make_annotations pdf !thispageannotations} Pdfpage.rest = make_annotations pdf !thispageannotations}
in in
pages := page :: !pages pages := page::!pages;
tagsout := rev !tags::!tagsout
in in
let rec typeset_element = function let rec typeset_element = function
| Text cps -> | Text cps ->
@ -340,9 +343,11 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i
thispageannotations := map annot !thisdestrectangles @ !thispageannotations; thispageannotations := map annot !thisdestrectangles @ !thispageannotations;
s.dest <- None; s.dest <- None;
thisdestrectangles := [] thisdestrectangles := []
| Tag (s, _) -> ops := Pdfops.Op_BDC ("/" ^ s, Pdf.Dictionary [("/MCID", Pdf.Integer (mcid ()))])::!ops | Tag (s, i) ->
tags := (s, i)::!tags;
ops := Pdfops.Op_BDC ("/" ^ s, Pdf.Dictionary [("/MCID", Pdf.Integer (mcid ()))])::!ops
| EndTag -> ops := Pdfops.Op_EMC::!ops | EndTag -> ops := Pdfops.Op_EMC::!ops
in in
iter typeset_element i; iter typeset_element i;
write_page (); write_page ();
rev !pages (rev !pages, rev !tagsout)

View File

@ -24,6 +24,6 @@ val font_widths : string -> Pdftext.font -> float -> float array
val width_of_string : float array -> char list -> float val width_of_string : float array -> char list -> float
(** [typeset lmargin rmargin tmargin bmargin papersize pdf contents] builds a list of pages of typset content. *) (** [typeset lmargin rmargin tmargin bmargin papersize pdf contents] builds a list of pages of typset content. *)
val typeset : process_struct_tree:bool -> float -> float -> float -> float -> Pdfpaper.t -> Pdf.t -> t -> Pdfpage.t list val typeset : process_struct_tree:bool -> float -> float -> float -> float -> Pdfpaper.t -> Pdf.t -> t -> Pdfpage.t list * (string * int) list list
val add_artifacts : Pdfops.t list -> Pdfops.t list val add_artifacts : Pdfops.t list -> Pdfops.t list