From cf564ac3da5e54ed2a8c63a2bd21b81cb7addaeb Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Sat, 29 Mar 2014 19:56:36 -0700 Subject: [PATCH] Fixes for text justification --- lib/mixins/text.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mixins/text.coffee b/lib/mixins/text.coffee index a535530..56203eb 100644 --- a/lib/mixins/text.coffee +++ b/lib/mixins/text.coffee @@ -171,9 +171,10 @@ module.exports = when 'justify' # calculate the word spacing value + words = text.trim().split(/\s+/) textWidth = @widthOfString(text.replace(/\s+/g, ''), options) spaceWidth = @widthOfString(' ') + characterSpacing - wordSpacing = Math.max 0, (options.lineWidth - textWidth) / Math.max(1, options.wordCount - 1) - spaceWidth + wordSpacing = Math.max 0, (options.lineWidth - textWidth) / Math.max(1, words.length - 1) - spaceWidth # calculate the actual rendered width of the string after word and character spacing renderedWidth = options.textWidth + (wordSpacing * (options.wordCount - 1)) + (characterSpacing * (text.length - 1)) @@ -231,7 +232,7 @@ module.exports = # since the normal Tw operator only works on character code 32, which isn't # used for embedded fonts. if wordSpacing - words = text.split(/\s+/) + words = text.trim().split(/\s+/) wordSpacing += @widthOfString(' ') + characterSpacing wordSpacing *= 1000 / @_fontSize