From e30714962d9bcb7ea50c1135d3126e963079ec4e Mon Sep 17 00:00:00 2001 From: John Whitington Date: Fri, 3 Dec 2021 21:08:39 -0800 Subject: [PATCH] more --- cpdfcommand.ml | 19 ++++++++++++++----- cpdfmanual.tex | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 8e2230d..35bd400 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -2960,6 +2960,11 @@ let typeset text = Pdfpage.add_root pageroot [] pdf (* FIXME: Calculate margins based on page size (+ cropbox!) *) +let rec split_toc_title a = function + | '\\'::'n'::r -> rev a :: split_toc_title [] r + | x::xs -> split_toc_title (x::a) xs + | [] -> [rev a] + let typeset_table_of_contents ~font pdf = let marks = Pdfmarks.read_bookmarks pdf in if marks = [] then (Printf.eprintf "No bookmarks, not making table of contents\n%!"; pdf) else @@ -2993,12 +2998,16 @@ let typeset_table_of_contents ~font pdf = (Pdfmarks.read_bookmarks pdf) in let toc_pages = + let title = + flatten + (map + (fun l -> [Cpdftype.Text l; Cpdftype.NewLine]) + (split_toc_title [] (explode args.toc_title))) + in Cpdftype.typeset 50. 50. 50. 50. firstpage_papersize pdf - ([Cpdftype.Font big; - Cpdftype.Text (explode args.toc_title); - Cpdftype.NewLine; - Cpdftype.VGlue {glen = args.fontsize *. 2.; gstretch = 0.}; - Cpdftype.Font f] @ flatten lines) + ([Cpdftype.Font big] @ title @ + [Cpdftype.VGlue {glen = args.fontsize *. 2.; gstretch = 0.}; + Cpdftype.Font f] @ flatten lines) in let original_pages = Pdfpage.pages_of_pagetree pdf in let toc_pages_len = length toc_pages in diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 914fbf4..a76f165 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -9,7 +9,7 @@ %Document -print-font-table %Document NOT and DUP page ranges %Document new colourspaces for -add-text -add-rectangle -%Document -table-of-contents, -table-of-contents-title, -font +%Document -table-of-contents, -table-of-contents-title (inc. newlines), -font %Document -typeset \documentclass{book} % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf etc.