more
This commit is contained in:
parent
e30714962d
commit
ad5a235c61
|
@ -2971,12 +2971,17 @@ let typeset_table_of_contents ~font pdf =
|
||||||
let f = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), args.fontsize) in
|
let f = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), args.fontsize) in
|
||||||
let big = (Pdftext.StandardFont (font, Pdftext.WinAnsiEncoding), args.fontsize *. 2.) 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, pmaxx, pmaxy =
|
||||||
let width, height =
|
let width, height, xmax, ymax =
|
||||||
match Pdf.parse_rectangle firstpage.Pdfpage.mediabox with
|
match Pdf.parse_rectangle firstpage.Pdfpage.mediabox with
|
||||||
xmin, ymin, xmax, ymax -> (xmax -. xmin, ymax -. ymin)
|
xmin, ymin, xmax, ymax -> xmax -. xmin, ymax -. ymin, xmax, ymax
|
||||||
in
|
in
|
||||||
Pdfpaper.make Pdfunits.PdfPoint width height
|
Pdfpaper.make Pdfunits.PdfPoint width height, xmax, ymax
|
||||||
|
in
|
||||||
|
let firstpage_cropbox =
|
||||||
|
match Pdf.lookup_direct pdf "/CropBox" firstpage.Pdfpage.rest with
|
||||||
|
| Some r -> Some (Pdf.parse_rectangle r)
|
||||||
|
| None -> None
|
||||||
in
|
in
|
||||||
let labels = Pdfpagelabels.read pdf in
|
let labels = Pdfpagelabels.read pdf in
|
||||||
let lines =
|
let lines =
|
||||||
|
@ -3004,10 +3009,27 @@ let typeset_table_of_contents ~font pdf =
|
||||||
(fun l -> [Cpdftype.Text l; Cpdftype.NewLine])
|
(fun l -> [Cpdftype.Text l; Cpdftype.NewLine])
|
||||||
(split_toc_title [] (explode args.toc_title)))
|
(split_toc_title [] (explode args.toc_title)))
|
||||||
in
|
in
|
||||||
Cpdftype.typeset 50. 50. 50. 50. firstpage_papersize pdf
|
let lm, rm, tm, bm =
|
||||||
([Cpdftype.Font big] @ title @
|
match firstpage_cropbox with
|
||||||
[Cpdftype.VGlue {glen = args.fontsize *. 2.; gstretch = 0.};
|
| None -> (50., 50., 50., 50.)
|
||||||
Cpdftype.Font f] @ flatten lines)
|
| Some (cminx, cminy, cmaxx, cmaxy) ->
|
||||||
|
(cminx +. 50., (pmaxx -. cmaxx) +. 50., cminy +. 50., (pmaxy -. cmaxy) +. 50.)
|
||||||
|
in
|
||||||
|
Cpdftype.typeset lm rm tm bm firstpage_papersize pdf
|
||||||
|
([Cpdftype.Font big] @ title @
|
||||||
|
[Cpdftype.VGlue {glen = args.fontsize *. 2.; gstretch = 0.};
|
||||||
|
Cpdftype.Font f] @ flatten lines)
|
||||||
|
in
|
||||||
|
let toc_pages =
|
||||||
|
match firstpage_cropbox with
|
||||||
|
| Some (a, b, c, d) ->
|
||||||
|
let rect =
|
||||||
|
Pdf.Array [Pdf.Real a; Pdf.Real b; Pdf.Real c; Pdf.Real d]
|
||||||
|
in
|
||||||
|
map
|
||||||
|
(fun p -> {p with Pdfpage.rest = Pdf.add_dict_entry p.Pdfpage.rest "/CropBox" rect})
|
||||||
|
toc_pages
|
||||||
|
| None -> toc_pages
|
||||||
in
|
in
|
||||||
let original_pages = Pdfpage.pages_of_pagetree pdf in
|
let original_pages = Pdfpage.pages_of_pagetree pdf in
|
||||||
let toc_pages_len = length toc_pages in
|
let toc_pages_len = length toc_pages in
|
||||||
|
|
|
@ -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, -table-of-contents-title (inc. newlines), -font
|
%Document -table-of-contents, -table-of-contents-title (inc. newlines), -font. Mention -upright.
|
||||||
%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.
|
||||||
|
|
|
@ -139,7 +139,7 @@ let paginate tmargin bmargin papersize i =
|
||||||
let o = ref [] in
|
let o = ref [] in
|
||||||
let s = initial_state () in
|
let s = initial_state () in
|
||||||
s.ypos <- tmargin;
|
s.ypos <- tmargin;
|
||||||
let max_ypos = height -. tmargin -. bmargin in
|
let max_ypos = height -. bmargin in
|
||||||
let rec process = function
|
let rec process = function
|
||||||
| VGlue {glen} as glue ->
|
| VGlue {glen} as glue ->
|
||||||
s.ypos <- s.ypos +. glen;
|
s.ypos <- s.ypos +. glen;
|
||||||
|
@ -174,6 +174,7 @@ let make_annotations annots =
|
||||||
dictionaries. New page only
|
dictionaries. New page only
|
||||||
creates a page when that page has content. *)
|
creates a page when that page has content. *)
|
||||||
let typeset lmargin rmargin tmargin bmargin papersize pdf i =
|
let typeset lmargin rmargin tmargin bmargin papersize pdf i =
|
||||||
|
Printf.printf "l = %f, r = %f, b = %f, t = %f\n" lmargin rmargin tmargin bmargin;
|
||||||
let debug = false in
|
let debug = false in
|
||||||
if debug then (print_endline "***input:\n\n"; print_endline (to_string i));
|
if debug then (print_endline "***input:\n\n"; print_endline (to_string i));
|
||||||
let i = layout lmargin rmargin papersize i in
|
let i = layout lmargin rmargin papersize i in
|
||||||
|
|
Loading…
Reference in New Issue