Plug more leaks (in the test, not the core)
[gnash.git] / libcore / fontlib.cpp
blob0c13bfd74284838cb7faffc0d802349d1d56b68e
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 "smart_ptr.h"
13 #include "Font.h"
14 #include "log.h"
15 #include "DefineShapeTag.h"
16 #include "LineStyle.h"
17 #include "movie_definition.h"
19 // Define to the name of a default font.
20 #define DEFAULT_FONT_NAME "_sans"
22 namespace gnash {
23 namespace fontlib {
25 namespace {
26 std::vector< boost::intrusive_ptr<Font> > s_fonts;
27 boost::intrusive_ptr<Font> _defaultFont;
32 // Public interface
36 void clear()
37 // Release all the fonts we know about.
39 s_fonts.clear();
42 boost::intrusive_ptr<Font>
43 get_default_font()
45 if ( _defaultFont ) return _defaultFont;
46 _defaultFont = new Font(DEFAULT_FONT_NAME);
47 return _defaultFont;
50 int get_font_count()
51 // Return the number of fonts in our library.
53 return s_fonts.size();
57 Font* get_font(int index)
58 // Retrieve one of our fonts, by index.
60 if (index < 0 || index >= (int) s_fonts.size())
62 return NULL;
65 return s_fonts[index].get();
69 Font* get_font(const std::string& name, bool bold, bool italic)
71 // Dumb linear search.
72 for (unsigned int i = 0; i < s_fonts.size(); i++)
74 Font* f = s_fonts[i].get();
75 assert(f);
76 if ( f->matches(name, bold, italic) )
78 return f;
81 Font* f = new Font(name, bold, italic);
82 s_fonts.push_back(f);
83 return f;
86 void add_font(Font* f)
87 // Add the given font to our library.
89 assert(f);
91 #ifndef NDEBUG
92 // Make sure font isn't already in the list.
93 for (unsigned int i = 0; i < s_fonts.size(); i++)
95 assert(s_fonts[i] != f);
97 #endif // not NDEBUG
99 s_fonts.push_back(f);
104 } // end namespace fontlib
105 } // end namespace gnash
108 // Local Variables:
109 // mode: C++
110 // c-basic-offset: 8
111 // tab-width: 8
112 // indent-tabs-mode: t
113 // End: