Skip to content

Commit f03af75

Browse files
authored
Update split_text_to_size.js (#1805)
1 parent 4efd59c commit f03af75

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

plugins/split_text_to_size.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
options = options || {};
4242

4343
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+
4547
var widths = options.widths ? options.widths : activeFont.metadata.Unicode.widths;
4648
var widthsFractionOf = widths.fof ? widths.fof : 1;
4749
var kerning = options.kerning ? options.kerning : activeFont.metadata.Unicode.kerning;
@@ -55,11 +57,15 @@
5557
var output = [];
5658

5759
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+
}
6369
prior_char_code = char_code;
6470
}
6571

0 commit comments

Comments
 (0)