• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

Font.h

Go to the documentation of this file.
00001 // Font.h -- Font class, for Gnash
00002 //
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00004 //   Foundation, Inc
00005 // 
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 
00021 // Based on the public domain work of Thatcher Ulrich <tu@tulrich.com> 2003
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 // @@ replace this with a flat hash, or else a sorted array
00050 //    (binary search)
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 // for use in standard algorithms
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     // This table maps from Unicode DisplayObject number to glyph index.
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         
00208     bool is_subpixel_font() const;
00209 
00211     bool isBold() const {
00212         return _bold;
00213     }
00214     
00216     bool isItalic() const {
00217         return _italic;
00218     }
00219 
00221     //
00223     struct FontNameInfo
00224     {
00225         std::string displayName;
00226         std::string copyrightName;
00227     };
00228 
00230     struct GlyphInfo
00231     {
00232         // no glyph, default textured glyph, 0 advance
00233         GlyphInfo();
00234 
00236         //
00238         GlyphInfo(std::auto_ptr<SWF::ShapeRecord> glyph, float advance);
00239 
00240         GlyphInfo(const GlyphInfo& o);
00241 
00242         boost::shared_ptr<SWF::ShapeRecord> glyph;
00243 
00244         float advance;
00245     };
00246 
00247     typedef std::vector<GlyphInfo> GlyphInfoRecords;
00248 
00250     //
00254     void addFontNameInfo(const FontNameInfo& fontName);
00255 
00257     //
00259     void setName(const std::string& name);
00260 
00262     //
00264     void setFlags(boost::uint8_t flags);
00265 
00267     //
00269     void setCodeTable(std::auto_ptr<CodeTable> table);
00270 
00272     GlyphInfoRecords::size_type glyphCount() const;
00273 
00275     //
00278     FreetypeGlyphsProvider* ftProvider() const;
00279 
00280 private:
00281 
00283     //
00290     int add_os_glyph(boost::uint16_t code);
00291 
00293     boost::scoped_ptr<SWF::DefineFontTag> _fontTag;
00294 
00295     // Device glyphs
00296     GlyphInfoRecords _deviceGlyphTable;
00297 
00298     std::string    _name;
00299     std::string _displayName;
00300     std::string _copyrightName;
00301 
00302     bool _unicodeChars;
00303     bool _shiftJISChars;
00304     bool _ansiChars;
00305     bool _italic;
00306     bool _bold;
00307 
00309     //
00319     boost::shared_ptr<const CodeTable> _embeddedCodeTable; 
00320 
00322     CodeTable _deviceCodeTable; 
00323 
00324     typedef std::map<kerning_pair, float> kernings_table;
00325     kernings_table m_kerning_pairs;
00326 
00327     mutable std::auto_ptr<FreetypeGlyphsProvider> _ftProvider;
00328 
00329 };
00330 
00331 
00332 }    // end namespace gnash
00333 
00334 
00335 
00336 #endif // GNASH_FONT_H
00337 
00338 // Local Variables:
00339 // mode: C++
00340 // c-basic-offset: 8 
00341 // tab-width: 8
00342 // indent-tabs-mode: t
00343 // End:

Generated on Fri Mar 16 2012 15:46:09 for Gnash by  doxygen 1.7.1