How to Install system (Windows 10) fonts for use with rinohtype/sphinx?

Question:

First I’m very much a beginner with Python/Sphinx/rinohtype.

I’m trying to figure out how to install fonts for use with rinohtype/Sphinx, rinohtype installs some fonts but I’m looking to use the fonts installed on my Windows 10 system, like Arial, I’ve trawled through the rinohtype docs looking for guidance but have been unable to figure this out.

Edit: output is as follows:

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:UsersmarjohlooDocumentsSphinxTest_buildrinohlxr.rtc
Typeface 'Arial' is not installed; searching Google Fonts.
-> not found: please check the typeface name (case-sensitive!)

Exception occurred:
  File "c:usersmarjohlooappdatalocalprogramspythonpython39libsite-packagesrinohresource.py", line 42, in parse_string
    raise ResourceNotFound(cls, resource_name, entry_point_name)
rinoh.resource.ResourceNotFound: (<class 'rinoh.font.Typeface'>, 'ARIAL', 'arial')
Asked By: marjohloo

||

Answers:

rinohtype does not yet support using system fonts (issue #75). Font support neither is properly documented yet, unfortunately (but this is a start). Your font options are currently:

  1. Free fonts packaged for rinohtype and published on PyPI (rinoh-typeface-* packages)
  2. Any of the 1000+ fonts available on Google Fonts. If a typeface specified in your style sheet is not installed, rinohtype will search the font on Google Fonts, download and install it. Note that the typeface name in your style sheet needs to match the font name on Google Fonts exactly (case-sensitive).
  3. The Microsoft Core Fonts for the Web are available as packages on PyPI. See rinoh-mscorefonts for the full list.
  4. Create your own Python package to make fonts available to rinohtype. Example included below.

You can list the installed fonts using rinoh:

rinoh --list-fonts

Specifically, for Arial, you can consider using TeX Gyre Heros font instead. The TeX Gyre font collection offers free alternatives for a number of other popular fonts, including Times, Helvetica (Arial), Courier and Palatino.

If you want the real thing instead, you can create your own font package for Arial. You can use rinoh-typeface-carlito as a template for that.

If you’re using Sphinx, you do not need to create and install a Python package. You can create this fonts.py file and import it in your Sphinx conf.py (after 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:WindowsFonts')


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)

I’m sure this is not straightforward for anyone who’s not familiar with Python. Let me know if you need more info. This situation should improve as rinohtype matures, however.

Answered By: Brecht Machiels
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.