Debian Codegraph @

Doc/source/ttLib/ttFont.rst

raw
1 ####################################
2 ttFont: Read and write font contents
3 ####################################
4
5 .. contents:: On this page:
6 :local:
7
8 .. rubric:: Overview
9 :heading-level: 2
10
11 :mod:`.ttLib.ttFont` is the primary fontTools interface for
12 inspecting, constructing, or deconstructing TrueType and OpenType
13 fonts.
14
15 The :class:`fontTools.ttLib.ttFont.TTFont` class provides access to
16 font-level data, including font metrics, substitution and positioning
17 features, and metadata, through a set of :doc:`table converters
18 </ttLib/tables>`. A :class:`.TTFont` may be instantiated from a single
19 font file, or it may be a member of a
20 :class:`.TTCollection`. :class:`.TTFont` objects can also be
21 constructed from scratch.
22
23
24 glyphSets and ttGlyphs
25 ----------------------
26
27 In addition to font-wide data, :mod:`.ttLib.ttFont` provides access to
28 individual glyphs through a :class:`.TTFont` instance's
29 ``.glyphSet[]`` attribute. A ``.glyphSet`` is a dict-like object that is
30 indexed by glyph names. Users can use the glyphSet to interact with
31 each glyph's contours, components, points, and glyph metrics.
32
33 Informally, some fontTools code or documentation will make reference to
34 the individual glyphs in a ``.glyphSet`` as a "ttGlyph" or the
35 like. This is convenient terminology, particularly for
36 discussion. However, it is important to note that there is not a
37 "ttGlyph" class. Instead, the ``.glyphSet`` attribute of a
38 :class:`.TTFont` serves as an abstraction layer that provides a
39 uniform interface to the glyphs, regardless of whether the
40 :class:`.TTFont` instance in use comes from a font file with
41 TrueType-flavored glyphs (and, therefore, has a `glyf` table
42 containing glyph contours) or a font with PostScript-flavored outlines
43 (and, therefore, with a ``CFF`` or ``CFF2`` table containing the glyph
44 contours).
45
46 Regardless of the flavor, each "ttGlyph" entry in the ``.glyphSet``
47 includes the corresponding Bezier outlines and components from the
48 ``glyf`` or ``CFF``/``CFF2`` table and the glyph's metrics. Horizontal
49 metrics are drawn from the font's ``hmtx`` table, and vertical metrics
50 (if any) are drawn from the ``vmtx`` table. These attributes are:
51
52 width
53 The advance width of the glyph
54
55 lsb
56 The left sidebearing of the glyph
57
58 height
59 (For vertical-layout fonts) The advance height of the glyph
60
61 tsb
62 (for vertical-layout fonts) The top sidebearing of the glyph
63
64 Note that these attributes do not describe the bounding box of the
65 glyph filled shape, because the filled area might include negative
66 coordinate values or extend beyond the advance width due to overhang.
67
68 The bounds of the glyph are accessible as ``xMin``, ``xMax``,
69 ``yMin``, and ``yMax`` attributes.
70
71 For implementation details regarding the different flavors of
72 "ttGlyph", see the :doc:`ttGlyphSet </ttLib/ttGlyphSet>`
73 documentation.
74
75 These glyph objects also implement the :doc:`Pen Protocol
76 </pens/index>` by providing ``.draw()`` and ``.drawPoints()``
77 methods. See the :doc:`pens </pens/index>` package documenation
78 for more.
79
80
81 Package contents
82 ----------------
83
84
85 .. autoclass:: fontTools.ttLib.ttFont.TTFont
86 :members:
87 :undoc-members:
88
89
90
91 .. autoclass:: fontTools.ttLib.ttFont.GlyphOrder
92 :members:
93 :undoc-members:
94 :private-members:
95
96
97 .. automodule:: fontTools.ttLib.ttFont
98 :members: getTableModule, registerCustomTableClass, unregisterCustomTableClass, getCustomTableClass, getClassTag, newTable, tagToIdentifier, identifierToTag, tagToXML, xmlToTag, sortedTagList, reorderFontTables
99 :exclude-members: TTFont, GlyphOrder