Last active
December 15, 2015 15:09
-
-
Save b123400/5279949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
if(!window.chrome)return; | |
var _fillText=CanvasRenderingContext2D.prototype.fillText; | |
CanvasRenderingContext2D.prototype.fillText=function(text,x,y,maxWidth){ | |
if(text.indexOf(' ')==-1){ | |
return _fillText.apply(this, arguments); | |
} | |
var text_arr=text.split(''); | |
var originalX=x; | |
for(var i=0;i<text_arr.length;i++){ | |
var thisText=text_arr[i], | |
thisTextWidth=this.measureText(thisText).width; | |
if(x+thisTextWidth-originalX>maxWidth){ | |
break; | |
} | |
_fillText.call(this,thisText,x,y); | |
x+=thisTextWidth; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment