SIL Non-Roman Script Initiative

Graphite

A free and open rendering engine for complex scripts

Graphite Tutorial

Unit 2: A very simple GDL program

Exercise

Discussion

The most fundamental aspect of GDL is the set of rules that define the writing system rendering behavior. The following is an example of a rule:

glyphid(80)  >  glyphid(81);

This simple rule is made up of two parts: the left-hand side (input) and the right-hand side (output). It says to replace every instance of the letter “a” (glyph 80 in this font) with the letter “b” (glyph 81).

Note that Graphite only works with glyphs. However, it is frequently easier for the programmer to work with Unicode values. So instead, one could write:

unicode(0x61) > unicode(0x62);

Graphite still works with the glyphs that these codepoints represent. The Graphite compiler will use the font’s cmap table to replace the Unicode Scalar Values with the appropriate glyph IDs in the compiled font.

Notice that hexadecimal numbers (which are the standard way to specify Unicode codepoints) must be prefixed with “0x” within the unicode function. You can also use decimal numbers; the following rule is equivalent to the one above:

unicode(97) > unicode(98);

An equivalent of the unicode function is the standard syntax for Unicode codepoints:

U+0061 > U+0062;

Note that is not necessary to include “0x” to indicate that the value is hexadecimal when using this syntax. The “U” must be capitalized.

Another way to reference glyphs is using the postscript function, which identifies a glyph using its Postscript name:

postscript(“a”) > postscript(“b”);

Note the quote marks surrounding the Postscript name string.

Rules are organized into tables. There are three kinds of tables that contain rules: the linebreak table (abbreviated lb), the substitution table (sub), and the positioning table (pos). The following syntax is used to indicate a table:

table(<table-name>)
  <rules in the table>
endtable;

Because the rule above is substituting one glyph for another, it is located in the substitution table.

To access the standard definitions and abbreviations, add the following statement at the beginning of your file:

#include “stddef.gdh”

Exercise 2

Write a simple GDL program to convert every instance of the dollar character to the symbol for the British pound. (Note that you are not trying to convert the actual currency values, just the currency symbol itself!) The Unicode codepoint for the dollar is U+0024 and the codepoint for the British pound is U+00A3.

Compile your program against the sildub3.ttf font, install it, and test it using WorldPad. Remember that gdlerr.txt contains error and warning messages resulting from the compilation. You may want to give the font a new face name, such as “Dollar to Pound Demo”, and/or specify a Graphite font file name other than the default.

Solution

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