API  0.9.7
 All Classes Files Functions Variables Macros Groups Pages
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
 
(id) - initWithCoder:
 
(BOOL) - isBold
 
(BOOL) - isEqual:
 
(BOOL) - isItalic
 
(BOOL) - isSystem
 
(BOOL) - isSystemSize
 
(float) - size
 

Class Methods

(CPFont+ boldFontWithName:size:
 
(CPFont+ boldFontWithName:size:italic:
 
(CPFont+ boldSystemFontOfSize:
 
(CPFont+ fontWithName:size:
 
(CPFont+ fontWithName:size:italic:
 
(void) + initialize
 
(CPString+ setSystemFontFace:
 
(float) + setSystemFontSize:
 
(CPString+ systemFontFace
 
(CPFont+ systemFontOfSize:
 
(float) + systemFontSize
 
(float) + systemFontSizeForControlSize:
 

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

- (float) ascender
implementation

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

Definition at line 334 of file CPFont.j.

+ (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 250 of file CPFont.j.

+ (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 263 of file CPFont.j.

+ (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 295 of file CPFont.j.

- (id) copy
implementation

Definition at line 417 of file CPFont.j.

- (CPString) cssString
implementation

Returns the font as a CSS string

Definition at line 384 of file CPFont.j.

- (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 363 of file CPFont.j.

- (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 348 of file CPFont.j.

- (CPString) description
implementation

Definition at line 412 of file CPFont.j.

- (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 461 of file CPFont.j.

- (CPString) familyName
implementation

Returns the font's family name

Definition at line 394 of file CPFont.j.

+ (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 225 of file CPFont.j.

+ (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 238 of file CPFont.j.

+ (void) initialize
implementation

Definition at line 122 of file CPFont.j.

- (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 446 of file CPFont.j.

- (BOOL) isBold
implementation

Synthesized accessor method.

Provided by category CPFont(CPSynthesizedAccessors).

Definition at line 520 of file CPFont.j.

- (BOOL) isEqual: (id)  anObject
implementation

Definition at line 407 of file CPFont.j.

- (BOOL) isItalic
implementation

Synthesized accessor method.

Provided by category CPFont(CPSynthesizedAccessors).

Definition at line 528 of file CPFont.j.

- (BOOL) isSystem
implementation

Synthesized accessor method.

Provided by category CPFont(CPSynthesizedAccessors).

Definition at line 536 of file CPFont.j.

- (BOOL) isSystemSize
implementation

Definition at line 402 of file CPFont.j.

+ (CPString) setSystemFontFace: (CPString aFace
implementation

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

Definition at line 155 of file CPFont.j.

+ (float) setSystemFontSize: (float)  size
implementation

Sets the default system font size.

Definition at line 194 of file CPFont.j.

- (float) size
implementation

Returns the font size (in CSS px)

Definition at line 376 of file CPFont.j.

+ (CPString) systemFontFace
implementation

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

Definition at line 147 of file CPFont.j.

+ (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 283 of file CPFont.j.

+ (float) systemFontSize
implementation

Returns the default system font size.

Definition at line 169 of file CPFont.j.

+ (float) systemFontSizeForControlSize: (CPControlSize)  aSize
implementation

Definition at line 174 of file CPFont.j.


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