Skip to content

Commit 72a27f7

Browse files
committed
Document Types of Fonts and Subsetting
1 parent d156771 commit 72a27f7

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

doc/users/fonts.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
All about Matplotlib and Fonts!
2+
===============================
3+
4+
The story of fonts has been quite eventful throughout time. It involves
5+
contributions of tech giants such as the likes of Adobe, Apple and Microsoft.
6+
7+
Types
8+
-----
9+
In practice, there are 3 types Matplotlib supports:
10+
11+
.. list-table:: Type of Fonts
12+
:header-rows: 1
13+
14+
* - Type 1 (PDF)
15+
- Type 3 (PDF/PS)
16+
- TrueType (PDF)
17+
* - One of the oldest types, introduced by Adobe
18+
- Similar to Type 1 in terms of introduction
19+
- Newer than previous types, most commonly used today, introduced by Apple
20+
* - They use simplified PostScript
21+
(subset of full PostScript language)
22+
- However, they use full PostScript language, which allows embedding
23+
arbitrary code!
24+
(in theory, even render fractals when rasterizing!)
25+
- They include a virtual machine that can execute code!
26+
* - These fonts support font hinting
27+
- Do not support font hinting
28+
- Hinting supported (virtual machine processes the "hints")
29+
* - Expressed in pretty compact bytecode
30+
- Expressed in simple ASCII form
31+
- Expressed in binary code points
32+
* - Difficult to subset!
33+
- Easy to subset!
34+
- Very hard to subset!
35+
36+
NOTE: Adobe will disable support for authoring with Type 1 fonts in
37+
January 2023. `Read more here. <https://helpx.adobe.com/fonts/kb/postscript-type-1-fonts-end-of-support.html>`_
38+
39+
Special Mentions
40+
~~~~~~~~~~~~~~~~
41+
- Type 42 fonts (PS):
42+
43+
- PostScript wrapper around TrueType fonts
44+
- 42 is the `Answer to Life, the Universe, and Everything! <https://en.wikipedia.org/wiki/Answer_to_Life,_the_Universe,_and_Everything>`_
45+
- Very hard to subset!
46+
47+
- OpenType fonts:
48+
49+
- OpenType is a new standard for digital type fonts, developed jointly by
50+
Adobe and Microsoft
51+
- Generally contain a much larger character set!
52+
- Limited Support with Matplotlib
53+
54+
55+
Subsetting
56+
----------
57+
Matplotlib is able to generate documents in multiple different formats. Some of
58+
those formats (for example, PDF, PS/EPS, SVG) allow embedding font data in such
59+
a way that when these documents are visually scaled, the text does not appear
60+
pixelated.
61+
62+
This can be achieved by virtually embedding the *whole* font file within the
63+
output document. However, this can lead to **very large documents**, wherein
64+
most of the size bandwidth is captured by that font file data.
65+
66+
Font Subsetting is a way to embed only the *required* glyphs within the
67+
documents. Fonts can be considered as a collection of glyphs, so ultimately the
68+
goal is to find out *which* glyphs are required for a certain piece of text,
69+
and embed only those within the output.
70+
71+
Since there is almost no consistency within multiple different backends and the
72+
types of subsetting, this is generally difficult! Luckily, Matplotlib uses a
73+
fork of an external dependency called
74+
`ttconv <https://github.com/sandflow/ttconv>`_, which helps in embedding and
75+
subsetting stuff. (however, recent versions have moved away from ttconv to pure
76+
Python)
77+
78+
| *Type 1 fonts are still non-subsetted* through Matplotlib.
79+
| **Type 3 and Type 42 fonts are subsetted**, with a fair amount of exceptions and bugs for the latter.

doc/users/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ User's Guide
1515
installing.rst
1616
../tutorials/index.rst
1717
interactive.rst
18+
fonts.rst
1819
release_notes.rst
1920
history.rst
2021
license.rst

0 commit comments

Comments
 (0)