This commit is contained in:
John Whitington 2022-09-24 11:58:09 +01:00
parent 39f8942f1a
commit ad442568db
3 changed files with 29 additions and 12 deletions

View File

@ -3,11 +3,10 @@ NONDOC = cpdfyojson cpdfxmlm cpdfutil
DOC = cpdfunicodedata cpdferror cpdfdebug cpdfjson cpdfstrftime cpdfcoord \
cpdfattach cpdfpagespec cpdfposition cpdfpresent cpdfmetadata \
cpdfbookmarks cpdfpage cpdfaddtext cpdfimage cpdffont cpdftype \
cpdfpad cpdfocg cpdfsqueeze cpdfdraft cpdfspot \
cpdfbookmarks cpdfpage cpdftruetype cpdfembed cpdfaddtext cpdfimage \
cpdffont cpdftype cpdfpad cpdfocg cpdfsqueeze cpdfdraft cpdfspot \
cpdfpagelabels cpdfcreate cpdfannot cpdfxobject cpdfimpose cpdftweak \
cpdftruetype cpdfembed cpdftexttopdf cpdftoc\
cpdfcommand
cpdftexttopdf cpdftoc cpdfcommand
MODS = $(NONDOC) $(DOC)
@ -31,7 +30,7 @@ $(foreach x,$(MODS),$x.cmti)
ifneq ($(shell ocamlopt -version),)
TARGETS += native-code native-code-library
LIBINSTALL_FILES += cpdf.a cpdf.cmxa $(foreach x,$(PDFMODS),$x.cmx)
LIBINSTALL_FILES += cpdf.a cpdf.cmxa $(foreach x,$(MODS),$x.cmx)
endif
all : $(TARGETS)

View File

@ -21,6 +21,12 @@ let charcodes_of_utf8 font s =
in
implode (map char_of_int charcodes)
let unicode_codepoint_of_pdfcode encoding_table glyphlist_table p =
try
hd (Hashtbl.find glyphlist_table (Hashtbl.find encoding_table p))
with
Not_found -> 0
(* Get the width of some text in the given font *)
let width_of_text font text =
match font with
@ -586,8 +592,19 @@ let
!pdf;
voffset := !voffset +. (linespacing *. fontsize))
lines;
let charcodes = map fst (list_of_hashtbl used) in
Printf.printf "%i charcodes used\n" (length charcodes);
begin match embedinfo with
| None -> ()
| Some (_, fontfile, fontname, encoding) ->
let charcodes = map fst (list_of_hashtbl used) in
let encoding_table = Pdftext.table_of_encoding encoding in
let glyphlist_table = Pdfglyphlist.glyph_hashes () in
let codepoints =
map (fun c -> unicode_codepoint_of_pdfcode encoding_table glyphlist_table (int_of_char c)) charcodes
in
let objnum = match fontpdfobj with Pdf.Indirect i -> i | _ -> failwith "bad fontpdfobj" in
let font = Cpdfembed.embed_truetype !pdf ~fontfile ~fontname ~codepoints ~encoding in
ignore (Pdftext.write_font ~objnum !pdf font)
end;
!pdf
let removetext range pdf =

View File

@ -3705,12 +3705,13 @@ let go () =
| Some (AddText text) ->
let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
let font =
let font, embedinfo =
match args.font with
| StandardFont f -> Some (Pdftext.StandardFont (f, args.fontencoding))
| OtherFont f -> None (* it's in fontname *)
| 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 (Cpdfembed.embed_truetype pdf ~fontfile ~fontname:args.fontname ~codepoints:[] ~encoding:args.fontencoding),
Some (pdf, fontfile, args.fontname, args.fontencoding)
in
warn_prerotate range pdf;
let pdf =
@ -3722,7 +3723,7 @@ let go () =
in
write_pdf false
(Cpdfaddtext.addtexts
args.linewidth args.outline args.fast args.fontname
?embedinfo args.linewidth args.outline args.fast args.fontname
font args.embedfonts args.bates args.batespad args.color args.position
args.linespacing args.fontsize args.underneath text range
() args.relative_to_cropbox args.opacity