我该如何在HTML5画布内对齐文本以实现两端对齐?在下面的代码中,文本可以左/右/居中对齐。我需要设置align="justify"
。请建议如何实现?
HTML:
<body onload="callMe()">
<canvas id="MyCanvas"></canvas>
</body>
JS:
function callMe() {
var canvas = document.getElementById("MyCanvas");
var ctx = canvas.getContext("2d");
var txt = "Welcome to the new hello world example";
cxt.font = "10pt Arial";
cxt.textAlign = "left";
/* code to text wrap*/
cxt.fillText(txt, 10, 20);
}