Code

snap indicator: try a diamond shaped indicator for snapping to nodes. see how we...
[inkscape.git] / src / libnrtype / font-lister.h
index 05511198c09da57969ce1b9f35c094bed72e0c92..13611caf7189bf438ca3006c66e34fe01370e2bb 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <glibmm.h>
 #include <gtkmm.h>
+#include "nrtype-forward.h"
+#include "nr-type-primitives.h"
 
 namespace Inkscape
 {
@@ -26,7 +28,14 @@ namespace Inkscape
                 class FontLister
                 {
                     public:
-                        ~FontLister ();
+
+                        enum Exceptions
+                        {
+                            FAMILY_NOT_FOUND
+                        };
+
+
+                        virtual ~FontLister ();
 
                         /** GtkTreeModelColumnRecord for the font list Gtk::ListStore
                          */
@@ -36,7 +45,7 @@ namespace Inkscape
                             public:
                                 /** Column containing the family name
                                  */
-                                Gtk::TreeModelColumn<std::string> font; 
+                                Gtk::TreeModelColumn<Glib::ustring> font; 
 
                                 /** Column containing an std::vector<std::string> with style names
                                  * for the corresponding family 
@@ -50,8 +59,22 @@ namespace Inkscape
                                 }
                         };
 
+                        /* Case-insensitive < compare for standard strings */
+                        class StringLessThan
+                        {
+                        public:
+                            bool operator () (std::string str1, std::string str2) const
+                            {
+                                std::string s1=str1; // Can't transform the originals!
+                                std::string s2=str2;
+                                std::transform(s1.begin(), s1.end(), s1.begin(), (int(*)(int)) toupper);
+                                std::transform(s2.begin(), s2.end(), s2.begin(), (int(*)(int)) toupper);
+                                return s1<s2;
+                            }
+                        };
+
                         FontListClass FontList;
-                        typedef std::map<std::string, Gtk::TreePath> IterMapType; 
+                        typedef std::map<Glib::ustring, Gtk::TreePath, StringLessThan> IterMapType; 
 
                         /** Returns the ListStore with the font names
                          *
@@ -70,9 +93,10 @@ namespace Inkscape
                         }
 
                         Gtk::TreePath
-                        get_row_for_font (std::string family)
+                        get_row_for_font (Glib::ustring family)
                         {
                             IterMapType::iterator iter = font_list_store_iter_map.find (family);
+                            if (iter == font_list_store_iter_map.end ()) throw FAMILY_NOT_FOUND; 
                             return (*iter).second;
                         }