Gnash
0.8.10
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 00003 // Free Software 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 <string> 00023 #include <vector> 00024 #include <boost/intrusive_ptr.hpp> 00025 00026 #include "RGBA.h" 00027 #include "SWF.h" 00028 #include "Font.h" 00029 00030 namespace gnash { 00031 class movie_definition; 00032 class SWFStream; 00033 class Font; 00034 class Renderer; 00035 class Transform; 00036 } 00037 00038 namespace gnash { 00039 namespace SWF { 00040 00042 // 00047 class TextRecord 00048 { 00049 public: 00050 00051 typedef std::vector<TextRecord> TextRecords; 00052 00053 struct GlyphEntry 00054 { 00055 int index; 00056 float advance; 00057 }; 00058 00059 TextRecord() 00060 : 00061 _color(0, 0, 0, 0), 00062 _textHeight(0), 00063 _hasXOffset(false), 00064 _hasYOffset(false), 00065 _xOffset(0.0f), 00066 _yOffset(0.0f), 00067 _font(0), 00068 _underline(false) 00069 {} 00070 00071 typedef std::vector<GlyphEntry> Glyphs; 00072 00074 struct RecordCounter 00075 { 00076 size_t operator()(size_t c, const TextRecord& t) { 00077 const Glyphs& glyphs = t.glyphs(); 00078 size_t ret = c + glyphs.size(); 00079 return ret; 00080 } 00081 }; 00082 00084 // 00093 bool read(SWFStream& in, movie_definition& m, int glyphBits, 00094 int advanceBits, TagType tag); 00095 00096 static void displayRecords(Renderer& renderer, const Transform& xform, 00097 const TextRecords& records, bool embedded = true); 00098 00099 const Glyphs& glyphs() const { 00100 return _glyphs; 00101 } 00102 00103 void addGlyph(const GlyphEntry& ge, Glyphs::size_type num = 1) { 00104 _glyphs.insert(_glyphs.end(), num, ge); 00105 } 00106 00107 void clearGlyphs(Glyphs::size_type num = 0) { 00108 if (!num) _glyphs.clear(); 00109 else _glyphs.resize(_glyphs.size() - num); 00110 } 00111 00112 // TODO: check font properly. 00113 void setFont(boost::intrusive_ptr<const Font> f) { 00114 _font = f; 00115 } 00116 00117 void setURL(std::string url) { 00118 _htmlURL = url; 00119 } 00120 00121 const std::string& getURL() const { 00122 return _htmlURL; 00123 } 00124 00125 void setTarget(std::string target) { 00126 _htmlTarget = target; 00127 } 00128 00129 const std::string& getTarget() const { 00130 return _htmlTarget; 00131 } 00132 00133 const Font* getFont() const { 00134 return _font.get(); 00135 } 00136 00137 void setTextHeight(boost::uint16_t height) { 00138 _textHeight = height; 00139 } 00140 00141 float recordWidth() const { 00142 float width = 0.0f; 00143 for (size_t i = 0; i < glyphs().size(); ++i) 00144 { 00145 width += glyphs()[i].advance; 00146 } 00147 return width; 00148 } 00149 00150 boost::uint16_t textHeight() const { 00151 return _textHeight; 00152 } 00153 00154 bool hasXOffset() const { 00155 return _hasXOffset; 00156 } 00157 00158 void setXOffset(float x) { 00159 _hasXOffset = true; 00160 _xOffset = x; 00161 } 00162 00163 float xOffset() const { 00164 return _xOffset; 00165 } 00166 00167 bool hasYOffset() const { 00168 return _hasYOffset; 00169 } 00170 00171 void setYOffset(float y) { 00172 _hasYOffset = true; 00173 _yOffset = y; 00174 } 00175 00176 float yOffset() const { 00177 return _yOffset; 00178 } 00179 00180 void setColor(const rgba& color) { 00181 _color = color; 00182 } 00183 00184 const rgba& color() const { 00185 return _color; 00186 } 00187 00188 bool underline() const { 00189 return _underline; 00190 } 00191 00192 void setUnderline(bool b) { 00193 _underline = b; 00194 } 00195 00196 private: 00197 00198 Glyphs _glyphs; 00199 00201 rgba _color; 00202 00204 boost::uint16_t _textHeight; 00205 00207 bool _hasXOffset; 00208 00210 bool _hasYOffset; 00211 00213 float _xOffset; 00214 00216 float _yOffset; 00217 00219 boost::intrusive_ptr<const Font> _font; 00220 00221 std::string _htmlURL; 00222 std::string _htmlTarget; 00224 bool _underline; 00225 }; 00226 00227 } // namespace SWF 00228 } // namespace gnash 00229 00230 00231 #endif