如何让 Firefox 使用 Helvetica、Times 等 MS TrueType 字体?

如何让 Firefox 使用 Helvetica、Times 等 MS TrueType 字体?

我在 Ubuntu 工作站上使用 (Windows) TrueType 字体 (细节),并且对字体的外观非常满意,无论是在桌面应用程序还是在网络上(使用 Firefox)。

然而,在某些网页上,像这个,字体太烂了:

截屏

我发现原因在于Helvetica该网站的 CSS:

font-family: Helvetica,Arial,Tahoma,sans-serif;

当我使用 Firebug 从列表中删除 Helvetica 时,它会使用 Arial 并且再次看起来很漂亮:

替代文本

我的问题是,如何让使用 Helvetica(或 Times 或其他类似字体)的网页自动看起来美观?换句话说,如何将 Times 和 Helvetica 字体系列映射到衬线和无衬线默认字体(在我的情况下分别为 Times New Roman 和 Arial)?

我对任何使 Firefox 在这种情况下使用 MS TrueType 字体的解决方案都感兴趣,无论它是基于调整 Ubuntu 字体配置还是 Firefox 中的自定义 CSS 规则(或我目前不知道的其他内容)。

更新:我现在已经完全解决了这个问题 -这个答案描述了我需要做的事情。

答案1

编辑:在得到同事的一些突破性建议后,我彻底更新了这个答案。

这是我插入的内容/etc/fonts/local.conf(在<fontconfig>元素内部):

<!-- Replace Helvetica with Arial -->
<match target="pattern">
    <test qual="any" name="family">
        <string>Helvetica</string>
    </test>
    <edit name="family" mode="assign" binding="strong">
        <string>Arial</string>
    </edit>
</match>    

Times -> Times New Roman 也类似。(查看我的完整local.conf 这里)关键是使用绑定="strong"对于<edit>元素。(此外,使用“assign_replace”模式代替“assign”也会导致类似的结果,只不过它太过激进:Verdana 也会被 Arial 取代)。

字体配置的更改会立即生效。除了在 Firefox 中测试外,您还可以通过以下方式检查其是否有效:

$ fc-match helvetica
Arial.ttf: "Arial" "Normal"

如果你遇到问题,最好的帮助就在附近:man fonts-conf。(尽管有文档,字体系统的工作原理对我来说似乎有些复杂或笨拙。)你也可以尝试使用以下命令“调试”到底发生了什么:

FC_DEBUG=4 fc-match helvetica

此外,还FC_DEBUG=1024 fc-match helvetica显示影响字体匹配的配置文件列表。

答案2

我在 Opera 中遇到了类似的问题,解决方法是在配置中禁用“Core X Fonts”。我建议看看 Firefox 中是否有类似的选项。

其他选择:

  • 检查您是否确实没有安装名为“Helvetica”的字体,类似的事情发生在我身上几次。如果我没记错的话,问题字体位于名为100dpi75dpi系统字体文件夹的文件夹中(/usr/local/share/fonts我认为)。我刚刚将这些文件夹完全移出那里。
  • 检查下面的默认值系统 > 首选项 > 外观 > 字体
  • 检查 Firefox 的默认设置偏好设置 > 内容

如果您对核心文件夹进行了更改,则需要使用以下命令重建字体缓存:

sudo fc-cache -f -v

答案3

油脂猴将会是您的问题的解决方案之一。安装此插件后,您可以自定义网页并更改字体。

以及一个将字体更改为 Helvita 的示例脚本

// ==UserScript==
// @name           Google Reader Font in Helvetica and enlarged
// @version        1.0
// @creator        Joe
// @description    Changes the font family and size from Google Reader page
// @namespace      userscripts.org
// @include        https://www.google.com/reader/*
// @include        http://www.google.com/reader/*

// ==/UserScript==

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

addGlobalStyle('.entry-body{font-family:Helvetica;font-size:110%;line-height:150%;}');
addGlobalStyle('A.entry-title-link {font-family:Helvetica;font-size: 20px;}');

答案4

无论如何您都需要向该脚本添加“Grant”......

Greasemonkey 1.0 添加了一个特殊的元数据块命令:@grant。

If a script does not specify any @grant values, Greasemonkey 1.0-1.9 will attempt to auto-detect the right settings. From GreaseMonkey 2.0, @grant none is assumed by default, if no other values are specified.[1]
If a script specifies any values (or they were auto detected), then it will be provided with only those API methods that it declares.
    The valid values are unsafeWindow, and the names of those GM_ prefixed values that you wish your script to be granted access to.
Otherwise the script will be granted no special API privileges, and thus run without the security constraints Greasemonkey scripts have traditionally had. If you want your script to operate in this mode, you should explicitly declare @grant none.

例子

脚本(上次统计时超过一半)通常根本不使用任何特殊 API。对于此类脚本,明确要求不授予任何特殊权限意味着脚本将直接在内容页面中执行。这意味着没有安全沙箱,也没有任何限制,因此可以访问页面中的变量,调用函数并读取其结果也可以。为此,只需:

// ==UserScript==
// @name        Grant None Example (can be omitted since GM 2.0)
// @include     http*
// @grant       none
// ==/UserScript==
console.log('This script grants no special privileges, so it runs without security limitations.');

如果您确实使用了 Greasemonkey 的 API 之一,您应该明确要求将其授予您的脚本:

// ==UserScript==
// @name        Grant Some Example
// @include     http*
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

var counter = GM_getValue('counter', 0);
console.log('This script has been run ' + counter + ' times.');
GM_setValue('counter', ++counter);

在这种情况下,脚本要求授予对 和 的访问权限GM_getValueGM_setValue每行一个@grant。指定要授予访问权限的任何 Greasemonkey API 的名称。(所有脚本始终都会获得访问权限,而GM_info无需特别请求。)暂时,这也可以工作:

// ==UserScript==
// @name        Grant Legacy Example
// @include     http*
// ==/UserScript==

var counter = GM_getValue('counter', 0);
console.log('This script has been run ' + counter + ' times.');
GM_setValue('counter', ++counter);

此示例将在 Greasemonkey 1.0 版中运行。当没有 @grant 行时,Greasemonkey 会尝试检测正在使用哪些 API,并像已指定这些 @grant 行一样进行操作。在某些情况下,尤其是在eval()使用 时,此检测可能会失败。

由于这一点,在 @grant 之前编写的所有脚本都应该可以继续工作,但您应尽早更改脚本以指定 @grant,以免将来出现问题。兼容层

许多 Greasemonkey API 已被 DOM Storage 等 Web 标准所复制。如果您只希望脚本在单个域上运行,则可以立即使用 @grant none 及其增强的兼容性,而不会产生任何缺点。只需使用 @require 库即可使用现在标准的浏览器功能模拟 Greasemonkey API:

// ==UserScript==
// @name        Grant None Example, With Shim
// @include     http://www.example.com/*
// @grant       none
// @require     https://gist.githubusercontent.com/arantius/3123124/raw/grant-none-shim.js
// ==/UserScript==

var counter = GM_getValue('counter', 0);
console.log('This script has been run ' + counter + ' times.');
GM_setValue('counter', ++counter);

此脚本的工作方式与上述示例相同,只是 grant none shim 提供具有标准浏览器功能的 API 模拟。当 shim 兼容层对您的脚本运行良好时,这是两全其美的选择。范围

在授予 none 的情况下,用户脚本仍然具有自己的全局作用域,与内容页面的全局作用域不同。这意味着顶级作用域var x = 1;对内容作用域不可见,因此不会破坏页面(即如果它依赖于具有不同值的变量 x)。要将值写入内容作用域,请执行window.x = 1;

如果您使用的@require是 jQuery 版本,它将隐式分配给window.$window.jQuery。如果您运行的页面依赖于不同版本的 jQuery,那么这可能会破坏页面。要解决此问题,请在脚本顶层的任意位置执行:

this.$ = this.jQuery = jQuery.noConflict(true);

此代码将保存一个 jQuery 引用(保存到此,即在授予无模式下运行时脚本的全局范围),同时将其从窗口(内容全局范围)中删除并恢复最初存储在那里的所有内容。

相关内容