如何对HTML5 canvas文本进行粗体和/或斜体处理? [英] How do I style HTML5 canvas text to be bold and/or italic?

查看:4177
本文介绍了如何对HTML5 canvas文本进行粗体和/或斜体处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以非常直接的方式将文本打印到画布上:

I'm printing text to a canvas in a pretty straight forward way:

var ctx = canvas.getContext('2d');
ctx.font = "10pt Courier";
ctx.fillText("Hello World", 100, 100);

但是如何将文本更改为粗体,斜体或两者?

But how can I change the text to bold, italic or both? Any suggestions to fix that simple example?

推荐答案

您可以使用以下任何方式:

You can use any of these:

ctx.font = "italic 10pt Courier";

ctx.font = "bold 10pt Courier";

ctx.font = "italic bold 10pt Courier";

有关详细信息,以下是一些资源:

For further information, here are a couple of resources:

  • Dive into HTML5
  • How to display text in canvas
  • HTML5 canvas - the basics

这篇关于如何对HTML5 canvas文本进行粗体和/或斜体处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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