Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef GNASH_FONT_H
00025 #define GNASH_FONT_H
00026
00027 #include <string>
00028 #include <boost/scoped_ptr.hpp>
00029 #include <boost/shared_ptr.hpp>
00030 #include <boost/cstdint.hpp>
00031 #include <memory>
00032 #include <vector>
00033 #include <map>
00034
00035 #include "ref_counted.h"
00036
00037 namespace gnash {
00038 class FreetypeGlyphsProvider;
00039 namespace SWF {
00040 class ShapeRecord;
00041 class DefineFontTag;
00042 }
00043 }
00044
00045 namespace gnash {
00046
00047
00048
00049
00050
00051 class kerning_pair
00052 {
00053 public:
00054 boost::uint16_t m_char0;
00055 boost::uint16_t m_char1;
00056
00057 bool operator==(const kerning_pair& k) const
00058 {
00059 return m_char0 == k.m_char0 && m_char1 == k.m_char1;
00060 }
00061 };
00062
00063
00064 inline bool
00065 operator< (const kerning_pair& p1, const kerning_pair& p2)
00066 {
00067 if (p1.m_char0 < p2.m_char0) return true;
00068 if (p1.m_char0 == p2.m_char0) {
00069 if (p1.m_char1 < p2.m_char1) return true;
00070 }
00071
00072 return false;
00073 }
00074
00075
00077
00083
00088
00090 class Font : public ref_counted
00091 {
00092 public:
00093
00094
00095 typedef std::map<boost::uint16_t, int> CodeTable;
00096
00097 Font(std::auto_ptr<SWF::DefineFontTag> ft);
00098
00100
00109 Font(const std::string& name, bool bold = false, bool italic = false);
00110
00111 ~Font();
00112
00113 boost::uint16_t codeTableLookup(int glyph, bool embedded) const;
00114
00116
00125 bool matches(const std::string& name, bool bold, bool italic) const;
00126
00128
00140 SWF::ShapeRecord* get_glyph(int glyph_index, bool embedded) const;
00141
00143 const std::string& name() const { return _name; }
00144
00146
00162 int get_glyph_index(boost::uint16_t code, bool embedded) const;
00163
00165
00167
00173 float get_advance(int glyph_index, bool embedded) const;
00174
00177
00184 float get_kerning_adjustment(int last_code, int this_code) const;
00185
00187
00191 size_t unitsPerEM(bool embedded) const;
00192
00194
00196 float ascent(bool embedded) const;
00197
00199
00201 float descent(bool embedded) const;
00202
00204
00206 float leading() const;
00207
00209 bool isBold() const {
00210 return _bold;
00211 }
00212
00214 bool isItalic() const {
00215 return _italic;
00216 }
00217
00219
00221 struct FontNameInfo
00222 {
00223 std::string displayName;
00224 std::string copyrightName;
00225 };
00226
00228 struct GlyphInfo
00229 {
00230
00231 GlyphInfo();
00232
00234
00236 GlyphInfo(std::auto_ptr<SWF::ShapeRecord> glyph, float advance);
00237
00238 GlyphInfo(const GlyphInfo& o);
00239
00240 boost::shared_ptr<SWF::ShapeRecord> glyph;
00241
00242 float advance;
00243 };
00244
00245 typedef std::vector<GlyphInfo> GlyphInfoRecords;
00246
00248
00252 void addFontNameInfo(const FontNameInfo& fontName);
00253
00255
00257 void setName(const std::string& name);
00258
00260
00262 void setFlags(boost::uint8_t flags);
00263
00265
00267 void setCodeTable(std::auto_ptr<CodeTable> table);
00268
00270 GlyphInfoRecords::size_type glyphCount() const;
00271
00273
00276 FreetypeGlyphsProvider* ftProvider() const;
00277
00278 private:
00279
00281
00288 int add_os_glyph(boost::uint16_t code);
00289
00291 boost::scoped_ptr<SWF::DefineFontTag> _fontTag;
00292
00293
00294 GlyphInfoRecords _deviceGlyphTable;
00295
00296 std::string _name;
00297 std::string _displayName;
00298 std::string _copyrightName;
00299
00300 bool _unicodeChars;
00301 bool _shiftJISChars;
00302 bool _ansiChars;
00303 bool _italic;
00304 bool _bold;
00305
00307
00317 boost::shared_ptr<const CodeTable> _embeddedCodeTable;
00318
00320 CodeTable _deviceCodeTable;
00321
00322 typedef std::map<kerning_pair, float> kernings_table;
00323 kernings_table m_kerning_pairs;
00324
00325 mutable std::auto_ptr<FreetypeGlyphsProvider> _ftProvider;
00326
00327 };
00328
00329
00330 }
00331
00332
00333
00334 #endif // GNASH_FONT_H
00335
00336
00337
00338
00339
00340
00341