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 #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
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 }
00226 }
00227
00228
00229 #endif