Gnash  0.8.10
Classes | Public Types | Public Member Functions
gnash::Font Class Reference

A Font resource. More...

#include <Font.h>

Inheritance diagram for gnash::Font:
gnash::ref_counted

List of all members.

Classes

struct  FontNameInfo
 A pair of strings describing the font. More...
struct  GlyphInfo
 Glyph info structure. More...

Public Types

typedef std::map
< boost::uint16_t, int > 
CodeTable
typedef std::vector< GlyphInfoGlyphInfoRecords

Public Member Functions

 Font (std::auto_ptr< SWF::DefineFontTag > ft)
 Font (const std::string &name, bool bold=false, bool italic=false)
 Create a device-font only font, using the given name to find it.
 ~Font ()
boost::uint16_t codeTableLookup (int glyph, bool embedded) const
bool matches (const std::string &name, bool bold, bool italic) const
 Return true if this font matches given name and flags.
SWF::ShapeRecordget_glyph (int glyph_index, bool embedded) const
 Get glyph by index.
const std::string & name () const
 Get name of this font.
int get_glyph_index (boost::uint16_t code, bool embedded) const
 Return the glyph index for a given character code.
float get_advance (int glyph_index, bool embedded) const
 Return the advance value for the given glyph index.
float get_kerning_adjustment (int last_code, int this_code) const
size_t unitsPerEM (bool embedded) const
 Return height of the EM square used for glyphs definition.
float ascent (bool embedded) const
 Return the ascent value of the font.
float descent (bool embedded) const
 Return the descent value of the font in EM units.
float leading () const
 Return the leading value of the font.
bool isBold () const
 Return true if the font is bold.
bool isItalic () const
 Return true if the font is italic.
void addFontNameInfo (const FontNameInfo &fontName)
 Add display name and copyright name for an embedded font.
void setName (const std::string &name)
 Set the name of the font.
void setFlags (boost::uint8_t flags)
 Set the language and encoding flags of the font.
void setCodeTable (std::auto_ptr< CodeTable > table)
 Add a CodeTable to the font.
GlyphInfoRecords::size_type glyphCount () const
 Retrieve the number of embedded glyphs in this font.
FreetypeGlyphsProviderftProvider () const
 Retrieve the FreetypeGlyphsProvider, initializing it if necessary.

Detailed Description

A Font resource.

All fonts used in the course of rendering a SWF are represented by this class. There are two types of Font object: device fonts and glyph fonts (also called embedded fonts). Device fonts contain no embedded glyphs, but glyph fonts may be rendered using device fonts if requested during runtime. The fact that one Font object may represent an embedded and a device font simultaneously means that callers must themselves ensure they specify which font they require. Failure to do this consistently may mean callers end up with the wrong information about a font. TODO: check whether it really needs to be ref_counted.


Member Typedef Documentation

typedef std::map<boost::uint16_t, int> gnash::Font::CodeTable

Constructor & Destructor Documentation

gnash::Font::Font ( std::auto_ptr< SWF::DefineFontTag ft)
gnash::Font::Font ( const std::string &  name,
bool  bold = false,
bool  italic = false 
)

Create a device-font only font, using the given name to find it.

Parameters:
nameName of the font face to look for.
boldWhether to use the bold variant of the font.
italicWhether to use the italic variant of the font.

References assert.

gnash::Font::~Font ( )

Member Function Documentation

void gnash::Font::addFontNameInfo ( const FontNameInfo fontName)

Add display name and copyright name for an embedded font.

It's a string copy, but a decent standard library implementation should be able to avoid actually copying. Since it's only two strings, it doesn't seem worth the effort to avoid the copy.

References IF_VERBOSE_MALFORMED_SWF, _, gnash::Font::FontNameInfo::displayName, and gnash::Font::FontNameInfo::copyrightName.

Referenced by gnash::SWF::DefineFontNameTag::loader().

float gnash::Font::ascent ( bool  embedded) const

Return the ascent value of the font.

Note: use unitsPerEM() to get the EM square.

References ftProvider(), and gnash::FreetypeGlyphsProvider::ascent().

boost::uint16_t gnash::Font::codeTableLookup ( int  glyph,
bool  embedded 
) const

References _.

float gnash::Font::descent ( bool  embedded) const

Return the descent value of the font in EM units.

Note: use unitsPerEM() to get the EM square.

References ftProvider(), and gnash::FreetypeGlyphsProvider::descent().

FreetypeGlyphsProvider * gnash::Font::ftProvider ( ) const

Retrieve the FreetypeGlyphsProvider, initializing it if necessary.

Always use this method rather than directly accessing the _ftProvider member to ensure that the provider is initialized. May return null.

References _, and gnash::FreetypeGlyphsProvider::createFace().

Referenced by unitsPerEM(), ascent(), and descent().

float gnash::Font::get_advance ( int  glyph_index,
bool  embedded 
) const

Return the advance value for the given glyph index.

Note: use unitsPerEM() to get the EM square.

Parameters:
glyph_indexIndex of the glyph. See get_glyph_index() to obtain by character code.
embeddedIf true, queries the 'embedded' glyphs table, otherwise, looks in the 'device' font table.

References assert.

SWF::ShapeRecord * gnash::Font::get_glyph ( int  glyph_index,
bool  embedded 
) const

Get glyph by index.

Parameters:
glyph_indexIndex of the glyph. See get_glyph_index() to obtain by character code.
embeddedIf true, queries the 'embedded' glyphs table, otherwise, looks in the 'device' font table.
Returns:
The glyph outline, or NULL if out of range. (would be a programming error most likely). The ShapeRecord is owned by the Font class.

Referenced by gnash::SWF::TextRecord::displayRecords().

int gnash::Font::get_glyph_index ( boost::uint16_t  code,
bool  embedded 
) const

Return the glyph index for a given character code.

Parameters:
codeCharacter code to fetch the corresponding glyph index of.
embeddedIf true, queries the 'embedded' glyphs table, otherwise, looks in the 'device' font table.

Note, when querying device fonts, glyphs are created on demand, this never happens for embedded fonts, in which case an unexistent glyph results in a return of -1

Returns:
-1 if there is no glyph for the specified code or a valid positive index to use in subsequent calls to other glyph-index-based methods.
float gnash::Font::get_kerning_adjustment ( int  last_code,
int  this_code 
) const

Return the adjustment in advance between the given two DisplayObjects (makes sense for embedded glyphs only) Normally this will be 0

NOTE: don't call this method when willing to work with device fonts, or you'll end up mixing information from device fonts with information from embedded fonts.

References gnash::key::k, gnash::kerning_pair::m_char0, and gnash::kerning_pair::m_char1.

Font::GlyphInfoRecords::size_type gnash::Font::glyphCount ( ) const

Retrieve the number of embedded glyphs in this font.

References assert.

Referenced by gnash::SWF::DefineFontAlignZonesTag::loader(), and gnash::SWF::DefineFontInfoTag::loader().

bool gnash::Font::isBold ( ) const [inline]

Return true if the font is bold.

bool gnash::Font::isItalic ( ) const [inline]

Return true if the font is italic.

float gnash::Font::leading ( ) const

Return the leading value of the font.

Note: use unitsPerEM() to get the EM square.

bool gnash::Font::matches ( const std::string &  name,
bool  bold,
bool  italic 
) const

Return true if this font matches given name and flags.

Parameters:
nameFont name
boldBold flag
italicItalic flag

Referenced by gnash::fontlib::get_font(), and gnash::SWFMovieDefinition::get_font().

const std::string& gnash::Font::name ( ) const [inline]

Get name of this font.

Referenced by setName().

void gnash::Font::setCodeTable ( std::auto_ptr< CodeTable table)

Add a CodeTable to the font.

This is used by SWF::DefineFontInfoTag

References IF_VERBOSE_MALFORMED_SWF, and _.

Referenced by gnash::SWF::DefineFontInfoTag::loader().

void gnash::Font::setFlags ( boost::uint8_t  flags)

Set the language and encoding flags of the font.

This is used by SWF::DefineFontInfoTag

Referenced by gnash::SWF::DefineFontInfoTag::loader().

void gnash::Font::setName ( const std::string &  name)

Set the name of the font.

This is used by SWF::DefineFontInfoTag

References name().

Referenced by gnash::SWF::DefineFontInfoTag::loader().

size_t gnash::Font::unitsPerEM ( bool  embedded) const

Return height of the EM square used for glyphs definition.

Parameters:
embeddedIf true, return is based on the SWF tag the font was read from, otherwise will query the FreeTypeGlyphsProvider

References ftProvider(), _, and gnash::FreetypeGlyphsProvider::unitsPerEM().

Referenced by gnash::SWF::TextRecord::displayRecords().


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