html5使用新字体,html5 – 使用带有canvas fillText的font-face字体

编辑:嗯,看起来字体是在DOM上的一个元素使用后加载的,所以我只是使用了一个隐藏的Div和一个使用font-face字体的文本,它现在正在工作…… 🙂

我正在使用此代码通过大量更新来更新favicon,但我想使用自定义像素字体来编写数字.

var canvas = document.createElement('canvas'),

ctx,

img = document.createElement('img'),

link = document.getElementById('favicon').cloneNode(true),

updates = data;

if (canvas.getContext) {

canvas.height = canvas.width = 16; // set the size

ctx = canvas.getContext('2d');

img.onload = function () { // once the image has loaded

ctx.drawImage(this, 0, 0);

ctx.font = 'normal 12px Visitor';

ctx.fillStyle = '#213B55';

ctx.textBaseline="middle";

ctx.textAlign="center";

ctx.fillText(updates, 10, 10);

link.href = canvas.toDataURL('image/png');

document.body.appendChild(link);

};

img.src = 'favicon_new.png';

}

这是我的CSS

@font-face {

font-family: 'Visitor';

font -style: normal;

font-weight: normal;

src: url('fonts/visitor.woff') format('woff');

如果我更改此行:

ctx.font = 'normal 12px Visitor';

使用’普通12px Arial’可以正常工作.如果我使用自定义“访客”字体,它只是更改图标,但我看不到该数字.

什么可能是问题的任何想法?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值