How to set 2 fonts for HTML5 canvas context?

删除回忆录丶 提交于 2020-01-12 10:00:27

问题


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?

Cheers


回答1:


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

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


来源:https://stackoverflow.com/questions/8113866/how-to-set-2-fonts-for-html5-canvas-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!