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

TextRecord.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_SWF_TEXTRECORD_H
00020 #define GNASH_SWF_TEXTRECORD_H
00021 
00022 #include "RGBA.h"
00023 #include "SWF.h"
00024 #include <string>
00025 #include <vector>
00026 
00027 namespace gnash {
00028     class movie_definition;
00029     class SWFStream;
00030     class SWFMatrix;
00031     class cxform;
00032     class Font;
00033     class Renderer;
00034 }
00035 
00036 namespace gnash {
00037 namespace SWF {
00038 
00040 //
00045 class TextRecord
00046 {
00047 public:
00048 
00049     typedef std::vector<TextRecord> TextRecords;
00050 
00051     struct GlyphEntry
00052     {
00053         int index;
00054         float advance;
00055     };
00056 
00057     TextRecord()
00058         :
00059         _color(0, 0, 0, 0),
00060         _textHeight(0),
00061         _hasXOffset(false),
00062         _hasYOffset(false),
00063         _xOffset(0.0f),
00064         _yOffset(0.0f),
00065         _font(0),
00066         _underline(false)
00067     {}
00068           
00069     typedef std::vector<GlyphEntry> Glyphs;  
00070 
00072     struct RecordCounter
00073     {
00074         size_t operator()(size_t c, const TextRecord& t) {
00075             const Glyphs& glyphs = t.glyphs();
00076             size_t ret = c + glyphs.size();
00077             return ret;
00078         }
00079     };
00080     
00082     //
00091     bool read(SWFStream& in, movie_definition& m, int glyphBits,
00092             int advanceBits, TagType tag);
00093 
00094     static void displayRecords(Renderer& renderer, const SWFMatrix& mat,
00095             const cxform& cx, const TextRecords& records, bool embedded = true);
00096 
00097     const Glyphs& glyphs() const {
00098         return _glyphs;
00099     }
00100 
00101     void addGlyph(const GlyphEntry& ge, Glyphs::size_type num = 1) {
00102         _glyphs.insert(_glyphs.end(), num, ge);
00103     }
00104 
00105     void clearGlyphs(Glyphs::size_type num = 0) {
00106         if (!num) _glyphs.clear();
00107         else _glyphs.resize(_glyphs.size() - num);
00108     }
00109 
00110     // TODO: check font properly.
00111     void setFont(const Font* f) {
00112         _font = f;
00113     }
00114 
00115         void setURL(std::string url) {
00116                 _htmlURL = url;
00117         }
00118         
00119         std::string getURL() {
00120                 return _htmlURL;
00121         }
00122         
00123         void setTarget(std::string target) {
00124                 _htmlTarget = target;
00125         }
00126         
00127         std::string getTarget() {
00128                 return _htmlTarget;
00129         }
00130         
00131     const Font* getFont() const {
00132         return _font;
00133     }
00134 
00135     void setTextHeight(boost::uint16_t height) {
00136         _textHeight = height;
00137     }
00138 
00139         float recordWidth() const {
00140                 float width = 0.0f;
00141                 for (size_t i = 0; i < glyphs().size(); ++i)
00142                 {
00143                         width += glyphs()[i].advance;
00144                 }
00145         return width;
00146         }
00147 
00148     boost::uint16_t textHeight() const {
00149         return _textHeight;
00150     }
00151 
00152     bool hasXOffset() const {
00153         return _hasXOffset;
00154     }
00155 
00156     void setXOffset(float x) {
00157         _hasXOffset = true;
00158         _xOffset = x;
00159     }
00160 
00161     float xOffset() const {
00162         return _xOffset;
00163     }
00164 
00165     bool hasYOffset() const {
00166         return _hasYOffset;
00167     }
00168 
00169     void setYOffset(float y) {
00170         _hasYOffset = true;
00171         _yOffset = y;
00172     }
00173 
00174     float yOffset() const {
00175         return _yOffset;
00176     }
00177 
00178     void setColor(const rgba& color) {
00179         _color = color;
00180     }
00181 
00182     const rgba& color() const {
00183         return _color;
00184     }
00185 
00186     bool underline() const {
00187         return _underline;
00188     }
00189 
00190     void setUnderline(bool b) {
00191         _underline = b;
00192     }
00193 
00194 private:
00195 
00196     Glyphs _glyphs;
00197     
00199     rgba _color;
00200 
00202     boost::uint16_t _textHeight;
00203 
00205     bool _hasXOffset;
00206 
00208     bool _hasYOffset;
00209 
00211     float _xOffset;
00212 
00214     float _yOffset;
00215 
00217     const Font* _font;
00218 
00219         std::string _htmlURL;
00220         std::string _htmlTarget;
00222     bool _underline;
00223 };
00224 
00225 } // namespace SWF
00226 } // namespace gnash
00227 
00228 
00229 #endif

Generated on Thu Sep 30 2010 14:35:04 for Gnash by  doxygen 1.7.1