File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 41
41
options = options || { } ;
42
42
43
43
var activeFont = options . font || this . internal . getFont ( ) ;
44
-
44
+ var fontSize = options . fontSize || this . internal . getFontSize ( ) ;
45
+ var charSpace = options . charSpace || this . internal . getCharSpace ( ) ;
46
+
45
47
var widths = options . widths ? options . widths : activeFont . metadata . Unicode . widths ;
46
48
var widthsFractionOf = widths . fof ? widths . fof : 1 ;
47
49
var kerning = options . kerning ? options . kerning : activeFont . metadata . Unicode . kerning ;
55
57
var output = [ ] ;
56
58
57
59
for ( i = 0 , l = text . length ; i < l ; i ++ ) {
58
- char_code = text . charCodeAt ( i )
59
- output . push (
60
- ( widths [ char_code ] || default_char_width ) / widthsFractionOf +
61
- ( kerning [ char_code ] && kerning [ char_code ] [ prior_char_code ] || 0 ) / kerningFractionOf
62
- ) ;
60
+ char_code = text . charCodeAt ( i ) ;
61
+
62
+ if ( typeof activeFont . metadata . widthOfString === "function" ) {
63
+ output . push ( ( ( activeFont . metadata . widthOfGlyph ( activeFont . metadata . characterToGlyph ( char_code ) ) + charSpace * ( 1000 / fontSize ) ) || 0 ) / 1000 ) ;
64
+ } else {
65
+ output . push (
66
+ ( widths [ char_code ] || default_char_width ) / widthsFractionOf + ( kerning [ char_code ] && kerning [ char_code ] [ prior_char_code ] || 0 ) / kerningFractionOf
67
+ ) ;
68
+ }
63
69
prior_char_code = char_code ;
64
70
}
65
71
You can’t perform that action at this time.
0 commit comments