API  1.0.0
CPFont Class Reference

#import <CPFont.h>

+ Inheritance diagram for CPFont:

Instance Methods

(float) - ascender
 
(id) - copy
 
(CPString- cssString
 
(float) - defaultLineHeightForFont
 
(float) - descender
 
(CPString- description
 
(void) - encodeWithCoder:
 
(CPString- familyName
 
(CPFontDescriptor- fontDescriptor
 
(id) - initWithCoder:
 
(BOOL) - isBold
 
(BOOL) - isEqual:
 
(BOOL) - isItalic
 
(BOOL) - isSystem
 
(BOOL) - isSystemSize
 
(float) - size
 
- Instance Methods inherited from CPObject
(void) - addObserver:forKeyPath:options:context:
 
(void) - applyChange:toKeyPath:
 
(id) - autorelease
 
(id) - awakeAfterUsingCoder:
 
(void) - awakeFromCib
 
(void) - bind:toObject:withKeyPath:options:
 
(Class) - classForCoder
 
(Class) - classForKeyedArchiver
 
(CPString- className
 
(void) - dealloc
 
(CPDictionary- dictionaryWithValuesForKeys:
 
(void) - didChange:valuesAtIndexes:forKey:
 
(void) - didChangeValueForKey:
 
(void) - didChangeValueForKey:withSetMutation:usingObjects:
 
(void) - doesNotRecognizeSelector:
 
(CPArray) - exposedBindings
 
(id) - forwardingTargetForSelector:
 
(void) - forwardInvocation:
 
(unsigned) - hash
 
(BOOL) - implementsSelector:
 
(CPDictionary- infoForBinding:
 
(id) - init
 
(BOOL) - isKindOfClass:
 
(BOOL) - isMemberOfClass:
 
(BOOL) - isProxy
 
(IMP) - methodForSelector:
 
(CPMethodSignature) - methodSignatureForSelector:
 
(id) - mutableArrayValueForKey:
 
(id) - mutableArrayValueForKeyPath:
 
(id) - mutableCopy
 
(id) - mutableSetValueForKey:
 
(id) - mutableSetValueForKeyPath:
 
(id) - performSelector:
 
(id) - performSelector:withObject:
 
(void) - performSelector:withObject:afterDelay:
 
(void) - performSelector:withObject:afterDelay:inModes:
 
(id) - performSelector:withObject:withObject:
 
(id) - performSelector:withObjects:
 
(void) - release
 
(void) - removeObserver:forKeyPath:
 
(id) - replacementObjectForArchiver:
 
(id) - replacementObjectForCoder:
 
(id) - replacementObjectForKeyedArchiver:
 
(BOOL) - respondsToSelector:
 
(id) - retain
 
(id) - self
 
(void) - setValue:forKey:
 
(void) - setValue:forKeyPath:
 
(void) - setValue:forUndefinedKey:
 
(void) - setValuesForKeysWithDictionary:
 
(CPString- UID
 
(void) - unbind:
 
(Class) - valueClassForBinding:
 
(id) - valueForKey:
 
(id) - valueForKeyPath:
 
(id) - valueForUndefinedKey:
 
(void) - willChange:valuesAtIndexes:forKey:
 
(void) - willChangeValueForKey:
 
(void) - willChangeValueForKey:withSetMutation:usingObjects:
 

Class Methods

(CPFont+ boldFontWithName:size:
 
(CPFont+ boldFontWithName:size:italic:
 
(CPFont+ boldSystemFontOfSize:
 
(CPFont+ fontWithDescriptor:size:
 
(CPFont+ fontWithName:size:
 
(CPFont+ fontWithName:size:italic:
 
(void) + initialize
 
(CPString+ setSystemFontFace:
 
(float) + setSystemFontSize:
 
(CPString+ systemFontFace
 
(CPFont+ systemFontForControlSize:
 
(CPFont+ systemFontOfSize:
 
(float) + systemFontSize
 
- Class Methods inherited from CPObject
(BOOL) + accessInstanceVariablesDirectly
 
(id) + alloc
 
(id) + allocWithCoder:
 
(BOOL) + automaticallyNotifiesObserversForKey:
 
(void) + cancelPreviousPerformRequestsWithTarget:
 
(void) + cancelPreviousPerformRequestsWithTarget:selector:object:
 
(Class) + class
 
(BOOL) + conformsToProtocol:
 
(void) + exposeBinding:
 
(IMP) + instanceMethodForSelector:
 
(BOOL) + instancesImplementSelector:
 
(BOOL) + instancesRespondToSelector:
 
(BOOL) + isBindingExclusive:
 
(BOOL) + isSubclassOfClass:
 
(CPSet) + keyPathsForValuesAffectingValueForKey:
 
(void) + load
 
(id) + new
 
(void) + object:performSelector:withObject:afterDelay:inModes:
 
(void) + setVersion:
 
(Class) + superclass
 
(int) + version
 

Detailed Description

The CPFont class allows control of the fonts used for displaying text anywhere on the screen. The primary method for getting a particular font is through one of the class methods that take a name and/or size as arguments, and return the appropriate CPFont.

System fonts

When you create a font using -systemFontOfSize: or -boldSystemFontOfSize:, a proxy font is created that always refers to the current system font face and size. By default the system font face/size is Arial 12px, with a fallback to sans-serif 12px. You may configure this at runtime in two ways:

  • By sending [CPFont setSystemFontFace:<face>] and/or [CPFont setSystemFontSize:<size>]. Note that if you change the system font face or size during runtime, the next time any view using a system font is redrawn, it will show the new font.
  • By configuring Info.plist for your application or for AppKit. You can set the font face by adding a CPSystemFontFace string item to the Info.plist, and you can set the font size by adding a CPSystemFontSize integer item to the Info.plist.

Note that in either case, you can specify a comma-delimited list of fonts as the font face. Do not quote enclose font faces that contain spaces, that is done automatically when a CSS representation of a font is requested.

The browser will use the first available font in the list you supply. CPFont always ensures that Arial and sans-serif are in the CSS representation of a font as a fallback, so there is no need to add them to the end of your font list.

nib2cib conversion

Fonts are converted by nib2cib according to the following algorithm:

  • If the font family is Lucida Grande, then a system font will be created.
  • If the font is Lucida Grande 13 (plain), the "default" font will be used at runtime. The default font is taken from the "font" theme attribute if one exists, otherwise from the current system font face and size.
  • Lucida Grande of any size other than 13 will retain its size.
  • Fonts using any family other than Lucida Grande will be used as is, including the size.

Using custom web fonts

The configurability of CPFont makes it easy to use a custom web font as the system font. For example, if you want to use the google font Asap as the system font, you would do the following:

  • Add a <link> to the <head> of index-debug.html and index.html:
    <link href='http://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>
  • Specify Asap as the system font in Info.plist by adding the following item:
    <key>CPSystemFontFace</key>
    <string>Asap</string>

Definition at line 2 of file CPFont.h.

Method Documentation

◆ ascender()

- (float) ascender
implementation

Returns the distance of the longest ascender's top y-coordinate from the baseline (in CSS px)

Definition at line 333 of file CPFont.j.

◆ boldFontWithName:size:()

+ (CPFont) boldFontWithName: (CPString aName
size: (float)  aSize 
implementation

Returns a bold font with the specified name and size.

Parameters
aNamethe name of the font
aSizethe size of the font (in px). 0 or negative will create a font in the current system font size.
Returns
the requested bold font

Definition at line 249 of file CPFont.j.

◆ boldFontWithName:size:italic:()

+ (CPFont) boldFontWithName: (CPString aName
size: (float)  aSize
italic: (BOOL)  italic 
implementation

Returns a bold font with the specified name, size and style.

Parameters
aNamethe name of the font
aSizethe size of the font (in px). 0 or negative will create a font in the current system font size.
italicwhether the font should be italicized
Returns
the requested font

Definition at line 262 of file CPFont.j.

◆ boldSystemFontOfSize:()

+ (CPFont) boldSystemFontOfSize: (CGSize)  aSize
implementation

Returns the bold system font scaled to the specified size

Parameters
aSizethe size of the font (in px). 0 creates a static font in the current system font size. Negative creates a font that dynamically tracks the current system font size.
Returns
the requested bold system font

Definition at line 294 of file CPFont.j.

◆ copy()

- (id) copy
implementation

Makes a deep copy of the receiver. The copy should be functionally equivalent to the receiver.

Returns
the copy of the receiver

Reimplemented from CPObject.

Definition at line 416 of file CPFont.j.

◆ cssString()

- (CPString) cssString
implementation

Returns the font as a CSS string

Definition at line 383 of file CPFont.j.

◆ defaultLineHeightForFont()

- (float) defaultLineHeightForFont
implementation

Returns the default line height.

NOTE: This was moved from NSFont to NSLayoutManager in Cocoa, but since there is no CPLayoutManager, it has been kept here.

Definition at line 362 of file CPFont.j.

◆ descender()

- (float) descender
implementation

Returns the bottom y coordinate (in CSS px), offset from the baseline, of the receiver's longest descender. Thus, if the longest descender extends 2 px below the baseline, descender will return –2.

Definition at line 347 of file CPFont.j.

◆ description()

- (CPString) description
implementation

Returns a human readable string describing the receiver

Reimplemented from CPObject.

Definition at line 411 of file CPFont.j.

◆ encodeWithCoder:()

- (void) encodeWithCoder: (CPCoder aCoder
implementation

Writes the font information out to a coder.

Parameters
aCoderthe coder to which the data will be written

Provided by category CPFont(CPCoding).

Definition at line 497 of file CPFont.j.

◆ familyName()

- (CPString) familyName
implementation

Returns the font's family name

Definition at line 393 of file CPFont.j.

◆ fontDescriptor()

- (CPFontDescriptor) fontDescriptor
implementation

Provided by category CPFont(DescriptorAdditions).

Definition at line 453 of file CPFont.j.

◆ fontWithDescriptor:size:()

+ (CPFont) fontWithDescriptor: (CPFontDescriptor fontDescriptor
size: (float)  aSize 
implementation

Provided by category CPFont(DescriptorAdditions).

Definition at line 444 of file CPFont.j.

◆ fontWithName:size:()

+ (CPFont) fontWithName: (CPString aName
size: (float)  aSize 
implementation

Returns a font with the specified name and size.

Parameters
aNamethe name of the font
aSizethe size of the font (in px). 0 or negative will create a font in the current system font size.
Returns
the requested font

Definition at line 224 of file CPFont.j.

◆ fontWithName:size:italic:()

+ (CPFont) fontWithName: (CPString aName
size: (float)  aSize
italic: (BOOL)  italic 
implementation

Returns a font with the specified name, size and style.

Parameters
aNamethe name of the font
aSizethe size of the font (in px). 0 or negative will create a font in the current system font size.
italicwhether the font should be italicized
Returns
the requested font

Definition at line 237 of file CPFont.j.

◆ initialize()

+ (void) initialize
implementation

Reimplemented from CPObject.

Definition at line 121 of file CPFont.j.

◆ initWithCoder:()

- (id) initWithCoder: (CPCoder aCoder
implementation

Initializes the font from a coder.

Parameters
aCoderthe coder from which to read the font data
Returns
the initialized font

Provided by category CPFont(CPCoding).

Definition at line 482 of file CPFont.j.

◆ isBold()

- (BOOL) isBold
implementation

Synthesized accessor method.

Provided by category CPFont(CPSynthesizedAccessors).

Definition at line 556 of file CPFont.j.

◆ isEqual:()

- (BOOL) isEqual: (id)  anObject
implementation

Determines if anObject is functionally equivalent to the receiver.

Returns
YES if anObject is functionally equivalent to the receiver.

Reimplemented from CPObject.

Definition at line 406 of file CPFont.j.

◆ isItalic()

- (BOOL) isItalic
implementation

Synthesized accessor method.

Provided by category CPFont(CPSynthesizedAccessors).

Definition at line 564 of file CPFont.j.

◆ isSystem()

- (BOOL) isSystem
implementation

Synthesized accessor method.

Provided by category CPFont(CPSynthesizedAccessors).

Definition at line 572 of file CPFont.j.

◆ isSystemSize()

- (BOOL) isSystemSize
implementation

Definition at line 401 of file CPFont.j.

◆ setSystemFontFace:()

+ (CPString) setSystemFontFace: (CPString aFace
implementation

Sets the default system font face, which may consist of several comma-separated family names.

Definition at line 154 of file CPFont.j.

◆ setSystemFontSize:()

+ (float) setSystemFontSize: (float)  size
implementation

Sets the default system font size.

Definition at line 193 of file CPFont.j.

◆ size()

- (float) size
implementation

Returns the font size (in CSS px)

Definition at line 375 of file CPFont.j.

◆ systemFontFace()

+ (CPString) systemFontFace
implementation

Returns the default system font face, which may consist of several comma-separated family names.

Definition at line 146 of file CPFont.j.

◆ systemFontForControlSize:()

+ (CPFont) systemFontForControlSize: (CPControlSize)  aSize
implementation

Definition at line 173 of file CPFont.j.

◆ systemFontOfSize:()

+ (CPFont) systemFontOfSize: (CGSize)  aSize
implementation

Returns the system font scaled to the specified size

Parameters
aSizethe size of the font (in px). 0 creates a static font in the current system font size. Negative creates a font that dynamically tracks the current system font size.
Returns
the requested system font

Definition at line 282 of file CPFont.j.

◆ systemFontSize()

+ (float) systemFontSize
implementation

Returns the default system font size.

Definition at line 168 of file CPFont.j.


The documentation for this class was generated from the following files: