Font Class Reference

Represents a particular font, including its size, style, etc. More...

List of all members.

Classes

class  SharedFontInternal

Public Types

enum  FontStyleFlags { plain = 0, bold = 1, italic = 2, underlined = 4 }
 

A combination of these values is used by the constructor to specify the style of font to use.

More...

Public Member Functions

 Font (float fontHeight, int styleFlags=plain) throw ()
 Creates a sans-serif font in a given size.
 Font (const String &typefaceName, float fontHeight, int styleFlags) throw ()
 Creates a font with a given typeface and parameters.
 Font (const Font &other) throw ()
 Creates a copy of another Font object.
 Font (const Typeface::Ptr &typeface) throw ()
 Creates a font for a typeface.
 Font () throw ()
 Creates a basic sans-serif font at a default height.
Fontoperator= (const Font &other) throw ()
 Copies this font from another one.
bool operator== (const Font &other) const throw ()
bool operator!= (const Font &other) const throw ()
 ~Font () throw ()
 Destructor.
void setTypefaceName (const String &faceName) throw ()
 Changes the name of the typeface family.
const StringgetTypefaceName () const throw ()
 Returns the name of the typeface family that this font uses.
float getHeight () const throw ()
 Returns the total height of this font.
void setHeight (float newHeight) throw ()
 Changes the font's height.
void setHeightWithoutChangingWidth (float newHeight) throw ()
 Changes the font's height without changing its width.
float getAscent () const throw ()
 Returns the height of the font above its baseline.
float getDescent () const throw ()
 Returns the amount that the font descends below its baseline.
int getStyleFlags () const throw ()
 Returns the font's style flags.
void setStyleFlags (const int newFlags) throw ()
 Changes the font's style.
void setBold (bool shouldBeBold) throw ()
 Makes the font bold or non-bold.
bool isBold () const throw ()
 Returns true if the font is bold.
void setItalic (bool shouldBeItalic) throw ()
 Makes the font italic or non-italic.
bool isItalic () const throw ()
 Returns true if the font is italic.
void setUnderline (bool shouldBeUnderlined) throw ()
 Makes the font underlined or non-underlined.
bool isUnderlined () const throw ()
 Returns true if the font is underlined.
void setHorizontalScale (float scaleFactor) throw ()
 Changes the font's horizontal scale factor.
float getHorizontalScale () const throw ()
 Returns the font's horizontal scale.
void setExtraKerningFactor (float extraKerning) throw ()
 Changes the font's kerning.
float getExtraKerningFactor () const throw ()
 Returns the font's kerning.
void setSizeAndStyle (float newHeight, int newStyleFlags, float newHorizontalScale, float newKerningAmount) throw ()
 Changes all the font's characteristics with one call.
int getStringWidth (const String &text) const throw ()
 Returns the total width of a string as it would be drawn using this font.
float getStringWidthFloat (const String &text) const throw ()
 Returns the total width of a string as it would be drawn using this font.
void getGlyphPositions (const String &text, Array< int > &glyphs, Array< float > &xOffsets) const throw ()
 Returns the series of glyph numbers and their x offsets needed to represent a string.
TypefacegetTypeface () const throw ()
 Returns the typeface used by this font.

Static Public Member Functions

static const String getDefaultSansSerifFontName () throw ()
 Returns a typeface name that represents the default sans-serif font.
static const String getDefaultSerifFontName () throw ()
 Returns a typeface name that represents the default sans-serif font.
static const String getDefaultMonospacedFontName () throw ()
 Returns a typeface name that represents the default sans-serif font.
static void getPlatformDefaultFontNames (String &defaultSans, String &defaultSerif, String &defaultFixed)
 Returns the typeface names of the default fonts on the current platform.
static void findFonts (Array< Font > &results) throw ()
 Creates an array of Font objects to represent all the fonts on the system.
static const StringArray findAllTypefaceNames ()
 Returns a list of all the available typeface names.
static const String getFallbackFontName () throw ()
 Returns the name of the typeface to be used for rendering glyphs that aren't found in the requested typeface.
static void setFallbackFontName (const String &name) throw ()
 Sets the (platform-specific) name of the typeface to use to find glyphs that aren't available in whatever font you're trying to use.

Detailed Description

Represents a particular font, including its size, style, etc.

Apart from the typeface to be used, a Font object also dictates whether the font is bold, italic, underlined, how big it is, and its kerning and horizontal scale factor.

See also:
Typeface

Member Enumeration Documentation

A combination of these values is used by the constructor to specify the style of font to use.

Enumerator:
plain 

indicates a plain, non-bold, non-italic version of the font.

See also:
setStyleFlags
bold 

boldens the font.

See also:
setStyleFlags
italic 

finds an italic version of the font.

See also:
setStyleFlags
underlined 

underlines the font.

See also:
setStyleFlags

Constructor & Destructor Documentation

Font::Font ( float  fontHeight,
int  styleFlags = plain 
) throw ()

Creates a sans-serif font in a given size.

Parameters:
fontHeight the height in pixels (can be fractional)
styleFlags the style to use - this can be a combination of the Font::bold, Font::italic and Font::underlined, or just Font::plain for the normal style.
See also:
FontStyleFlags, getDefaultSansSerifFontName
Font::Font ( const String typefaceName,
float  fontHeight,
int  styleFlags 
) throw ()

Creates a font with a given typeface and parameters.

Parameters:
typefaceName the name of the typeface to use
fontHeight the height in pixels (can be fractional)
styleFlags the style to use - this can be a combination of the Font::bold, Font::italic and Font::underlined, or just Font::plain for the normal style.
See also:
FontStyleFlags, getDefaultSansSerifFontName
Font::Font ( const Font other  )  throw ()

Creates a copy of another Font object.

Font::Font ( const Typeface::Ptr typeface  )  throw ()

Creates a font for a typeface.

Font::Font (  )  throw ()

Creates a basic sans-serif font at a default height.

You should use one of the other constructors for creating a font that you're planning on drawing with - this constructor is here to help initialise objects before changing the font's settings later.

Font::~Font (  )  throw ()

Destructor.


Member Function Documentation

Font& Font::operator= ( const Font other  )  throw ()

Copies this font from another one.

bool Font::operator== ( const Font other  )  const throw ()
bool Font::operator!= ( const Font other  )  const throw ()
void Font::setTypefaceName ( const String faceName  )  throw ()

Changes the name of the typeface family.

e.g. "Arial", "Courier", etc.

This may also be set to Font::getDefaultSansSerifFontName(), Font::getDefaultSerifFontName(), or Font::getDefaultMonospacedFontName(), which are not actual platform-specific font names, but are generic names that are used to represent the various default fonts. If you need to know the exact typeface name being used, you can call Font::getTypeface()->getTypefaceName(), which will give you the platform-specific name.

If a suitable font isn't found on the machine, it'll just use a default instead.

const String& Font::getTypefaceName (  )  const throw ()

Returns the name of the typeface family that this font uses.

e.g. "Arial", "Courier", etc.

This may also be set to Font::getDefaultSansSerifFontName(), Font::getDefaultSerifFontName(), or Font::getDefaultMonospacedFontName(), which are not actual platform-specific font names, but are generic names that are used to represent the various default fonts.

If you need to know the exact typeface name being used, you can call Font::getTypeface()->getTypefaceName(), which will give you the platform-specific name.

static const String Font::getDefaultSansSerifFontName (  )  throw () [static]

Returns a typeface name that represents the default sans-serif font.

This is also the typeface that will be used when a font is created without specifying any typeface details.

Note that this method just returns a generic placeholder string that means "the default sans-serif font" - it's not the actual name of this font. To get the actual name, use getPlatformDefaultFontNames() or LookAndFeel::getTypefaceForFont().

See also:
setTypefaceName, getDefaultSerifFontName, getDefaultMonospacedFontName
static const String Font::getDefaultSerifFontName (  )  throw () [static]

Returns a typeface name that represents the default sans-serif font.

Note that this method just returns a generic placeholder string that means "the default serif font" - it's not the actual name of this font. To get the actual name, use getPlatformDefaultFontNames() or LookAndFeel::getTypefaceForFont().

See also:
setTypefaceName, getDefaultSansSerifFontName, getDefaultMonospacedFontName
static const String Font::getDefaultMonospacedFontName (  )  throw () [static]

Returns a typeface name that represents the default sans-serif font.

Note that this method just returns a generic placeholder string that means "the default monospaced font" - it's not the actual name of this font. To get the actual name, use getPlatformDefaultFontNames() or LookAndFeel::getTypefaceForFont().

See also:
setTypefaceName, getDefaultSansSerifFontName, getDefaultSerifFontName
static void Font::getPlatformDefaultFontNames ( String defaultSans,
String defaultSerif,
String defaultFixed 
) [static]

Returns the typeface names of the default fonts on the current platform.

float Font::getHeight (  )  const throw ()

Returns the total height of this font.

This is the maximum height, from the top of the ascent to the bottom of the descenders.

See also:
setHeight, setHeightWithoutChangingWidth, getAscent
void Font::setHeight ( float  newHeight  )  throw ()

Changes the font's height.

See also:
getHeight, setHeightWithoutChangingWidth
void Font::setHeightWithoutChangingWidth ( float  newHeight  )  throw ()

Changes the font's height without changing its width.

This alters the horizontal scale to compensate for the change in height.

float Font::getAscent (  )  const throw ()

Returns the height of the font above its baseline.

This is the maximum height from the baseline to the top.

See also:
getHeight, getDescent
float Font::getDescent (  )  const throw ()

Returns the amount that the font descends below its baseline.

This is calculated as (getHeight() - getAscent()).

See also:
getAscent, getHeight
int Font::getStyleFlags (  )  const throw ()

Returns the font's style flags.

This will return a bitwise-or'ed combination of values from the FontStyleFlags enum, to describe whether the font is bold, italic, etc.

See also:
FontStyleFlags
void Font::setStyleFlags ( const int  newFlags  )  throw ()

Changes the font's style.

Parameters:
newFlags a bitwise-or'ed combination of values from the FontStyleFlags enum, to set the font's properties
See also:
FontStyleFlags
void Font::setBold ( bool  shouldBeBold  )  throw ()

Makes the font bold or non-bold.

bool Font::isBold (  )  const throw ()

Returns true if the font is bold.

void Font::setItalic ( bool  shouldBeItalic  )  throw ()

Makes the font italic or non-italic.

bool Font::isItalic (  )  const throw ()

Returns true if the font is italic.

void Font::setUnderline ( bool  shouldBeUnderlined  )  throw ()

Makes the font underlined or non-underlined.

bool Font::isUnderlined (  )  const throw ()

Returns true if the font is underlined.

void Font::setHorizontalScale ( float  scaleFactor  )  throw ()

Changes the font's horizontal scale factor.

Parameters:
scaleFactor a value of 1.0 is the normal scale, less than this will be narrower, greater than 1.0 will be stretched out.
float Font::getHorizontalScale (  )  const throw ()

Returns the font's horizontal scale.

A value of 1.0 is the normal scale, less than this will be narrower, greater than 1.0 will be stretched out.

See also:
setHorizontalScale
void Font::setExtraKerningFactor ( float  extraKerning  )  throw ()

Changes the font's kerning.

Parameters:
extraKerning a multiple of the font's height that will be added to space between the characters. So a value of zero is normal spacing, positive values spread the letters out, negative values make them closer together.
float Font::getExtraKerningFactor (  )  const throw ()

Returns the font's kerning.

This is the extra space added between adjacent characters, as a proportion of the font's height.

A value of zero is normal spacing, positive values will spread the letters out more, and negative values make them closer together.

void Font::setSizeAndStyle ( float  newHeight,
int  newStyleFlags,
float  newHorizontalScale,
float  newKerningAmount 
) throw ()

Changes all the font's characteristics with one call.

int Font::getStringWidth ( const String text  )  const throw ()

Returns the total width of a string as it would be drawn using this font.

For a more accurate floating-point result, use getStringWidthFloat().

float Font::getStringWidthFloat ( const String text  )  const throw ()

Returns the total width of a string as it would be drawn using this font.

See also:
getStringWidth
void Font::getGlyphPositions ( const String text,
Array< int > &  glyphs,
Array< float > &  xOffsets 
) const throw ()

Returns the series of glyph numbers and their x offsets needed to represent a string.

An extra x offset is added at the end of the run, to indicate where the right hand edge of the last character is.

Typeface* Font::getTypeface (  )  const throw ()

Returns the typeface used by this font.

Note that the object returned may go out of scope if this font is deleted or has its style changed.

static void Font::findFonts ( Array< Font > &  results  )  throw () [static]

Creates an array of Font objects to represent all the fonts on the system.

If you just need the names of the typefaces, you can also use findAllTypefaceNames() instead.

Parameters:
results the array to which new Font objects will be added.
static const StringArray Font::findAllTypefaceNames (  )  [static]

Returns a list of all the available typeface names.

The names returned can be passed into setTypefaceName().

You can use this instead of findFonts() if you only need their names, and not font objects.

static const String Font::getFallbackFontName (  )  throw () [static]

Returns the name of the typeface to be used for rendering glyphs that aren't found in the requested typeface.

static void Font::setFallbackFontName ( const String name  )  throw () [static]

Sets the (platform-specific) name of the typeface to use to find glyphs that aren't available in whatever font you're trying to use.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Apr 26 11:42:12 2010 for JUCE by  doxygen 1.6.3