From 5cc462180a7448fb6e1b9cacd861b3254338afea Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sat, 11 Dec 2021 05:51:05 +0000 Subject: [PATCH] more --- cpdftoc.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cpdftoc.ml b/cpdftoc.ml index cda8c9b..329a6b2 100644 --- a/cpdftoc.ml +++ b/cpdftoc.ml @@ -1,6 +1,6 @@ open Pdfutil -(* We allow \n in titles. *) +(* We allow \n in titles. Split for typesetter. *) let rec split_toc_title_inner a = function | '\\'::'n'::r -> rev a :: split_toc_title_inner [] r | 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 [] +(* 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 *) let of_utf8 f 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 newmark = {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.isopen = false} in