HTML5 Canvas +下标和上标 [英] HTML5 Canvas + Subscript and Superscript
问题描述
我想在canvas中填充文本作为脚本和上标选项。
由于您不能在 drawText
中使用HTML,您不能使用< sup>
和 sub
。
换句话说,当你想要上标时,你需要将字体更小,或者以更高的y值来绘制文本,位置或设置 textBaseline =top
。对于下标,您必须执行类似操作。
否则,您可以使用unicode。例如,它有效地写:
ctx.fillText('x2',50,50);
ctx.fillText('normalText01230¹2 34 6 6 7 8 9',50,50);
等。
I would like to fill text in canvas as Subsccript and Superscript options. How do I acheive this.
Please help.
Since you aren't allowed to use HTML in drawText
you can't use <sup>
and sub
. Instead have to do it yourself.
In other words, when you want superscript you will need to change the font to be smaller and either draw the text at a higher y-position or else set textBaseline = "top"
. For subscript you will have to do similar.
Otherwise you can use unicode. For instance it is valid to write:
ctx.fillText('x₂', 50, 50);
, ctx.fillText('normalText0123₀₁₂₃₄₅₆₇₈₉', 50, 50);
, etc.
这篇关于HTML5 Canvas +下标和上标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!