This commit is contained in:
John Whitington 2022-09-21 16:10:48 +01:00
parent c08b0351ca
commit 3237daebb7
1 changed files with 24 additions and 27 deletions

View File

@ -360,7 +360,7 @@ let output_pdfs : Pdf.t list ref = ref []
type font = type font =
| StandardFont of Pdftext.standard_font | StandardFont of Pdftext.standard_font
| FontToEmbed of Pdfio.bytes * Pdftext.encoding | FontToEmbed of Pdfio.bytes
| OtherFont of string | OtherFont of string
type args = type args =
@ -382,6 +382,7 @@ type args =
mutable effect_duration : float; mutable effect_duration : float;
mutable font : font; mutable font : font;
mutable fontname : string; mutable fontname : string;
mutable fontencoding : Pdftext.encoding;
mutable fontsize : float; mutable fontsize : float;
mutable fontttfmore : bool; mutable fontttfmore : bool;
mutable color : Cpdfaddtext.color; mutable color : Cpdfaddtext.color;
@ -505,6 +506,7 @@ let args =
font = StandardFont Pdftext.TimesRoman; font = StandardFont Pdftext.TimesRoman;
fontname = "Times-Roman"; fontname = "Times-Roman";
fontsize = 12.; fontsize = 12.;
fontencoding = Pdftext.WinAnsiEncoding;
fontttfmore = false; fontttfmore = false;
color = Cpdfaddtext.RGB (0., 0., 0.); color = Cpdfaddtext.RGB (0., 0., 0.);
opacity = 1.; opacity = 1.;
@ -627,6 +629,7 @@ let reset_arguments () =
args.font <- StandardFont Pdftext.TimesRoman; args.font <- StandardFont Pdftext.TimesRoman;
args.fontname <- "Times-Roman"; args.fontname <- "Times-Roman";
args.fontsize <- 12.; args.fontsize <- 12.;
args.fontencoding <- Pdftext.WinAnsiEncoding;
args.fontttfmore <- false; args.fontttfmore <- false;
args.color <- Cpdfaddtext.RGB (0., 0., 0.); args.color <- Cpdfaddtext.RGB (0., 0., 0.);
args.opacity <- 1.; args.opacity <- 1.;
@ -1722,25 +1725,19 @@ let setnowarnrotate () =
args.no_warn_rotate <- true args.no_warn_rotate <- true
let setfontttf s = let setfontttf s =
args.font <- FontToEmbed (Pdfio.bytes_of_string (contents_of_file s), Pdftext.WinAnsiEncoding); args.font <- FontToEmbed (Pdfio.bytes_of_string (contents_of_file s));
args.fontname <- Filename.remove_extension (Filename.basename s) args.fontname <- Filename.remove_extension (Filename.basename s)
let setfontttfmore () = let setfontttfmore () =
args.fontttfmore <- true args.fontttfmore <- true
let setfontttfencoding s = let setfontttfencoding s =
let e = args.fontencoding <-
match s with match s with
| "MacRomanEncoding" -> Pdftext.MacRomanEncoding | "MacRomanEncoding" -> Pdftext.MacRomanEncoding
| "WinAnsiEncoding" -> Pdftext.WinAnsiEncoding | "WinAnsiEncoding" -> Pdftext.WinAnsiEncoding
| "StandardEncoding" -> Pdftext.StandardEncoding | "StandardEncoding" -> Pdftext.StandardEncoding
| _ -> error "Unknown encoding" | _ -> error "Unknown encoding"
in
match args.font with
| FontToEmbed (b, _) ->
args.font <- FontToEmbed (b, e)
| _ ->
error "Must specift -font-ttf before -font-ttf-encoding"
let whingemalformed () = let whingemalformed () =
prerr_string "Command line must be of exactly the form\ncpdf <infile> -gs <path> -gs-malformed-force -o <outfile>\n"; prerr_string "Command line must be of exactly the form\ncpdf <infile> -gs <path> -gs-malformed-force -o <outfile>\n";
@ -2046,18 +2043,18 @@ and specs =
("-font", ("-font",
Arg.String setfont, Arg.String setfont,
" Set the font"); " Set the font");
("-font-ttf",
Arg.String setfontttf,
" Load a TrueType font");
("-font-ttf-encoding",
Arg.String setfontttfencoding,
" Set the encoding for the TrueType font");
("-font-ttf-more",
Arg.Unit setfontttfmore,
" Signal that more text is coming for this font");
("-font-size", ("-font-size",
Arg.Float setfontsize, Arg.Float setfontsize,
" Set the font size"); " Set the font size");
("-font-encoding",
Arg.String setfontttfencoding,
" Set the encoding for the TrueType font");
("-font-ttf",
Arg.String setfontttf,
" Load a TrueType font");
("-font-ttf-more",
Arg.Unit setfontttfmore,
" Signal that more text is coming for this font");
("-no-embed-font", ("-no-embed-font",
Arg.Unit setnoembedfont, Arg.Unit setnoembedfont,
" Do not embed fonts"); " Do not embed fonts");
@ -3721,10 +3718,10 @@ let go () =
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
let font = let font =
match args.font with match args.font with
| StandardFont f -> Some (Pdftext.StandardFont (f, Pdftext.WinAnsiEncoding)) | StandardFont f -> Some (Pdftext.StandardFont (f, args.fontencoding))
| OtherFont f -> None (* it's in fontname *) | OtherFont f -> None (* it's in fontname *)
| FontToEmbed (fontfile, encoding) -> | FontToEmbed fontfile ->
Some (Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding) Some (Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding:args.fontencoding)
in in
warn_prerotate range pdf; warn_prerotate range pdf;
let pdf = let pdf =
@ -3989,9 +3986,9 @@ let go () =
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let font = let font =
match args.font with match args.font with
| StandardFont f -> Pdftext.StandardFont (f, Pdftext.WinAnsiEncoding) | StandardFont f -> Pdftext.StandardFont (f, args.fontencoding)
| FontToEmbed (fontfile, encoding) -> | FontToEmbed fontfile ->
Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding:args.fontencoding
| _ -> error "TOC: not a standard or embedded font" | _ -> error "TOC: not a standard or embedded font"
in in
let pdf = Cpdftoc.typeset_table_of_contents ~font ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf in let pdf = Cpdftoc.typeset_table_of_contents ~font ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf in
@ -4001,9 +3998,9 @@ let go () =
let pdf = Pdf.empty () in let pdf = Pdf.empty () in
let font = let font =
match args.font with match args.font with
| StandardFont f -> Pdftext.StandardFont (f, Pdftext.WinAnsiEncoding) | StandardFont f -> Pdftext.StandardFont (f, args.fontencoding)
| FontToEmbed (fontfile, encoding) -> | FontToEmbed fontfile ->
Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding:args.fontencoding
| _ -> error "text to PDF: not a standard or embedded font" | _ -> error "text to PDF: not a standard or embedded font"
in in
let pdf = let pdf =