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

< Previous PageNext Page > Hide TOC

Kerning Text

Kerning increases the overlap between glyphs that fit together naturally. As such, it does not apply evenly to all glyphs in a style run. ATSUI uses information supplied by the font to determine how much to increase or decrease the space between glyphs. In the general case, this amount can depend on more than just the two adjacent glyphs. The amount of kerning can also depend on the preceding or following glyphs, or even on glyphs in other parts of the line.

You can control how much kerning is applied to text, or you can specify that no kerning should occur. Kerning is controlled by the style attribute kATSUKerningInhibitFactorTag. As its name implies, when you associate a value with the kATSUKerningInhibitFactorTag you specify to what degree to inhibit the kerning set by the font designer.

If you set the value associated with this tag to 1, kerning is inhibited completely. If you set the value to 0, kerning is used to the full amount specified by the font designer. If you specify a value between 0 and 1, kerning is reduced. The specific amount of reduction is based on the values specified by the font designer. If glyphs aren’t usually kerned, then kerning inhibition has no effect. If glyphs are usually kerned, then ATSUI uses the value you provide to calculate a percentage of what’s specified by the font designer.

Listing 5-4 shows a function that sets a kerning inhibition value for a style object. A detailed explanation for each numbered line of code follows the listing.

Listing 5-4  A function that sets kerning inhibition for a style object

status MySetKerningInhibitFactor (ATSUStyle myStyleObject,
                                Fract kerningInhibitFactor)// 1
{
    OSStatus                status = noErr;
    ATSUAttributeTag        theTag;
    ByteCount               theSize;
    ATSUAttributeValuePtr   theValue;
 
    theTag = kATSUKerningInhibitFactorTag;// 2
    theSize = (ByteCount) sizeof(Fract);
    theValue = (ATSUAttributeValuePtr) &kerningInhibitFactor;
 
    status = ATSUSetAttributes (myStyleObject, 1,
                        &theTag, &theSize, &theValue);// 3
    return status;
}

Here’s what the code does:

  1. The MySetKerningInhibitFactor function takes two parameters, a previously created style object and a kerning inhibition value. Values can be from 0 to 1.0, with 0 having no effect on kerning and 1.0 specifying not to use kerning.

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

  3. Associates the kerning inhibition attribute with a style object.

After you have associated a kerning inhibition value with a style object, you must then call the function ATSUSetRunStyle to associate the style object with the run of text whose kerning you want to inhibit. If you want to affect kerning for an entire text object, you can supply this style object when you create the text layout object.



< 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