Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
Binary file added doc/_static/usetex_tutorial.png
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the image in the tutorial, which is likely saved somewhere

Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced it with a figure that matches the first image embedded in the tutorial — the cosine wave with the "TeX is Number" formula title, rendered via mathtext (no LaTeX required for the static image). If you'd prefer a different image from the tutorial, happy to swap it out

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the goal is no saved image/use the one that's already embedded in the file

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Comment thread
story645 marked this conversation as resolved.

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'
1 change: 1 addition & 0 deletions galleries/users_explain/text/usetex.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@
.. _underscore: https://ctan.org/pkg/underscore
.. _Xpdf: http://www.xpdfreader.com/
"""
# sphinx_gallery_thumbnail_path = '_static/usetex_tutorial.png'
Loading