MCIDs first go

This commit is contained in:
John Whitington 2024-10-02 15:26:30 +01:00
parent 7ee3d1997d
commit 9d50e3588f
2 changed files with 9 additions and 6 deletions

View File

@ -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

View File

@ -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 ();