jtopo文字换行

来源:互联网 发布:linux循环 编辑:程序博客网 时间:2024/05/22 00:09

转自:http://blog.csdn.net/mytianhe/article/details/46559289

一、在jtopo.min.js文件中修改如下方法

this.paintText = function(a) {var b = this.text;if (null != b && "" != b) {a.beginPath(), a.font = this.font;var c = a.measureText(b).width,d = a.measureText("田").width;a.fillStyle = "rgba(" + this.fontColor + ", " + this.alpha + ")";ar e = this.getTextPostion(this.textPosition, c, d);a.fillText(b, e.x, e.y), a.closePath()}},

二、在jsp页面生成stage的前面添加如下代码

CanvasRenderingContext2D.prototype.wrapText = function(str,x,y){        var textArray = str.split('-'); //以-为换行符if(textArray==undefined||textArray==null)return false;var rowCnt = textArray.length;var i = 0,imax  = rowCnt,maxLength = 0;maxText = textArray[0];for(;i<imax;i++){var nowText = textArray[i],textLength = nowText.length;if(textLength >=maxLength){maxLength = textLength;        maxText = nowText;}}var maxWidth = this.measureText(maxText).width;var lineHeight = this.measureText("元").width;x+= lineHeight*(rowCnt-1)*1.7;    //可以自己调节x、y位置for(var j= 0;j<textArray.length;j++){var words = textArray[j];this.fillText(words,x,y-textArray.length*lineHeight/2); y+= lineHeight;}};


0 0