SIL Non-Roman Script Initiative

Graphite

A free and open rendering engine for complex scripts

Graphite Tutorial

Exercise

Unit 11: Glyph metrics

Discussion

To position glyphs correctly, it is often necessary to make use of the glyph’s metrics from within the font. Glyph metrics are numeric values for standard measurements defined for each glyph within the TrueType font. The following metrics can be used in a GDL program:

  • boundingbox.top (bb.top)
  • boundingbox.bottom (bb.bottom)
  • boundingbox.right (bb.right)
  • boundingbox.left (bb.left)
  • boundingbox.height (bb.height)
  • boundingbox.width (bb.width)
  • advanceheight (ah)
  • advancewidth (aw)
  • leftsidebearing (lsb)
  • rightsidebearing (rsb)
  • ascent
  • descent

Useful abbreviations (as defined in stddef.gdh) are shown in parenthesis. Note that ascent and descent are not metrics of an individual glyph but of the font as a whole.

Exercise 11

For this exercise use sildub3.ttf. Use shifting and/or kerning to position diacritics (such as those shown in the table below) over various base characters. The diacritics should be attached to the previous base character.

What is required to position them correctly over base characters of widely different widths and heights (eg, m vs. l)?

What is necessary to handle diacritics that have overstriking built in to their glyph metrics?

What is necessary to render i and j correctly with diacritics? (Hint: other glyphs you may find useful include: dotless i [glyphid 175] and dotless j [glyphid 217]).

To test your program, open file test_ex11.wpx, and set the font of writing system TUT11 to your font. Or install the “Graphite Tutorial” (graphite_tutorial.kmx) Keyman keyboard and use the keystrokes shown in the table below.

CharacterGlyphKeystroke(s)Unicode (hex)
acute ' (apostrophe) 0301
grave ` (backquote) 0300
diaeresis : (colon) 0308
circumflex ^ 0302
hacek + v 030C
macron + - 0304
tilde ~ 0303

Hint: instead of including numbers directly in the rules, define glyph attributes indicating the amounts by which to shift. You may also need to define a glyph attribute on the base characters as well as the diacritics being positioned. To access glyph attributes for a slot in the rule other than the one being shifted, use the following syntax:

@slot-number.glyph-attr

Solution

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