2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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
19 #ifndef GNASH_SWF_TEXTRECORD_H
20 #define GNASH_SWF_TEXTRECORD_H
28 class movie_definition
;
38 /// Store a TextRecord.
40 /// This consists of style information and a number of glyphs.
41 /// This may be parsed from a SWFStream, or it can be constructed
42 /// dynamically by TextField. A static TextField has fewer possible
43 /// properties than a dynamic one.
48 typedef std::vector
<TextRecord
> TextRecords
;
68 typedef std::vector
<GlyphEntry
> Glyphs
;
70 /// Accumulate the number of glyphs in a TextRecord.
73 size_t operator()(size_t c
, const TextRecord
& t
) {
74 const Glyphs
& glyphs
= t
.glyphs();
75 size_t ret
= c
+ glyphs
.size();
80 /// Read a TextRecord from the stream
82 /// @param in The SWFStream to read from.
83 /// @param m The movie_definition containing this TextRecord.
84 /// @param glyphBits The number of bits per glyph
85 /// @param advanceBits The number of bits per advance
86 /// @param tag The tag type of this TextRecord. This must be
87 /// DefineText or DefineText2
88 /// @return False if we have reached the end of the
89 /// TextRecords, true if there are more to parse.
90 bool read(SWFStream
& in
, movie_definition
& m
, int glyphBits
,
91 int advanceBits
, TagType tag
);
93 static void displayRecords(Renderer
& renderer
, const Transform
& xform
,
94 const TextRecords
& records
, bool embedded
= true);
96 const Glyphs
& glyphs() const {
100 void addGlyph(const GlyphEntry
& ge
, Glyphs::size_type num
= 1) {
101 _glyphs
.insert(_glyphs
.end(), num
, ge
);
104 void clearGlyphs(Glyphs::size_type num
= 0) {
105 if (!num
) _glyphs
.clear();
106 else _glyphs
.resize(_glyphs
.size() - num
);
109 // TODO: check font properly.
110 void setFont(const Font
* f
) {
114 void setURL(std::string url
) {
118 const std::string
& getURL() const {
122 void setTarget(std::string target
) {
123 _htmlTarget
= target
;
126 const std::string
& getTarget() const {
130 const Font
* getFont() const {
134 void setTextHeight(boost::uint16_t height
) {
135 _textHeight
= height
;
138 float recordWidth() const {
140 for (size_t i
= 0; i
< glyphs().size(); ++i
)
142 width
+= glyphs()[i
].advance
;
147 boost::uint16_t textHeight() const {
151 bool hasXOffset() const {
155 void setXOffset(float x
) {
160 float xOffset() const {
164 bool hasYOffset() const {
168 void setYOffset(float y
) {
173 float yOffset() const {
177 void setColor(const rgba
& color
) {
181 const rgba
& color() const {
185 bool underline() const {
189 void setUnderline(bool b
) {
200 /// The height of the text in TWIPS.
201 boost::uint16_t _textHeight
;
203 /// Whether the TextRecord has an x offset.
206 /// Whether the TextRecord has a y offset.
209 /// The x offset of the text, by default 0.0
212 /// The y offset of the text, by default 0.0
215 /// The font associated with the TextRecord. Can be NULL.
218 std::string _htmlURL
;
219 std::string _htmlTarget
;
220 /// Whether the text should be underlined.