SIL Writing Systems Technology


A free and open rendering engine for complex scripts

Graphite Tutorial

Unit 3: The glyph table



In addition to the tables that contain rules, there are tables containing other information. One of these is the glyph table. Among other purposes, the glyph table can be used to define classes of glyphs, and/or give meaningful names to single glyphs. The glyph table is marked by the following syntax:

  <glyph class definitions>

The glyph class definitions include lists of glyphs or codepoints that comprise the members of the class. The syntax of the glyph class definition is the following:

class-name = <list-of-glyphs>;

For instance, you can give names to a group of digit characters as follows:

gZero = U+0030;
gOne = U+0031;
gTwo = U+0032;
gThree = U+0033;
gFour = U+0034;
gFive = U+0035;
gSix = U+0036;
gSeven = U+0037;
gEight = U+0038;
gNine = U+0039;
clsDigit = (U+0030..U+0039);

Notice the final statement defines a class of glyphs that includes ten digits. It could also have been written as follows:

clsDigit = (gZero, gOne, gTwo, gThree, gFour, gFive, gSix, gSeven, gEight, gNine);

Parentheses are needed around the list of glyphs when more than one item is included. (Note: the use of an initial “g” to indicate single-glyph definitions and “cls” to indicate multiple-glyph classes is simply a convention.)

In Unit 2 we mentioned briefly that glyphid can be used to reference a glyph directly, i.e.:


where the number is the ID of the glyph in the font. (Note that glyphid can be less useful than postscript because it is more font-specific and therefore makes a program that is not as easily converted to work with a different font.)

A fourth way to identify a glyph is using the codepoint function. It takes as an argument either a string that contains a list of characters or a numerical value. The codepage can be included as an optional second argument (Codepage 1252 is the default).

codepoint(97, 1252);

As indicated in the example above, the codepoint, unicode, and glyphid functions can specify ranges of values by including the “..” syntax, for instance:

clsLowercase = codepoint(97..122);   // a through z

(Note that a comment is preceded by two slashes as shown above.) When a glyph has been given a name within the glyph table, that name can be used within a rule in place of the functions. The following is equivalent to the rule discussed in Unit 2 that replaces a’s with b’s.

  g_a = unicode(0x61);
  g_b = unicode(0x62);

  g_a  >  g_b;

Exercise 3a

Rewrite your program from Exercise 2 to define the dollar and pound glyphs in the glyph table.


Exercise 3b

Write a program to replace all digits with an asterisk. Use the glyph table to define a class containing the digit characters.


Copyright © 2012 SIL International® and released under the  Creative Commons Attribution-ShareAlike 3.0 license (CC-BY-SA) unless noted otherwise.