Retired Document
Important: This document is deprecated. Please see Cocoa Text Architecture Guide for information about font handling in the Cocoa text system.
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.
Copyright © 1997, 2012 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2012-07-23