User Guide
Macro Programming
707
You can replace “Glyph” with the name of any class mentioned above to get
a description of its members and operations.
Here are some examples:
Marking all glyphs with a different color depending on the
number of components.
Non-composite glyphs are not marked. Glyphs that have exactly 2
components are marked green and glyphs that have some other number of
components or have outline and components are marked red:
for g in fl.font.glyphs: for every glyph in the current font
c_len = len(g.components)
store the number of components (length of the
components array
n_len = len(g) store the number of nodes (length of the nodes
array)
if c_len == 0: if number of components is 0
g.mark = 0 unmark the glyph
elseif c_len == 2 and n_len == 0:
if number of components is 2 and number of
nodes is 0
g.mark = 100 Mark the glyph with green
else if all conditions above are false
g.mark = 1 Mark the glyph with red
fl.UpdateFont() finally, update the font so the Font window will
refresh
Selecting all glyphs that have no outline or components:
fl.Unselect()
for g in fl.font:
if len(g) == 0 and len(g.components) == 0:
fl.Select(g.index)
First thing we do is deselect the font. It is faster to deselect all glyphs at
once than to change the selection of all glyphs. In our example we are
selecting only those glyphs that comply with the condition.
Please, refer to our website (www.fontlab.com) for more examples and
information about macro programs. You may also examine the source code
of the sample programs that are supplied with FontLab.