This commit is contained in:
John Whitington 2022-09-27 17:14:57 +01:00
parent 89a82b553d
commit a0b30c5843
1 changed files with 13 additions and 28 deletions

View File

@ -3047,6 +3047,14 @@ let warn_prerotate range pdf =
let prerotate range pdf = let prerotate range pdf =
Cpdfpage.upright ~fast:args.fast range pdf Cpdfpage.upright ~fast:args.fast range pdf
let embed_font pdf =
match args.font with
| StandardFont f -> Some (Pdftext.StandardFont (f, args.fontencoding)), None
| OtherFont f -> None, None (* it's in fontname *)
| FontToEmbed fontfile ->
Some (Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding:args.fontencoding),
Some (pdf, fontfile, args.fontname, args.fontencoding)
(* Main function *) (* Main function *)
let go () = let go () =
match args.op with match args.op with
@ -3712,14 +3720,7 @@ let go () =
| Some (AddText text) -> | Some (AddText text) ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
let font, embedinfo = let font, embedinfo = embed_font pdf in
match args.font with
| StandardFont f -> Some (Pdftext.StandardFont (f, args.fontencoding)), None
| OtherFont f -> None, None (* it's in fontname *)
| FontToEmbed fontfile ->
Some (Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding:args.fontencoding),
Some (pdf, fontfile, args.fontname, args.fontencoding)
in
warn_prerotate range pdf; warn_prerotate range pdf;
let pdf = let pdf =
if args.prerotate then prerotate range pdf else pdf if args.prerotate then prerotate range pdf else pdf
@ -3981,30 +3982,14 @@ 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 font, embedinfo = let font, embedinfo = embed_font pdf in
match args.font with let pdf = Cpdftoc.typeset_table_of_contents ?embedinfo ~font:(unopt font) ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf in
| StandardFont f -> (Pdftext.StandardFont (f, args.fontencoding), None)
| FontToEmbed fontfile ->
Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding:args.fontencoding,
(Some (pdf, fontfile, args.fontname, args.fontencoding))
| _ -> error "TOC: not a standard or embedded font"
in
let pdf = Cpdftoc.typeset_table_of_contents ?embedinfo ~font ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark 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
let pdf = Pdf.empty () in let pdf = Pdf.empty () in
let font, embedinfo = let font, embedinfo = embed_font pdf in
match args.font with let pdf = Cpdftexttopdf.typeset ?embedinfo ~papersize:args.createpdf_pagesize ~font:(unopt font) ~fontsize:args.fontsize text in
| StandardFont f -> (Pdftext.StandardFont (f, args.fontencoding), None)
| FontToEmbed fontfile ->
Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding:args.fontencoding,
(Some (pdf, fontfile, args.fontname, args.fontencoding))
| _ -> error "text to PDF: not a standard or embedded font"
in
let pdf =
Cpdftexttopdf.typeset ?embedinfo ~papersize:args.createpdf_pagesize ~font ~fontsize:args.fontsize text
in
write_pdf false pdf write_pdf false pdf
(* Advise the user if a combination of command line flags makes little sense, (* Advise the user if a combination of command line flags makes little sense,