Inherits from NSObject
Declared in PXFont.h
PXFont.m

Overview

The base class for all fonts.

Also lets the user register fonts and query for available system fonts.

Tasks

Class Methods

availableSystemFonts

A list of names of all the available system fonts. These are the font names that can always be passed into the PXTextField.font property without registering them as font before hand.

+ (NSArray *)availableSystemFonts

Declared In

PXFont.m

containsFontWithName:

Returns whether or not a font is registered by that name.

+ (BOOL)containsFontWithName:(NSString *)name

Parameters

name

The name of a font previously registered by you.

Return Value

YES if a font by that name was registered, otherwise NO.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXFontLoader *fontLoader = [[PXFontLoader alloc] initWithSystemFont:@"helvetica" options:fontOptions];

// If the loading failed, don't register anything
if (!fontLoader)
{
    // Handle this problem
}
PXTextureFont *font = (PXTextureFont *)([fontLoader newFont]);
// font retain count = 1
[fontLoader release];
[fontOptions release];

// Register the font, then release our copy.
[PXFont registerFont:font withName:@"font1"];
// font retain count = 2
[font release];
// font retain count = 1
// Size 12 Helvetica font with all letters, numbers and special characters
// ',.' will now be registered under the name "font1".

[PXFont containsFontWithName:@"font1"]; // YES
[PXFont containsFontWithName:@"font2"]; // NO

Declared In

PXFont.m

fontWithContentsOfFile:options:

Makes a font by loading the file and parsing the data.

+ (PXFont *)fontWithContentsOfFile:(NSString *)path options:(PXFontOptions *)options

Parameters

path

The location of the font to load.

options

The options that describe what type of font you want back. If nil is supplied, then the default type of font for the font type is used. If no default type is found, then no new font can be made.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont fontWithContentsOfFile:@"font.ttf" options:fontOptions];

[PXFont registerFont:font withName:@"font1"];

[fontOptions release];

// Size 12 font loaded from a true type font file, it contains all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "font1".

Declared In

PXFont.m

fontWithContentsOfURL:options:

Makes a font by loading the file and parsing the data.

+ (PXFont *)fontWithContentsOfURL:(NSURL *)url options:(PXFontOptions *)options

Parameters

url

The location of the font to load.

options

The options that describe what type of font you want back. If nil is supplied, then the default type of font for the font type is used. If no default type is found, then no new font can be made.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont fontWithContentsOfURL:[NSURL URLWithString:@"www.myWebsite.com/font.ttf"] options:fontOptions];

[PXFont registerFont:font withName:@"font1"];

[fontOptions release];

// Size 12 font loaded from a true type font file, it contains all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "font1".

Declared In

PXFont.m

fontWithData:options:

Makes a font that has parses the data given.

+ (PXFont *)fontWithData:(NSData *)data options:(PXFontOptions *)options

Parameters

data

The data to parse.

options

The options that describe what type of font you want back. If nil is supplied, then the default type of font for the font type is used. If no default type is found, then no new font can be made.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

NSData *data = [[NSData alloc] initWithContentsOfFile:@"font.ttf"];
PXTextureFont *font = [PXFont fontWithData:data options:fontOptions];

[PXFont registerFont:font withName:@"font1"];

[fontOptions release];
[data release];

// Size 12 font loaded from a true type font file, it contains all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "font1".

Declared In

PXFont.m

fontWithName:

Returns a registered font with the given name.

+ (PXFont *)fontWithName:(NSString *)name

Parameters

name

The name of a font previously registered by you.

Return Value

The registered font. If no font was registered with that name, then nil will be returned instead.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXFontLoader *fontLoader = [[PXFontLoader alloc] initWithSystemFont:@"helvetica" options:fontOptions];

// If the loading failed, don't register anything
if (!fontLoader)
{
    // Handle this problem
}
PXTextureFont *font = (PXTextureFont *)([fontLoader newFont]);
// font retain count = 1
[fontLoader release];
[fontOptions release];

// Register the font, then release our copy.
[PXFont registerFont:font withName:@"font1"];
// font retain count = 2
[font release];
// font retain count = 1
// Size 12 Helvetica font with all letters, numbers and special characters
// ',.' will now be registered under the name "font1".

PXFont *registeredFont = [PXFont fontWithName:@"font1"];
// registeredFont will now be the same as font

Declared In

PXFont.m

fontWithSystemFont:options:

Makes a font that has parses the data described in the system font.

+ (PXFont *)fontWithSystemFont:(NSString *)systemFontName options:(PXFontOptions *)options

Parameters

options

The options that describe what type of font you want back. If nil is supplied, then the default type of font for the font type is used. If no default type is found, then no new font can be made.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont fontWithSystemFont:@"helvetica" options:fontOptions];
[PXFont registerFont:font withName:@"helvetica"];
[fontOptions release];

// Size 12 font, helvetica, will be parsed. It will contain all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "helvetica".
systemFont

The system font to parse.

Declared In

PXFont.m

isSystemFontAvailable:

Checks if the given font name is available. If it is available it can be safely passed to the PXTextField.font property

+ (BOOL)isSystemFontAvailable:(NSString *)name

Declared In

PXFont.m

registerFont:withName:

Registers a font to the font library with the given name. To access this font again use [PXFont fontWithName:]

+ (PXFont *)registerFont:(PXFont *)font withName:(NSString *)name

Parameters

font

The font to be registered.

name

The name you wish to reference the font by.

Return Value

The registered font.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];
PXFontLoader *fontLoader = [[PXFontLoader alloc] initWithSystemFont:@"helvetica" options:fontOptions];

// If the loading failed, don't register anything
if (!fontLoader)
{
    // Handle this problem
}
PXTextureFont *font = (PXTextureFont *)([fontLoader newFont]);
// font retain count = 1
[fontLoader release];
[fontOptions release];

// Register the font, then release our copy.
[PXFont registerFont:font withName:@"font1"];
// font retain count = 2
[font release];
// font retain count = 1
// Size 12 Helvetica font with all letters, numbers and special characters
// ',.' will now be registered under the name "font1".

Declared In

PXFont.m

registerFontWithContentsOfFile:name:options:

Loads, parses and registers a font to the font library with the given name. To access this font again use [PXFont fontWithName:]

+ (PXFont *)registerFontWithContentsOfFile:(NSString *)path name:(NSString *)name options:(PXFontOptions *)options

Parameters

path

The location of the font to load.

name

The name you wish to reference the font by.

options

The options that describe how to parse the font.

Return Value

The registered font.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont registerFontWithContentsOfFile:@"font.ttf" name:@"font1" options:fontOptions];
// font retain count = 1
[fontOptions release];

// Size 12 font loaded from a true type font file, it contains all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "font1".

Declared In

PXFont.m

registerFontWithContentsOfURL:name:options:

Loads, parses and registers a font to the font library with the given name. To access this font again use [PXFont fontWithName:]

+ (PXFont *)registerFontWithContentsOfURL:(NSURL *)url name:(NSString *)name options:(PXFontOptions *)options

Parameters

url

The location of the font to load.

name

The name you wish to reference the font by.

options

The options that describe how to parse the font.

Return Value

The registered font.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont registerFontWithContentsOfURL:[NSURL URLWithString:@"www.myWebsite.com/font.ttf"]
                                                       name:@"font1"
                                                    options:fontOptions];
// font retain count = 1
[fontOptions release];

// Size 12 font loaded from a true type font file, it contains all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "font1".

Declared In

PXFont.m

registerFontWithData:name:options:

Parses and registers a font to the font library with the given name. To access this font again use [PXFont fontWithName:]

+ (PXFont *)registerFontWithData:(NSData *)data name:(NSString *)name options:(PXFontOptions *)options

Parameters

data

The loaded font data.

name

The name you wish to reference the font by.

options

The options that describe how to parse the font.

Return Value

The registered font.

Example:

NSData *data = [[NSData alloc] initWithContentsOfFile:@"font.ttf"];
PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont registerFontWithData:data name:@"font1" options:fontOptions];
// font retain count = 1
[data release];
[fontOptions release];

// Size 12 font loaded from a true type font file, it contains all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "font1".

Declared In

PXFont.m

registerFontWithSystemFont:name:options:

Parses and registers a font to the font library with the given name. To access this font again use [PXFont fontWithName:]

+ (PXFont *)registerFontWithSystemFont:(NSString *)systemFont name:(NSString *)name options:(PXFontOptions *)options

Parameters

systemFont

The system font to parse.

name

The name you wish to reference the font by.

options

The options that describe how to parse the font.

Return Value

The registered font.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont registerFontWithSystemFont:@"helvetica" name:@"font1" options:fontOptions];
// font retain count = 1
[fontOptions release];

// Size 12 font, helvetica, will be parsed. It will contain all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "font1".

Declared In

PXFont.m

registerFontWithSystemFont:options:

Parses and registers a font to the font library with the same name. To access this font again use [PXFont fontWithName:]

+ (PXFont *)registerFontWithSystemFont:(NSString *)systemFont options:(PXFontOptions *)options

Parameters

systemFont

The system font to parse. Note: The name of this font will be the same as the system font.

options

The options that describe how to parse the font.

Return Value

The registered font.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont registerFontWithSystemFont:@"helvetica" options:fontOptions];
// font retain count = 1
[fontOptions release];

// Size 12 font, helvetica, will be parsed. It will contain all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "helvetica".

Declared In

PXFont.m

unregisterAllFonts

Unregisters all registered fonts with the font library.

+ (void)unregisterAllFonts

Discussion

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXFontLoader *systemFontLoader = [[PXFontLoader alloc] initWithSystemFont:@"helvetica" options:fontOptions];
PXFontLoader *externalFontLoader = [[PXFontLoader alloc] initWithContentsOfFile:@"font.ttf" options:fontOptions];

// If the loading failed, don't register anything
if (!systemFontLoader)
{
    // Handle this problem
}
if (!externalFontLoader)
{
    // Handle this problem
}

PXTextureFont *systemFont = (PXTextureFont *)([systemFontLoader newFont]);
PXTextureFont *externalFont = (PXTextureFont *)([externalFontLoader newFont]);
// systemFont retain count = 1, externalFont retain count = 1

[systemFontLoader release];
[externalFontLoader release];
[fontOptions release];

// Register the font, then release our copy.
[PXFont registerFont:systemFont   withName:@"systemFont"];
[PXFont registerFont:externalFont withName:@"externalFont"];
[systemFont release];
[externalFont release];

[PXFont unregisterAllFonts];
// systemFont retain count = 0, externalFont retain count = 0
systemFont = nil;
externalFont = nil;

Declared In

PXFont.m

unregisterFontWithName:

Unregisters a registered font with the font library associated with the given name.

+ (void)unregisterFontWithName:(NSString *)name

Parameters

name

The name of a previously registered font.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];
PXFontLoader *fontLoader = [[PXFontLoader alloc] initWithSystemFont:@"helvetica" options:fontOptions];

// If the loading failed, don't register anything
if (!fontLoader)
{
    // Handle this problem
}
PXTextureFont *font = (PXTextureFont *)([fontLoader newFont]);
// font retain count = 1
[fontLoader release];
[fontOptions release];

// Register the font, then release our copy.
[PXFont registerFont:font withName:@"font1"];
// font retain count = 2
[font release];
// font retain count = 1
// Size 12 Helvetica font with all letters, numbers and special characters
// ',.' will now be registered under the name "font1".

[PXFont unregisterFontWithName:@"font1"];
// font retain count = 0
font = nil;

Declared In

PXFont.m

Instance Methods

initWithData:options:

Makes a new font that has parses the data given.

- (id)initWithData:(NSData *)data options:(PXFontOptions *)options

Parameters

data

The data to parse.

options

The options that describe what type of font you want back. If nil is supplied, then the default type of font for the font type is used. If no default type is found, then no new font can be made.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

NSData *data = [[NSData alloc] initWithContentsOfFile:@"font.ttf"];
PXTextureFont *font = [PXFont initWithData:data options:fontOptions];
// font retain count = 1
[PXFont registerFont:font withName:@"font1"];
// font retain count = 2
[font release];
// font retain count = 1
[fontOptions release];
[data release];

// Size 12 font loaded from a true type font file, it contains all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "font1".

Declared In

PXFont.m

initWithSystemFont:options:

Makes a new font that has parses the data described in the system font.

- (id)initWithSystemFont:(NSString *)systemFont options:(PXFontOptions *)options

Parameters

systemFont

The system font to parse.

options

The options that describe what type of font you want back. If nil is supplied, then the default type of font for the font type is used. If no default type is found, then no new font can be made.

Example:

PXTextureFontOptions *fontOptions = [[PXTextureFontOptions alloc] initWithSize:12.0f
                                                                 characterSets:PXFontCharacterSet_AllLetters | PXFontCharacterSet_Numerals
                                                             specialCharacters:@",."]];

PXTextureFont *font = [PXFont initWithSystemFont:@"helvetica" options:fontOptions];
// font retain count = 1
[PXFont registerFont:font withName:@"helvetica"];
// font retain count = 2
[font release];
// font retain count = 1
[fontOptions release];

// Size 12 font, helvetica, will be parsed. It will contain all letters,
// numbers and special characters ',.' (assuming those glyphs could be found
// in the file) will now be registered under the name "helvetica".

Declared In

PXFont.m