Skip to content

Instantly share code, notes, and snippets.

@b123400
Last active December 15, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b123400/5279949 to your computer and use it in GitHub Desktop.
Save b123400/5279949 to your computer and use it in GitHub Desktop.
(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