1 // FreetypeGlyphsProvider.h: Freetype glyphs manager
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
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.
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.
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
20 #ifndef GNASH_FREETYPE_H
21 #define GNASH_FREETYPE_H
24 #include <memory> // for unique_ptr
29 # include <ft2build.h>
30 # include FT_FREETYPE_H
34 // Forward declarations
44 /// Truetype font rasterizer/converter based on freetype library
46 /// Instances of this class provide rasterized or vectorial glyphs
47 /// for a given truetype font face.
49 /// The rasterized glyphs have a max size of 96 (TODO: make parametrizable)
50 /// but I think the actual size could change between glyphs (see the 'box'
51 /// parameter of getRenderedGlyph() method).
53 /// Vectorial glyphs are instances of a SWF::ShapeRecord, same class
54 /// resulting from parsing of embedded fonts.
56 class FreetypeGlyphsProvider
61 /// Named constructor for a face-bound rasterizer.
64 /// Name of the font to get glyphs info from
67 /// Whether to use a bold version of the font
70 /// Whether to use an italic version of the font
72 /// @return a rasterizer bound to the given font name,
73 /// or a NULL unique_ptr if the given truetype font
74 /// could not be found.
76 static std::unique_ptr
<FreetypeGlyphsProvider
> createFace(
77 const std::string
& name
, bool bold
, bool italic
);
81 /// Release face resources
83 ~FreetypeGlyphsProvider();
87 /// Return the given DisplayObject glyph as a shape DisplayObject definition
88 /// in unitsPerEM() coordinates.
91 /// TODO: allow using a custom EM square ?
97 /// Output parameter... units to advance horizontally from this
98 /// glyph to the next, in unitsPerEM() units.
100 /// @return A DefineShapeTag in unitsPerEM() coordinates,
101 /// or a NULL pointer if the given DisplayObject code
102 /// doesn't exist in this font.
104 std::unique_ptr
<SWF::ShapeRecord
> getGlyph(std::uint16_t code
,
107 /// Return the font's ascender in terms of its EM own square.
108 float ascent() const;
110 /// Return the font's descender in terms of its own EM square.
111 float descent() const;
113 /// Return the number of units of glyphs EM
115 /// This is currently hard-coded to 1024, but could in future depend
116 /// on actual font file being used.
118 unsigned short unitsPerEM() const;
122 /// Use the named constructor to create an instance
124 /// throw a GnashException on error (unkonwn font name or similar).
126 FreetypeGlyphsProvider(const std::string
& fontname
, bool bold
, bool italic
);
130 /// Scale factor to make the freetype glyph metrix match our unitsPerEM()
131 /// coordinate space. Not all font faces have am EM square of unitsPerEM(), so we
132 /// use this value to scale both coordinates and advance values
133 /// The value is computed by the costructor, as soon as a face is initialized.
136 /// Get filename containing given font
142 /// Want bold version
145 /// Want italic version
148 /// Where to return the filename to
150 /// @return true if the font was found, false otherwise.
151 /// Actually, this function should return a default
152 /// filename in any case, so false should only be
153 /// returned if not even a default font was found.
155 bool getFontFilename(const std::string
& name
, bool bold
, bool italic
,
156 std::string
& filename
);
158 /// Initialize the FreeType library if not done so yet
163 /// Mutex protecting FreeType library (for initialization basically)
164 static std::mutex m_lib_mutex
;
167 static FT_Library m_lib
;
171 #endif // USE_FREETYPE
178 #endif // GNASH_FREETYPE_H