Gnash
0.8.11dev
|
#include <Font.h>
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< GlyphInfo > | GlyphInfoRecords |
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::ShapeRecord * | get_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... | |
FreetypeGlyphsProvider * | ftProvider () const |
Retrieve the FreetypeGlyphsProvider, initializing it if necessary. More... | |
![]() | |
ref_counted () | |
ref_counted (const ref_counted &) | |
void | add_ref () const |
void | drop_ref () const |
long | get_ref_count () const |
Additional Inherited Members | |
![]() | |
virtual | ~ref_counted () |
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.
typedef std::map<std::uint16_t, int> gnash::Font::CodeTable |
typedef std::vector<GlyphInfo> gnash::Font::GlyphInfoRecords |
gnash::Font::Font | ( | std::unique_ptr< SWF::DefineFontTag > | ft | ) |
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.
name | Name of the font face to look for. |
bold | Whether to use the bold variant of the font. |
italic | Whether to use the italic variant of the font. |
gnash::Font::~Font | ( | ) |
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().
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().
std::uint16_t gnash::Font::codeTableLookup | ( | int | glyph, |
bool | embedded | ||
) | const |
References _, and gnash::log_error().
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().
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().
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.
glyph_index | Index of the glyph. See get_glyph_index() to obtain by character code. |
embedded | If true, queries the 'embedded' glyphs table, otherwise, looks in the 'device' font table. |
Referenced by gnash::TextField::setFont(), and gnash::textformat_class_init().
SWF::ShapeRecord * gnash::Font::get_glyph | ( | int | glyph_index, |
bool | embedded | ||
) | const |
Get glyph by index.
glyph_index | Index of the glyph. See get_glyph_index() to obtain by character code. |
embedded | If true, queries the 'embedded' glyphs table, otherwise, looks in the 'device' font table. |
Referenced by gnash::SWF::TextRecord::displayRecords().
int gnash::Font::get_glyph_index | ( | std::uint16_t | code, |
bool | embedded | ||
) | const |
Return the glyph index for a given character code.
code | Character code to fetch the corresponding glyph index of. |
embedded | If 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
Referenced by gnash::TextField::setFont(), and gnash::textformat_class_init().
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().
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().
|
inline |
Return true if the font is bold.
Referenced by gnash::registerTextFieldNative(), and gnash::TextField::setFont().
|
inline |
Return true if the font is italic.
Referenced by gnash::registerTextFieldNative(), and gnash::TextField::setFont().
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.
name | Font name |
bold | Bold flag |
italic | Italic flag |
Referenced by gnash::SWFMovieDefinition::get_font().
|
inline |
Get name of this font.
Referenced by gnash::registerTextFieldNative(), gnash::TextField::setFont(), and setName().
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().
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().
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.
embedded | If 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().