Gnash  0.8.11dev
TextRecord.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_SWF_TEXTRECORD_H
20 #define GNASH_SWF_TEXTRECORD_H
21 
22 #include <string>
23 #include <vector>
24 #include <boost/intrusive_ptr.hpp>
25 
26 #include "RGBA.h"
27 #include "SWF.h"
28 #include "Font.h"
29 
30 namespace gnash {
31  class movie_definition;
32  class SWFStream;
33  class Font;
34  class Renderer;
35  class Transform;
36 }
37 
38 namespace gnash {
39 namespace SWF {
40 
42 //
48 {
49 public:
50 
51  typedef std::vector<TextRecord> TextRecords;
52 
53  struct GlyphEntry
54  {
55  int index;
56  float advance;
57  };
58 
60  :
61  _color(0, 0, 0, 0),
62  _textHeight(0),
63  _hasXOffset(false),
64  _hasYOffset(false),
65  _xOffset(0.0f),
66  _yOffset(0.0f),
67  _font(nullptr),
68  _underline(false)
69  {}
70 
71  typedef std::vector<GlyphEntry> Glyphs;
72 
75  {
76  size_t operator()(size_t c, const TextRecord& t) {
77  const Glyphs& glyphs = t.glyphs();
78  size_t ret = c + glyphs.size();
79  return ret;
80  }
81  };
82 
84  //
93  bool read(SWFStream& in, movie_definition& m, int glyphBits,
94  int advanceBits, TagType tag);
95 
96  static void displayRecords(Renderer& renderer, const Transform& xform,
97  const TextRecords& records, bool embedded = true);
98 
99  const Glyphs& glyphs() const {
100  return _glyphs;
101  }
102 
103  void addGlyph(const GlyphEntry& ge, Glyphs::size_type num = 1) {
104  _glyphs.insert(_glyphs.end(), num, ge);
105  }
106 
107  void clearGlyphs(Glyphs::size_type num = 0) {
108  if (!num) _glyphs.clear();
109  else _glyphs.resize(_glyphs.size() - num);
110  }
111 
112  // TODO: check font properly.
113  void setFont(boost::intrusive_ptr<const Font> f) {
114  _font = f;
115  }
116 
117  void setURL(std::string url) {
118  _htmlURL = url;
119  }
120 
121  const std::string& getURL() const {
122  return _htmlURL;
123  }
124 
125  void setTarget(std::string target) {
126  _htmlTarget = target;
127  }
128 
129  const std::string& getTarget() const {
130  return _htmlTarget;
131  }
132 
133  const Font* getFont() const {
134  return _font.get();
135  }
136 
137  void setTextHeight(std::uint16_t height) {
138  _textHeight = height;
139  }
140 
141  float recordWidth() const {
142  float width = 0.0f;
143  for (const auto& glyph : glyphs())
144  {
145  width += glyph.advance;
146  }
147  return width;
148  }
149 
150  std::uint16_t textHeight() const {
151  return _textHeight;
152  }
153 
154  bool hasXOffset() const {
155  return _hasXOffset;
156  }
157 
158  void setXOffset(float x) {
159  _hasXOffset = true;
160  _xOffset = x;
161  }
162 
163  float xOffset() const {
164  return _xOffset;
165  }
166 
167  bool hasYOffset() const {
168  return _hasYOffset;
169  }
170 
171  void setYOffset(float y) {
172  _hasYOffset = true;
173  _yOffset = y;
174  }
175 
176  float yOffset() const {
177  return _yOffset;
178  }
179 
180  void setColor(const rgba& color) {
181  _color = color;
182  }
183 
184  const rgba& color() const {
185  return _color;
186  }
187 
188  bool underline() const {
189  return _underline;
190  }
191 
192  void setUnderline(bool b) {
193  _underline = b;
194  }
195 
196 private:
197 
198  Glyphs _glyphs;
199 
201  rgba _color;
202 
204  std::uint16_t _textHeight;
205 
207  bool _hasXOffset;
208 
210  bool _hasYOffset;
211 
213  float _xOffset;
214 
216  float _yOffset;
217 
219  boost::intrusive_ptr<const Font> _font;
220 
221  std::string _htmlURL;
222  std::string _htmlTarget;
224  bool _underline;
225 };
226 
227 } // namespace SWF
228 } // namespace gnash
229 
230 
231 #endif
const rgba & color() const
Definition: TextRecord.h:184
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
bool hasYOffset() const
Definition: TextRecord.h:167
A Font resource.
Definition: Font.h:89
std::vector< GlyphEntry > Glyphs
Definition: TextRecord.h:71
float yOffset() const
Definition: TextRecord.h:176
const Glyphs & glyphs() const
Definition: TextRecord.h:99
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:30
void clearGlyphs(Glyphs::size_type num=0)
Definition: TextRecord.h:107
void setTarget(std::string target)
Definition: TextRecord.h:125
bool hasXOffset() const
Definition: TextRecord.h:154
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void setXOffset(float x)
Definition: TextRecord.h:158
float xOffset() const
Definition: TextRecord.h:163
void addGlyph(const GlyphEntry &ge, Glyphs::size_type num=1)
Definition: TextRecord.h:103
Definition: klash_part.cpp:329
Definition: GnashKey.h:149
Definition: GnashKey.h:152
Base class for render handlers.
Definition: Renderer.h:188
bool underline() const
Definition: TextRecord.h:188
Accumulate the number of glyphs in a TextRecord.
Definition: TextRecord.h:74
float advance
Definition: TextRecord.h:56
Definition: GnashKey.h:166
Definition: klash_part.cpp:329
void setTextHeight(std::uint16_t height)
Definition: TextRecord.h:137
void setYOffset(float y)
Definition: TextRecord.h:171
Store a TextRecord.
Definition: TextRecord.h:47
void setURL(std::string url)
Definition: TextRecord.h:117
bool read(SWFStream &in, movie_definition &m, int glyphBits, int advanceBits, TagType tag)
Read a TextRecord from the stream.
Definition: TextRecord.cpp:39
TextRecord()
Definition: TextRecord.h:59
std::vector< TextRecord > TextRecords
Definition: TextRecord.h:51
void setColor(const rgba &color)
Definition: TextRecord.h:180
std::int32_t x
Definition: BitmapData_as.cpp:434
Definition: GnashKey.h:148
const std::string & getTarget() const
Definition: TextRecord.h:129
std::int32_t y
Definition: BitmapData_as.cpp:435
size_t operator()(size_t c, const TextRecord &t)
Definition: TextRecord.h:76
std::string url
Definition: gnash.cpp:59
float recordWidth() const
Definition: TextRecord.h:141
static void displayRecords(Renderer &renderer, const Transform &xform, const TextRecords &records, bool embedded=true)
Render the given glyph records.
Definition: TextRecord.cpp:163
Definition: GnashKey.h:159
const std::string & getURL() const
Definition: TextRecord.h:121
int index
Definition: TextRecord.h:55
void setFont(boost::intrusive_ptr< const Font > f)
Definition: TextRecord.h:113
void setUnderline(bool b)
Definition: TextRecord.h:192
std::uint16_t textHeight() const
Definition: TextRecord.h:150
const Font * getFont() const
Definition: TextRecord.h:133
Definition: GnashKey.h:331
Definition: TextRecord.h:53
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:33
SWF stream wrapper class.
Definition: SWFStream.h:58
A basic RGBA type.
Definition: RGBA.h:35