| 1 |
Editing Contextual or Chaining Contextual lookups |
| 2 |
================================================= |
| 3 |
|
| 4 |
|
| 5 |
What is a Contextual Positioning lookup? |
| 6 |
---------------------------------------- |
| 7 |
|
| 8 |
There are two types of contextual positioning modes: Contextual Positioning and |
| 9 |
Chained Contextual Positioning. In the simplest form of the first you may |
| 10 |
specify a list glyphs and specify repositioning to occur if that sequence is |
| 11 |
matched. For example you might specify (in English) :: |
| 12 |
|
| 13 |
5 t h |
| 14 |
|
| 15 |
and if that sequence were found raise the "t" and "h" to 5\ :sup:`th`. You can |
| 16 |
also specify classes of glyphs so you could say something like: :: |
| 17 |
|
| 18 |
[0-9] t h |
| 19 |
|
| 20 |
to raise "t" and "h" after any digit. |
| 21 |
|
| 22 |
After applying this lookup, a word processor will skip over the three glyphs |
| 23 |
matched by the pattern, at least it will in a simple "Contextual Positioning" |
| 24 |
lookup. The "Chained Contextual Positioning" lookup is a bit more general and |
| 25 |
allows you to divide the pattern into three parts: A part before the current |
| 26 |
glyph (called backtracking), a part including the current glyph, and a part |
| 27 |
after the current glyph (called lookahead). Positioning changes may only be made |
| 28 |
to the part including the current glyph, and the word processor will advance by |
| 29 |
the number of glyphs in that subset of the pattern. |
| 30 |
|
| 31 |
|
| 32 |
What is a Contextual Substitution lookup? |
| 33 |
----------------------------------------- |
| 34 |
|
| 35 |
Substitutions come in three types. The first two are similar to the two types |
| 36 |
for positioning, the third is designed to handle a very specific case of arabic |
| 37 |
typography and is applied backwards. |
| 38 |
|
| 39 |
Suppose you had a script font where most letters join at the base line, but |
| 40 |
after some letters (b,o,v,w) the join is near the x-height, so a special version |
| 41 |
of each lower case letter needs to be created designed for a left side join near |
| 42 |
the x-height. You would want to be able to say: :: |
| 43 |
|
| 44 |
[bovw] [a-z] |
| 45 |
|
| 46 |
Note that this just specifies the cases in which the substitution may be |
| 47 |
applied. It does not specify the substitution itself, that is done in a separate |
| 48 |
lookup. |
| 49 |
|
| 50 |
You may pull down an example script font with this substitution from |
| 51 |
`FormalScript.tgz <http://fontforge.sf.net/sfds/FormalScript.tgz>`__, this |
| 52 |
example is worked out in detail in the :doc:`tutorial </tutorial/editexample6-5>`. |
| 53 |
|
| 54 |
|
| 55 |
More complete descriptions |
| 56 |
-------------------------- |
| 57 |
|
| 58 |
For more information on contextual lookups see Adobe's Docs: |
| 59 |
|
| 60 |
* `The GPOS table <http://partners.adobe.com/public/developer/opentype/index_table_formats2.html>`__, |
| 61 |
for positioning glyphs |
| 62 |
* `The GSUB table <http://partners.adobe.com/public/developer/opentype/index_table_formats1.html>`__, |
| 63 |
for substituting glyphs |
| 64 |
* `The feature tag registry <http://partners.adobe.com/public/developer/opentype/index_tag3.html>`__. |
| 65 |
|
| 66 |
|
| 67 |
How do these relate to Apple Advanced Typography features? |
| 68 |
---------------------------------------------------------- |
| 69 |
|
| 70 |
In some cases a contextual or chaining contextual substitution can be converted |
| 71 |
into one of Apple's contextual glyph substitution subtables. See the page on |
| 72 |
:ref:`Apple Advanced Typography <gposgsub.sometimes>` for more information as to |
| 73 |
when and caveats about how. |
| 74 |
|
| 75 |
|
| 76 |
Creating a contextual lookup |
| 77 |
---------------------------- |
| 78 |
|
| 79 |
First you must create a contextual lookup with the |
| 80 |
:ref:`Element->Font Info->Lookups dialog <fontinfo.Lookups>`, then in that same |
| 81 |
dialog create and name a subtable in that lookup. Then the contextual editor |
| 82 |
will open. |
| 83 |
|
| 84 |
|
| 85 |
Editing a lookup |
| 86 |
---------------- |
| 87 |
|
| 88 |
|
| 89 |
Format |
| 90 |
^^^^^^ |
| 91 |
|
| 92 |
.. figure:: /images/contextchain-format.png |
| 93 |
|
| 94 |
Except for the reverse chaining features, any of these may come in one of three |
| 95 |
formats. |
| 96 |
|
| 97 |
The simplest format is a list of :ref:`glyphs <contextchain.Glyphs>`. You may |
| 98 |
specify several glyph sequences in a single feature. So the script example above |
| 99 |
could be specified (quite inefficiently) by 4*26 lines like: :: |
| 100 |
|
| 101 |
b a |
| 102 |
b b |
| 103 |
... |
| 104 |
o a |
| 105 |
... |
| 106 |
|
| 107 |
The next format allows you to specify a list of |
| 108 |
:ref:`classes <contextchain.Classes>`. In the script example we would define 2 |
| 109 |
classes: :: |
| 110 |
|
| 111 |
[bovw] |
| 112 |
[ac-np-ux-z] |
| 113 |
|
| 114 |
and define two patterns as: :: |
| 115 |
|
| 116 |
class1 [class2] |
| 117 |
class1 [class1] |
| 118 |
|
| 119 |
The third format is the most general and allows you to specify your pattern by a |
| 120 |
:ref:`separate list of glyphs <contextchain.Coverage>` for each glyph position: :: |
| 121 |
|
| 122 |
[bovw] [a-z] |
| 123 |
|
| 124 |
Most contextual specifications are fairly simple, FontForge has two dialog |
| 125 |
formats, one for simpler specifications and one for more complicated ones. The |
| 126 |
complicated dialog is (I think) more difficult to understand, but allows for |
| 127 |
greater generality. |
| 128 |
|
| 129 |
In both the glyph and the class format you are allowed to specify multiple |
| 130 |
matching rules (in the coverage format you may only specify one rule. I know |
| 131 |
this sounds odd, I did not design the system). **UNFORTUNATELY** the OpenType |
| 132 |
interpreters do not seem to support multiple rules within a single subtable. |
| 133 |
Instead I suggest you use multiple subtables. It will have the same effect but |
| 134 |
is less efficient. FontForge still supports multiple rules because the spec says |
| 135 |
it should. |
| 136 |
|
| 137 |
|
| 138 |
.. _contextchain.Coverage: |
| 139 |
|
| 140 |
Simple Coverage |
| 141 |
^^^^^^^^^^^^^^^ |
| 142 |
|
| 143 |
.. figure:: /images/contextchain-simplecoverage.png |
| 144 |
|
| 145 |
This display shows a list of three items, the first column consists of coverage |
| 146 |
tables -- that is lists of glyphs. A match occurs if the current glyph matches |
| 147 |
one of the glyphs named in the current coverage table. The second column |
| 148 |
contains the name of a lookup that should be applied to the glyph associated |
| 149 |
with the coverage table if the entire rule matches. |
| 150 |
|
| 151 |
As noted earlier the rule is divided into three sections, backtrack, match and |
| 152 |
lookahead. The third column indicates when each section starts. Lookups may only |
| 153 |
occur in the middle (the "match") section. If you don't specify the start of |
| 154 |
each section FontForge will figure it out for you assuming that the match |
| 155 |
section starts with the first lookup and ends with the last. **WARNING:** this |
| 156 |
simple heuristic does not work for ligatures. The match section must be long |
| 157 |
enough to provide all glyphs that might be consumed by the ligature conversion. |
| 158 |
|
| 159 |
This lookup does not directly describe how transformations are to happen to the |
| 160 |
glyphs, merely WHEN. Instead it invokes a nested lookup that will be applied to |
| 161 |
specific positions in the match string (positions in the backtrack and lookahead |
| 162 |
lists may not be transformed). |
| 163 |
|
| 164 |
So in the example at right, the first list of glyphs is a coverage table in the |
| 165 |
backtrack section, while the second line starts the match section. The rule says |
| 166 |
that if one of the letters [bovw] is followed by any other letter, then the |
| 167 |
second letter should be transformed using the nested lookup "To-TopJoin" (which |
| 168 |
will convert the glyph into an alternate format). Here there is no need for a |
| 169 |
lookahead list (and there is none). |
| 170 |
|
| 171 |
|
| 172 |
Setting a coverage table |
| 173 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 174 |
|
| 175 |
You can change a coverage table by editing it. You may enter either glyph names |
| 176 |
or unicode characters (which will be converted to a glyph name -- a few |
| 177 |
characters which have special meaning: space, right parenthesis, asterix; must |
| 178 |
have their names typed in full). If you click on the little box on the right you |
| 179 |
will get a dialog containing a font view. In this view you may select glyphs to |
| 180 |
your heart's content, when you press OK these glyphs become your table. |
| 181 |
|
| 182 |
|
| 183 |
Coverage |
| 184 |
^^^^^^^^ |
| 185 |
|
| 186 |
.. figure:: /images/contextchain-coverage.png |
| 187 |
|
| 188 |
This display shows a list whose entries are coverage tables -- that is lists of |
| 189 |
glyphs. A match occurs if the current glyph matches one of the glyphs named in |
| 190 |
the current coverage table. |
| 191 |
|
| 192 |
In the example at right there is only a single coverage table here (but there |
| 193 |
could be more). |
| 194 |
|
| 195 |
In a Chaining Contextual feature it is also possible to specify a list of |
| 196 |
coverage tables to match glyphs before the current glyph, and another list to |
| 197 |
match glyphs after. |
| 198 |
|
| 199 |
In the example at right, the lookup 'high' will be applied to any glyph that |
| 200 |
matches the coverage table at the top of the list. Again the buttons under the |
| 201 |
sequence lookup list allow you to add, change, remove or reorder these |
| 202 |
transformations. (And yes, the order the transformations are applied can matter |
| 203 |
in complex situations). |
| 204 |
|
| 205 |
|
| 206 |
Creating or editing a lookup position pair |
| 207 |
"""""""""""""""""""""""""""""""""""""""""" |
| 208 |
|
| 209 |
You can change a lookup by clicking on it, this will produce a pull down menu of |
| 210 |
all lookups that can be applied. You can change the position by editing it. |
| 211 |
|
| 212 |
You can add a new entry by pressing the <New> button, and then selecting a |
| 213 |
lookup. |
| 214 |
|
| 215 |
|
| 216 |
.. _contextchain.Glyphs: |
| 217 |
|
| 218 |
Simple Glyphs |
| 219 |
^^^^^^^^^^^^^ |
| 220 |
|
| 221 |
.. figure:: /images/contextchain-simpleglyph.png |
| 222 |
|
| 223 |
In the glyph format each rule allows you to specify a list of glyphs that need |
| 224 |
to be matched along with lookups that should be applied to appropriate glyphs |
| 225 |
after the match has been made. |
| 226 |
|
| 227 |
Again each rule is divided into sections (here marked with the vertical bar |
| 228 |
"|"). In the match section glyphs may be followed by lookup names, and those |
| 229 |
lookups will be applied to the preceding glyph if a match occurs. |
| 230 |
|
| 231 |
So the example at right is an attempt to do with a series of glyph rules what |
| 232 |
was done easily with one coverage table rule. Every possible combination of |
| 233 |
letters must be spelled out as a separate rule. |
| 234 |
|
| 235 |
At the bottom of the list are two buttons, one to add a lookup reference after a |
| 236 |
glyph, and the other to start a new section. |
| 237 |
|
| 238 |
|
| 239 |
Glyphs |
| 240 |
^^^^^^ |
| 241 |
|
| 242 |
.. figure:: /images/contextchain-glyphlists.png |
| 243 |
|
| 244 |
This format allows you to specify several glyph lists to match. In the example |
| 245 |
at right the string "A,B,C" will be matched in the glyphs before the current |
| 246 |
glyph, then "D E" starting at the current location, and finally "F G H" after |
| 247 |
them. If everything matched then the lookup "Smallcaps" will be applied to |
| 248 |
location 0 (in this case "D") , and "superscript" to location 1 (here, "E"). |
| 249 |
|
| 250 |
The order is significant, word processors will stop at the first match they find |
| 251 |
so in the following pattern strings: :: |
| 252 |
|
| 253 |
b a |
| 254 |
b a f |
| 255 |
|
| 256 |
the second entry would never be matched because "b a" would be applied first. |
| 257 |
While: :: |
| 258 |
|
| 259 |
b a f |
| 260 |
b a |
| 261 |
|
| 262 |
would apply match "b a f" when an "f" was present, and "b a" otherwise. |
| 263 |
|
| 264 |
|
| 265 |
Selecting glyphs |
| 266 |
^^^^^^^^^^^^^^^^ |
| 267 |
|
| 268 |
.. figure:: /images/contextchain-pickglyph.png |
| 269 |
|
| 270 |
The text field may be manipulated as above. However here we are specifying a |
| 271 |
string of glyphs each of which must be matched, rather than a class of glyphs |
| 272 |
any of which could match. So in the example at right, "DE" would match, but "E" |
| 273 |
would not. |
| 274 |
|
| 275 |
As above a set of lookups can be applied after the match occurs. |
| 276 |
|
| 277 |
|
| 278 |
.. _contextchain.Classes: |
| 279 |
|
| 280 |
Simple Classes |
| 281 |
^^^^^^^^^^^^^^ |
| 282 |
|
| 283 |
.. figure:: /images/contextchain-simpleclasses.png |
| 284 |
|
| 285 |
When specifying a class match, you must specify at least one set of glyph |
| 286 |
classes. If you only specify one set these classes will be used in all sections, |
| 287 |
alternately each section may have its own set of glyph classes. You may give |
| 288 |
each glyph class a name (if you don't then the class will be named something |
| 289 |
dull like "1", "2", etc.) |
| 290 |
|
| 291 |
You must also specify a list of patterns where each pattern is a list of class |
| 292 |
names (or numbers). |
| 293 |
|
| 294 |
Every set of classes has a magic class at index 0 which matches whatever glyphs |
| 295 |
are not explicitly mentioned in another class. FontForge displays this by |
| 296 |
calling it "{Everything Else}". You may not delete, edit nor reorder this class. |
| 297 |
Other classes are just unordered lists of glyph names (rather like coverage |
| 298 |
tables above), however any specific glyph may belong to at most one class at a |
| 299 |
time (whereas a glyph may occur in as many coverage tables as desired). |
| 300 |
|
| 301 |
In the example at right, any letter that occurs after one of the special letters |
| 302 |
[bovw] will be changed into an alternate form. |
| 303 |
|
| 304 |
There is a small bug here. Because classes must be disjoint, the "letters" class |
| 305 |
does not contain the letters [bovw]. So there actually needs to be a second rule |
| 306 |
that looks like ``"high-after | high-after @<To-TopJoin> |"``. As I mentioned |
| 307 |
early, multiple rules don't actually work, so that rule is in a separate |
| 308 |
subtable (which is in the same lookup) and isn't displayed here. |
| 309 |
|
| 310 |
|
| 311 |
Classes |
| 312 |
^^^^^^^ |
| 313 |
|
| 314 |
.. figure:: /images/contextchain-class.png |
| 315 |
|
| 316 |
|
| 317 |
A list of Class numbers |
| 318 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 319 |
|
| 320 |
.. figure:: /images/contextchain-classlist.png |
| 321 |
|
| 322 |
Once you have set up your classes, you may then edit the patterns you want to |
| 323 |
match. To remind you of what your classes are, FontForge displays the class list |
| 324 |
underneath the pattern. Clicking on a class will insert that class's index into |
| 325 |
the pattern. |
| 326 |
|
| 327 |
Finally you must set the nested lookups. This is exactly the same as previous |
| 328 |
sequence / lookup settings. |