~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/libnrtype/font-lister.h

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef FONT_LISTER_H
 
2
#define FONT_LISTER_H
 
3
 
 
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
 */
 
16
 
 
17
#include <glibmm.h>
 
18
#include <gtkmm.h>
 
19
#include "nrtype-forward.h"
 
20
#include "nr-type-primitives.h"
 
21
 
 
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:
 
31
 
 
32
                        enum Exceptions
 
33
                        {
 
34
                            FAMILY_NOT_FOUND
 
35
                        };
 
36
 
 
37
 
 
38
                        virtual ~FontLister ();
 
39
 
 
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; 
 
49
 
 
50
                                /** Column containing an std::vector<std::string> with style names
 
51
                                 * for the corresponding family 
 
52
                                 */
 
53
                                Gtk::TreeModelColumn<GList*> styles;
 
54
 
 
55
                                FontListClass ()
 
56
                                {
 
57
                                    add (font);
 
58
                                    add (styles);
 
59
                                }
 
60
                        };
 
61
 
 
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
                        };
 
75
 
 
76
                        FontListClass FontList;
 
77
                        typedef std::map<Glib::ustring, Gtk::TreePath, StringLessThan> IterMapType; 
 
78
 
 
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;
 
87
 
 
88
                        static Inkscape::FontLister*
 
89
                        get_instance ()
 
90
                        {
 
91
                            static Inkscape::FontLister* instance = new Inkscape::FontLister();
 
92
                            return instance;
 
93
                        }
 
94
 
 
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
                        }
 
102
 
 
103
                        const NRNameList
 
104
                        get_name_list () const
 
105
                        {
 
106
                            return families;
 
107
                        }
 
108
                        
 
109
 
 
110
                    private:
 
111
 
 
112
                        FontLister ();
 
113
       
 
114
                        NRNameList families;
 
115
 
 
116
                        Glib::RefPtr<Gtk::ListStore> font_list_store;
 
117
                        IterMapType font_list_store_iter_map;
 
118
 
 
119
                };
 
120
}
 
121
 
 
122
#endif
 
123
 
 
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 :