1 #ifndef FONT_LISTER_H
2 #define FONT_LISTER_H
4 /*
5 * Font selection widgets
6 *
7 * Authors:
8 * Chris Lahey <clahey@ximian.com>
9 * Lauris Kaplinski <lauris@kaplinski.com>
10 *
11 * Copyright (C) 1999-2001 Ximian, Inc.
12 * Copyright (C) 2002 Lauris Kaplinski
13 *
14 * Released under GNU GPL, read the file 'COPYING' for more information
15 */
17 #include <glibmm.h>
18 #include <gtkmm.h>
19 #include "nrtype-forward.h"
20 #include "nr-type-primitives.h"
22 namespace Inkscape
23 {
24 /**
25 * This class enumerates fonts using libnrtype into reusable data stores and
26 * allows for random access to the font list
27 */
28 class FontLister
29 {
30 public:
32 enum Exceptions
33 {
34 FAMILY_NOT_FOUND
35 };
38 virtual ~FontLister ();
40 /** GtkTreeModelColumnRecord for the font list Gtk::ListStore
41 */
42 class FontListClass
43 : public Gtk::TreeModelColumnRecord
44 {
45 public:
46 /** Column containing the family name
47 */
48 Gtk::TreeModelColumn<Glib::ustring> font;
50 /** Column containing an std::vector<std::string> with style names
51 * for the corresponding family
52 */
53 Gtk::TreeModelColumn<GList*> styles;
55 FontListClass ()
56 {
57 add (font);
58 add (styles);
59 }
60 };
62 /* Case-insensitive < compare for standard strings */
63 class StringLessThan
64 {
65 public:
66 bool operator () (std::string str1, std::string str2) const
67 {
68 std::string s1=str1; // Can't transform the originals!
69 std::string s2=str2;
70 std::transform(s1.begin(), s1.end(), s1.begin(), (int(*)(int)) toupper);
71 std::transform(s2.begin(), s2.end(), s2.begin(), (int(*)(int)) toupper);
72 return s1<s2;
73 }
74 };
76 FontListClass FontList;
77 typedef std::map<Glib::ustring, Gtk::TreePath, StringLessThan> IterMapType;
79 /** Returns the ListStore with the font names
80 *
81 * The return is const and the function is declared as const.
82 * The ListStore is ready to be used after class instantiation
83 * and should not (cannot) be modified.
84 */
85 const Glib::RefPtr<Gtk::ListStore>
86 get_font_list () const;
88 static Inkscape::FontLister*
89 get_instance ()
90 {
91 static Inkscape::FontLister* instance = new Inkscape::FontLister();
92 return instance;
93 }
95 Gtk::TreePath
96 get_row_for_font (Glib::ustring family)
97 {
98 IterMapType::iterator iter = font_list_store_iter_map.find (family);
99 if (iter == font_list_store_iter_map.end ()) throw FAMILY_NOT_FOUND;
100 return (*iter).second;
101 }
103 const NRNameList
104 get_name_list () const
105 {
106 return families;
107 }
110 private:
112 FontLister ();
114 NRNameList families;
116 Glib::RefPtr<Gtk::ListStore> font_list_store;
117 IterMapType font_list_store_iter_map;
119 };
120 }
122 #endif
124 /*
125 Local Variables:
126 mode:c++
127 c-file-style:"stroustrup"
128 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
129 indent-tabs-mode:nil
130 fill-column:99
131 End:
132 */
133 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :