Skip to content

Commit 89d3885

Browse files
Use native font stack / remove vendored open-sans + lato fonts (#285)
Co-authored-by: Nicholas Bollweg <[email protected]>
1 parent f2d189a commit 89d3885

39 files changed

+98
-386
lines changed

docs/contributing.rst

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,31 +215,44 @@ Then run the tests by calling ``pytest`` from the repository root.
215215
Changing fonts
216216
--------------
217217

218-
Fonts are an important, performance-sensitive, but ultimately, subjective, part
219-
of the theme. The current font selections are:
218+
Three "styles" of the `FontAwesome 5 Free <https://fontawesome.com/icons?m=free>`__
219+
icon font are used for :ref:`icon links <icon-links>` and admonitions, and is
220+
the only `vendored` font. Further font choices are described in the :ref:`customizing`
221+
section of the user guide, and require some knowledge of HTML and CSS.
220222

221-
- managed as dependencies in ``package.json``
223+
.. Attention::
224+
225+
Previously-included fonts like `Lato` have been removed, preferring
226+
the most common default system fonts of the reader's computer. This provides
227+
both better performance, and better script/glyph coverage than custom fonts,
228+
and is recommended in most cases.
229+
230+
The remaining vendored font selection is:
231+
232+
- managed as a dependency in ``package.json``
222233

223-
- allowing the versions to be managed centrally
234+
- allowing the version to be managed centrally
224235

225236
- copied directly into the site statics, including licenses
226237

227-
- allowing the chosen fonts to be replaced (or removed entirely) with minimal
228-
templating changes
238+
- allowing the chosen font to be replaced (or removed entirely) with minimal
239+
templating changes: practically, changing the icon font is difficult at this
240+
point.
229241

230-
- partially preloaded (mostly icons)
242+
- partially preloaded
231243

232-
- reducing flicker and re-layout artifacts
244+
- reducing flicker and re-layout artifacts of early icon renders
233245

234246
- mostly managed in ``webpack.common.js``
235247

236-
- allowing upgrades to be handled in a relatively sane, manageable way
248+
- allowing upgrades to be handled in a relatively sane, manageable way, to
249+
ensure the most recent icons
237250

238251

239252
Upgrading a font
240253
^^^^^^^^^^^^^^^^
241254

242-
If *only* the version of an `existing` font must change, for example to enable
255+
If *only* the version of the `existing` font must change, for example to enable
243256
new icons, run:
244257

245258
.. code-block:: bash
@@ -255,21 +268,21 @@ Changing a font
255268
^^^^^^^^^^^^^^^
256269

257270
If the above doesn't work, for example if file names for an existing font change,
258-
or a new font altogether is being added, hand-editing of ``webpack.common.js`` is
259-
required. The steps are roughly:
271+
or a new font variant altogether is being added, hand-editing of ``webpack.common.js``
272+
is required. The steps are roughly:
260273

261274
- install the new font, as above, with ``yarn add``
262275
- in ``webpack.common.js``:
263276

264277
- add the new font to ``vendorVersions`` and ``vendorPaths``
265278
- add new ``link`` tags to the appropriate macro in ``macroTemplate``
266279
- add the new font files (including the license) to ``CopyPlugin``
267-
- remove referencs to the font being replaced/removed, if applicable
280+
- remove references to the font being replaced/removed, if applicable
268281

269282
- restart the development server, if running
270283
- rebuild the production assets, as above, with ``yarn build:production``
271284
- potentially remove the font being replaced from ``package.json`` and re-run ``yarn``
272-
- commit all of the changes files
285+
- commit all of the changed files
273286

274287

275288
Contributing changes

docs/user_guide/configuring.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ If you'd like it to link to another page or use an external link instead, use th
2929
}
3030
3131
32+
.. _icon-links:
33+
3234
Configure icon links
3335
====================
3436

docs/user_guide/customizing.rst

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ To add a custom stylesheet, follow these steps:
3030
3131
When you build your documentation, this stylesheet should now be activated.
3232

33+
.. _css-variables:
34+
3335
CSS Theme variables
3436
===================
3537

@@ -49,7 +51,7 @@ In order to change a variable, follow these steps:
4951
.. code-block:: none
5052
5153
:root {
52-
--font-size-base: 17px;
54+
--pst-font-size-base: 17px;
5355
}
5456
5557
For a complete list of the theme variables that you may override, see the
@@ -65,37 +67,60 @@ For a complete list of the theme variables that you may override, see the
6567
Replacing/Removing Fonts
6668
========================
6769

68-
The theme contains custom web fonts, in several formats, for different purposes:
70+
The theme includes the `FontAwesome 5 Free <https://fontawesome.com/icons?m=free>`__
71+
icon font (the ``.fa, .far, .fas`` styles, which are used for
72+
:ref:`icon links <icon-links>` and admonitions).
73+
This is the only `vendored` font, and otherwise the theme by default relies on
74+
available system fonts for normal body text and headers.
75+
76+
.. Attention::
77+
78+
Previously-included fonts like `Lato` have been removed, preferring
79+
the most common default system fonts of the reader's computer. This provides
80+
both better performance, and better script/glyph coverage than custom fonts,
81+
and is recommended in most cases.
82+
83+
The default body and header fonts can be changed as follows:
84+
85+
- Using :ref:`custom-css`, you can specify which fonts to use for body, header
86+
and monospace text. For example, the following can be added to a custom
87+
css file:
6988

70-
- "normal" body text, on ``body``
71-
- page and section headers, on ``.header-style``
72-
- icons, on ``.fa, .far, .fas``
89+
.. code-block:: none
7390
74-
While altering the icon font is presently somewhat involved, the body and header fonts,
75-
often paired together, can be replaced (or removed altogether) by:
91+
:root {
92+
--pst-font-family-base: Verdana, var(--pst-font-family-base-system);
93+
--pst-font-family-heading: Cambria, Georgia, Times, var(--pst-font-family-base-system);
94+
--pst-font-family-monospace: Courier, var(--pst-font-family-monospace-system);
95+
}
7696
77-
- configuring `template_path <https://www.sphinx-doc.org/en/master/theming.html#templating>`__
78-
in your ``conf.py``
79-
- creating a custom ``layout.html`` Jinja2 template which overloads the ``fonts`` block
97+
The ``-system`` variables are available to use as fallback to the default fonts.
8098

81-
.. code-block:: html+jinja
99+
- If the font you want to specify in the section above is not generally available
100+
by default, you will additionally need to ensure the font is loaded.
101+
For example, you could download and vendor the font in the ``_static`` directory
102+
of your Sphinx site, and then update the base template to load the font resources:
82103

83-
{% extends "pydata_sphinx_theme/layout.html" %}
104+
- Configure the `template_path <https://www.sphinx-doc.org/en/master/theming.html#templating>`__
105+
in your ``conf.py``
106+
- Create a custom ``layout.html`` Jinja2 template which overloads the ``fonts`` block
107+
(example for loading the Lato font that is included in the ``_static/vendor`` directory):
84108

85-
{% block fonts %}
109+
.. code-block:: html+jinja
110+
111+
{% extends "pydata_sphinx_theme/layout.html" %}
112+
113+
{% block fonts %}
86114
<!-- add `style` or `link` tags with your CSS `@font-face` declarations here -->
87-
<!-- ... and a `style` tag with setting `font-family` in `body` and `.header-style` -->
88115
<!-- ... and optionally preload the `woff2` for snappier page loads -->
89-
<!-- or add a `style` tag with a font fallback chain with good cross-platform coverage -->
90-
<style>
91-
body {
92-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
93-
}
94-
.header-style {
95-
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
96-
}
97-
</style>
98-
{% endblock %}
116+
<link rel="stylesheet" href="{{ pathto('_static/vendor/lato_latin-ext/1.44.1/index.css', 1) }}">
117+
118+
{% endblock %}
119+
120+
To reduce the `Flash of Unstyled Content`, you may wish to explore various options for
121+
`preloading content <https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content>`__,
122+
specifically the binary font files. This ensure the files will be loaded
123+
before waiting for the CSS to be parsed, but should be used with care.
99124

100125
.. _pydata-css-variables: https://github.com/pydata/pydata-sphinx-theme/blob/master/pydata_sphinx_theme/static/css/theme.css
101126
.. _css-variable-help: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
},
3232
"dependencies": {
3333
"@fortawesome/fontawesome-free": "^5.13.0",
34-
"@openfonts/lato_latin-ext": "^1.44.1",
35-
"@openfonts/open-sans_all": "^1.44.1",
3634
"bootstrap": "^4.4.1",
3735
"jquery": "3.5.1",
3836
"optimize-css-assets-webpack-plugin": "^5.0.3",

pydata_sphinx_theme/static/css/index.57d3cd9fdfd1e83932aa4eb4774f9fb9.css renamed to pydata_sphinx_theme/static/css/index.101715efdecc9b59cb6e1ddfa685c31f.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pydata_sphinx_theme/static/css/theme.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@
2323
/*****************************************************************************
2424
* Font family
2525
**/
26-
--pst-font-family-base: 'Lato', sans-serif;
27-
--pst-font-family-heading: 'Open Sans', sans-serif;
26+
/* These are adapted from https://systemfontstack.com/ */
27+
--pst-font-family-base-system: -apple-system, BlinkMacSystemFont, Segoe UI, "Helvetica Neue",
28+
Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
29+
--pst-font-family-monospace-system: "SFMono-Regular", Menlo, Consolas, Monaco,
30+
Liberation Mono, Lucida Console, monospace;
31+
32+
--pst-font-family-base: var(--pst-font-family-base-system);
33+
--pst-font-family-heading: var(--pst-font-family-base);
34+
--pst-font-family-monospace: var(--pst-font-family-monospace-system);
2835

2936
/*****************************************************************************
3037
* Color

pydata_sphinx_theme/static/vendor/lato_latin-ext/1.44.1/LICENSE.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

pydata_sphinx_theme/static/vendor/lato_latin-ext/1.44.1/index.css

Lines changed: 0 additions & 120 deletions
This file was deleted.

pydata_sphinx_theme/static/vendor/open-sans_all/1.44.1/LICENSE.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)