Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Adjusting Interglyph Positions

You can expand or contract the spacings of all glyphs in a style run by applying a tracking setting to that style run. The tracking setting controls the relative proportion of font-defined adjustments to apply to interglyph positions. (See “ATSUI Style and Text Layout Objects” for more information on the tracking setting style attribute.)

You can set and retrieve the tracking setting using the kATSUTrackingTag style attribute tag. Specifying a tracking setting of 0 means to space “normally” according to the specifications set by the font designer. That does not necessarily mean that no adjustment to spacing occurs. The font designer may decide that normal spacing includes some spacing adjustment in certain point size ranges. A positive tracking setting increases interglyph position while a negative one decreases the interglyph position.

Listing 5-5 shows a function that sets a tracking value for a style object. A detailed explanation for each numbered line of code appears following the listing.

Listing 5-5  A function that sets a tracking value

OSStatus MySetTracking (ATSUStyle theStyle, Fixed myTrackingValue)// 1
{
    OSStatus                status = noERR;
    ATSUAttributeTag        theTag;
    ByteCount               theSize;
    ATSUAttributeValuePtr   theValue;
 
    theTag = kATSUTrackingTag;// 2
    theSize = (ByteCount) sizeof(Fixed);
    theValue = (ATSUAttributeValuePtr) &myTrackingValue;
 
    status = ATSUSetAttributes (theStyle,
                            1,
                            &theTag,
                            &theValueSize,
                            &theValue);// 3
    return status;
 
}

Here’s what the code does:

  1. The MySetTracking function takes a style object and the tracking value you want to associate with the style object. The value must be a Fixed value; positive for loose tracking and negative for tight tracking.

  2. Sets up a triple (tag, size, value) for the tracking attribute.

  3. Calls the function ATSUSetAttributes to associate the tracking value with the style object.

Whenever you want to apply a tracking setting to a line of text, you can include code similar to that shown in Listing 5-6. A detailed explanation for each numbered line of code appears following the listing.

Listing 5-6  Code that applies a tracking setting to a line of text

    myTrackingValue =  Long2Fix (-4);// 1
    status = MySetTracking (myStyle, myTrackingValue);// 2
    require_noerr (status, TrackSettingFailed);
    status = ATSUSetRunStyle (myTextLayout, myStyle,
                            theOffset, theUniLen);// 3
    status = ATSUDrawText (myTextLayout, theOffset,
                    theUniLen, penX, penY);// 4

Here’s what the code does:

  1. Assigns a Fixed value as the tracking value. In this case, the negative value indicates a reduction in interglyph positions—tight tracking.

  2. Calls the function MySetTracking (see Listing 5-5) to associate the tracking value with the style object.

  3. Calls the function ATSUSetRunStyle to associate the style object with the run of text whose tracking you want to modify.

  4. Calls the function ATSUDrawText to render the text onscreen. This line of code assumes you have already determined values for the text offset and length of text to be drawn, as well as the pen location. You must make sure you supply the appropriate parameter values when you call ATSUDrawText.



< Previous PageNext Page > Hide TOC


Last updated: 2007-07-10




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice