Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 37 additions & 44 deletions galleries/users_explain/text/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@

.. table:: Types of Fonts

+--------------------------+----------------------------+-------------------------------+
| Type 1 (PDF with usetex) | Type 3 (PDF/PS) | TrueType (PDF) / Type 42 (PS) |
+==========================+============================+===============================+
| Old font types introduced by Adobe. | Newer font type introduced by |
| | Apple; commonly used today. |
+--------------------------+----------------------------+-------------------------------+
| Restricted subset of | Full PostScript language, | Includes a virtual machine |
| PostScript, charstrings | allows embedding arbitrary | that can execute code. |
| are in bytecode. | code. | |
+--------------------------+----------------------------+-------------------------------+
| Supports font hinting. | Does not support font | Supports font hinting, |
| | hinting. | through the virtual machine. |
+--------------------------+----------------------------+-------------------------------+
| Subsetted by code in | Subsetted via external module |
| `matplotlib._type1font`. | `fontTools <https://github.com/fonttools/fonttools>`__. |
+--------------------------+----------------------------+-------------------------------+
+------------------------+--------------------------+-----------------------------+
| Type 1 (PDF usetex) | Type 3 (PDF/PS) | TrueType (PDF) / Type 42 PS |
+========================+==========================+=============================+
| Old font types introduced by Adobe. | Newer font type introduced |
| | by Apple; commonly used. |
+------------------------+--------------------------+-----------------------------+
| Restricted subset of | Full PostScript language,| Includes a virtual machine |
| PostScript, | allows embedding | that can execute code. |
| charstrings in bytecode| arbitrary code. | |
+------------------------+--------------------------+-----------------------------+
| Supports font hinting. | Does not support font | Supports font hinting, via |
| | hinting. | the virtual machine. |
+------------------------+--------------------------+-----------------------------+
| Subsetted by code in | Subsetted via external module |
| `_type1font`. | `fontTools <https://github.com/fonttools/fonttools>`__. |
+------------------------+--------------------------+-----------------------------+

.. note::

Expand Down Expand Up @@ -155,32 +155,25 @@
Font fallback
-------------

There is no font that covers the entire Unicode space thus it is possible for the
users to require a mix of glyphs that cannot be satisfied from a single font.
While it has been possible to use multiple fonts within a Figure, on distinct
`.Text` instances, it was not previous possible to use multiple fonts in the
same `.Text` instance (as a web browser does). As of Matplotlib 3.6 the Agg,
SVG, PDF, and PS backends will "fallback" through multiple fonts in a single
`.Text` instance:

.. plot::
:include-source:
:caption: The string "There are 几个汉字 in between!" rendered with 2 fonts.

fig, ax = plt.subplots()
ax.text(
.5, .5, "There are 几个汉字 in between!",
family=['DejaVu Sans', 'Noto Sans CJK JP', 'Noto Sans TC'],
ha='center'
)

Internally this is implemented by setting The "font family" on
`.FontProperties` objects to a list of font families. A (currently)
private API extracts a list of paths to all of the fonts found and then
constructs a single `.ft2font.FT2Font` object that is aware of all of the fonts.
Each glyph of the string is rendered using the first font in the list that
contains that glyph.

A majority of this work was done by Aitik Gupta supported by Google Summer of
Code 2021.
As of Matplotlib 3.6 the Agg, SVG, PDF, and PS backends will "fallback" through multiple fonts in a single `.Text` instance. For example, the string "There are 几个汉字 in between!" is rendered with 2 fonts:
""" # noqa: E501

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.text(
.5, .5, "There are 几个汉字 in between!",
family=['DejaVu Sans', 'Noto Sans CJK JP', 'Noto Sans TC'],
ha='center'
)

# %%
# Internally this is implemented by setting The "font family" on
# `.FontProperties` objects to a list of font families. A (currently)
# private API extracts a list of paths to all of the fonts found and then
# constructs a single `.ft2font.FT2Font` object that is aware of all of the fonts.
# Each glyph of the string is rendered using the first font in the list that
# contains that glyph.
#
# A majority of this work was done by Aitik Gupta supported by Google Summer of
# Code 2021.
1 change: 1 addition & 0 deletions galleries/users_explain/text/pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,4 @@
.. _LaTeX: http://www.tug.org
.. _TeXLive: http://www.tug.org/texlive/
"""
# sphinx_gallery_thumbnail_path = '_static/pgf_preamble.png'
2 changes: 2 additions & 0 deletions galleries/users_explain/text/usetex.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,5 @@
.. _underscore: https://ctan.org/pkg/underscore
.. _Xpdf: http://www.xpdfreader.com/
"""
# sphinx_gallery_thumbnail_path = (
# '/gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png')
Loading