/*! CanvasTextWrapper (https://github.com/namniak/CanvasTextWrapper) * Version: 0.1.0 * * MIT License (http://www.opensource.org/licenses/mit-license.html) * Copyright (c) 2014 Vadim Namniak */ !function(){"use strict";var a={font:"18px Arial, sans-serif",textAlign:"left",verticalAlign:"top",paddingX:0,paddingY:0,fitParent:!1,lineBreak:"auto",sizeToFill:!1};window.CanvasTextWrapper=function(b,c,d){if(!(this instanceof CanvasTextWrapper))throw new TypeError('CanvasTextWrapper constructor failed. Use "new" keyword when instantiating.');this.canvas=b,this.text=c;for(var e in a)this[e]=d&&d[e]?d[e]:a[e];this.lineHeight=parseInt(this.font.replace(/^\D+/g,""),10),this.validate(),this.context=this.canvas.getContext("2d"),this.context.font=this.font,this.context.textBaseline="bottom",this.drawText()},CanvasTextWrapper.prototype={drawText:function(){var a=this.fitParent===!1?this.canvas.width:this.canvas.parentNode.clientWidth,b={x:0,y:0};if(this.sizeToFill){var c=(this.fitParent===!1?this.canvas.height:this.canvas.parentNode.clientHeight)-2*this.paddingX,d=0;do{this.setFontSize(++d);var e=this.getWrappedText(a),f=e.length*this.lineHeight}while(c>f);this.setFontSize(--d);var e=this.getWrappedText(a),f=e.length*this.lineHeight}else var e=this.getWrappedText(a),f=e.length*this.lineHeight;this.setTextVerticalAlign(b,f);for(var g=0;gc){for(var g=0;a.measureText(e+b[d][g]).width<=c&&g