From 9d50e3588fc5e7a4111ac8a1e6b36df54d9358ab Mon Sep 17 00:00:00 2001 From: John Whitington Date: Wed, 2 Oct 2024 15:26:30 +0100 Subject: [PATCH] MCIDs first go --- cpdftexttopdf.ml | 8 ++++---- cpdftype.ml | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cpdftexttopdf.ml b/cpdftexttopdf.ml index 07150dc..bb782fc 100644 --- a/cpdftexttopdf.ml +++ b/cpdftexttopdf.ml @@ -82,15 +82,15 @@ let typeset ~process_struct_tree ?subformat ?title ~papersize ~font ~fontsize te raise (Pdf.PDFError "Can't use existing named font for text-to-PDF") in let instrs = of_utf8_with_newlines fontpack fontsize (Pdfio.string_of_bytes text) in - flprint (Cpdftype.to_string instrs); - flprint "------------------------------"; + (*flprint (Cpdftype.to_string instrs); + flprint "------------------------------";*) let tagged = tag_paragraphs instrs in - flprint (Cpdftype.to_string tagged); + (*flprint (Cpdftype.to_string tagged);*) let margin = Pdfunits.points (Pdfpaper.width papersize) (Pdfpaper.unit papersize) /. 15. in let instrs = if tagged = [] then [] else let firstfont = hd (keep (function Cpdftype.Font _ -> true | _ -> false) tagged) in - [firstfont; Cpdftype.BeginDocument] @ instrs + [firstfont; Cpdftype.BeginDocument] @ tagged in let pages = Cpdftype.typeset ~process_struct_tree margin margin margin margin papersize pdf instrs in let pdf, pageroot = Pdfpage.add_pagetree pages pdf in diff --git a/cpdftype.ml b/cpdftype.ml index eb9ffc1..7497754 100644 --- a/cpdftype.ml +++ b/cpdftype.ml @@ -238,6 +238,8 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i let s = initial_state () in s.xpos <- lmargin; s.ypos <- tmargin; + let mcidr = ref ~-1 in + let mcid () = incr mcidr; !mcidr in let ops = ref [] in let fonts = ref [] in let thispagefontnums = ref [] in @@ -300,6 +302,7 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i thispagefontnums := []; thispageannotations := []; ops := []; + mcidr := -1; if s.font <> None && s.fontid <> None then typeset_element (Font (unopt s.fontid, unopt s.font, s.fontsize)); s.xpos <- lmargin; s.ypos <- tmargin +. s.fontsize @@ -320,8 +323,8 @@ let typeset ~process_struct_tree lmargin rmargin tmargin bmargin papersize pdf i thispageannotations := map annot !thisdestrectangles @ !thispageannotations; s.dest <- None; thisdestrectangles := [] - | Tag s -> () - | EndTag -> () + | Tag s -> ops := Pdfops.Op_BDC ("/" ^ s, Pdf.Dictionary [("/MCID", Pdf.Integer (mcid ()))])::!ops + | EndTag -> ops := Pdfops.Op_EMC::!ops in iter typeset_element i; write_page ();