有没有办法用画布创建弧形文本?我按照我们的回答:
How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)
我得到的最好的东西是从屋顶或者底部的曲线。我想要像这样的弧:
答案 0 :(得分:0)
这是画布代码:
https://codepen.io/creativedev/pen/oybGMQ
function drawTextArc(context, str, centerX, centerY, radius, angle) {
var len = str.length,
s;
context.save();
context.translate(centerX, centerY);
context.rotate(-1 * angle / 2);
context.rotate(-1 * (angle / len) / 2);
for (var n = 0; n < len; n++) {
context.rotate(angle / len);
context.save();
context.translate(0, -1 * radius);
s = str[n];
context.fillText(s, 0, 0);
context.restore();
}
context.restore();
}
var canvas = document.getElementById('myCanvas'),
context = canvas.getContext('2d'),
centerX = canvas.width / 2,
centerY = canvas.height - 30,
angle = Math.PI * 0.8,
radius = 150;
context.font = '30pt Calibri';
context.textAlign = 'center';
context.fillStyle = 'green';
context.lineWidth = 4;
drawTextArc(context, 'Vertical Arc', centerX, centerY, radius, angle);
// draw circle underneath text
context.arc(centerX, centerY, radius - 10, 0, 2 * Math.PI, false);