微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何安装用于 rinohtype/sphinx 的系统 (Windows 10) 字体?

如何解决如何安装用于 rinohtype/sphinx 的系统 (Windows 10) 字体?

首先,我是 Python/Sphinx/rinohtype 的初学者。

我正在尝试弄清楚如何安装用于 rinohtype/Sphinx 的字体,rinohtype 安装了一些字体,但我希望使用安装在我的 Windows 10 系统上的字体,比如 Arial,我已经浏览了rinohtype 文档正在寻找指导,但一直无法解决这个问题。

编辑:输出如下:

rinohtype 0.5.3 (2021-06-16)  copyright (c) Brecht Machiels and contributors
This program comes with ABSOLUTELY NO WARRANTY. Its use is subject
to the terms of the GNU Affero General Public License version 3.
rendering...
References cache read from C:\Users\marjohloo\Documents\Sphinx\Test\_build\rinoh\lxr.rtc
Typeface 'Arial' is not installed; searching Google Fonts.
-> not found: please check the typeface name (case-sensitive!)

Exception occurred:
  File "c:\users\marjohloo\appdata\local\programs\python\python39\lib\site-packages\rinoh\resource.py",line 42,in parse_string
    raise ResourceNotFound(cls,resource_name,entry_point_name)
rinoh.resource.ResourceNotFound: (<class 'rinoh.font.Typeface'>,'ARIAL','arial')

解决方法

rinohtype 尚不支持使用系统字体 (issue #75)。不幸的是,字体支持也没有被正确记录(但这是一个开始)。您当前的字体选项是:

  1. 为 rinohtype 和 published on PyPI 打包的免费字体(rinoh-typeface-* 包)
  2. Google Fonts 上可用的 1000 多种字体中的任何一种。如果未安装样式表中指定的字体,rinohtype 将在 Google Fonts 上搜索该字体,下载并安装它。请注意,样式表中的字体名称需要与 Google Fonts 上的字体名称完全匹配(区分大小写)。
  3. 创建您自己的 Python 包,使字体可用于 rinohtype。示例如下。
  4. (我正在努力将 Microsoft Core Fonts for the Web 作为包在 PyPI 上提供,但由于许可限制,这涉及到一些障碍。当实现时我会更新此答案。)

您可以使用 rinoh 列出已安装的字体:

rinoh --list-fonts

具体来说,对于 Arial,您可以考虑使用 TeX Gyre Heros 字体代替。 TeX Gyre 字体集提供了许多其他流行字体的免费替代品,包括 Times、Helvetica (Arial)、Courier 和 Palatino。

如果你想要真正的东西,你可以为 Arial 创建你自己的字体包。您可以使用 rinoh-typeface-carlito 作为模板。

如果您使用的是 Sphinx,则无需创建和安装 Python 包。您可以创建此 fonts.py 文件并将其导入您的 Sphinx conf.py(在 sys.path.insert(0,os.path.abspath('.')) 之后):

from pathlib import Path

from rinoh import register_typeface
from rinoh.font import Typeface
from rinoh.font.opentype import OpenTypeFont


FONTS_DIR = Path(r'C:\Windows\Fonts')


def otf(filename,**kwargs):
    return OpenTypeFont(str(FONTS_DIR / filename),**kwargs)


arial = Typeface('Arial',otf('arial.ttf'),otf('arialbd.ttf'),otf('ariali.ttf'),otf('arialbi.ttf'),)
register_typeface('arial',arial)

我敢肯定,对于不熟悉 Python 的人来说,这并不容易。如果您需要更多信息,请告诉我。不过,随着 rinohtype 的成熟,这种情况应该会有所改善。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。