This commit is contained in:
John Whitington 2022-10-19 16:32:56 +01:00
parent b4c07ea798
commit 4e2bd4ce5d
3 changed files with 19 additions and 13 deletions

View File

@ -421,7 +421,7 @@ let unescape_string s =
implode (unescape_chars [] (explode s))
let
addtexts ?embedinfo linewidth outline fast fontname font bates batespad
addtexts linewidth outline fast fontname (cpdffont : Cpdfembed.cpdffont) bates batespad
colour position linespacing fontsize underneath text pages cropbox opacity
justification midline topline filename extract_text_font_size shift
?(raw=false) pdf
@ -429,6 +429,14 @@ let
let time = Cpdfstrftime.current_time () in
if pages = [] then error "addtexts: empty page range" else
let realfontname = ref fontname in
let font =
match cpdffont with
| Cpdfembed.PreMadeFontPack f -> Some (hd (fst f))
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
let embedded = Cpdfembed.embed_truetype pdf ~fontfile ~fontname ~codepoints:[] ~encoding in
Some (hd (fst embedded))
| Cpdfembed.ExistingNamedFont _ -> None
in
let fontpdfobj =
match font with
| Some (Pdftext.StandardFont _ as font) ->
@ -521,9 +529,8 @@ let
!pdf;
voffset := !voffset +. (linespacing *. fontsize))
lines;
begin match embedinfo with
| None -> ()
| Some (_, fontfile, fontname, encoding) ->
begin match cpdffont with
| Cpdfembed.EmbedInfo {fontfile; fontname; encoding} ->
let charcodes =
match Hashtbl.find used fontname with
| exception Not_found -> []
@ -537,6 +544,7 @@ let
let objnum = match fontpdfobj with Pdf.Indirect i -> i | _ -> failwith "bad fontpdfobj" in
let font = hd (fst (Cpdfembed.embed_truetype !pdf ~fontfile ~fontname ~codepoints ~encoding)) in
ignore (Pdftext.write_font ~objnum !pdf font)
| _ -> ()
end;
!pdf

View File

@ -19,12 +19,11 @@ type justification =
position linespacing fontsize underneath text pages orientation
relative_to_cropbox midline_adjust topline filename pdf]. For details see cpdfmanual.pdf *)
val addtexts :
?embedinfo:(Pdf.t * Pdfio.bytes * string * Pdftext.encoding) ->
float -> (*linewidth*)
bool -> (*outline*)
bool -> (*fast*)
string -> (*fontname*)
Pdftext.font option -> (*font*)
Cpdfembed.cpdffont -> (*font*)
int -> (* bates number *)
int option -> (* bates padding width *)
color -> (*colour*)

View File

@ -3743,9 +3743,9 @@ let go () =
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
write_pdf false (Cpdfdraft.draft args.removeonly args.boxes range pdf)
| 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 cpdffont = embed_font pdf in
let cpdffont = embed_font () in
warn_prerotate range pdf;
let pdf =
if args.prerotate then prerotate range pdf else pdf
@ -3756,13 +3756,12 @@ let go () =
in
write_pdf false
(Cpdfaddtext.addtexts
cpdffont args.linewidth args.outline args.fast args.fontname
font args.bates args.batespad args.color args.position
args.linewidth args.outline args.fast args.fontname
cpdffont args.bates args.batespad args.color args.position
args.linespacing args.fontsize args.underneath text range
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)*)
()
args.extract_text_font_size args.coord ~raw:(args.encoding = Raw) pdf)
| Some RemoveText ->
let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in