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
gnash::SWF::TextRecord::RecordCounter::operator()
size_t operator()(size_t c, const TextRecord &t)
Definition: TextRecord.h:76
gnash::SWF::TextRecord::displayRecords
static void displayRecords(Renderer &renderer, const Transform &xform, const TextRecords &records, bool embedded=true)
Render the given glyph records.
Definition: TextRecord.cpp:163
gnash::SWFCxForm::transform
rgba transform(const rgba &in) const
Transform the given color, return the result.
Definition: SWFCxForm.cpp:49
gnash::Transform::colorTransform
SWFCxForm colorTransform
Definition: Transform.h:60
gnash::SWFStream::ensureBits
void ensureBits(unsigned long needed)
Ensure the requested number of bits are available for a bitwise read in currently opened tag.
Definition: SWFStream.h:382
gnash::SWFStream::read_uint
unsigned read_uint(unsigned short bitcount)
Reads a bit-packed unsigned integer from the stream and returns it. The given bitcount determines the...
Definition: SWFStream.cpp:102
TypesParser.h
gnash::Font::get_glyph
SWF::ShapeRecord * get_glyph(int glyph_index, bool embedded) const
Get glyph by index.
Definition: Font.cpp:101
gnash::SWF::DEFINETEXT
@ DEFINETEXT
Definition: SWF.h:43
gnash::SWFStream::read_sint
int read_sint(unsigned short bitcount)
Reads a bit-packed little-endian signed integer from the stream. The given bitcount determines the nu...
Definition: SWFStream.cpp:191
height
@ height
Definition: klash_part.cpp:329
gnash::SWF::TextRecord::setTarget
void setTarget(std::string target)
Definition: TextRecord.h:125
gnash::log_swferror
void log_swferror(StringType msg, Args... args)
Definition: log.h:325
gnash::SWF::TextRecord::TextRecord
TextRecord()
Definition: TextRecord.h:59
gnash::SWF::TextRecord::setFont
void setFont(boost::intrusive_ptr< const Font > f)
Definition: TextRecord.h:113
gnash::SWF::TagType
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:31
gnash::Transform::matrix
SWFMatrix matrix
Definition: Transform.h:59
gnash::SWF::TextRecord::glyphs
const Glyphs & glyphs() const
Definition: TextRecord.h:99
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
y
std::int32_t y
Definition: BitmapData_as.cpp:435
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::rgba
A basic RGBA type.
Definition: RGBA.h:36
gnash::Renderer::drawLine
virtual void drawLine(const std::vector< point > &coords, const rgba &color, const SWFMatrix &mat)=0
Draw a line-strip directly, using a thin, solid line.
_
#define _(String)
Definition: log.h:44
Renderer.h
gnash::SWF::TextRecord::GlyphEntry::advance
float advance
Definition: TextRecord.h:56
gnash::SWF::TextRecord::hasXOffset
bool hasXOffset() const
Definition: TextRecord.h:154
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::SWF::TextRecord::setUnderline
void setUnderline(bool b)
Definition: TextRecord.h:192
gnash::SWF::TextRecord::underline
bool underline() const
Definition: TextRecord.h:188
gnash::SWF::TextRecord::yOffset
float yOffset() const
Definition: TextRecord.h:176
gnash::Renderer
Base class for render handlers.
Definition: Renderer.h:189
gnash::SWF::TextRecord::setXOffset
void setXOffset(float x)
Definition: TextRecord.h:158
gnash::key::m
@ m
Definition: GnashKey.h:159
gnash::SWF::TextRecord::TextRecords
std::vector< TextRecord > TextRecords
Definition: TextRecord.h:51
gnash::SWFCxForm
Color transformation record.
Definition: SWFCxForm.h:35
gnash::SWF::TextRecord::setTextHeight
void setTextHeight(std::uint16_t height)
Definition: TextRecord.h:137
TextRecord.h
gnash::SWF::TextRecord::read
bool read(SWFStream &in, movie_definition &m, int glyphBits, int advanceBits, TagType tag)
Read a TextRecord from the stream.
Definition: TextRecord.cpp:39
gnash::movie_definition
Client program's interface to the definition of a movie or sprite.
Definition: movie_definition.h:96
SWFCxForm.h
gnash::SWF::TextRecord::getURL
const std::string & getURL() const
Definition: TextRecord.h:121
gnash::SWFStream::read_s16
std::int16_t read_s16()
Read a aligned signed 16-bit value from the stream.
Definition: SWFStream.cpp:355
IF_VERBOSE_MALFORMED_SWF
#define IF_VERBOSE_MALFORMED_SWF(x)
Definition: log.h:404
gnash::SWF::TextRecord::xOffset
float xOffset() const
Definition: TextRecord.h:163
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::SWF::TextRecord::addGlyph
void addGlyph(const GlyphEntry &ge, Glyphs::size_type num=1)
Definition: TextRecord.h:103
gnash::SWF::TextRecord::getTarget
const std::string & getTarget() const
Definition: TextRecord.h:129
gnash::SWF::TextRecord::setColor
void setColor(const rgba &color)
Definition: TextRecord.h:180
gnash::Renderer::drawGlyph
virtual void drawGlyph(const SWF::ShapeRecord &rec, const rgba &color, const SWFMatrix &mat)=0
Draws a glyph (font character).
gnash::SWF::TextRecord::recordWidth
float recordWidth() const
Definition: TextRecord.h:141
gnash::SWF::TextRecord::RecordCounter
Accumulate the number of glyphs in a TextRecord.
Definition: TextRecord.h:75
gnash::SWF::TextRecord::setYOffset
void setYOffset(float y)
Definition: TextRecord.h:171
RGBA.h
gnash::SWF::TextRecord::clearGlyphs
void clearGlyphs(Glyphs::size_type num=0)
Definition: TextRecord.h:107
gnash::point
geometry::Point2d point
Definition: Point2d.h:143
gnash::SWFMatrix::tx
std::int32_t tx() const
Definition: SWFMatrix.h:95
gnash::Font::unitsPerEM
size_t unitsPerEM(bool embedded) const
Return height of the EM square used for glyphs definition.
Definition: Font.cpp:257
gnash::SWF::TextRecord::GlyphEntry
Definition: TextRecord.h:54
Font.h
gnash::SWFMatrix
Definition: SWFMatrix.h:54
gnash::SWFMatrix::get_x_scale
double get_x_scale() const
return the magnitude scale of our x coord output
Definition: SWFMatrix.cpp:314
gnash::SWF::TextRecord::color
const rgba & color() const
Definition: TextRecord.h:184
gnash::SWF::TextRecord::setURL
void setURL(std::string url)
Definition: TextRecord.h:117
IF_VERBOSE_PARSE
#define IF_VERBOSE_PARSE(x)
Definition: log.h:378
DisplayObject.h
gnash::rgba::m_a
std::uint8_t m_a
Definition: RGBA.h:113
gnash::log_parse
void log_parse(StringType msg, Args... args)
Definition: log.h:313
log.h
gnash::SWF::TextRecord::GlyphEntry::index
int index
Definition: TextRecord.h:55
gnash::readRGB
rgba readRGB(SWFStream &in)
Read an RGB rgba from input stream.
Definition: TypesParser.cpp:106
gnash::SWF::TextRecord::Glyphs
std::vector< GlyphEntry > Glyphs
Definition: TextRecord.h:71
url
std::string url
Definition: gnash.cpp:59
gnash::key::f
@ f
Definition: GnashKey.h:152
gnash::Font
A Font resource.
Definition: Font.h:90
SWF.h
gnash::SWFStream::read_u16
std::uint16_t read_u16()
Read a aligned unsigned 16-bit value from the stream.
Definition: SWFStream.cpp:332
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::SWF::TextRecord::hasYOffset
bool hasYOffset() const
Definition: TextRecord.h:167
gnash::SWFMatrix::ty
std::int32_t ty() const
Definition: SWFMatrix.h:99
gnash::SWFStream::read_u8
std::uint8_t read_u8()
Read a aligned unsigned 8-bit value from the stream.
Definition: SWFStream.cpp:319
movie_definition.h
gnash::SWFMatrix::get_y_scale
double get_y_scale() const
return the magnitude scale of our y coord output
Definition: SWFMatrix.cpp:322
gnash::SWF::ShapeRecord
Holds information needed to draw a shape.
Definition: ShapeRecord.h:127
gnash::SWFStream
SWF stream wrapper class.
Definition: SWFStream.h:59
gnash::Transform
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:34
gnash::SWFStream::ensureBytes
void ensureBytes(unsigned long needed)
Ensure the requested number of bytes are available for an aligned read in the currently opened tag.
Definition: SWFStream.cpp:50
width
@ width
Definition: klash_part.cpp:329
gnash::key::SWF
@ SWF
Definition: GnashKey.h:331
gnash::SWF::TextRecord
Store a TextRecord.
Definition: TextRecord.h:48
x
std::int32_t x
Definition: BitmapData_as.cpp:434
SWFStream.h
gnash::key::b
@ b
Definition: GnashKey.h:148
gnash::SWF::TextRecord::getFont
const Font * getFont() const
Definition: TextRecord.h:133
SWFMatrix.h
gnash::readRGBA
rgba readRGBA(SWFStream &in)
Read an RGBA rgba from input stream.
Definition: TypesParser.cpp:95
gnash::SWF::TextRecord::textHeight
std::uint16_t textHeight() const
Definition: TextRecord.h:150