| 1 |
--- |
| 2 |
title: Font |
| 3 |
--- |
| 4 |
Represents a font, with one or more masters. |
| 5 |
## Font._formatspecific |
| 6 |
|
| 7 |
* Python type: `dict` |
| 8 |
|
| 9 |
|
| 10 |
Each object in Babelfont has an optional attached dictionary to allow the storage |
| 11 |
of format-specific information. Font creation software may store any additional |
| 12 |
information that they wish to have preserved on import and export under a |
| 13 |
namespaced (reverse-domain) key in this dictionary. For example, information |
| 14 |
specific to the Glyphs software should be stored under the key `com.glyphsapp`. |
| 15 |
The value stored under this key may be any data serializable in JSON; typically |
| 16 |
it will be a `dict`. |
| 17 |
|
| 18 |
Note that there is an important distinction between the Python object format |
| 19 |
of this field and the Babelfont-JSON representation. When stored to JSON, this key |
| 20 |
is exported not as `_formatspecific` but as a simple underscore (`_`). |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
## Font.upm |
| 25 |
|
| 26 |
* Python type: `int` |
| 27 |
|
| 28 |
The font's units per em. |
| 29 |
*If not provided, defaults to* `1000`. |
| 30 |
|
| 31 |
|
| 32 |
## Font.version |
| 33 |
|
| 34 |
* Python type: `(int, int)` |
| 35 |
|
| 36 |
* Babelfont-JSON type: `[int,int]` |
| 37 |
|
| 38 |
Font version number as a tuple of integers (major, minor). |
| 39 |
*If not provided, defaults to* `(1, 0)`. |
| 40 |
|
| 41 |
|
| 42 |
## Font.axes |
| 43 |
|
| 44 |
* Python type: [[`Axis`](Axis.html)] |
| 45 |
|
| 46 |
* When writing to Babelfont-JSON, each item in the list must be placed on a separate line. |
| 47 |
|
| 48 |
A list of axes, in the case of variable/multiple master font. May be empty. |
| 49 |
|
| 50 |
|
| 51 |
## Font.instances |
| 52 |
|
| 53 |
* Python type: [[`Instance`](Instance.html)] |
| 54 |
|
| 55 |
* When writing to Babelfont-JSON, each item in the list must be placed on a separate line. |
| 56 |
|
| 57 |
A list of named/static instances. |
| 58 |
|
| 59 |
|
| 60 |
## Font.masters |
| 61 |
|
| 62 |
* Python type: [[`Master`](Master.html)] |
| 63 |
|
| 64 |
* When writing to Babelfont-JSON, each item in the list must be placed on a separate line. |
| 65 |
|
| 66 |
A list of the font's masters. |
| 67 |
|
| 68 |
|
| 69 |
## Font.glyphs |
| 70 |
|
| 71 |
* Python type: `GlyphList` |
| 72 |
|
| 73 |
* Babelfont-JSON type: `[dict]` |
| 74 |
|
| 75 |
* When writing to Babelfont-JSON, this structure is stored under the separate file `glyphs.json`. |
| 76 |
|
| 77 |
* When writing to Babelfont-JSON, each item in the list must be placed on a separate line. |
| 78 |
|
| 79 |
A list of all glyphs supported in the font. |
| 80 |
|
| 81 |
The `GlyphList` structure in the Python object is a dictionary with array-like |
| 82 |
properties (or you might think of it as an array with dictionary-like properties) |
| 83 |
containing [`Glyph`](Glyph.html) objects. The `GlyphList` may be iterated |
| 84 |
directly, and may be appended to, but may also be used to index a `Glyph` by |
| 85 |
its name. This is generally what you want: |
| 86 |
|
| 87 |
```Python |
| 88 |
|
| 89 |
for g in font.glyphs: |
| 90 |
assert isinstance(g, Glyph) |
| 91 |
|
| 92 |
font.glyphs.append(newglyph) |
| 93 |
|
| 94 |
glyph_ampersand = font.glyphs["ampersand"] |
| 95 |
``` |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
## Font.note |
| 100 |
|
| 101 |
* Python type: `str` |
| 102 |
|
| 103 |
Any user-defined textual note about this font. |
| 104 |
*If not provided, defaults to* `None`. |
| 105 |
|
| 106 |
|
| 107 |
## Font.date |
| 108 |
|
| 109 |
* Python type: `datetime` |
| 110 |
|
| 111 |
* Babelfont-JSON type: `str` |
| 112 |
|
| 113 |
The font's date. When writing to Babelfont-JSON, this |
| 114 |
should be stored in the format `%Y-%m-%d %H:%M:%S`. *If not provided, defaults |
| 115 |
to the current date/time*. |
| 116 |
|
| 117 |
|
| 118 |
## Font.names |
| 119 |
|
| 120 |
* Python type: [`Names`](Names.html) |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
## Font.customOpenTypeValues |
| 126 |
|
| 127 |
* Python type: [[`OTValue`](OTValue.html)] |
| 128 |
|
| 129 |
Any values to be placed in OpenType tables on export to override defaults |
| 130 |
|
| 131 |
|
| 132 |
## Font.features |
| 133 |
|
| 134 |
* Python type: `FontFeatures` |
| 135 |
|
| 136 |
A representation of the font's OpenType features |
| 137 |
|
| 138 |
|