Code

Merge from trunk.
[inkscape.git] / src / libnrtype / font-lister.cpp
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
5 #include <libnr/nr-blit.h>
6 #include <libnrtype/font-instance.h>
7 #include <libnrtype/raster-glyph.h>
8 #include <libnrtype/RasterFont.h>
9 #include <libnrtype/TextWrapper.h>
10 #include <libnrtype/one-glyph.h>
12 #include <glibmm.h>
13 #include <gtkmm.h>
14 #include <gtkmm/treemodel.h>
15 #include <gtkmm/liststore.h>
17 #include "font-lister.h"
18 #include "FontFactory.h"
20 namespace Inkscape
21 {
22     FontLister::FontLister ()
23     {
24         font_list_store = Gtk::ListStore::create (FontList);
25         
26         FamilyToStylesMap familyStyleMap;
27         font_factory::Default()->GetUIFamiliesAndStyles(&familyStyleMap);
28        
29         // Grab the family names into a list and then sort them
30         std::list<Glib::ustring> familyList;
31         for (FamilyToStylesMap::iterator iter = familyStyleMap.begin();
32                  iter != familyStyleMap.end();
33                  iter++) {
34             familyList.push_back((*iter).first);
35         }
36         familyList.sort();
37         
38         // Traverse through the family names and set up the list store (note that
39         // the styles list that are the map's values are already sorted)
40         while (!familyList.empty()) {
41             Glib::ustring familyName = familyList.front();
42             familyList.pop_front();
43             
44             if (!familyName.empty()) {
45                 Gtk::TreeModel::iterator treeModelIter = font_list_store->append();
46                 (*treeModelIter)[FontList.font] = reinterpret_cast<const char*>(g_strdup(familyName.c_str()));
47                 
48                 // Now go through the styles
49                 GList *styles = NULL;
50                 std::list<Glib::ustring> &styleStrings = familyStyleMap[familyName];
51                 for (std::list<Glib::ustring>::iterator it=styleStrings.begin();
52                         it != styleStrings.end();
53                         it++) {
54                     styles = g_list_append(styles, g_strdup((*it).c_str()));
55                 }
56                 
57                 (*treeModelIter)[FontList.styles] = styles;
58                 
59                 font_list_store_iter_map.insert(std::make_pair(familyName, Gtk::TreePath(treeModelIter)));
60             }
61         }
62     }
64     FontLister::~FontLister ()
65     {
66     };
68     const Glib::RefPtr<Gtk::ListStore>
69     FontLister::get_font_list () const
70     {
71         return font_list_store;
72     }
73 }