From 5d3180aee590af79a2bc7a70cb7bca37b2f036b7 Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Sun, 10 Feb 2013 17:36:47 -0800 Subject: [PATCH] added text metric caching to improve text drawing performance a bit --- src/shapes/Text.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/shapes/Text.js b/src/shapes/Text.js index e091c4c3..22d246a4 100644 --- a/src/shapes/Text.js +++ b/src/shapes/Text.js @@ -93,7 +93,7 @@ lineHeightPx = this.getLineHeight() * textHeight, textArr = this.textArr, textArrLen = textArr.length, - width = this.getWidth(); + totalWidth = this.getWidth(); context.font = fontStyle + SPACE + fontSize + PX_SPACE + fontFamily; context.textBaseline = MIDDLE; @@ -104,15 +104,17 @@ // draw text lines for(var n = 0; n < textArrLen; n++) { - var text = textArr[n]; + var obj = textArr[n], + text = obj.text, + width = obj.width; // horizontal alignment context.save(); if(this.getAlign() === RIGHT) { - context.translate(width - this._getTextSize(text).width - p * 2, 0); + context.translate(totalWidth - width - p * 2, 0); } else if(this.getAlign() === CENTER) { - context.translate((width - this._getTextSize(text).width - p * 2) / 2, 0); + context.translate((totalWidth - width - p * 2) / 2, 0); } this.partialText = text; @@ -190,6 +192,22 @@ height: parseInt(fontSize, 10) }; }, + _expandTextData: function(arr) { + var len = arr.length; + n = 0, + text = EMPTY_STRING, + newArr = []; + + for (n=0; n