HTML5 Canvas + 下标和上标 [英] HTML5 Canvas + Subscript and Superscript

查看:23
本文介绍了HTML5 Canvas + 下标和上标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在画布中填充文本作为 Subscript 和 Superscript 选项.我如何做到这一点.

I would like to fill text in canvas as Subsccript and Superscript options. How do I acheive this.

请帮忙.

推荐答案

由于你不能在 drawText 中使用 HTML 你不能使用 <sup>.而是必须自己做.

Since you aren't allowed to use HTML in drawText you can't use <sup> and sub. Instead have to do it yourself.

换句话说,当您想要上标时,您需要将字体更改为更小,或者在更高的 y 位置绘制文本,或者设置 textBaseline = "top".对于下标,你必须做类似的事情.

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.

否则你可以使用 unicode.例如写是有效的:

Otherwise you can use unicode. For instance it is valid to write:

ctx.fillText('x₂', 50, 50);, ctx.fillText('normalText0123₀₁₂₃₄₅₆₇₈₉', 50, 50);

这篇关于HTML5 Canvas + 下标和上标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆