diff --git a/Makefile b/Makefile index 901616d..133e055 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/cpdfaddtext.ml b/cpdfaddtext.ml index 63662e3..857d1ed 100644 --- a/cpdfaddtext.ml +++ b/cpdfaddtext.ml @@ -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 = diff --git a/cpdfembed.mli b/cpdfembed.mli index 7cdadd7..08510ec 100644 --- a/cpdfembed.mli +++ b/cpdfembed.mli @@ -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 :