html5 canvas 画一个矩形,在矩形里添加文字。 文字超出矩形怎样自动换行???
var canvas = document.getElementById("demo") var ctx = canvas.getContext('2d'); ctx.font = "32pt Arial"; ctx.beginPath(); ctx.lineWidth = "1"; ctx.strokeStyle = "blue"; ctx.moveTo(100, 100); ctx.lineTo(100, 400); ctx.lineTo(400, 400); ctx.lineTo(400, 100); ctx.closePath(); ctx.stroke(); ctx.strokeText("hello world hello world hello world hello world hello world", 120, 200); ctx.strokeStyle = "red"; ctx.stroke();