Added fontpack width calculation in -add-text
This commit is contained in:
parent
6a92be56cf
commit
291c5391c3
2
Makefile
2
Makefile
|
@ -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 \
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
|
@ -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 :
|
||||||
|
|
Loading…
Reference in New Issue