Debian Codegraph @

site/tutorial/graphite_tut_solutions.md

raw
1 ---
2 layout: default
3 title: Solutions to Tutorial Exercises
4 nav_order: 999
5 parent: Graphite Tutorial
6 grand_parent: Developers
7 ---
8
9 # Solutions to tutorial exercises
10
11 ## Exercise 2
12
13 ```
14 #include "stddef.gdh"
15
16 table(sub)
17 unicode(0x0024) > unicode(0x00A3); // or U+0024 > U+00A3
18 endtable;
19 ```
20
21 ## Exercise 3a
22
23 ```
24 #include "stddef.gdh"
25
26 table(glyph)
27 gDollar = unicode(0x0024);
28 gPound = unicode(0x00A3);
29 endtable;
30
31 table(sub)
32 gDollar > gPound;
33 endtable;
34 ```
35
36 ## Exercise 3b
37
38 ```
39 #include "stddef.gdh"
40
41 table(glyph)
42 clsDigit = (U+0030..U+0039);
43 gAsterisk = U+002A;
44 endtable;
45
46 table(sub)
47 clsDigit > gAsterisk;
48 endtable;
49 ```
50
51 ## Exercise 4a
52
53 ```
54 #include "stddef.gdh"
55
56 table(glyph)
57 clsLower = unicode(0x61..0x7A);
58 clsUpper = unicode(0x41..0x5A);
59 endtable;
60
61 table(sub)
62 clsLower > clsUpper;
63 endtable;
64 ```
65
66 ## Exercise 4b
67
68 ```
69 #include "stddef.gdh"
70
71 table(glyph)
72 clsLowerVowel = (U+0061, U+0065, U+0069, U+006F, U+0075); // a e i o u
73 clsUpperVowel = (U+0041, U+0045, U+0049, U+004F, U+0055); // A E I O U
74
75 clsLowerCons = ((U+0062..U+0064), // b..d
76 (U+0066..U+0068), // f..h
77 (U+006A..U+006E), // j..n
78 (U+0070..U+0074), // p..t
79 (U+0076..U+007A)); // v..z
80 clsUpperCons = ((U+0042..U+0044), // B..D
81 (U+0046..U+0048), // F..H
82 (U+004A..U+004E), // J..N
83 (U+0050..U+0054), // P..T
84 (U+0056..U+005A)); // V..Z
85 endtable;
86
87 table(sub)
88 clsLowerVowel > clsUpperVowel;
89 clsUpperCons > clsLowerCons;
90 endtable;
91 ```
92
93 ## Exercise 4c
94
95 ```
96 #include "stddef.gdh"
97
98 table(glyph)
99 clsRoman = ((U+0061..U+0069), // a..i
100 (U+006B..U+0075), // k..u
101 (U+0077..U+007a)); // w..z
102
103 clsGreek = (U+03b1, // alpha
104 U+03b2, // beta
105 U+03c7, // chi
106 U+03b4, // delta
107 U+03b5, // epsilon
108 U+03c6, // phi
109 U+03b3, // gamma
110 U+03b7, // eta
111 U+03b9, // iota
112 U+03ba, // kappa
113 U+03BB, // lambda - use BB to avoid compiler bug
114 U+03bc, // mu
115 U+03bd, // nu
116 U+03bf, // omicron
117 U+03d0, // pi
118 U+03b8, // theta
119 U+03c1, // rho
120 U+03c2, // sigma
121 U+03c4, // tau
122 U+03c5, // upsilon
123 U+03c9, // omega
124 U+03be, // xi
125 U+03c8, // psi
126 U+03b6); // zeta
127 endtable;
128
129 table(sub)
130 clsRoman > clsGreek;
131 endtable;
132 ```
133
134 ## Exercise 5a
135
136 Note that this program will generate warnings for the deletion rules.
137
138 {: .red-warning }
139 > **NOTE**
140 >
141 > Linux users have reported compilation errors for this exercise.
142
143 ```
144 #include "stddef.gdh"
145
146 table(glyph)
147
148 // Roman
149
150 clsRoman = ((U+0061..U+0069), // a..i
151 (U+006B..U+0075), // k..u
152 (U+0077..U+007a)); // w..z
153
154 gJ = U+006a;
155 gV = U+0076;
156 gH = U+0068;
157 gT = U+0074;
158 gP = U+0070;
159 gS = U+0073;
160
161 // Greek
162
163 clsGreek = (U+03b1, // alpha
164 U+03b2, // beta
165 U+03c7, // chi
166 U+03b4, // delta
167 U+03b5, // epsilon
168 U+03c6, // phi
169 U+03b3, // gamma
170 U+03b7, // eta
171 U+03b9, // iota
172 U+03ba, // kappa
173 U+03BB, // lambda - use BB to avoid compiler bug
174 U+03bc, // mu
175 U+03bd, // nu
176 U+03bf, // omicron
177 U+03d0, // pi
178 U+03b8, // theta
179 U+03c1, // rho
180 U+03c2, // sigma
181 U+03c4, // tau
182 U+03c5, // upsilon
183 U+03c9, // omega
184 U+03be, // xi
185 U+03c8, // psi
186 U+03b6); // zeta
187
188 gTheta = U+03b8;
189 gPhi = U+03c6;
190 gPsi = U+03c8;
191
192 endtable;
193
194 table(sub)
195 // Delete j and v. Here we do not associate them
196 // with any surface glyph, so it will be impossible
197 // to select or manipulate them.
198 gJ > _;
199 gV > _;
200
201 // Handle sequences.
202 gT gH > gTheta:(1 2) _;
203 gP gH > gPhi:(1 2) _;
204 gP gS > gPsi:(1 2) _;
205
206 // Everything else:
207 clsRoman > clsGreek;
208 endtable;
209 ```
210
211 ## Exercise 5b
212
213 ```
214 #include "stddef.gdh"
215
216 table(glyph)
217 clsQ = (unicode(0x71), unicode(0x51));
218 gU = unicode(0x75);
219 endtable;
220
221 table(sub)
222 clsQ _ > clsQ gU:1;
223
224 // Note: you can also use the @ syntax to copy an item through unchanged:
225 // clsQ _ > @1 gU:1;
226 endtable;
227 ```
228
229 ## Exercise 6a
230
231 ```
232 #include "stddef.gdh"
233
234 table(glyph)
235 gC = (U+0063, U+0043);
236 gK = (U+006b, U+004b);
237 gS = (U+0073, U+0053);
238 clsSoftVowel =
239 (U+0065, U+0069, U+0079, // eiy
240 U+0045, U+0049, U+0059); // EIY
241 endtable;
242
243 table(sub)
244 gC > gS / _ clsSoftVowel;
245 gC > gK;
246 endtable;
247 ```
248
249 ## Exercise 6b
250
251 ```
252 #include "stddef.gdh"
253
254 table(glyph)
255 gQLower = unicode(0x71);
256 gQUpper = unicode(0x51);
257 gULower = unicode(0x75) ;
258 gUUpper = unicode(0x55);
259
260 clsUpper = unicode(0x41..0x5a);
261 endtable;
262
263 table(sub)
264 _ > gUUpper:1 / gQUpper _ clsUpper;
265 _ > gULower:1 / (gQUpper gQLower) _;
266 endtable;
267 ```
268
269 ## Exercise 6c
270
271 ```
272 #include "stddef.gdh"
273
274 table(glyph)
275
276 // Roman
277
278 clsRoman = ((U+0061..U+0069), // a..i
279 (U+006B..U+0075), // k..u
280 (U+0077..U+007a)); // w..z
281
282 gJ = U+006a;
283 gV = U+0076;
284 gH = U+0068;
285 gT = U+0074;
286 gP = U+0070;
287 gS = U+0073;
288
289 // Greek
290
291 clsGreek = (U+03b1, // alpha
292 U+03b2, // beta
293 U+03c7, // chi
294 U+03b4, // delta
295 U+03b5, // epsilon
296 U+03c6, // phi
297 U+03b3, // gamma
298 U+03b7, // eta
299 U+03b9, // iota
300 U+03ba, // kappa
301 U+03BB, // lambda - use BB to avoid compiler bug
302 U+03bc, // mu
303 U+03bd, // nu
304 U+03bf, // omicron
305 U+03d0, // pi
306 U+03b8, // theta
307 U+03c1, // rho
308 U+03c2, // sigma
309 U+03c4, // tau
310 U+03c5, // upsilon
311 U+03c9, // omega
312 U+03be, // xi
313 U+03c8, // psi
314 U+03b6); // zeta
315
316 gTheta = U+03b8;
317 gPhi = U+03c6;
318 gPsi = U+03c8;
319
320 gSigma = U+03c3;
321 gSigmaFinal = U+03c2;
322
323 endtable;
324
325 table(sub)
326 // Delete j and v. Here we do not associate them
327 // with any surface glyph, so it will be impossible
328 // to select or manipulate them.
329 gJ > _;
330 gV > _;
331
332 // Replace s with the right kind of sigma.
333 gS > gSigma / _ clsRoman; // ie, a Roman letter follows
334 gS > gSigmaFinal; // followed by space, punctuation, or nothing at all
335
336
337 // Handle sequences.
338 gT gH > gTheta:(1 2) _;
339 gP gH > gPhi:(1 2) _;
340 gP gS > gPsi:(1 2) _;
341
342 // Everything else:
343 clsRoman > clsGreek;
344
345 endtable;
346 ```
347
348 ## Exercise 7
349
350 ```
351 #include "stddef.gdh"
352
353 // The following is true by default, so does not really need to
354 // be stated. It needs to be true because we are overriding
355 // the value of followsHardC for soft vowels in the glyph table.
356 environment { AttributeOverride = true };
357
358 table(glyph)
359 gC = (U+0063 U+0043);
360 gK = (U+006b U+004b);
361 gS = (U+0073 U+0053);
362 clsLetter = ((U+0061..U+007a), (U+0041..U+005a))
363 {followsHardC = true};
364 clsSoftVowel =
365 (U+0065, U+0069, U+0079, // eiy
366 U+0045, U+0049, U+0059) // EIY
367 {followsHardC = false}; // overrides above
368 endtable;
369
370 table(sub)
371 gC > gK / _ clsLetter { followsHardC };
372 gC > gS / _ clsLetter { !followsHardC };
373 endtable;
374
375 endenvironment;
376 ```
377
378 ## Exercise 9
379
380 ```
381 #include "stddef.gdh"
382
383 #define hardC user1
384
385 table(glyph)
386 gC = (U+0063 U+0043);
387 gK = (U+006b U+004b);
388 gS = (U+0073 U+0053);
389
390 clsHardLetter = (
391 (U+0061..U+0064), // a..d
392 (U+0066..U+0068), // f..h
393 (U+006A..U+0078), // j..x
394 U+007A, // z
395 (U+0041..U+0044), // A..D
396 (U+0046..U+0058), // F..H
397 (U+004A..U+0058), // J..X
398 U+005A); // Z
399 clsSoftLetter =
400 (U+0065, U+0069, U+0079, // eiy
401 U+0045, U+0049, U+0059) // EIY
402
403 endtable;
404
405 table(sub)
406
407 pass(1)
408 // Mark the C based on its context.
409 gC {hardC = true} / _ clsHardLetter;
410 gC {hardC = false} / _ clsSoftLetter;
411 endpass;
412
413 pass(2);
414 // Make the substitution.
415 gC > gK / _ {hardC};
416 gC > gS / _ {!hardC};
417 endpass;
418
419 endtable;
420 ```
421
422 ## Exercise 10a
423
424 ```
425 #include "stddef.gdh"
426
427 table(glyph)
428 clsDigit = (U+0030..U+0039);
429 endtable;
430
431 table(pos) { MUnits = 1000 }
432 clsDigit {shift.y = -300m} ;
433 endtable;
434 ```
435
436 ## Exercise 10b
437
438 ```
439 #include "stddef.gdh"
440
441 table(glyph)
442 clsAUpper = U+0041;
443 clsVWUpper = (U+0056, U+0057);
444 endtable;
445
446 table(pos)
447 clsAUpper { kern.x = -175m } / clsVWUpper _ ;
448 clsVWUpper { kern.x = -175m } / clsAUpper _ ;
449 endtable;
450 ```
451
452 ## Exercise 11
453
454 ```
455 #include "stddef.gdh"
456
457 table(glyph)
458 clsDotted = (unicode(0x69), unicode(0x6a)); // i, j
459 clsDotless = (glyphid(194), glyphid(195));
460 clsDiac = (unicode(0x0300..0x0304), unicode(0x0308), unicode(0x030c))
461 { halfWidth = bb.width/2 };
462 clsBase = (unicode(0x61..0x7a), unicode(0x41..0x5a), clsDotless)
463 { halfWidth = bb.width/2;
464 baseHt = bb.top + 100m;
465 rtSide = rsb;
466 };
467 endtable;
468
469 table(sub)
470 // Remove any dot.
471 clsDotted > clsDotless / _ clsDiac;
472 endtable;
473
474 table(pos)
475 clsBase clsDiac {
476 // "0 – lsb - ... " is a workaround for a bug in the compiler.
477 shift {
478 x = 0 - lsb - halfWidth - @1.halfWidth - @1.rtSide;
479 y = @1.baseHt - bb.bottom } };
480 endtable;
481 ```
482
483 ## Exercise 12a
484
485 ```
486 #include "stddef.gdh"
487
488 environment { PointRadius = 0 } // workaround for hinting bug
489
490 table(glyph)
491 clsDotted = (unicode(0x69), unicode(0x6a)); // i, j
492 clsDotless = (glyphid(194), glyphid(195));
493 clsDiac = (unicode(0x0300..0x0304), unicode(0x0308), unicode(0x030c))
494 { upperAttPtM= point(lsb + bb.width/2, bb.bottom – 50m) };
495 clsBase = (unicode(0x61..0x7a), unicode(0x41..0x5a), clsDotless)
496 // An alternative to "advancewidth/2" is "lsb + bb.width/2".
497 { upperAttPtS = point(advancewidth/2, bb.top) };
498 endtable;
499
500 table(sub)
501 // Remove any dot.
502 clsDotted > clsDotless / _ clsDiac;
503 endtable;
504
505 table(pos)
506 clsBase clsDiac { attach { to=@1; at=upperAttPtS; with=upperAttPtM } };
507 endtable;
508
509 endenvironment;
510 The following is the result when using Graide to create attachment points:
511
512 #include "stddef.gdh"
513
514 table(glyph)
515 clsDotted = (unicode(0x69), unicode(0x6a)); // i, j
516 clsDotless = (glyphid(194), glyphid(195));
517 endtable;
518
519 table(sub)
520 // Remove any dot.
521 clsDotted > clsDotless / _ cupperDia;
522 endtable;
523
524 // upperS and upperM are defined in the auto-generated file
525 table(pos)
526 cTakesupperDia cupperDia { attach { to=@1; at=upperS; with=upperM } };
527 endtable;
528 ```
529
530 ## Exercise 12b
531
532 ```
533 #include "stddef.gdh"
534
535 environment { PointRadius = 0 } // workaround for hinting bug
536
537 table(glyph)
538 clsDiac = (unicode(0x0316) unicode(0x0317), unicode(0x031f), unicode(0x0327..0x0330))
539 { lowerM = point(lsb + bb.width/2, bb.top + 50m) };
540 clsBase = (unicode(0x61..0x7a), unicode(0x41..0x5a))
541 // An alternative to "advancewidth/2" is lsb + bb.width/2.
542 { lowerS = point(advancewidth/2, bb.bottom) };
543 endtable;
544
545 table(pos)
546 clsBase clsDiac { attach { to=@1; at=lowerS; with=lowerM } };
547 endtable;
548
549 endenvironment;
550 The following is the result when using Graide to create attachment points:
551
552 #include "stddef.gdh"
553
554 // lowerS and lowerM are defined in the auto-generated file
555 table(pos)
556 cTakeslowerDia clowerDia { attach { to=@1; at=lowerS; with=lowerM } };
557 endtable;
558 ```
559
560 ## Exercise 12c
561
562 ```
563 #include "stddef.gdh"
564
565 table(glyph)
566 clsBase = (unicode(0x03b1) unicode(0x03b7), unicode(0x03c9))
567 { attPtIota = point(lsb + bb.width/2, bb.bottom);
568 attPtBreath = point(lsb + bb.width/2, bb.top)
569 };
570 // Adjust x-position of attachment point for eta. We are in
571 // effect overriding the value set above.
572 gEta = unicode(0x03b7)
573 { attPtIota = point(lsb + (bb.width*3/8), bb.bottom + 160m) };
574 gIotaDiac = unicode(0x0345)
575 { attPt = point(lsb + bb.width/2, bb.bottom + 50m) };
576 clsBreathDiac = unicode(0x0313..0x0314)
577 { attPt = point(lsb + bb.width/2, bb.bottom – 50m) };
578 endtable;
579
580 table(pos)
581 clsBase
582 clsBreathDiac { attach { to=@1; at=attPtBreath; with=attPt } }
583 gIotaDiac { attach { to=@1; at=attPtIota; with=attPt } };
584
585 clsBase gIotaDiac { attach { to=@1; at= attPtIota; with=attPt } };
586 endtable;
587 ```
588
589 The following is the result when using Graide to create attachment points:
590
591 ```
592 #include "stddef.gdh"
593
594 // lowerIotaS and lowerIotaM are defined in the auto-generated file
595 table(pos)
596
597 cTakeslowerIotaDia clowerIotaDia {attach {to = @1; at = lowerIotaS; with = lowerIotaM}};
598
599 endtable;
600 ```
601
602 ## Exercise 13a
603
604 ```
605 include "stddef.gdh"
606
607 table(glyph)
608 clsDigit = (U+0030..U+0039);
609 endtable;
610
611 table(feature)
612
613 supersub {
614 id = "digt";
615 name.LG_USENG = string("Superscript or Subscript");
616 default = super;
617 settings {
618 no {
619 value = 0;
620 name.LG_USENG=string("Neither")
621 }
622 super {
623 value = 1;
624 name.LG_USENG=string("Superscript")
625 }
626 subsc { // unfortunately, can't call it "sub"
627 value = 2;
628 name.LG_USENG=string("Subscript")
629 }
630 }
631 }
632
633 endtable;
634
635 table(pos)
636
637 if (supersub == super)
638 clsDigit {shift.y = 300m};
639 elseif (supersub == subsc)
640 clsDigit {shift.y = -300m};
641 endif;
642
643 endtable;
644 ```
645
646 ## Exercise 13b
647
648 ```
649 #include "stddef.gdh"
650 table(glyph)
651 clsAUpper = U+0041;
652 clsVWUpper = (U+0056, U+0057);
653 endtable;
654
655 table(feature)
656
657 doKerning {
658 id = "k_wv" ;
659 name.LG_USENG = string("Kerning");
660 }
661
662 endtable;
663
664 table(pos)
665
666 if (doKerning)
667 clsAUpper { kern.x = -175m } / clsVWUpper _ ;
668 clsVWUpper { kern.x = -175m } / clsAUpper _ ;
669 endif;
670
671 endtable;
672 ```
673
674 ## Exercise 13c
675
676 ```
677 #include "stddef.gdh"
678
679 table(glyph)
680 // same as previous
681 endtable;
682
683 table(feature)
684
685 greek_xlit {
686 id = "r2gk"
687 name.LG_USENG = string("Greek Transliteration");
688 }
689
690 endtable;
691
692 table(sub)
693
694 if (greek_xlit)
695 // rules go here
696 endif;
697
698 endtable;
699 ```
700
701 ## Exercise 14a
702
703 {: .blue-note }
704 > **Note**
705 >
706 > This solution has not been tested. Try at your own risk!
707
708 ```
709 #include "stddef.gdh"
710
711 table(glyph)
712 clsLigComp1 =
713 (unicode(0x6f), unicode(0x66), unicode(0x66)); // off
714 clsLigComp2 =
715 (unicode(0x65), unicode(0x69), unicode(0x6c)); // eil
716 // Each component is half the width of the bounding box:
717 clsLig = (glyphid(155), // oe
718 glyphid(168), // fi
719 glyphid(169)) // fl
720 {
721 comp.c1 = box(bb.left, bb.bottom, bb.width/2, bb.top);
722 comp.c2 = box(bb.width/2, bb.bottom, bb.right, bb.top)
723 };
724
725 endtable;
726
727 table(feature)
728
729 lig {
730 id = "ligs";
731 name.LG_USENG = string("Ligatures");
732 }
733
734 endtable;
735
736 table(sub)
737
738 if (lig)
739 // Note: we use the second character as the selector of
740 // the replacement ligature, since it can unambiguously
741 // identify it
742 clsLigComp1 clsLigComp2 >
743 _ clsLig:(1 2) { comp.c1.ref = @1; comp.c2.ref = @2 };
744 endif;
745
746 endtable;
747 ```
748
749 ## Exercise 14b
750
751 ```
752 #include "stddef.gdh"
753
754 table(glyph)
755 gNum1 = unicode(0x31); // 1
756 gNum3 = unicode(0x33); // 3
757 clsDenom1 = (unicode(0x34), unicode(0x32)); // 4,2
758 clsDenom3 = unicode(0x34); // 4
759 gSlash = unicode(0x2f);
760 clsLig1 = (unicode(0xbc), unicode(0xbd)); // 1/4, 1/2
761 clsLig3 = unicode(0xbe); // 3/4
762
763 // Each component is half the width of the bounding box:
764 clsLig = unicode(0xbc..0xbe) // 1/4, 1/2, 3/4
765 { comp.num = box(bb.left, bb.bottom + 200m, lsb + bb.width*3/8, bb.top);
766 comp.slash = box(lsb + bb.width/3, bb.bottom, (lsb + bb.width*2/3, bb.top) ;
767 comp.denom = box(lsb + bb.width*5/8, bb.bottom – 100m, bb.right, bb.bottom + 600m)
768 };
769 endtable;
770
771 table(sub)
772 // 1/4, 1/2
773 gNum1 gSlash clsDenom1 >
774 _ _ clsLig1:(1 2 3) {
775 comp {num.ref = @1; slash.ref = @2; denom.ref = @3}};
776 // 3/4
777 gNum3 gSlash clsDenom3 >
778 _ _ clsLig3:(1 2 3) {
779 comp {num.ref = @1; slash.ref = @2; denom.ref = @3}};
780 endtable;
781 ```
782
783 ## Exercise 14c
784
785 ```
786 #include "stddef.gdh"
787
788 table(glyph)
789 one = U+0031; // 1
790 two = U+0032; // 2
791 thr = U+0033; // 3
792
793 clsNumber = (one, two, thr);
794
795 oneTone = (glyphid(381), glyphid(368), glyphid(354));
796
797 // Two-tone combinations:
798
799 low2 = (glyphid(381), glyphid(382), glyphid(383));
800 mid2 = (glyphid(367), glyphid(368), glyphid(369));
801 high2 = (glyphid(352), glyphid(353), glyphid(354));
802
803 twoTone = (low2, mid2, high2)
804 { comp { tone1 = box(0, -descent, aw/2, ascent);
805 tone2 = box(aw/2, -descent, aw, ascent) } };
806
807 // Three-tone combinations:
808 lowLow3 = (glyphid(381), glyphid(391), glyphid(392));
809 lowMid3 = (glyphid(446), glyphid(447), glyphid(383));
810 lowHigh3 = (glyphid(450), glyphid(451), glyphid(452));
811 midLow3 = (glyphid(376), glyphid(377), glyphid(378));
812 midMid3 = (glyphid(433), glyphid(368), glyphid(434));
813 midHigh3 = (glyphid(437), glyphid(438), glyphid(439));
814 highLow3 = (glyphid(362), glyphid(363), glyphid(364));
815 highMid3 = (glyphid(352), glyphid(420), glyphid(421));
816 highHigh3 = (glyphid(424), glyphid(425), glyphid(354));
817
818 threeTone = (lowLow3, lowMid3, lowHigh3,
819 midLow3, midMid3, midHigh3,
820 highLow3, highMid3, highHigh3)
821 { comp{ tone1 = box(0, -descent, aw/3, ascent);
822 tone2 = box(aw/3, -descent, aw * 2/3, ascent);
823 tone3 = box(aw * 2/3, -descent, aw, ascent) } };
824 endtable;
825
826 table(sub)
827 // Three-tone sequences:
828
829 one one clsNumber > _ _ lowLow3:(1 2 3)
830 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
831 one two clsNumber > _ _ lowMid3:(1 2 3)
832 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
833 one thr clsNumber > _ _ lowHigh3:(1 2 3)
834 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
835
836 two one clsNumber > _ _ midLow3:(1 2 3)
837 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
838 two two clsNumber > _ _ midMid3:(1 2 3)
839 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
840 two thr clsNumber > _ _ midHigh3:(1 2 3)
841 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
842
843 thr one clsNumber > _ _ highLow3:(1 2 3)
844 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
845 thr two clsNumber > _ _ highMid3:(1 2 3)
846 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
847 thr thr clsNumber > _ _ highHigh3:(1 2 3)
848 {comp { tone1.ref = @1; tone2.ref = @2; tone3.ref = @3 }};
849
850 // Two-tone sequences:
851
852 one clsNumber > _ low2:(1 2)
853 {comp { tone1.ref = @1; tone2.ref = @2 }} ;
854 two clsNumber > _ mid2:(1 2)
855 {comp { tone1.ref = @1; tone2.ref = @2 }} ;
856 thr clsNumber > _ high2:(1 2)
857 {comp { tone1.ref = @1; tone2.ref = @2 }} ;
858
859 // Single tones:
860
861 clsNumber > oneTone;
862
863 endtable;
864 ```
865
866 ## Exercise 15
867
868 ```
869 #include "stddef.gdh"
870
871 Bidi = true;
872
873 table(glyph)
874
875 // Not needed; true by default:
876 //clsLower = (U+0061..U+007a) { dir = DIR_LEFT };
877
878 clsUpper = (U+0041..U+005a) { dir = DIR_RIGHT };
879
880 endtable;
881
882 // No rules needed!
883 ```
884
885 ## Exercise 16
886
887 ```
888 #include "stddef.gdh"
889
890 table(glyph)
891 clsBackRoundedVowel = (unicode(0x6f), unicode(0x75)); // o, u
892 clsCons = (unicode(0x62..0x64), // b..d
893 unicode(0x66..0x68), // f..h
894 unicode(0x6A..0x6E), // j..n
895 unicode(0x70..0x74) // p..t
896 unicode(0x76..0x7A)); // v..z
897 endtable;
898
899 table(sub)
900 clsCons clsBackRoundedVowel > @2 @1;
901 endtable;
902 ```
903
904 ## Exercise 17
905
906 ```
907 #include "stddef.gdh"
908
909 table(glyph)
910 clsBackRoundedVowel = (unicode(0x6f), unicode(0x75)); // o, u
911 clsCons = (unicode(0x62..0x64), // b..d
912 unicode(0x66..0x68), // f..h
913 unicode(0x6A..0x6E), // j..n
914 unicode(0x70..0x74) // p..t
915 unicode(0x76..0x7A)); // v..z
916 endtable;
917
918 table(sub)
919 _ clsCons clsBackRoundedVowel > @5 @2 _
920 / _ _ [clsCons clsCons? ]? _;
921 endtable;
922 ```
923
924 ## Exercise 18
925
926 ```
927 #include "stddef.gdh"
928 table(glyph)
929 clsBackRndVowelLC = (unicode(0x6f), unicode(0x75)); // o, u
930 clsBackRndVowelUC = (unicode(0x4f), unicode(0x55)); // O, U
931 clsBackRndVowel = (clsBackRndVowelLC clsBackRndVowelUC);
932
933 clsConsLC = (unicode(0x62..0x64), // b..d
934 unicode(0x66..0x68), // f..h
935 unicode(0x6A..0x6E), // j..n
936 unicode(0x70..0x74), // p..t
937 unicode(0x76..0x7A)); // v..z
938 clsConsUC = (unicode(0x42..0x44), // B..D
939 unicode(0x46..0x48), // F..H
940 unicode(0x4A..0x4E), // J..N
941 unicode(0x50..0x54), // P..T
942 unicode(0x56..0x5A)); // V..Z
943 clsCons = (clsConsLC clsConsUC);
944 endtable;
945
946 table(sub)
947 // Move upper-case from consonant to reordered vowel.
948 _ clsConsUC clsBackRndVowelLC > clsBackRndVowelUC$5:5 clsConsLC$2:2 _ // see note below
949 / _ _ [clsCons clsCons? ]? _;
950
951 // Move upper-case from vowel to consonant (odd, but you never know!).
952 _ clsConsLC clsBackRndVowelUC > clsBackRndVowelLC$5:5 clsConsUC$2:2
953 / _ _ [clsCons clsCons? ]? _;
954
955 // Otherwise, case matches on vowel and consonant; just reorder.
956 _ clsCons clsBackRndVowel > @5 @2 _
957 / _ _ [clsCons clsCons? ]? _;
958 endtable;
959 ```
960
961 Note that `clsConsLC$2:2` could be written as `clsConsLC`; the `$2:2` is included only to make the code clearer.
962
963 ## Exercise 19a
964
965 ```
966 #include "stddef.gdh"
967 table(glyph)
968 clsHyphenLike = (unicode(0x2d), unicode(0x003d), unicode(0x5f), unicode(0x7e))
969 { break = BREAK_INTRA };
970 endtable;
971
972 // No rules needed!
973 ```
974
975 ## Exercise 19b
976
977 ```
978 #include "stddef.gdh"
979
980 table(glyph)
981 clsSylBreak = U+002a { break = BREAK_INTRA };
982 gHyphen = U+002d;
983 endtable;
984
985 table(sub)
986 // Replace an * with a hyphen at a line break, otherwise delete it.
987 clsSylBreak > gHyphen / _ # {break == BREAK_INTRA};
988 clsSylBreak > _;
989 endtable;
990 ```
991
992 ## Exercise 19c
993
994 ```
995 #include "stddef.gdh"
996
997 table(glyph)
998 clsConsStop = (unicode(0x70), // p
999 unicode(0x62), // b
1000 unicode(0x74), // t
1001 unicode(0x64), // d
1002 unicode(0x6b), // k
1003 unicode(0x67)); // g
1004 gHyphen = unicode(0x2d);
1005 endtable;
1006
1007 table(lb)
1008 clsConsStop {break = BREAK_INTRA} / _ clsConsStop;
1009 endtable;
1010
1011 table(sub)
1012 _ > gHyphen:1 / clsConsStop { break == BREAK_INTRA } _ #;
1013 endtable;
1014 ```
1015
1016 ## Exercise 19d
1017
1018 Modifying 19a:
1019
1020 ```
1021 #include "stddef.gdh"
1022
1023 table(glyph)
1024 clsHyphenLike = (unicode(0x2d), unicode(0x003d), unicode(0x5f), unicode(0x7e))
1025 { break = BREAK_INTRA };
1026 endtable;
1027
1028 table(sub)
1029 // Insert a copy of the "hyphen" at the beginning of the following line.
1030 _ > @1 / clsHyphenLike # _;
1031 endtable;
1032 ```
1033
1034 Modifying 19b:
1035
1036 ```
1037 #include "stddef.gdh"
1038
1039 table(glyph)
1040 clsSylBreak = U+002a { break = BREAK_INTRA };
1041 gHyphen = U+002d;
1042 endtable;
1043
1044 table(sub)
1045 // Replace an * with a hyphen at a line break;
1046 // also insert a hyphen at the beginning of the following line.
1047 clsSylBreak _ > gHyphen gHyphen:1
1048 / _ # {break == BREAK_INTRA} _;
1049
1050 // Otherwise delete it.
1051 clsSylBreak > _;
1052 endtable;
1053 ```
1054
1055 Modifying 19c:
1056
1057 ```
1058 #include "stddef.gdh"
1059 table(glyph)
1060 clsConsStop = (unicode(0x70), // p
1061 unicode(0x62), // b
1062 unicode(0x74), // t
1063 unicode(0x64), // d
1064 unicode(0x6b), // k
1065 unicode(0x67)); // g
1066 gHyphen = unicode(0x2d);
1067 endtable;
1068
1069 table(lb)
1070 clsConsStop {break = BREAK_INTRA} / _ clsConsStop;
1071 endtable;
1072
1073 table(sub)
1074 // A bug in the Graphite engine forces us to test the
1075 // breakweight of the line-break itself, not the consonant.
1076 _ _ > gHyphen:1 gHyphen:1
1077 / clsConsStop _ # { break == BREAK_INTRA } _;
1078 endtable;
1079 ```