more
This commit is contained in:
parent
c05fbc0164
commit
733a94d882
|
@ -3047,7 +3047,7 @@ 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 =
|
let embed_font () =
|
||||||
let fontpack_of_standardfont sf =
|
let fontpack_of_standardfont sf =
|
||||||
let te = Pdftext.text_extractor_of_font_real sf in
|
let te = Pdftext.text_extractor_of_font_real sf in
|
||||||
let table = null_hash () in
|
let table = null_hash () in
|
||||||
|
@ -3743,7 +3743,7 @@ let go () =
|
||||||
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
|
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
|
||||||
write_pdf false (Cpdfdraft.draft args.removeonly args.boxes range pdf)
|
write_pdf false (Cpdfdraft.draft args.removeonly args.boxes range pdf)
|
||||||
| 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 cpdffont = embed_font pdf in
|
let cpdffont = embed_font pdf in
|
||||||
warn_prerotate range pdf;
|
warn_prerotate range pdf;
|
||||||
|
@ -3754,17 +3754,15 @@ let go () =
|
||||||
| (InFile inname, _, _, _, _, _)::_ -> inname
|
| (InFile inname, _, _, _, _, _)::_ -> inname
|
||||||
| _ -> ""
|
| _ -> ""
|
||||||
in
|
in
|
||||||
let fontname =
|
write_pdf false
|
||||||
match embedinfo with Some (_, _, fontname, _) -> fontname | None -> args.fontname
|
(Cpdfaddtext.addtexts
|
||||||
in
|
cpdffont args.linewidth args.outline args.fast args.fontname
|
||||||
write_pdf false
|
font args.bates args.batespad args.color args.position
|
||||||
(Cpdfaddtext.addtexts
|
args.linespacing args.fontsize args.underneath text range
|
||||||
?embedinfo args.linewidth args.outline args.fast fontname
|
args.relative_to_cropbox args.opacity
|
||||||
font args.bates args.batespad args.color args.position
|
args.justification args.midline args.topline filename
|
||||||
args.linespacing args.fontsize args.underneath text range
|
args.extract_text_font_size args.coord ~raw:(args.encoding = Raw) pdf)*)
|
||||||
args.relative_to_cropbox args.opacity
|
()
|
||||||
args.justification args.midline args.topline filename
|
|
||||||
args.extract_text_font_size args.coord ~raw:(args.encoding = Raw) pdf)
|
|
||||||
| Some RemoveText ->
|
| Some RemoveText ->
|
||||||
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
|
||||||
|
@ -4009,15 +4007,18 @@ 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 font, embedinfo = embed_font pdf in
|
let cpdffont = embed_font () in
|
||||||
let pdf = Cpdftoc.typeset_table_of_contents ?embedinfo ~font:(unopt font) ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf in
|
let pdf =
|
||||||
write_pdf false pdf
|
Cpdftoc.typeset_table_of_contents
|
||||||
|
cpdffont ~fontsize:args.fontsize ~title:args.toc_title ~bookmark:args.toc_bookmark pdf
|
||||||
|
in
|
||||||
|
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 cpdffont = embed_font () in
|
||||||
let font, embedinfo = embed_font pdf in
|
let pdf = Cpdftexttopdf.typeset ~font:cpdffont ~papersize:args.createpdf_pagesize ~fontsize:args.fontsize text in
|
||||||
let pdf = Cpdftexttopdf.typeset ?embedinfo ~papersize:args.createpdf_pagesize ~font:(unopt 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,
|
||||||
|
|
|
@ -5,7 +5,7 @@ type t = Pdftext.font list * (int, int * int) Hashtbl.t
|
||||||
|
|
||||||
type cpdffont =
|
type cpdffont =
|
||||||
PreMadeFontPack of t
|
PreMadeFontPack of t
|
||||||
| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; fontencoding : Pdftext.encoding}
|
| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding}
|
||||||
| ExistingNamedFont of string
|
| ExistingNamedFont of string
|
||||||
|
|
||||||
let pdfcode_of_unicode_codepoint encoding_table glyphlist_table u =
|
let pdfcode_of_unicode_codepoint encoding_table glyphlist_table u =
|
||||||
|
|
|
@ -6,7 +6,7 @@ type t = Pdftext.font list * (int, int * int) Hashtbl.t
|
||||||
|
|
||||||
type cpdffont =
|
type cpdffont =
|
||||||
PreMadeFontPack of t
|
PreMadeFontPack of t
|
||||||
| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; fontencoding : Pdftext.encoding}
|
| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding}
|
||||||
| ExistingNamedFont of string
|
| ExistingNamedFont of string
|
||||||
|
|
||||||
val embed_truetype :
|
val embed_truetype :
|
||||||
|
|
|
@ -28,11 +28,16 @@ let rec of_utf8_with_newlines used charcode_extractor t =
|
||||||
if c <> [] then items := Text (charcodes_of_codepoints c)::!items;
|
if c <> [] then items := Text (charcodes_of_codepoints c)::!items;
|
||||||
rev !items
|
rev !items
|
||||||
|
|
||||||
(* The optional pdf argument is for providing a pre-embedded font - this will
|
let typeset ~papersize ~font ~fontsize text =
|
||||||
be removed when we re-embed subsetted? *)
|
let pdf = Pdf.empty () in
|
||||||
let typeset ?embedinfo ~papersize ~font ~fontsize text =
|
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 "Can't use existing named font for text-to-PDF")
|
||||||
|
in
|
||||||
let charcode_extractor = Pdftext.charcode_extractor_of_font_real font in
|
let charcode_extractor = Pdftext.charcode_extractor_of_font_real font in
|
||||||
let pdf = match embedinfo with None -> Pdf.empty () | Some (pdf, _, _, _) -> pdf in
|
|
||||||
let margin =
|
let margin =
|
||||||
Pdfunits.convert
|
Pdfunits.convert
|
||||||
72. (Pdfpaper.unit papersize) (Pdfunits.PdfPoint) (Pdfpaper.width papersize) /. 15.
|
72. (Pdfpaper.unit papersize) (Pdfunits.PdfPoint) (Pdfpaper.width papersize) /. 15.
|
||||||
|
@ -40,12 +45,6 @@ let typeset ?embedinfo ~papersize ~font ~fontsize text =
|
||||||
let used = null_hash () in
|
let used = null_hash () in
|
||||||
let instrs = of_utf8_with_newlines used charcode_extractor (Pdfio.string_of_bytes text) in
|
let instrs = of_utf8_with_newlines used charcode_extractor (Pdfio.string_of_bytes text) in
|
||||||
let codepoints = map fst (list_of_hashtbl used) 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
|
|
||||||
let pages =
|
let pages =
|
||||||
Cpdftype.typeset
|
Cpdftype.typeset
|
||||||
margin margin margin margin papersize pdf
|
margin margin margin margin papersize pdf
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(** Text to PDF *)
|
(** Text to PDF *)
|
||||||
|
|
||||||
(** Typeset a text file as a PDF. *)
|
(** Typeset a text file as a PDF. *)
|
||||||
val typeset : ?embedinfo:(Pdf.t * Pdfio.bytes * string * Pdftext.encoding) -> papersize:Pdfpaper.t -> font:Pdftext.font -> fontsize:float -> Pdfio.bytes -> Pdf.t
|
val typeset : papersize:Pdfpaper.t -> font:Cpdfembed.cpdffont -> fontsize:float -> Pdfio.bytes -> Pdf.t
|
||||||
|
|
Loading…
Reference in New Issue