如何为HTML5画布上下文设置2种字体? [英] How to set 2 fonts for HTML5 canvas context?

查看:65
本文介绍了如何为HTML5画布上下文设置2种字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Canvas在绘制文本时使用两种字体。这是因为我的主要字体是Comic Sans MS(这是一个儿童应用程序)。由于我无法在iPad上找到Comic Sans,因此我试图用MarkerFelt-Thin代替它。

I'm trying to get the Canvas to use two fonts when drawing text. This is because my main font is Comic Sans MS (It's a kids app). Since I can't find Comic Sans on iPad, I'm trying to substitute it with MarkerFelt-Thin.

我尝试使用以下语句的几种变体:

I've tried to use several variations of the following statement:

ctx.font = "40pt MarkerFelt-Thin; 40pt Comic Sans MS";

似乎没有用。因此,目前我正在使用用户代理检测,并为每个用户代理手动分配不同的字体。

Doesn't seem to be working. So at the moment I'm using user agent detection and manually assigning different fonts for each user agent.

有人知道正确的方法吗?

Anyone know the right way to do this?

欢呼

推荐答案

画布的字体使用相同的语法作为CSS font 属性。因此,请尝试:

Canvas's font uses the same syntax as the CSS font attribute. So try:

ctx.font = "40pt MarkerFelt-Thin, Comic Sans MS";

这篇关于如何为HTML5画布上下文设置2种字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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