简体   繁体   English

在 Firefox 扩展中获取 fonts 的列表

[英]Get a list of fonts in a Firefox extension

In a Firefox extension of mine, the preferences window apparently broke somewhere after Firefox 2.0, and (a part of) the problem lies in the following line:在我的 Firefox 扩展中,偏好 window 显然在 Firefox 2.0 之后某处中断,并且(部分)问题在于以下行:

var fontList  = Components.classes["@mozilla.org/gfx/fontlist;1"].
    createInstance(Components.interfaces.nsIFontList);

which errors with a哪个错误

Error: Components.classes['@mozilla.org/gfx/fontlist;1'] is undefined

Some digging suggests that fontlist is in fact a wrapper around nsIFontEnumerator ( https://bugzilla.mozilla.org/show_bug.cgi?id=397813 ) but I can't find anything on how to use nsIFontEnumerator.一些挖掘表明 fontlist 实际上是 nsIFontEnumerator ( https://bugzilla.mozilla.org/show_bug.cgi?id=397813 )的包装,但我找不到任何关于如何使用 nsIFontEnumerator 的信息。

Stackoverflow itself only has one question which sort of touches on the topic, which is unanswered: How to discover Font Type? Stackoverflow 本身只有一个与主题相关的问题,没有答案:如何发现字体类型?

The interface you refer to no longer exists in current Firefox versions.您提到的接口在当前的 Firefox 版本中不再存在。 What exists however is nsIFontEnumerator :然而存在的是nsIFontEnumerator

var enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
                           .getService(Components.interfaces.nsIFontEnumerator);
var fonts = enumerator.EnumerateAllFonts({});

It doesn't seem to be documented on MDC so http://www.oxymoronical.com/experiments/apidocs/interface/nsIFontEnumerator is the best reference you can get.它似乎没有在 MDC 上记录,因此http://www.oxymoronical.com/experiments/apidocs/interface/nsIFontEnumerator是您可以获得的最佳参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM