Gnash  0.8.11dev
Classes | Public Types | Public Member Functions | List of all members
gnash::Font Class Reference

A Font resource. More...

#include <Font.h>

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

Classes

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

Public Types

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

Public Member Functions

 Font (std::unique_ptr< SWF::DefineFontTag > ft)
 
 Font (std::string name, bool bold=false, bool italic=false)
 Create a device-font only font, using the given name to find it. More...
 
 ~Font ()
 
std::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. More...
 
SWF::ShapeRecordget_glyph (int glyph_index, bool embedded) const
 Get glyph by index. More...
 
const std::string & name () const
 Get name of this font. More...
 
int get_glyph_index (std::uint16_t code, bool embedded) const
 Return the glyph index for a given character code. More...
 
float get_advance (int glyph_index, bool embedded) const
 Return the advance value for the given glyph index. More...
 
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. More...
 
float ascent (bool embedded) const
 Return the ascent value of the font. More...
 
float descent (bool embedded) const
 Return the descent value of the font in EM units. More...
 
float leading () const
 Return the leading value of the font. More...
 
bool isBold () const
 Return true if the font is bold. More...
 
bool isItalic () const
 Return true if the font is italic. More...
 
void addFontNameInfo (const FontNameInfo &fontName)
 Add display name and copyright name for an embedded font. More...
 
void setName (const std::string &name)
 Set the name of the font. More...
 
void setFlags (std::uint8_t flags)
 Set the language and encoding flags of the font. More...
 
void setCodeTable (std::unique_ptr< CodeTable > table)
 Add a CodeTable to the font. More...
 
GlyphInfoRecords::size_type glyphCount () const
 Retrieve the number of embedded glyphs in this font. More...
 
FreetypeGlyphsProviderftProvider () const
 Retrieve the FreetypeGlyphsProvider, initializing it if necessary. More...
 
- Public Member Functions inherited from gnash::ref_counted
 ref_counted ()
 
 ref_counted (const ref_counted &)
 
void add_ref () const
 
void drop_ref () const
 
long get_ref_count () const
 

Additional Inherited Members

- Protected Member Functions inherited from gnash::ref_counted
virtual ~ref_counted ()
 

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

§ CodeTable

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

§ GlyphInfoRecords

Constructor & Destructor Documentation

§ Font() [1/2]

gnash::Font::Font ( std::unique_ptr< SWF::DefineFontTag ft)

§ Font() [2/2]

gnash::Font::Font ( 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.

§ ~Font()

gnash::Font::~Font ( )

Member Function Documentation

§ addFontNameInfo()

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 _, gnash::Font::FontNameInfo::copyrightName, gnash::Font::FontNameInfo::displayName, IF_VERBOSE_MALFORMED_SWF, and gnash::log_swferror().

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

§ ascent()

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

Return the ascent value of the font.

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

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

Referenced by gnash::textformat_class_init().

§ codeTableLookup()

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

References _, and gnash::log_error().

§ descent()

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 gnash::FreetypeGlyphsProvider::descent(), and ftProvider().

Referenced by gnash::textformat_class_init().

§ ftProvider()

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 _, gnash::FreetypeGlyphsProvider::createFace(), and gnash::log_error().

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

§ get_advance()

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.

Referenced by gnash::TextField::setFont(), and gnash::textformat_class_init().

§ get_glyph()

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().

§ get_glyph_index()

int gnash::Font::get_glyph_index ( std::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.

Referenced by gnash::TextField::setFont(), and gnash::textformat_class_init().

§ get_kerning_adjustment()

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.

Referenced by gnash::TextField::setFont().

§ glyphCount()

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

Retrieve the number of embedded glyphs in this font.

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

§ isBold()

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

Return true if the font is bold.

Referenced by gnash::registerTextFieldNative(), and gnash::TextField::setFont().

§ isItalic()

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

Return true if the font is italic.

Referenced by gnash::registerTextFieldNative(), and gnash::TextField::setFont().

§ leading()

float gnash::Font::leading ( ) const

Return the leading value of the font.

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

§ matches()

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::SWFMovieDefinition::get_font().

§ name()

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

Get name of this font.

Referenced by gnash::registerTextFieldNative(), gnash::TextField::setFont(), and setName().

§ setCodeTable()

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

Add a CodeTable to the font.

This is used by SWF::DefineFontInfoTag

References _, IF_VERBOSE_MALFORMED_SWF, and gnash::log_swferror().

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

§ setFlags()

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

Set the language and encoding flags of the font.

This is used by SWF::DefineFontInfoTag

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

§ setName()

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().

§ unitsPerEM()

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(), gnash::FreetypeGlyphsProvider::getGlyph(), gnash::log_error(), and gnash::FreetypeGlyphsProvider::unitsPerEM().

Referenced by gnash::SWF::TextRecord::displayRecords(), and gnash::textformat_class_init().


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