我发现了一个在fabric.js之外使用Cufon的方法,但它确实是一个肮脏的黑客攻击。
首先我在github的页面上添加了另一个cufon.js。然后我在编辑器中打开它,并将'Cufon'自动重命名为'CufonBase'。
我写了一个wraper功能registerFont,调用它两次,每次的Cufón和CufonBase:
var makeWrap = function(fn1, fn2){
return function(){
try{
fn2.apply(this, arguments);
return fn1.apply(this, arguments);
}catch(ex){
ErrorHandler.Exception(ex);
}
};
};
Cufon.registerFont = makeWrap(Cufon.registerFont, CufonBase.registerFont);
这将覆盖字体加载并调用CufonBase.registerFont也,所以你的Cufón的基础方法不必修改你的字体js。
然后你就可以拨打:
CufonBase.replace('h1', {fontFamily: 'font_name'});
而且它为我工作。