From 8eece7e9ea27618c04b8dee387a004aeda99697e Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Sat, 29 Mar 2014 20:36:10 -0700 Subject: [PATCH] Make sure heightOfString doesn't break pages --- lib/mixins/text.coffee | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/mixins/text.coffee b/lib/mixins/text.coffee index 19a43a3..5fe29e2 100644 --- a/lib/mixins/text.coffee +++ b/lib/mixins/text.coffee @@ -57,14 +57,17 @@ module.exports = widthOfString: (string, options = {}) -> @_font.widthOfString(string, @_fontSize) + (options.characterSpacing or 0) * (string.length - 1) - heightOfString: (text, options) -> + heightOfString: (text, options = {}) -> {x,y} = this - lineGap = options.lineGap or @_lineGap or 0 - @_text text, 0, 0, options, (line, options) => + options = @_initOptions(options) + options.height = Infinity # don't break pages + + lineGap = options.lineGap or @_lineGap or 0 + @_text text, @x, @y, options, (line, options) => @y += @currentLineHeight(true) + lineGap - height = @y # we started at y=0 + height = @y - y @x = x @y = y