I would like to fill text in canvas as Subsccript and Superscript options. How do I acheive this.
Please help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since you aren’t allowed to use HTML in
drawTextyou can’t use<sup>andsub. 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.