1 // DefineFontTag.h   Read DefineFont and DefineFontInfo tags
2 //
3 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 //   Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 //
20 
21 // Based on the public domain work of Thatcher Ulrich <tu@tulrich.com> 2003
22 
23 /// This file handles DefineFont, DefineFontInfo, DefineFontInfo2,
24 /// DefineFont2, and DefineFont3.
25 //
26 /// They are all handled in one file because a DefineFont2 or 3 tag
27 /// contains practically the same as a DefineFont plus DefineFontInfo
28 /// or DefineFontInfo2.
29 
30 #ifndef GNASH_SWF_DEFINEFONTTAG_H
31 #define GNASH_SWF_DEFINEFONTTAG_H
32 
33 #include "SWF.h"
34 #include "Font.h"
35 #include <map>
36 #include <string>
37 #include <cstdint>
38 
39 // Forward declarations
40 namespace gnash {
41     class SWFStream;
42     class movie_definition;
43     class RunResources;
44 }
45 
46 namespace gnash {
47 namespace SWF {
48 
49 /// Read and store DefineFont and DefineFont2 tag.
50 class DefineFontTag
51 {
52 public:
53 
54     /// Load a DefineFont tag.
55     //
56     /// A corresponding Font is created and added to the movie_definition.
57     static void loader(SWFStream& in, TagType tag, movie_definition& m,
58             const RunResources& r);
59 
60     /// Return the glyphs read from the DefineFont tag.
glyphTable()61     const Font::GlyphInfoRecords& glyphTable() const {
62         return _glyphTable;
63     }
64 
65     /// Check for the existence of a Font::CodeTable.
66     //
67     /// @return     True if the tag has a Font::CodeTable.
68     //
69     /// This can only be true for a DefineFont2 tag.
hasCodeTable()70     bool hasCodeTable() const {
71         return _codeTable.get();
72     }
73 
74     /// Retrieve the tag's Font::CodeTable.
75     //
76     /// This DefineFontTag always retains ownership, and the CodeTable
77     /// may not be altered.
78     //
79     /// @return     shared ownership of the tag's Font::CodeTable. This
80     ///             may be NULL, which can be checked first with
81     ///             hasCodeTable().
getCodeTable()82     std::shared_ptr<const Font::CodeTable> getCodeTable() const {
83         return _codeTable;
84     }
85 
ansiChars()86     bool ansiChars() const { return _ansiChars; }
shiftJISChars()87     bool shiftJISChars() const { return _shiftJISChars; }
unicodeChars()88     bool unicodeChars() const { return _unicodeChars; }
italic()89     bool italic() const { return _italic; }
bold()90     bool bold() const { return _bold; }
subpixelFont()91     bool subpixelFont() const { return _subpixelFont; }
92 
93     /// The font leading value
94     //
95     /// This is documented to be int16_t, but may be uint16_t like advance.
leading()96     std::int16_t leading() const {
97         return _leading;
98     }
99 
100     /// The font ascent value
101     //
102     /// This is documented to be int16_t, but may be uint16_t like advance.
ascent()103     std::int16_t ascent() const {
104         return _ascent;
105     }
106 
107     /// The font descent value
108     //
109     /// This is documented to be int16_t, but may be uint16_t like advance.
descent()110     std::int16_t descent() const {
111         return _descent;
112     }
113 
name()114     const std::string& name() const { return _name; }
115 
116     /// Read Font::CodeTable, which maps glyph indices to DisplayObject codes.
117     static void readCodeTable(SWFStream& in, Font::CodeTable& table,
118         bool wideCodes, size_t glyphCount);
119 
120 private:
121 
122     DefineFontTag(SWFStream& in, movie_definition& m, TagType tag,
123             const RunResources& r);
124 
125     /// Read a DefineFont tag.
126     void readDefineFont(SWFStream& in, movie_definition& m,
127             const RunResources& r);
128 
129     /// Read a DefineFont2 or DefineFont3 tag.
130     void readDefineFont2Or3(SWFStream& in, movie_definition& m,
131             const RunResources& r);
132 
133     /// The GlyphInfo records contained in the tag.
134     Font::GlyphInfoRecords _glyphTable;
135 
136     std::string _name;
137     bool _subpixelFont;
138 	bool _unicodeChars;
139 	bool _shiftJISChars;
140 	bool _ansiChars;
141 	bool _italic;
142 	bool _bold;
143 
144     std::int16_t _ascent;
145     std::int16_t _descent;
146     std::int16_t _leading;
147 
148 	typedef std::map<kerning_pair, std::int16_t> KerningTable;
149 	KerningTable _kerningPairs;
150 
151     std::shared_ptr<const Font::CodeTable> _codeTable;
152 };
153 
154 
155 class DefineFontInfoTag
156 {
157 public:
158     /// Load a DefineFontInfo tag.
159     //
160     /// Adds a CodeTable and other information to a Font created by a
161     /// DefineFont tag. The information is already contained in a
162     /// DefineFont2 or DefineFont3 tag.
163     static void loader(SWFStream& in, TagType tag, movie_definition& m,
164             const RunResources& r);
165 };
166 
167 }
168 }
169 
170 #endif
171