more
This commit is contained in:
parent
e3421cdcc2
commit
b4c07ea798
|
@ -4007,14 +4007,13 @@ let go () =
|
||||||
let pdf = get_single_pdf args.op true in
|
let pdf = get_single_pdf args.op true in
|
||||||
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 cpdffont = embed_font () in
|
let cpdffont = embed_font () in
|
||||||
let pdf =
|
let pdf =
|
||||||
Cpdftoc.typeset_table_of_contents
|
Cpdftoc.typeset_table_of_contents
|
||||||
cpdffont ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf
|
~font:cpdffont ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf
|
||||||
in
|
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
|
||||||
let cpdffont = embed_font () in
|
let cpdffont = embed_font () in
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
encoding, adding the fontfiles to the PDF and returning a list of font objects,
|
encoding, adding the fontfiles to the PDF and returning a list of font objects,
|
||||||
together with a unicode codepoint --> (font number in list, charcode) table *)
|
together with a unicode codepoint --> (font number in list, charcode) table *)
|
||||||
|
|
||||||
|
(* FIXME: Really we want to create an interactive fontpack which creates fonts
|
||||||
|
when needed, but delays the actual production of the subset truetype data
|
||||||
|
until later. This will mean we don't need to pre-calculate the USED set. For
|
||||||
|
now, we just hack Cpdftoc, cpdfaddtext and cpdftextofpdf to pre-calculate
|
||||||
|
the subset. *)
|
||||||
|
|
||||||
type t = Pdftext.font list * (int, int * int) Hashtbl.t
|
type t = Pdftext.font list * (int, int * int) Hashtbl.t
|
||||||
|
|
||||||
type cpdffont =
|
type cpdffont =
|
||||||
|
|
18
cpdftoc.ml
18
cpdftoc.ml
|
@ -41,7 +41,15 @@ let shorten_text widths l t =
|
||||||
(and CropBox) copied from first page of existing PDF. Margin of 10% inside
|
(and CropBox) copied from first page of existing PDF. Margin of 10% inside
|
||||||
CropBox. Font size of title twice body font size. Null page labels added for
|
CropBox. Font size of title twice body font size. Null page labels added for
|
||||||
TOC, others bumped up and so preserved. *)
|
TOC, others bumped up and so preserved. *)
|
||||||
let typeset_table_of_contents ?embedinfo ~font ~fontsize ~title ~bookmark pdf =
|
let typeset_table_of_contents ~font ~fontsize ~title ~bookmark pdf =
|
||||||
|
let codepoints = [] (* FIXME *) in
|
||||||
|
let font =
|
||||||
|
match font with
|
||||||
|
| Cpdfembed.PreMadeFontPack t -> hd (fst t)
|
||||||
|
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
|
||||||
|
hd (fst (Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding))
|
||||||
|
| Cpdfembed.ExistingNamedFont _ -> raise (Pdf.PDFError "Cannot use existing font with -table-of-contents")
|
||||||
|
in
|
||||||
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, fs = (font, fontsize) in
|
let f, fs = (font, fontsize) in
|
||||||
|
@ -110,13 +118,7 @@ let typeset_table_of_contents ?embedinfo ~font ~fontsize ~title ~bookmark pdf =
|
||||||
| Some (cminx, cminy, cmaxx, cmaxy) ->
|
| Some (cminx, cminy, cmaxx, cmaxy) ->
|
||||||
(cminx +. margin, (pmaxx -. cmaxx) +. margin, cminy +. margin, (pmaxy -. cmaxy) +. margin)
|
(cminx +. margin, (pmaxx -. cmaxx) +. margin, cminy +. margin, (pmaxy -. cmaxy) +. margin)
|
||||||
in
|
in
|
||||||
let codepoints = map fst (list_of_hashtbl used) in
|
|
||||||
let font =
|
|
||||||
match embedinfo with
|
|
||||||
| None -> font
|
|
||||||
| Some (pdf, fontfile, fontname, encoding) ->
|
|
||||||
hd (fst (Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints ~encoding))
|
|
||||||
in
|
|
||||||
Cpdftype.typeset lm rm tm bm firstpage_papersize pdf
|
Cpdftype.typeset lm rm tm bm firstpage_papersize pdf
|
||||||
([Cpdftype.Font (font, bfs); Cpdftype.BeginDocument] @ title @
|
([Cpdftype.Font (font, bfs); Cpdftype.BeginDocument] @ title @
|
||||||
[Cpdftype.Font (font, fs)] @ flatten lines)
|
[Cpdftype.Font (font, fs)] @ flatten lines)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(** Table of contents *)
|
(** Table of contents *)
|
||||||
|
|
||||||
(** Typeset a table of contents and prepend to the document. *)
|
(** Typeset a table of contents and prepend to the document. *)
|
||||||
val typeset_table_of_contents : ?embedinfo:(Pdf.t * Pdfio.bytes * string * Pdftext.encoding) -> font:Pdftext.font -> fontsize:float -> title:string -> bookmark:bool -> Pdf.t -> Pdf.t
|
val typeset_table_of_contents : font:Cpdfembed.cpdffont -> fontsize:float -> title:string -> bookmark:bool -> Pdf.t -> Pdf.t
|
||||||
|
|
Loading…
Reference in New Issue