Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ffc56e

Browse files
committed
Add high-level documentation
1 parent 8f3f410 commit 6ffc56e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

doc/users/fonts.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,58 @@ This is especially helpful to generate *really lightweight* documents.::
128128
free versions of the proprietary fonts.
129129

130130
This also violates the *what-you-see-is-what-you-get* feature of Matplotlib.
131+
132+
Are we reinventing the wheel?
133+
-----------------------------
134+
Internally, a feasible response to the question of 'reinventing the
135+
wheel would be, well, Yes *and No*. The font-matching algorithm used
136+
by Matplotlib has been *inspired* by web browsers, more specifically,
137+
`CSS Specifications <http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_!
138+
139+
Currently, the simplest way (and the only way) to tell Matplotlib what fonts
140+
you want it to use for your document is via the **font.family** rcParam,
141+
see :doc:`Customizing text properties </tutorials/text/text_props>`.
142+
143+
This is similar to how one tells a browser to use multiple font families
144+
(specified in their order of preference) for their HTML webpages. By using
145+
**font-family** in their stylesheet, users can essentially trigger a very
146+
useful feature provided by browers, known as Font-Fallback. For example, the
147+
following snippet in an HTMl markup would:
148+
149+
.. code-block:: html
150+
151+
<style>
152+
someTag {
153+
font-family: Arial, Helvetica, sans-serif;
154+
}
155+
</style>
156+
157+
<!-- somewhere in the main body -->
158+
<someTag>
159+
some text
160+
</someTag>
161+
162+
163+
For every character/glyph in *"some text"*, the browser will iterate through
164+
the whole list of font-families, and check whether that character/glyph is
165+
available in that font-family. As soon as a font is found which has the
166+
required glyph(s), the browser moves on to the next character.
167+
168+
How does Matplotlib achieve this?
169+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
170+
Well, Matplotlib doesn't achieve this, *yet*. It was initially only designed to
171+
use a **single font** throughout the document, i.e., no matter how many
172+
families you pass to **font.family** rcParam, Matplotlib would use the very
173+
first font it's able to find on your system, and try to render all your
174+
characters/glyphs from that *and only that* font.
175+
176+
.. note::
177+
This is, because the internal font matching was written/adapted
178+
from a very old `CSS1 spec <http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_,
179+
**written in 1998**!
180+
181+
However, allowing multiple fonts for a single document (also enabling
182+
Font-Fallback) is one of the goals for 2021's Google Summer of Code project.
183+
184+
`Read more on Matplotblog <https://matplotlib.org/matplotblog/>`_!
185+

0 commit comments

Comments
 (0)