Add patch to fix #35635, mmap problems with a hardened kernel.
[gnash.git] / libcore / fontlib.cpp
blob24e63dcf28ed9336f32de1df9b3a40ec9af8f105
3 // This source code has been donated to the Public Domain. Do
4 // whatever you want with it.
6 // A module to take care of all of gnash's loaded fonts.
8 #ifdef HAVE_CONFIG_H
9 #include "gnashconfig.h" // HAVE_ZLIB_H, USE_SWFTREE
10 #endif
12 #include "Font.h"
13 #include "log.h"
14 #include "DefineShapeTag.h"
15 #include "LineStyle.h"
16 #include "movie_definition.h"
18 // Define to the name of a default font.
19 #define DEFAULT_FONT_NAME "_sans"
21 namespace gnash {
22 namespace fontlib {
24 namespace {
25 std::vector< boost::intrusive_ptr<Font> > s_fonts;
26 boost::intrusive_ptr<Font> _defaultFont;
31 // Public interface
35 void
36 clear()
38 s_fonts.clear();
41 boost::intrusive_ptr<Font>
42 get_default_font()
44 if ( _defaultFont ) return _defaultFont;
45 _defaultFont = new Font(DEFAULT_FONT_NAME);
46 return _defaultFont;
49 Font*
50 get_font(const std::string& name, bool bold, bool italic)
52 // Dumb linear search.
53 for (unsigned int i = 0; i < s_fonts.size(); i++)
55 Font* f = s_fonts[i].get();
56 assert(f);
57 if ( f->matches(name, bold, italic) )
59 return f;
62 Font* f = new Font(name, bold, italic);
63 s_fonts.push_back(f);
64 return f;
67 void
68 add_font(Font* f)
70 assert(f);
71 #ifndef NDEBUG
72 // Make sure font isn't already in the list.
73 for (unsigned int i = 0; i < s_fonts.size(); i++)
75 assert(s_fonts[i] != f);
77 #endif // not NDEBUG
79 s_fonts.push_back(f);
84 } // end namespace fontlib
85 } // end namespace gnash
88 // Local Variables:
89 // mode: C++
90 // c-basic-offset: 8
91 // tab-width: 8
92 // indent-tabs-mode: t
93 // End: