Added fontpack width calculation in -add-text

This commit is contained in:
John Whitington 2023-07-18 14:51:13 +01:00
parent 6a92be56cf
commit 291c5391c3
3 changed files with 9 additions and 2 deletions

View File

@ -4,7 +4,7 @@ NONDOC = cpdfyojson cpdfxmlm
DOC = cpdfunicodedata cpdferror cpdfdebug cpdfjson cpdfstrftime cpdfcoord \
cpdfattach cpdfpagespec cpdfposition cpdfpresent cpdfmetadata \
cpdfbookmarks cpdfpage cpdftruetype cpdfremovetext cpdfextracttext \
cpdfembed cpdfaddtext cpdffont cpdftype cpdfpad cpdfocg \
cpdfembed cpdffont cpdftype cpdfaddtext cpdfpad cpdfocg \
cpdfsqueeze cpdfdraft cpdfspot cpdfpagelabels cpdfcreate cpdfannot \
cpdfxobject cpdfimpose cpdftweak cpdftexttopdf cpdftoc cpdfjpeg \
cpdfpng cpdfimage cpdfdraw cpdfcomposition cpdfshape \

View File

@ -259,8 +259,14 @@ let addtext
| None -> Pdf.Dictionary []
| Some d -> d
in
(* FIXME If a fontpack is available, we need to calculate the width from the codepoints in preference. *)
let calc_textwidth text =
match fontpack with
| Some fontpack ->
let widthss = map (fun font -> Cpdftype.font_widths font fontsize) (fst fontpack) in
let triples = option_map (Cpdfembed.get_char fontpack) (Pdftext.codepoints_of_utf8 text) in
let widths = map (fun (charcode, fontnum, _) -> (List.nth widthss fontnum).(charcode)) triples in
fsum widths
| None ->
match font with
| Some (Pdftext.StandardFont (f, _)) ->
let rawwidth =

View File

@ -11,6 +11,7 @@ type cpdffont =
val fontpack_of_standardfont : Pdftext.font -> t
(* Returns (charcode, fontnumber, font) *)
val get_char : t -> int -> (int * int * Pdftext.font) option
val embed_truetype :