@@ -19,9 +19,9 @@ Fonts in PDF and PostScript
19
19
---------------------------
20
20
21
21
Fonts have a long (and sometimes incompatible) history in computing, leading to
22
- different platforms supporting different types of fonts. In practice, there
23
- are 3 types of font specifications Matplotlib supports (in addition to 'core
24
- fonts' in pdf which is explained later in the guide):
22
+ different platforms supporting different types of fonts. In practice,
23
+ Matplotlib supports three font specifications (in addition to pdf 'core fonts',
24
+ which are explained later in the guide):
25
25
26
26
.. list-table :: Type of Fonts
27
27
:header-rows: 1
@@ -40,33 +40,35 @@ fonts' in pdf which is explained later in the guide):
40
40
- Do not support font hinting
41
41
- Hinting supported (virtual machine processes the "hints")
42
42
* - Non-subsetted through Matplotlib
43
- - Subsetted via external module ` ttconv < https://github.com/sandflow/ttconv >`_
44
- - Subsetted via external module `fonttools <https://github.com/fonttools/fonttools >`__
43
+ - Subsetted via external module ttconv
44
+ - Subsetted via external module `fontTools <https://github.com/fonttools/fonttools >`__
45
45
46
- NOTE: Adobe will disable support for authoring with Type 1 fonts in
47
- January 2023. `Read more here. <https://helpx.adobe.com/fonts/kb/postscript-type-1-fonts-end-of-support.html >`_
46
+ .. note ::
48
47
48
+ Adobe disabled __ support for authoring with Type 1 fonts in January 2023.
49
+
50
+ __ https://helpx.adobe.com/fonts/kb/postscript-type-1-fonts-end-of-support.html
49
51
50
52
Other font specifications which Matplotlib supports:
51
53
52
54
- Type 42 fonts (PS):
53
55
54
56
- PostScript wrapper around TrueType fonts
55
57
- 42 is the `Answer to Life, the Universe, and Everything! <https://en.wikipedia.org/wiki/Answer_to_Life,_the_Universe,_and_Everything >`_
56
- - Matplotlib uses an external library called ` fonttools <https://github.com/fonttools/fonttools >`__
58
+ - Matplotlib uses the external library ` fontTools <https://github.com/fonttools/fonttools >`__
57
59
to subset these types of fonts
58
60
59
61
- OpenType fonts:
60
62
61
63
- OpenType is a new standard for digital type fonts, developed jointly by
62
64
Adobe and Microsoft
63
65
- Generally contain a much larger character set!
64
- - Limited Support with Matplotlib
66
+ - Limited support with Matplotlib
65
67
66
- Font Subsetting
68
+ Font subsetting
67
69
~~~~~~~~~~~~~~~
68
70
69
- The PDF and PostScript formats support embedding fonts in files allowing the
71
+ The PDF and PostScript formats support embedding fonts in files, allowing the
70
72
display program to correctly render the text, independent of what fonts are
71
73
installed on the viewer's computer and without the need to pre-rasterize the text.
72
74
This ensures that if the output is zoomed or resized the text does not become
@@ -79,10 +81,9 @@ only embed the glyphs actually used. This gets both vector text and small
79
81
files sizes. Computing the subset of the font required and writing the new
80
82
(reduced) font are both complex problem and thus Matplotlib relies on
81
83
`fontTools <https://fonttools.readthedocs.io/en/latest/ >`__ and a vendored fork
82
- of `ttconv <https://github.com/sandflow/ttconv >`_.
83
-
84
- Currently Type 3, Type 42, and TrueType fonts are subseted. Type 1 fonts are not.
84
+ of ttconv.
85
85
86
+ Currently Type 3, Type 42, and TrueType fonts are subsetted. Type 1 fonts are not.
86
87
87
88
Core Fonts
88
89
~~~~~~~~~~
@@ -91,11 +92,11 @@ In addition to the ability to embed fonts, as part of the `PostScript
91
92
<https://en.wikipedia.org/wiki/PostScript_fonts#Core_Font_Set> `_ and `PDF
92
93
specification
93
94
<https://docs.oracle.com/cd/E96927_01/TSG/FAQ/What%20are%20the%2014%20base%20fonts%20distributed%20with%20Acroba.html> `_
94
- there are 14 Core Font that compliant viewers must ensure are available. If
95
+ there are 14 Core Fonts that compliant viewers must ensure are available. If
95
96
you restrict your document to only these fonts you do not have to embed any
96
97
font information in the document but still get vector text.
97
98
98
- This is especially helpful to generate *really lightweight * documents. ::
99
+ This is especially helpful to generate *really lightweight * documents::
99
100
100
101
# trigger core fonts for PDF backend
101
102
plt.rcParams["pdf.use14corefonts"] = True
@@ -109,7 +110,6 @@ This is especially helpful to generate *really lightweight* documents.::
109
110
fig.savefig("AFM_PDF.pdf", format="pdf")
110
111
fig.savefig("AFM_PS.ps", format="ps)
111
112
112
-
113
113
Fonts in SVG
114
114
------------
115
115
@@ -118,12 +118,11 @@ Text can output to SVG in two ways controlled by :rc:`svg.fonttype`:
118
118
- as a path (``'path' ``) in the SVG
119
119
- as string in the SVG with font styling on the element (``'none' ``)
120
120
121
-
122
121
When saving via ``'path' `` Matplotlib will compute the path of the glyphs used
123
- as vector paths and write those to the output. The advantage of this is that
124
- the SVG will look the same on all computers independent of what fonts are
122
+ as vector paths and write those to the output. The advantage of doing so is
123
+ that the SVG will look the same on all computers independent of what fonts are
125
124
installed. However the text will not be editable after the fact.
126
- In contrast saving with ``'none' `` will result in smaller files and the
125
+ In contrast, saving with ``'none' `` will result in smaller files and the
127
126
text will appear directly in the markup. However, the appearance may vary
128
127
based on the SVG viewer and what fonts are available.
129
128
@@ -135,11 +134,10 @@ To output text to raster formats via Agg, Matplotlib relies on `FreeType
135
134
changes between FreeType versions we pin to a specific version for our image
136
135
comparison tests.
137
136
138
-
139
137
How Matplotlib selects fonts
140
138
----------------------------
141
139
142
- Internally using a Font in Matplotlib is a three step process:
140
+ Internally, using a font in Matplotlib is a three step process:
143
141
144
142
1. a `.FontProperties ` object is created (explicitly or implicitly)
145
143
2. based on the `.FontProperties ` object the methods on `.FontManager ` are used
@@ -153,16 +151,16 @@ specified by the `CSS1 Specifications
153
151
<http://www.w3.org/TR/1998/REC-CSS2-19980512/> `_ which is used by web browsers.
154
152
This algorithm takes into account the font family name (e.g. "Arial", "Noto
155
153
Sans CJK", "Hack", ...), the size, style, and weight. In addition to family
156
- names that map directly to fonts there are five "generic font family names" (
157
- serif, monospace, fantasy, cursive, and sans-serif) that will internally be
154
+ names that map directly to fonts there are five "generic font family names"
155
+ ( serif, monospace, fantasy, cursive, and sans-serif) that will internally be
158
156
mapped to any one of a set of fonts.
159
157
160
158
Currently the public API for doing step 2 is `.FontManager.findfont ` (and that
161
159
method on the global `.FontManager ` instance is aliased at the module level as
162
160
`.font_manager.findfont `), which will only find a single font and return the absolute
163
161
path to the font on the filesystem.
164
162
165
- Font Fallback
163
+ Font fallback
166
164
-------------
167
165
168
166
There is no font that covers the entire Unicode space thus it is possible for the
@@ -173,7 +171,6 @@ same `.Text` instance (as a web browser does). As of Matplotlib 3.6 the Agg,
173
171
SVG, PDF, and PS backends will "fallback" through multiple fonts in a single
174
172
`.Text ` instance:
175
173
176
-
177
174
.. plot ::
178
175
:include-source:
179
176
:caption: The string "There are 几个汉字 in between!" rendered with 2 fonts.
@@ -185,7 +182,6 @@ SVG, PDF, and PS backends will "fallback" through multiple fonts in a single
185
182
ha='center'
186
183
)
187
184
188
-
189
185
Internally this is implemented by setting The "font family" on
190
186
`.FontProperties ` objects to a list of font families. A (currently)
191
187
private API extracts a list of paths to all of the fonts found and then
0 commit comments