SIL Non-Roman Script Initiative

Graphite

A free and open rendering engine for complex scripts

Graphite Tutorial

Unit 4: Corresponding class items

Exercises

Discussion

So far the right-hand (output) side of our GDL rules have contained single glyphs. It is also possible to use a multi-glyph class for substititution.

When one glyph is substituted for another, the Graphite engine determines the position of the input glyph within the input class, and uses the corresponding item from the output class in the substitution. For instance, the following two classes define classes of uppercase and lowercase letters:

table(glyph);
  clsUppercase = unicode(65..90);   // A .. Z
  clsLowercase = unicode(97..122);  // a .. z
endtable;

table(sub);
  clsUppercase > clsLowercase;
endtable;

When, say, the uppercase “H” is encountered in the input, the corresponding lowercase “h” is placed into the output. Keep in mind that the order of the items in the classes becomes very significant when this mechanism is being used.

Note that you need to use parenthesis around the members of a class when there are more than one. For instance:

clsConsVoiced = (gB, gD, gG);
clsConsVoiceless = (gP, gT, gK);

Exercise 4a

Write a program to capitalize all text.

Solution

Exercise 4b

Write a program to make all vowels uppercase and all consonants lowercase.

Solution

Exercise 4c

Write a program to create a Greek transliteration of Roman text, using the mappings in the table below. (You may ignore uppercase for this exercise.) Note that the Unicode codepoints are not in strict numerical order, and that there are no mappings for the letters j and v.

Roman letterGreek letterGlyphUnicode (hex)
a alpha 03B1
b beta 03B2
c chi 03C7
d delta 03B4
e epsilon 03B5
f phi 03C6
g gamma 03B3
h eta 03B7
i iota 03B9
k kappa 03BA
l lambda 03BB
m mu 03BC
n nu 03BD
o omicron 03BF
p pi 03C0
q theta 03B8
r rho 03C1
s sigma 03C3
t tau 03C4
u upsilon 03C5
w omega 03C9
x xi 03BE
y psi 03C8
z zeta 03B6

Compile your program against the SIL Galatia Unicode font (SilGalUni20b1.ttf) that is provided with the tutorial materials.

Note

If you use lowercase in the hexadecimal numbers representing your Unicode codepoints, you may see a compilation error: "Undefined glyph class: oundingbox". This a bug in the pre-processor, where it interprets the hex digits 'bb' as 'boundingbox'. The work-around is to use 'BB' in instead of 'bb'.

Solution

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