某些字体不支持CSS斜体或粗体(例如,Zapfino不支持斜体,因为它已经非常符合脚本)。我想检测何时不支持字体样式,因此我可以在编辑器中禁用样式按钮。检测粗体和斜体支持
我试过的东西like this:
that.checkFontData = function(fontList)
{ var test = $("<span style='font-size:24px;absolute;visibility:hidden;height:auto;width:auto;white-space:nowrap;'>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678910</span>");
$('body').append(test);
for (var i= 0, iMax = fontList.length; i < iMax; ++i)
{ test.css('fontFamily', fontList[i]);
var normalWidth = test.outerWidth(true);
var normalHeight = test.outerHeight(true);
test.css('fontStyle', 'italic');
var italicWidth = test.outerWidth(true);
var italicHeight = test.outerHeight(true);
test.css('fontStyle', 'normal');
test.css('fontWeight', 'bold');
var boldWidth = test.outerWidth(true);
var boldHeight = test.outerHeight(true);
console.log(fontList[i] + ", normal: " + normalWidth + ", bold: " + boldWidth + ", italic: " + italicWidth );
}
test.remove();
};
,但它不工作...许多字体的斜体提供或加粗的报告相同的宽度。
接下来,我想用canvas元素来检测这个,但是,唉,firefox甚至不会在画布中呈现斜体文本,所以那个想法就不明显了。
你会建议什么?
OCR,如果真的很重要。不能拿出更好的东西 – user1721135
手动检查它,并硬编码结果 – P1nGu1n
像P1nGu1n这样的硬编码结果将是我脑海中最好的最合理的解决方案。大概你控制自己的字体 - 这应该很容易。 – rlemon