Gnash  0.8.11dev
Font.h
Go to the documentation of this file.
1 // Font.h -- Font class, for Gnash
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 
24 #ifndef GNASH_FONT_H
25 #define GNASH_FONT_H
26 
27 #include <string>
28 #include <memory>
29 #include <cstdint>
30 #include <memory>
31 #include <vector>
32 #include <map>
33 
34 #include "ref_counted.h"
35 
36 namespace gnash {
37  class FreetypeGlyphsProvider;
38  namespace SWF {
39  class ShapeRecord;
40  class DefineFontTag;
41  }
42 }
43 
44 namespace gnash {
45 
46 
47 
48 // @@ replace this with a flat hash, or else a sorted array
49 // (binary search)
51 {
52 public:
53  std::uint16_t m_char0;
54  std::uint16_t m_char1;
55 
56  bool operator==(const kerning_pair& k) const
57  {
58  return m_char0 == k.m_char0 && m_char1 == k.m_char1;
59  }
60 };
61 
62 // for use in standard algorithms
63 inline bool
64 operator< (const kerning_pair& p1, const kerning_pair& p2)
65 {
66  if (p1.m_char0 < p2.m_char0) return true;
67  if (p1.m_char0 == p2.m_char0) {
68  if (p1.m_char1 < p2.m_char1) return true;
69  }
70 
71  return false;
72 }
73 
74 
76 //
82 //
87 //
89 class Font : public ref_counted
90 {
91 public:
92 
93  // This table maps from Unicode DisplayObject number to glyph index.
94  typedef std::map<std::uint16_t, int> CodeTable;
95 
96  Font(std::unique_ptr<SWF::DefineFontTag> ft);
97 
99  //
108  Font(std::string name, bool bold = false, bool italic = false);
109 
110  ~Font();
111 
112  std::uint16_t codeTableLookup(int glyph, bool embedded) const;
113 
115  //
124  bool matches(const std::string& name, bool bold, bool italic) const;
125 
127  //
139  SWF::ShapeRecord* get_glyph(int glyph_index, bool embedded) const;
140 
142  const std::string& name() const { return _name; }
143 
145  //
161  int get_glyph_index(std::uint16_t code, bool embedded) const;
162 
164  //
166  //
172  float get_advance(int glyph_index, bool embedded) const;
173 
176  //
183  float get_kerning_adjustment(int last_code, int this_code) const;
184 
186  //
190  size_t unitsPerEM(bool embedded) const;
191 
193  //
195  float ascent(bool embedded) const;
196 
198  //
200  float descent(bool embedded) const;
201 
203  //
205  float leading() const;
206 
208  bool isBold() const {
209  return _bold;
210  }
211 
213  bool isItalic() const {
214  return _italic;
215  }
216 
218  //
221  {
222  std::string displayName;
223  std::string copyrightName;
224  };
225 
227  struct GlyphInfo
228  {
229  // no glyph, default textured glyph, 0 advance
230  GlyphInfo();
231 
233  //
235  GlyphInfo(std::unique_ptr<SWF::ShapeRecord> glyph, float advance);
236 
237  std::unique_ptr<SWF::ShapeRecord> glyph;
238 
239  float advance;
240  };
241 
242  typedef std::vector<GlyphInfo> GlyphInfoRecords;
243 
245  //
249  void addFontNameInfo(const FontNameInfo& fontName);
250 
252  //
254  void setName(const std::string& name);
255 
257  //
259  void setFlags(std::uint8_t flags);
260 
262  //
264  void setCodeTable(std::unique_ptr<CodeTable> table);
265 
267  GlyphInfoRecords::size_type glyphCount() const;
268 
270  //
273  FreetypeGlyphsProvider* ftProvider() const;
274 
275 private:
276 
278  //
285  int add_os_glyph(std::uint16_t code);
286 
288  std::unique_ptr<SWF::DefineFontTag> _fontTag;
289 
290  // Device glyphs
291  GlyphInfoRecords _deviceGlyphTable;
292 
293  std::string _name;
294  std::string _displayName;
295  std::string _copyrightName;
296 
297  bool _unicodeChars;
298  bool _shiftJISChars;
299  bool _ansiChars;
300  bool _italic;
301  bool _bold;
302 
304  //
314  std::shared_ptr<const CodeTable> _embeddedCodeTable;
315 
317  CodeTable _deviceCodeTable;
318 
319  typedef std::map<kerning_pair, float> kernings_table;
320  kernings_table m_kerning_pairs;
321 
322  mutable std::unique_ptr<FreetypeGlyphsProvider> _ftProvider;
323 
324 };
325 
326 
327 } // end namespace gnash
328 
329 
330 
331 #endif // GNASH_FONT_H
332 
333 // Local Variables:
334 // mode: C++
335 // c-basic-offset: 8
336 // tab-width: 8
337 // indent-tabs-mode: t
338 // End:
Glyph info structure.
Definition: Font.h:227
std::string copyrightName
Definition: Font.h:223
const std::string & name() const
Get name of this font.
Definition: Font.h:142
A pair of strings describing the font.
Definition: Font.h:220
A Font resource.
Definition: Font.h:89
For stuff that&#39;s tricky to keep track of w/r/t ownership & cleanup. The only use for this class seems...
Definition: ref_counted.h:34
bool isBold() const
Return true if the font is bold.
Definition: Font.h:208
Definition: GnashKey.h:157
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
std::uint16_t m_char1
Definition: Font.h:54
std::uint16_t m_char0
Definition: Font.h:53
code
Definition: GnashKey.h:43
float advance
Definition: Font.h:239
std::string displayName
Definition: Font.h:222
bool operator==(const kerning_pair &k) const
Definition: Font.h:56
bool isItalic() const
Return true if the font is italic.
Definition: Font.h:213
bool operator<(const event_id &a, const event_id &b)
Comparator for use in stdlib containers.
Definition: event_id.h:170
std::unique_ptr< SWF::ShapeRecord > glyph
Definition: Font.h:237
std::vector< GlyphInfo > GlyphInfoRecords
Definition: Font.h:242
Definition: Font.h:50
Truetype font rasterizer/converter based on freetype library.
Definition: FreetypeGlyphsProvider.h:56
std::map< std::uint16_t, int > CodeTable
Definition: Font.h:94
Holds information needed to draw a shape.
Definition: ShapeRecord.h:126
std::string name
Definition: LocalConnection_as.cpp:149
Definition: GnashKey.h:331