jTopo 使文字在连线上面 并修改文字大小

this.paintText = function(a, b) {
			var c = b[0],
				d = b[b.length - 1];
			if (4 == b.length && (c = b[1], d = b[2]), this.text && this.text.length > 0) {
				var e = (d.x + c.x) / 2 + this.textOffsetX,
					f = (d.y + c.y) / 2 + this.textOffsetY;
				a.save(), a.beginPath(), a.font = this.font;
				var g = a.measureText(this.text).width,
					h = a.measureText("ç”°").width;
					//---------新增的代码
                    a.translate(e ,f );
                    a.rotate(Math.atan((d.y-c.y)/(d.x-c.x)));
				if (a.fillStyle = "rgba(" + this.fontColor + ", " + this.alpha + ")", this.nodeA === this.nodeZ) {
					var j = this.bundleGap * (this.nodeIndex + 1) / 2,
						e = this.nodeA.x + j * Math.cos(i),
						f = this.nodeA.y + j * Math.sin(i);
					a.fillText(this.text, e, f)
				} else
                // a.fillText(this.text, e - g / 2, f - h / 2);//源码计算文字位置
                //修改文本字体大小
                a.font = "7pt Calibri";
                //----------修改代码
                a.fillText(this.text, -g/2+10,-h/2+20);
				a.stroke(), a.closePath(), a.restore()
			}
		}

在源码找到paintText方法 在canvas对象a下面加上
a.translate(e ,f ); a.rotate(Math.atan((d.y-c.y)/(d.x-c.x)));
详情如上面代码。
然后修改 a.fillText(this.text, e - g / 2, f - h / 2);a.fillText(this.text, -g/2+10,-h/2+20);
其中+10和+20是调整文字在连线上的位置;
调整字体大小a.font = "7pt Calibri";

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值