SIL Non-Roman Script Initiative

Graphite

A free and open rendering engine for complex scripts

Graphite Tutorial

Unit 3: The glyph table

Exercises

Discussion

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:

table(glyph)
  <glyph class definitions>
endtable;

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.:

glyphid(<number>);

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(“a”);
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.

table(glyph)
  g_a = unicode(0x61);
  g_b = unicode(0x62);
endtable;

table(sub)
  g_a  >  g_b;
endtable;

Exercise 3a

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

Solution

Exercise 3b

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

Solution

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