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 ~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<std::string> 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 FontListClass FontList;
63 typedef std::map<std::string, Gtk::TreePath> IterMapType;
65 /** Returns the ListStore with the font names
66 *
67 * The return is const and the function is declared as const.
68 * The ListStore is ready to be used after class instantiation
69 * and should not (cannot) be modified.
70 */
71 const Glib::RefPtr<Gtk::ListStore>
72 get_font_list () const;
74 static Inkscape::FontLister*
75 get_instance ()
76 {
77 static Inkscape::FontLister* instance = new Inkscape::FontLister();
78 return instance;
79 }
81 Gtk::TreePath
82 get_row_for_font (std::string family)
83 {
84 IterMapType::iterator iter = font_list_store_iter_map.find (family);
85 if (iter == font_list_store_iter_map.end ()) throw FAMILY_NOT_FOUND;
86 return (*iter).second;
87 }
89 const NRNameList
90 get_name_list () const
91 {
92 return families;
93 }
96 private:
98 FontLister ();
100 NRNameList families;
102 Glib::RefPtr<Gtk::ListStore> font_list_store;
103 IterMapType font_list_store_iter_map;
105 };
106 }
108 #endif
110 /*
111 Local Variables:
112 mode:c++
113 c-file-style:"stroustrup"
114 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
115 indent-tabs-mode:nil
116 fill-column:99
117 End:
118 */
119 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :