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

Skip to content

Commit 8a01d90

Browse files
aitikguptatacaswell
authored andcommitted
Add high-level documentation
1 parent a68f21f commit 8a01d90

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

doc/users/explain/fonts.rst

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

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

0 commit comments

Comments
 (0)