~ubuntu-branches/debian/squeeze/inkscape/squeeze

« back to all changes in this revision

Viewing changes to src/libnrtype/font-lister.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <gtkmm/liststore.h>
16
16
 
17
17
#include "font-lister.h"
 
18
#include "FontFactory.h"
18
19
 
19
20
namespace Inkscape
20
21
{
21
 
                FontLister::FontLister ()
22
 
                {
23
 
                    font_list_store = Gtk::ListStore::create (FontList);
24
 
                    
25
 
                    if (font_factory::Default()->Families(&families))
26
 
                    {
27
 
                        for (unsigned int i = 0; i < families.length; ++i)
28
 
                        {
29
 
                            Gtk::TreeModel::iterator iter = font_list_store->append();
30
 
                            (*iter)[FontList.font] = reinterpret_cast<const char*>(families.names[i]);
31
 
 
32
 
                            NRStyleList styles;
33
 
                            if (font_factory::Default()->Styles (reinterpret_cast<const char*>(families.names[i]), &styles));
34
 
 
35
 
                            GList *Styles=0;
36
 
                            for (unsigned int n = 0; n < styles.length; ++n)
37
 
                            {
38
 
                                    NRStyleRecord style_record = styles.records[n];
39
 
                                    Styles = g_list_append (Styles, strdup(style_record.name));
40
 
                            }
41
 
 
42
 
                            (*iter)[FontList.styles] = Styles;
43
 
 
44
 
                            font_list_store_iter_map.insert (std::make_pair (reinterpret_cast<const char*>(families.names[i]), Gtk::TreePath (iter)));
45
 
                        }
46
 
                    }
47
 
                    
48
 
                }
49
 
 
50
 
                FontLister::~FontLister ()
51
 
                {
52
 
                };
53
 
 
54
 
                const Glib::RefPtr<Gtk::ListStore>
55
 
                FontLister::get_font_list () const
56
 
                {
57
 
                    return font_list_store;
58
 
                }
 
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
    }
 
63
 
 
64
    FontLister::~FontLister ()
 
65
    {
 
66
    };
 
67
 
 
68
    const Glib::RefPtr<Gtk::ListStore>
 
69
    FontLister::get_font_list () const
 
70
    {
 
71
        return font_list_store;
 
72
    }
59
73
}
60
74
 
 
75
 
 
76
 
 
77