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 \ DOC = cpdfunicodedata cpdferror cpdfdebug cpdfjson cpdfstrftime cpdfcoord \
cpdfattach cpdfpagespec cpdfposition cpdfpresent cpdfmetadata \ cpdfattach cpdfpagespec cpdfposition cpdfpresent cpdfmetadata \
cpdfbookmarks cpdfpage cpdftruetype cpdfremovetext cpdfextracttext \ cpdfbookmarks cpdfpage cpdftruetype cpdfremovetext cpdfextracttext \
cpdfembed cpdfaddtext cpdffont cpdftype cpdfpad cpdfocg \ cpdfembed cpdffont cpdftype cpdfaddtext cpdfpad cpdfocg \
cpdfsqueeze cpdfdraft cpdfspot cpdfpagelabels cpdfcreate cpdfannot \ cpdfsqueeze cpdfdraft cpdfspot cpdfpagelabels cpdfcreate cpdfannot \
cpdfxobject cpdfimpose cpdftweak cpdftexttopdf cpdftoc cpdfjpeg \ cpdfxobject cpdfimpose cpdftweak cpdftexttopdf cpdftoc cpdfjpeg \
cpdfpng cpdfimage cpdfdraw cpdfcomposition cpdfshape \ cpdfpng cpdfimage cpdfdraw cpdfcomposition cpdfshape \

View File

@ -259,8 +259,14 @@ let addtext
| None -> Pdf.Dictionary [] | None -> Pdf.Dictionary []
| Some d -> d | Some d -> d
in in
(* FIXME If a fontpack is available, we need to calculate the width from the codepoints in preference. *)
let calc_textwidth text = 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 match font with
| Some (Pdftext.StandardFont (f, _)) -> | Some (Pdftext.StandardFont (f, _)) ->
let rawwidth = let rawwidth =

View File

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