This commit is contained in:
John Whitington 2021-12-01 16:01:54 -08:00
parent b7ad66df73
commit d5111ccfcf
2 changed files with 11 additions and 7 deletions

View File

@ -2958,11 +2958,12 @@ let typeset text =
let pdf, pageroot = Pdfpage.add_pagetree pages pdf in let pdf, pageroot = Pdfpage.add_pagetree pages pdf in
Pdfpage.add_root pageroot [] pdf Pdfpage.add_root pageroot [] pdf
let typeset_table_of_contents pdf = (* FIXME: Calculate margins based on page size (+ cropbox!) *)
let typeset_table_of_contents ~font pdf =
let marks = Pdfmarks.read_bookmarks pdf in let marks = Pdfmarks.read_bookmarks pdf in
if marks = [] then (Printf.eprintf "No bookmarks, not making table of contents\n%!"; pdf) else if marks = [] then (Printf.eprintf "No bookmarks, not making table of contents\n%!"; pdf) else
let f = (Pdftext.StandardFont (Pdftext.Courier, Pdftext.WinAnsiEncoding), 10.) in let f = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), args.fontsize) in
let big = (Pdftext.StandardFont (Pdftext.Courier, Pdftext.WinAnsiEncoding), 20.) in let big = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), args.fontsize *. 2.) in
let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in
let firstpage_papersize = let firstpage_papersize =
let width, height = let width, height =
@ -2975,7 +2976,7 @@ let typeset_table_of_contents pdf =
map map
(fun mark -> (fun mark ->
[Cpdftype.BeginDest mark.Pdfmarks.target; [Cpdftype.BeginDest mark.Pdfmarks.target;
Cpdftype.HGlue {Cpdftype.glen = float mark.Pdfmarks.level *. 20.; Cpdftype.gstretch = 0.}; Cpdftype.HGlue {Cpdftype.glen = float mark.Pdfmarks.level *. args.fontsize *. 2.; Cpdftype.gstretch = 0.};
Cpdftype.Text (of_pdfdocencoding f mark.Pdfmarks.text); Cpdftype.Text (of_pdfdocencoding f mark.Pdfmarks.text);
Cpdftype.EndDest; Cpdftype.EndDest;
Cpdftype.NewLine]) Cpdftype.NewLine])
@ -2986,7 +2987,7 @@ let typeset_table_of_contents pdf =
([Cpdftype.Font big; ([Cpdftype.Font big;
Cpdftype.Text args.toc_title; Cpdftype.Text args.toc_title;
Cpdftype.NewLine; Cpdftype.NewLine;
Cpdftype.VGlue {glen = 20.; gstretch = 0.}; Cpdftype.VGlue {glen = args.fontsize *. 2.; gstretch = 0.};
Cpdftype.Font f] @ flatten lines) Cpdftype.Font f] @ flatten lines)
in in
let original_pages = Pdfpage.pages_of_pagetree pdf in let original_pages = Pdfpage.pages_of_pagetree pdf in
@ -3918,7 +3919,10 @@ let go () =
Cpdffont.print_font_table pdf fontname args.copyfontpage Cpdffont.print_font_table pdf fontname args.copyfontpage
| Some TableOfContents -> | Some TableOfContents ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let pdf = typeset_table_of_contents pdf in let font =
match args.font with StandardFont f -> f | _ -> error "TOC requires standard font only"
in
let pdf = typeset_table_of_contents ~font pdf in
write_pdf false pdf write_pdf false pdf
| Some (Typeset filename) -> | Some (Typeset filename) ->
let text = Pdfio.bytes_of_input_channel (open_in filename) in let text = Pdfio.bytes_of_input_channel (open_in filename) in

View File

@ -9,7 +9,7 @@
%Document -print-font-table %Document -print-font-table
%Document NOT and DUP page ranges %Document NOT and DUP page ranges
%Document new colourspaces for -add-text -add-rectangle %Document new colourspaces for -add-text -add-rectangle
%Document -table-of-contents %Document -table-of-contents, -table-of-contents-title, -font
%Document -typeset %Document -typeset
\documentclass{book} \documentclass{book}
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf etc. % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf etc.