| 1 |
The Mac State Machine Dialog |
| 2 |
============================ |
| 3 |
|
| 4 |
.. figure:: /images/statemachine-context.png |
| 5 |
|
| 6 |
The mac uses state machines where opentype would use a contextual lookup. The |
| 7 |
example at right (with appropriate substitutions attached to it) will convert an |
| 8 |
initial or medial short-s into a long-s (for doing renaissance printing). |
| 9 |
|
| 10 |
FontForge currently supports 4 types of state machines: contextual glyph |
| 11 |
substitution, indic rearrangement, contextual glyph insertion, and contextual |
| 12 |
kerning. The example at right is of contextual glyph substitution. |
| 13 |
|
| 14 |
An example conditional substitution state machine is provided in the |
| 15 |
:ref:`tutorial <editexample6-5.Apple>`. |
| 16 |
|
| 17 |
On the mac there are four predefined classes, one meaning the end of input, one |
| 18 |
for all glyphs not specified elsewhere, one for the magic "deleted" glyph (Apple |
| 19 |
does not always delete a glyph when asked to do so, instead it retains a special |
| 20 |
mark in the glyph stream indicating that the glyph should be deleted later), and |
| 21 |
finally a class for the end of a line of text. Any classes after this are user |
| 22 |
defined. In the example at right there are many user defined classes |
| 23 |
representing various groupings of arabic letters. Any other glyphs in the font |
| 24 |
(the digits for example) will automatically be assigned to class 1 ("{Everything |
| 25 |
Else}"). |
| 26 |
|
| 27 |
The state machine itself is shown as a two dimensional matrix of transitions, |
| 28 |
one transition for every state and class. Classes are shown at the top of the |
| 29 |
matrix, and states down the side. The transition from state 0 when given input |
| 30 |
from class 0 is shown in the upper left corner of the matrix, and so on. |
| 31 |
|
| 32 |
When the state machine starts up it will be in one of the first two states. It |
| 33 |
will be in state 0 at the beginning of input, and in state1 when it starts at |
| 34 |
the beginning of a new line. |
| 35 |
|
| 36 |
.. _statemachine.transitions: |
| 37 |
|
| 38 |
The transitions look slightly differently depending on the type of state |
| 39 |
machine: |
| 40 |
|
| 41 |
.. flex-grid:: |
| 42 |
|
| 43 |
* - .. figure:: /images/transition-indic.png |
| 44 |
:align: left |
| 45 |
|
| 46 |
Indic |
| 47 |
- .. figure:: /images/transition-context.png |
| 48 |
:align: left |
| 49 |
|
| 50 |
Contextual |
| 51 |
|
| 52 |
- .. figure:: /images/transition-insert.png |
| 53 |
:align: left |
| 54 |
|
| 55 |
Insertion |
| 56 |
- .. figure:: /images/transition-kern.png |
| 57 |
:align: left |
| 58 |
|
| 59 |
Kerning |
| 60 |
|
| 61 |
The first line of all transitions shows the next state. The next line contains a |
| 62 |
set of flags where "M" => the current glyph should be marked (the meaning of |
| 63 |
this becomes apparent later), "A" => processing should advance to the next |
| 64 |
glyph. For indic tables there is a third flag shown, "L" => the current glyph is |
| 65 |
the last glyph of the indic rearrangement, while for kerning tables there is a |
| 66 |
"P" flag indicating that the current glyph should be pushed onto the kerning |
| 67 |
stack. |
| 68 |
|
| 69 |
The last two lines have varied meanings depending on the type of the state |
| 70 |
machine. |
| 71 |
|
| 72 |
* For Indic transitions the two lines should be appended to get the indic |
| 73 |
rearrangement verb (in the example above that would be "Ax => xA" meaning that |
| 74 |
the first glyph marked should be moved after the last glyph marked) |
| 75 |
* For contextual transitions the two lines specify the lookup names of simple |
| 76 |
substitutions. The first one is applied to the last glyph marked and the second |
| 77 |
one to the current glyph (if a line is blank, no substitution is applied to that |
| 78 |
glyph here). |
| 79 |
|
| 80 |
If a transition has both a "marked substitution" and the "mark current glyph" |
| 81 |
flag, I believe the substitution applies to the glyph that was previously |
| 82 |
marked, and not to the current glyph. (Apple doesn't document this) |
| 83 |
|
| 84 |
.. note:: |
| 85 |
|
| 86 |
Apple's 'mort' format was not designed to allow fonteditors to figure out |
| 87 |
what a state machine did. FontForge can usually make a good guess of what |
| 88 |
substitutions do which apply to the current glyph, but it will often include |
| 89 |
extraneous glyph substitutions when a substitution applies to a marked glyph. |
| 90 |
These should not be harmful (they should never get invoked) but they are |
| 91 |
annoying ('morx' tables should not have this problem). |
| 92 |
* For insertion transitions the lines specify the glyphs that are to be inserted. |
| 93 |
The first line applies to the marked glyph, the second line to current glyph |
| 94 |
(there may not be room enough to show all the inserted glyphs, in which case the |
| 95 |
glyph list is truncated). There are additional flags here that are also not |
| 96 |
shown because of lack of room. They may be viewed by clicking on a transition. |
| 97 |
* For kerning transitions the first line shows the first (few) kerning values, the |
| 98 |
second line shows either "..." if there are more kerning values, or nothing. |
| 99 |
|
| 100 |
.. note:: |
| 101 |
|
| 102 |
Note: The number of kerning values **MUST** match the number of glyphs pushed |
| 103 |
on the kern stack, or your application crashes. |
| 104 |
|
| 105 |
For a complete description of what these state machines can do you should read |
| 106 |
Apple's documentation |
| 107 |
|
| 108 |
* On the |
| 109 |
`'morx' <http://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6morx.html>`__ and |
| 110 |
`'mort' <http://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6mort.html>`__ |
| 111 |
tables |
| 112 |
* On the |
| 113 |
`'kern' <http://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6kern.html>`__ table |
| 114 |
(format 1) |
| 115 |
* `On state machines in general <http://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6Tables.html#StateTables>`__ |
| 116 |
* `The 'feat' (feature) table <http://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6feat.html>`__ |
| 117 |
* `Apple's Font Feature registry <http://developer.apple.com/fonts/Registry/index.html>`__ |
| 118 |
|
| 119 |
The general idea is that a word processor converts text into a string of glyphs, |
| 120 |
and then the state machine is applied to that string. The state machine starts |
| 121 |
in state 0 or 1, it figures out what class the first glyph belongs to, and |
| 122 |
indexes into the current state by that class. The transition at that location |
| 123 |
provides a new state to move to (which might be the same as the current one), it |
| 124 |
will usually advance to the next glyph (so the new state will be indexed by a |
| 125 |
different glyph) but sometimes you will want to continue processing the current |
| 126 |
glyph in the new state. Also it will perform a set of operations which differ |
| 127 |
depending on the type of state machine. |
| 128 |
|
| 129 |
Many of the state machines have the concept of a "marked" glyph. This is |
| 130 |
important if the desired change for a given glyph depends on what glyphs follow |
| 131 |
it. In that case when we reach an interesting glyph we "mark" it, and then, |
| 132 |
after reading a few more glyphs when we know what to do, we apply a |
| 133 |
transformation to the marked glyph. |
| 134 |
|
| 135 |
Indic |
| 136 |
In addition to a "mark"ed glyph, indic transformations also have a the |
| 137 |
concept of a "last" glyph. There are 16 transformations which may be applied |
| 138 |
the the glyphs between the "mark"ed and "last" glyphs. Suppose the glyph |
| 139 |
stream looks like |
| 140 |
|
| 141 |
abcdef |
| 142 |
|
| 143 |
And "a" was "mark"ed and "d" was "last" then a transition "AxD => DxA" refers |
| 144 |
to the marked glyph as "A", the last glyph as "D" and everything in between |
| 145 |
as "x", so this would change the glyph stream to |
| 146 |
|
| 147 |
dbcaef |
| 148 |
Contextual |
| 149 |
This can apply a substitution to the current glyph, a different substitution |
| 150 |
to the marked glyph, and it may mark the current glyph. The substitutions are |
| 151 |
indicated by 4 character tags and should be "Nested" substitutions which may |
| 152 |
be created by the :menuselection:`Element --> Char Info` dialog. |
| 153 |
Insertion |
| 154 |
This can insert a string (up to 31 glyphs) before or after the current and |
| 155 |
the marked glyphs. |
| 156 |
Kerning |
| 157 |
Kerning does not have a single "mark"ed glyph, instead it can push up to 8 |
| 158 |
glyphs onto a stack, and at a later point a set of kerning values may be |
| 159 |
applied to those glyphs (so the flag which is usually indicated as "M" for |
| 160 |
mark, is here "P" for push). Once all the glyphs have been pushed, a set of |
| 161 |
kerning values may be applied. One value for each pushed glyph. This is a |
| 162 |
number which indicates how much the glyph in question should be kerned. If |
| 163 |
the glyph stream looks like: |
| 164 |
|
| 165 |
F." |
| 166 |
|
| 167 |
and you want to kern "." by -300, and """ by 0 em-units, then you would enter |
| 168 |
|
| 169 |
-300 0 |
| 170 |
|
| 171 |
as kerning values. |
| 172 |
|
| 173 |
.. _statemachine.EditTransition: |
| 174 |
|
| 175 |
Editing Transitions |
| 176 |
------------------- |
| 177 |
|
| 178 |
To edit a transition, simply click on it and a dialog will pop up, appropriate |
| 179 |
to the type of state machine. |
| 180 |
|
| 181 |
.. flex-grid:: |
| 182 |
|
| 183 |
* - .. figure:: /images/edittransition-indic.png |
| 184 |
|
| 185 |
Indic |
| 186 |
- .. figure:: /images/edittransition-context.png |
| 187 |
|
| 188 |
Contextual |
| 189 |
- .. figure:: /images/edittransition-insert.png |
| 190 |
|
| 191 |
Insertion |
| 192 |
- .. figure:: /images/edittransition-kern.png |
| 193 |
|
| 194 |
Kerning |
| 195 |
|
| 196 |
See :ref:`above <statemachine.transitions>` for a description of what the fields |
| 197 |
mean. |
| 198 |
|
| 199 |
If you wish to add a new state, simply edit a transition so that its next state |
| 200 |
field is the state number desired. FontForge will automatically create the state |
| 201 |
for you. |