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