Home Segments Index Top Previous Next

685: Sidetrip

If you want to exert fine control over text placement, you need to know about the descender and the stringWidthOf: messages.

When you display strings, the characters are placed on a baseline. Portions of all characters appear above the baseline. Characters such as g have descenders that appear below the baseline.

The distance by which a font extends above the baseline is that font's height, whereas the distance by which the font's characters extends below the baseline is the font's descent. The height and descender methods answer the maxima for the height and descent when sent to a font instance:

 *-- A font                      *-- A font 
 v                               v 
----------                      ---------- 
a pen font height           a pen font descender 
-----------------               ----------------- 
 ^                               ^ 
 *-- The font's height           *-- The font's descent 

The stringWidthOf: method, when sent to a graphics context, answers the width that a specified string would occupy if the string were displayed in the font associated with graphics context:

 *-- A graphic context 
 v 
----- 
a pen stringWidthOf: a string 
----------------------------- 
 ^ 
 *-- The width of the displayed string