[英]Draw a text with orientation is upright and mode is vertical-rl in canvas html5
I have a text in html with below css: 我在css下面的html中有一个文本:
.overlay-imageOrientation-left { font-size: 20px; text-orientation: upright; writing-mode: vertical-rl; color: #ffffff; position: absolute; top: 45%; left: 3px; }
How can i draw this text in canvas html5 with text-orientation: upright and writing-mode: vertical-rl ? 我如何在画布html5中以文本方向绘制此文本,其文本方向为:upright,而写作模式为vertical-rl?
Normally, you would have to draw each character separately: 通常,您必须分别绘制每个字符:
ctx = c.getContext('2d'); // set the font to 20px and line-height to 1 ctx.font = '20px/1 sans-serif'; ctx.textAlign = "center"; var str = "Hello World"; for(var i=0; i<str.length; i++){ ctx.fillText(str[i], 20, 20*(i+1)); }
<canvas id="c" height=300></canvas>
But some browsers (actually only Firefox for now, I will open an issue on chrome about it), also do accept that you set these exact CSS properties on the canvas element directly: 但是某些浏览器(目前实际上仅是Firefox,我将在chrome上打开一个问题),也接受您直接在canvas元素上设置了这些确切的CSS属性:
ctx = c.getContext('2d'); ctx.font = '20px/1 sans-serif' ctx.fillText('Hello World', 20,20);
canvas{ text-orientation: upright; writing-mode: vertical-rl; }
<canvas id="c" height=300></canvas>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.