Update with current status
[gnash.git] / libcore / fontlib.cpp
blob5adb6957ec2948423523468b209a646947769317
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 (auto& font : s_fonts)
55 assert(font);
56 if ( font->matches(name, bold, italic) )
58 return font.get();
61 Font* f = new Font(name, bold, italic);
62 s_fonts.push_back(f);
63 return f;
66 void
67 add_font(Font* f)
69 assert(f);
70 #ifndef NDEBUG
71 // Make sure font isn't already in the list.
72 for (auto& font : s_fonts)
74 assert(font != f);
76 #endif // not NDEBUG
78 s_fonts.push_back(f);
83 } // end namespace fontlib
84 } // end namespace gnash
87 // Local Variables:
88 // mode: C++
89 // c-basic-offset: 8
90 // tab-width: 8
91 // indent-tabs-mode: t
92 // End: