当我在带有通过@ font-face加载的字体的画布上绘制文本时,文本无法正确显示.它根本不显示(在Chrome 13和Firefox 5中),或者字体错误(Opera 11).此类意外行为仅在第一次使用字体绘图时发生.之后一切正常.
这是标准行为还是什么?
谢谢.
PS:以下是测试用例的源代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>@font-face and <canvas></title>
<style id="css">
@font-face {
font-family: 'Press Start 2P';
src: url('fonts/PressStart2P.ttf');
}
</style>
<style>
canvas, pre {
border: 1px solid black;
padding: 0 1em;
}
</style>
</head>
<body>
<h1>@font-face and <canvas></h1>
<p>
Description: click the button several times, and you will see the problem.
The first line won't show at all, or with a wrong typeface even if it does.
<strong>If you have visited …Run Code Online (Sandbox Code Playgroud) 我正在尝试将事件处理程序附加到链接标记的加载事件,以在加载样式表后执行某些代码.
new_element = document.createElement('link');
new_element.type = 'text/css';
new_element.rel = 'stylesheet';
new_element.href = 'http://domain.tld/file.css';
new_element.addEventListener('load', function() { alert('foo'); }, false);
document.getElementsByTagName('head')[0].appendChild(new_element)
Run Code Online (Sandbox Code Playgroud)
我也试过onreadystatechange
new_element.onreadystatechange = function() { alert('foo'); }
Run Code Online (Sandbox Code Playgroud)
不幸的是,这两种方法都没有导致触发警报.此外,在使用addEventListener注册'load'事件的处理程序后,new_element.onload为null.这是正常的吗?
谢谢,安德鲁
ps:我可能不会使用任何框架来解决这个问题