< Previous PageNext Page > Hide TOC

Responding to Font Changes

The font manager responds to a font-changing action method by sending a changeFont action message up the responder chain. A text-bearing object that receives this message should have the font manager convert the fonts in its selection by invoking convertFont for each font and using the NSFont object returned. The convertFont method uses the information recorded by the font-changing action method, such as addFontTrait, modifying the font provided appropriately. (There’s no way to explicitly set the font-changing action or trait; instead, you use the methods described in “Converting Fonts Manually.”)

This simple Objective-C example assumes there’s only one font in the selection:

- (void)changeFont:(id)sender
{
    NSFont *oldFont = [self selectionFont];
    NSFont *newFont = [sender convertFont:oldFont];
    [self setSelectionFont:newFont];
    return;
}

Most text-bearing objects have to scan the selection for ranges with different fonts and invoke convertFont for each one.



< Previous PageNext Page > Hide TOC


© 1997, 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-02-08)


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.