PXFont Class Reference
| 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
-
– initWithData:options:Makes a new font that has parses the data given.
-
– initWithSystemFont:options:Makes a new font that has parses the data described in the system font.
-
+ registerFont:withName:Registers a font to the font library with the given name. To access this font again use [PXFont fontWithName:]
-
+ 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:]
-
+ 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:]
-
+ registerFontWithData:name:options:Parses and registers a font to the font library with the given name. To access this font again use [PXFont fontWithName:]
-
+ registerFontWithSystemFont:options:Parses and registers a font to the font library with the same name. To access this font again use [PXFont fontWithName:]
-
+ registerFontWithSystemFont:name:options:Parses and registers a font to the font library with the given name. To access this font again use [PXFont fontWithName:]
-
+ unregisterFontWithName:Unregisters a registered font with the font library associated with the given name.
-
+ unregisterAllFontsUnregisters all registered fonts with the font library.
-
+ fontWithName:Returns a registered font with the given name.
-
+ containsFontWithName:Returns whether or not a font is registered by that name.
-
+ availableSystemFontsA 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.
-
+ isSystemFontAvailable:Checks if the given font name is available. If it is available it can be safely passed to the PXTextField.font property
-
+ fontWithContentsOfFile:options:Makes a font by loading the file and parsing the data.
-
+ fontWithContentsOfURL:options:Makes a font by loading the file and parsing the data.
-
+ fontWithData:options:Makes a font that has parses the data given.
-
+ fontWithSystemFont:options:Makes a font that has parses the data described in the system font.
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 *)availableSystemFontsSee Also
Declared In
PXFont.mcontainsFontWithName:
Returns whether or not a font is registered by that name.
+ (BOOL)containsFontWithName:(NSString *)nameParameters
- 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.mfontWithContentsOfFile:options:
Makes a font by loading the file and parsing the data.
+ (PXFont *)fontWithContentsOfFile:(NSString *)path options:(PXFontOptions *)optionsParameters
- path
The location of the font to load.
- options
The options that describe what type of font you want back. If
nilis 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.mfontWithContentsOfURL:options:
Makes a font by loading the file and parsing the data.
+ (PXFont *)fontWithContentsOfURL:(NSURL *)url options:(PXFontOptions *)optionsParameters
- url
The location of the font to load.
- options
The options that describe what type of font you want back. If
nilis 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.mfontWithData:options:
Makes a font that has parses the data given.
+ (PXFont *)fontWithData:(NSData *)data options:(PXFontOptions *)optionsParameters
- data
The data to parse.
- options
The options that describe what type of font you want back. If
nilis 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.mfontWithName:
Returns a registered font with the given name.
+ (PXFont *)fontWithName:(NSString *)nameParameters
- 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.mfontWithSystemFont:options:
Makes a font that has parses the data described in the system font.
+ (PXFont *)fontWithSystemFont:(NSString *)systemFontName options:(PXFontOptions *)optionsParameters
- options
The options that describe what type of font you want back. If
nilis 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.misSystemFontAvailable:
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 *)nameSee Also
Declared In
PXFont.mregisterFont: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 *)nameParameters
- 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.mregisterFontWithContentsOfFile: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 *)optionsParameters
- 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.mregisterFontWithContentsOfURL: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 *)optionsParameters
- 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.mregisterFontWithData: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 *)optionsParameters
- 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.mregisterFontWithSystemFont: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 *)optionsParameters
- 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.mregisterFontWithSystemFont: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 *)optionsParameters
- 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.munregisterAllFonts
Unregisters all registered fonts with the font library.
+ (void)unregisterAllFontsDiscussion
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.munregisterFontWithName:
Unregisters a registered font with the font library associated with the given name.
+ (void)unregisterFontWithName:(NSString *)nameParameters
- 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.mInstance Methods
initWithData:options:
Makes a new font that has parses the data given.
- (id)initWithData:(NSData *)data options:(PXFontOptions *)optionsParameters
- data
The data to parse.
- options
The options that describe what type of font you want back. If
nilis 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.minitWithSystemFont:options:
Makes a new font that has parses the data described in the system font.
- (id)initWithSystemFont:(NSString *)systemFont options:(PXFontOptions *)optionsParameters
- systemFont
The system font to parse.
- options
The options that describe what type of font you want back. If
nilis 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