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