From 4554eb081d7a6076bcef6075e3f2143871d9c30d Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Tue, 5 Jun 2018 10:18:09 +0200 Subject: [PATCH] Update split_text_to_size.js --- plugins/split_text_to_size.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/split_text_to_size.js b/plugins/split_text_to_size.js index 620337578..891b45eb1 100644 --- a/plugins/split_text_to_size.js +++ b/plugins/split_text_to_size.js @@ -41,7 +41,9 @@ options = options || {}; var activeFont = options.font || this.internal.getFont(); - + var fontSize = options.fontSize || this.internal.getFontSize(); + var charSpace = options.charSpace || this.internal.getCharSpace(); + var widths = options.widths ? options.widths : activeFont.metadata.Unicode.widths; var widthsFractionOf = widths.fof ? widths.fof : 1; var kerning = options.kerning ? options.kerning : activeFont.metadata.Unicode.kerning; @@ -55,11 +57,15 @@ var output = []; for (i = 0, l = text.length; i < l; i++) { - char_code = text.charCodeAt(i) - output.push( - ( widths[char_code] || default_char_width ) / widthsFractionOf + - ( kerning[char_code] && kerning[char_code][prior_char_code] || 0 ) / kerningFractionOf - ); + char_code = text.charCodeAt(i); + + if (typeof activeFont.metadata.widthOfString === "function") { + output.push(((activeFont.metadata.widthOfGlyph(activeFont.metadata.characterToGlyph(char_code)) + charSpace * (1000/ fontSize)) || 0) / 1000); + } else { + output.push( + ( widths[char_code] || default_char_width ) / widthsFractionOf + ( kerning[char_code] && kerning[char_code][prior_char_code] || 0 ) / kerningFractionOf + ); + } prior_char_code = char_code; }