This commit is contained in:
John Whitington 2021-12-11 05:51:05 +00:00
parent 3bc02d71ec
commit 5cc462180a
1 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,6 @@
open Pdfutil open Pdfutil
(* We allow \n in titles. *) (* We allow \n in titles. Split for typesetter. *)
let rec split_toc_title_inner a = function let rec split_toc_title_inner a = function
| '\\'::'n'::r -> rev a :: split_toc_title_inner [] r | '\\'::'n'::r -> rev a :: split_toc_title_inner [] r
| x::xs -> split_toc_title_inner (x::a) xs | x::xs -> split_toc_title_inner (x::a) xs
@ -8,6 +8,12 @@ let rec split_toc_title_inner a = function
let split_toc_title = split_toc_title_inner [] let split_toc_title = split_toc_title_inner []
(* And for new bookmark for TOC, change \\n to \n *)
let rec real_newline = function
| '\\'::'n'::r -> '\n'::real_newline r
| x::r -> x::real_newline r
| [] -> []
(* Cpdftype codepoints from a font and UTF8 *) (* Cpdftype codepoints from a font and UTF8 *)
let of_utf8 f t = let of_utf8 f t =
Pdftext.codepoints_of_utf8 t Pdftext.codepoints_of_utf8 t
@ -105,7 +111,7 @@ let typeset_table_of_contents ~font ~fontsize ~title ~bookmark pdf =
let refnums = Pdf.page_reference_numbers pdf in let refnums = Pdf.page_reference_numbers pdf in
let newmark = let newmark =
{Pdfmarks.level = 0; {Pdfmarks.level = 0;
Pdfmarks.text = Pdftext.pdfdocstring_of_utf8 title; Pdfmarks.text = Pdftext.pdfdocstring_of_utf8 (implode (real_newline (explode title)));
Pdfmarks.target = Pdfdest.XYZ (Pdfdest.PageObject (hd refnums), None, None, None); Pdfmarks.target = Pdfdest.XYZ (Pdfdest.PageObject (hd refnums), None, None, None);
Pdfmarks.isopen = false} Pdfmarks.isopen = false}
in in