| 1 |
h1. Compositor Usage Reference |
|---|
| 2 |
|
|---|
| 3 |
This document covers the basic usage of the compositor package. For more detailed information read the documentation strings in the source. |
|---|
| 4 |
|
|---|
| 5 |
h2. Asumptions |
|---|
| 6 |
|
|---|
| 7 |
Some assumptions about the OpenType fonts being used are made by the package: |
|---|
| 8 |
* The font is valid. |
|---|
| 9 |
* The font's _cmap_ table contains Platform 3 Encoding 1. |
|---|
| 10 |
* The font does not contain _GSUB_ or _GPOS_ lookup types that are not supported by the GSUB or GPOS objects. If an unsupported lookup type is present, the lookup will simply be ignored. It will not raise an error. |
|---|
| 11 |
|
|---|
| 12 |
h2. The Font Object |
|---|
| 13 |
|
|---|
| 14 |
h3. Importing |
|---|
| 15 |
|
|---|
| 16 |
<pre> |
|---|
| 17 |
from compositor import Font |
|---|
| 18 |
</pre> |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
h3. Construction |
|---|
| 22 |
|
|---|
| 23 |
<pre> |
|---|
| 24 |
font = Font(path) |
|---|
| 25 |
</pre> |
|---|
| 26 |
|
|---|
| 27 |
*path* A path to an OpenType font. |
|---|
| 28 |
|
|---|
| 29 |
h3. Special Behavior |
|---|
| 30 |
|
|---|
| 31 |
<pre> |
|---|
| 32 |
glyph = font["aGlyphName"] |
|---|
| 33 |
</pre> |
|---|
| 34 |
|
|---|
| 35 |
Returns the glyph object named "aGlyphName". This will raise a KeyError if "aGlyphName" is not in the font. |
|---|
| 36 |
|
|---|
| 37 |
<pre> |
|---|
| 38 |
isThere = "aGlyphName" in font |
|---|
| 39 |
</pre> |
|---|
| 40 |
|
|---|
| 41 |
Returns a boolean representing if "aGlyphName" is in the font. |
|---|
| 42 |
|
|---|
| 43 |
h3. Methods |
|---|
| 44 |
|
|---|
| 45 |
<pre> |
|---|
| 46 |
font.keys() |
|---|
| 47 |
</pre> |
|---|
| 48 |
|
|---|
| 49 |
A list of all glyph names in the font. |
|---|
| 50 |
|
|---|
| 51 |
<pre> |
|---|
| 52 |
glyphRecords = font.process(aString) |
|---|
| 53 |
</pre> |
|---|
| 54 |
|
|---|
| 55 |
This is the most important method. It takes a string (Unicode or plain ASCII) and processes it with the features defined in the font's _GSUB_ and _GPOS_ tables. A list of _GlyphRecord_ objects will be returned. |
|---|
| 56 |
|
|---|
| 57 |
<pre> |
|---|
| 58 |
featureTags = font.getFeatureList() |
|---|
| 59 |
</pre> |
|---|
| 60 |
|
|---|
| 61 |
A list of all available features in GSUB and GPOS. |
|---|
| 62 |
|
|---|
| 63 |
<pre> |
|---|
| 64 |
state = font.getFeatureState(featureTag) |
|---|
| 65 |
</pre> |
|---|
| 66 |
|
|---|
| 67 |
Get a boolean representing if a feature is on or not. This assumes that the feature state is consistent in both the GSUB and GPOS tables. A _CompositorError_ will be raised if the feature is inconsistently applied. A _CompositorError_ will be raised if featureTag is not defined in GSUB or GPOS. |
|---|
| 68 |
|
|---|
| 69 |
<pre> |
|---|
| 70 |
font.setFeatureState(self, featureTag, state) |
|---|
| 71 |
</pre> |
|---|
| 72 |
|
|---|
| 73 |
Set the application state of a feature. |
|---|
| 74 |
|
|---|
| 75 |
h3. Attributes |
|---|
| 76 |
|
|---|
| 77 |
*info* The Info object for the font. |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
h2. The GlyphRecord Object |
|---|
| 82 |
|
|---|
| 83 |
h3. Attributes |
|---|
| 84 |
|
|---|
| 85 |
*glyphName* The name of the referenced glyph. |
|---|
| 86 |
|
|---|
| 87 |
*xPlacement* Horizontal placement. |
|---|
| 88 |
|
|---|
| 89 |
*yPlacement* Vertical placement. |
|---|
| 90 |
|
|---|
| 91 |
*xAdvance* Horizontal adjustment for advance. |
|---|
| 92 |
|
|---|
| 93 |
*yAdvance* Vertical adjustment for advance. |
|---|
| 94 |
|
|---|
| 95 |
*alternates* A list of _GlyphRecords_ indicating alternates for the glyph. |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
h2. The Glyph Object |
|---|
| 100 |
|
|---|
| 101 |
h3. Methods |
|---|
| 102 |
|
|---|
| 103 |
<pre> |
|---|
| 104 |
glyph.draw(pen) |
|---|
| 105 |
</pre> |
|---|
| 106 |
|
|---|
| 107 |
Draws the glyph with a FontTools pen. |
|---|
| 108 |
|
|---|
| 109 |
h3. Attributes |
|---|
| 110 |
|
|---|
| 111 |
*name* The name of the glyph. |
|---|
| 112 |
|
|---|
| 113 |
*index* The glyph's index within the source font. |
|---|
| 114 |
|
|---|
| 115 |
*width* The width of the glyph. |
|---|
| 116 |
|
|---|
| 117 |
*bounds* The bounding box for the glyph. Formatted as (xMin, yMin, xMax, yMax). If the glyph contains no outlines, this will return _None_. |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
h2. The Info Object |
|---|
| 122 |
|
|---|
| 123 |
h3. Attributes |
|---|
| 124 |
|
|---|
| 125 |
*familyName* |
|---|
| 126 |
|
|---|
| 127 |
*styleName* |
|---|
| 128 |
|
|---|
| 129 |
*unitsPerEm* |
|---|
| 130 |
|
|---|
| 131 |
*ascender* |
|---|
| 132 |
|
|---|
| 133 |
*descender* |
|---|