summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-06-09 08:52:16 +0000
committertavmjong-free <tavmjong@free.fr>2014-06-09 08:52:16 +0000
commit2bcf58d0c4e5d928af272c17201fbadae788ad0c (patch)
tree606b91ba7af39387a6816ddeb58ad1dda7d816b7 /src
parentBetter ordering of font-face styles in UI. Rely on CSS values rather than gue... (diff)
downloadinkscape-2bcf58d0c4e5d928af272c17201fbadae788ad0c.tar.gz
inkscape-2bcf58d0c4e5d928af272c17201fbadae788ad0c.zip
Display name of face from font file in Text and Font dialog (as well as CSS/Pango name).
Partial fix for #165521, #167353, #1008514 (bzr r13414)
Diffstat (limited to 'src')
-rw-r--r--src/libnrtype/FontFactory.cpp17
-rw-r--r--src/libnrtype/FontFactory.h23
-rw-r--r--src/libnrtype/font-lister.cpp50
-rw-r--r--src/libnrtype/font-lister.h13
-rw-r--r--src/widgets/font-selector.cpp30
5 files changed, 91 insertions, 42 deletions
diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp
index 6ab8c77b8..6859a4a5c 100644
--- a/src/libnrtype/FontFactory.cpp
+++ b/src/libnrtype/FontFactory.cpp
@@ -508,9 +508,9 @@ static int StyleNameValue( const Glib::ustring &style )
}
// Determines order in which styles are presented (sorted by CSS style values)
-static bool StyleNameCompareInternal(const Glib::ustring &style1, const Glib::ustring &style2)
+static bool StyleNameCompareInternal(const StyleNames &style1, const StyleNames &style2)
{
- return( StyleNameValue( style1 ) < StyleNameValue( style2 ) );
+ return( StyleNameValue( style1.CssName ) < StyleNameValue( style2.CssName ) );
}
void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map)
@@ -536,7 +536,8 @@ void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map)
// If the face has a name, describe it, and then use the
// description to get the UI family and face strings
- if (pango_font_face_get_face_name(faces[currentFace]) == NULL) {
+ const gchar* displayName = pango_font_face_get_face_name(faces[currentFace]);
+ if (displayName == NULL) {
continue;
}
@@ -566,26 +567,26 @@ void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map)
// Insert new family
if (iter == map->end()) {
- map->insert(std::make_pair(familyUIName, std::list<Glib::ustring>()));
+ map->insert(std::make_pair(familyUIName, std::list<StyleNames>()));
}
// Insert into the style list and save the info in the reference maps
// only if the style does not yet exist
bool exists = false;
- std::list<Glib::ustring> &styleList = (*map)[familyUIName];
+ std::list<StyleNames> &styleList = (*map)[familyUIName];
- for (std::list<Glib::ustring>::iterator it=styleList.begin();
+ for (std::list<StyleNames>::iterator it=styleList.begin();
it != styleList.end();
++it) {
- if (*it == styleUIName) {
+ if ( (*it).CssName == styleUIName) {
exists = true;
break;
}
}
if (!exists) {
- styleList.push_back(styleUIName);
+ styleList.push_back( StyleNames(styleUIName,displayName) );
// Add the string info needed in the reference maps
fontStringMap.insert(
diff --git a/src/libnrtype/FontFactory.h b/src/libnrtype/FontFactory.h
index 7b606d200..513ee4bf7 100644
--- a/src/libnrtype/FontFactory.h
+++ b/src/libnrtype/FontFactory.h
@@ -51,15 +51,26 @@ struct font_descr_equal : public std::binary_function<PangoFontDescription*, Pan
bool operator()(PangoFontDescription *const &a, PangoFontDescription *const &b) const;
};
-// Comparison functions for style names
-int style_name_compare(char const *aa, char const *bb);
-int family_name_compare(char const *a, char const *b);
-
// Wraps calls to pango_font_description_get_family with some name substitution
const char *sp_font_description_get_family(PangoFontDescription const *fontDescr);
-// Map type for gathering UI family and style strings
-typedef std::map<Glib::ustring, std::list<Glib::ustring> > FamilyToStylesMap;
+// Class for style strings: both CSS and as suggested by font.
+class StyleNames {
+
+public:
+ StyleNames() {};
+ StyleNames( Glib::ustring name ) :
+ CssName( name ), DisplayName( name ) {};
+ StyleNames( Glib::ustring cssname, Glib::ustring displayname ) :
+ CssName( cssname ), DisplayName( displayname ) {};
+
+public:
+ Glib::ustring CssName; // Style as Pango/CSS would write it.
+ Glib::ustring DisplayName; // Style as Font designer named it.
+};
+
+// Map type for gathering UI family and style names
+typedef std::map<Glib::ustring, std::list<StyleNames> > FamilyToStylesMap;
class font_factory {
public:
diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp
index 8ce5eccfc..9ff4fad05 100644
--- a/src/libnrtype/font-lister.cpp
+++ b/src/libnrtype/font-lister.cpp
@@ -64,11 +64,13 @@ namespace Inkscape
// Now go through the styles
GList *styles = NULL;
- std::list<Glib::ustring> &styleStrings = familyStyleMap[familyName];
- for (std::list<Glib::ustring>::iterator it=styleStrings.begin();
+ std::list<StyleNames> &styleStrings = familyStyleMap[familyName];
+ for (std::list<StyleNames>::iterator it=styleStrings.begin();
it != styleStrings.end();
++it) {
- styles = g_list_append(styles, g_strdup((*it).c_str()));
+ // Our own copy
+ StyleNames *copy = new StyleNames( *it );
+ styles = g_list_append(styles, copy);
}
(*treeModelIter)[FontList.styles] = styles;
@@ -81,11 +83,11 @@ namespace Inkscape
current_fontspec = "sans-serif"; // Empty style -> Normal
current_fontspec_system = "Sans";
- /* Create default styles for use when font-family is unknown on system. */
- default_styles = g_list_append( NULL, g_strdup("Normal") );
- default_styles = g_list_append( default_styles, g_strdup("Italic") );
- default_styles = g_list_append( default_styles, g_strdup("Bold") );
- default_styles = g_list_append( default_styles, g_strdup("Bold Italic") );
+ /* Create default styles for use when font-family is unknown on system. */
+ default_styles = g_list_append( NULL, new StyleNames( "Normal" ) );
+ default_styles = g_list_append( default_styles, new StyleNames( "Italic" ) );
+ default_styles = g_list_append( default_styles, new StyleNames( "Bold" ) );
+ default_styles = g_list_append( default_styles, new StyleNames( "Bold Italic" ) );
font_list_store->thaw_notify();
@@ -96,11 +98,31 @@ namespace Inkscape
style_list_store->clear();
for (GList *l=default_styles; l; l = l->next) {
Gtk::TreeModel::iterator treeModelIter = style_list_store->append();
- (*treeModelIter)[FontStyleList.styles] = (char*)l->data;
+ (*treeModelIter)[FontStyleList.cssStyle] = ((StyleNames*)l->data)->CssName;
+ (*treeModelIter)[FontStyleList.displayStyle] = ((StyleNames*)l->data)->DisplayName;
}
style_list_store->thaw_notify();
}
+ FontLister::~FontLister() {
+
+ // Delete default_styles
+ for (GList *l=default_styles; l; l = l->next) {
+ delete ((StyleNames*)l->data);
+ }
+
+ // Delete other styles
+ Gtk::TreeModel::iterator iter = font_list_store->get_iter( "0" );
+ while( iter != font_list_store->children().end() ) {
+ Gtk::TreeModel::Row row = *iter;
+ GList *styles = row[FontList.styles];
+ for (GList *l=styles; l; l = l->next) {
+ delete ((StyleNames*)l->data);
+ }
+ ++iter;
+ }
+ }
+
// Example of how to use "foreach_iter"
// bool
// FontLister::print_document_font( const Gtk::TreeModel::iterator &iter ) {
@@ -113,7 +135,6 @@ namespace Inkscape
// }
// font_list_store->foreach_iter( sigc::mem_fun(*this, &FontLister::print_document_font ));
-
/* Used to insert a font that was not in the document and not on the system into the font list. */
void
FontLister::insert_font_family( Glib::ustring new_family ) {
@@ -471,7 +492,8 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
for (GList *l=styles; l; l = l->next) {
Gtk::TreeModel::iterator treeModelIter = style_list_store->append();
- (*treeModelIter)[FontStyleList.styles] = (char*)l->data;
+ (*treeModelIter)[FontStyleList.cssStyle] = ((StyleNames*)l->data)->CssName;
+ (*treeModelIter)[FontStyleList.displayStyle] = ((StyleNames*)l->data)->DisplayName;
}
style_list_store->thaw_notify();
@@ -856,7 +878,7 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
Gtk::TreeModel::Row row = *iter;
- if( familyNamesAreEqual( style, row[FontStyleList.styles] ) ) {
+ if( familyNamesAreEqual( style, row[FontStyleList.cssStyle] ) ) {
return row;
}
@@ -983,10 +1005,6 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
return best_style;
}
- FontLister::~FontLister ()
- {
- };
-
const Glib::RefPtr<Gtk::ListStore>
FontLister::get_font_list () const
{
diff --git a/src/libnrtype/font-lister.h b/src/libnrtype/font-lister.h
index a460388d3..c89dab550 100644
--- a/src/libnrtype/font-lister.h
+++ b/src/libnrtype/font-lister.h
@@ -100,13 +100,18 @@ namespace Inkscape
: public Gtk::TreeModelColumnRecord
{
public:
- /** Column containing the styles
+ /** Column containing the styles as Font designer used.
*/
- Gtk::TreeModelColumn<Glib::ustring> styles;
+ Gtk::TreeModelColumn<Glib::ustring> displayStyle;
+
+ /** Column containing the styles in CSS/Pango format.
+ */
+ Gtk::TreeModelColumn<Glib::ustring> cssStyle;
FontStyleListClass ()
{
- add (styles);
+ add (cssStyle);
+ add (displayStyle);
}
};
@@ -276,7 +281,7 @@ namespace Inkscape
private:
FontLister ();
-
+
NRNameList families;
Glib::RefPtr<Gtk::ListStore> font_list_store;
diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp
index 0e862638c..ccaf93e55 100644
--- a/src/widgets/font-selector.cpp
+++ b/src/widgets/font-selector.cpp
@@ -179,6 +179,7 @@ static void sp_font_selector_init(SPFontSelector *fsel)
Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance();
Glib::RefPtr<Gtk::ListStore> store = fontlister->get_font_list();
gtk_tree_view_set_model (GTK_TREE_VIEW(fsel->family_treeview), GTK_TREE_MODEL (Glib::unwrap (store)));
+ //gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(fsel->family_treeview),2);
gtk_container_add(GTK_CONTAINER(sw), fsel->family_treeview);
gtk_widget_show_all (sw);
@@ -210,12 +211,22 @@ static void sp_font_selector_init(SPFontSelector *fsel)
gtk_box_pack_start(GTK_BOX (vb), sw, TRUE, TRUE, 0);
fsel->style_treeview = gtk_tree_view_new ();
- column = gtk_tree_view_column_new ();
+
+ // CSS Style name
cell = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, cell, FALSE);
- gtk_tree_view_column_set_attributes (column, cell, "text", 0, NULL);
+ column = gtk_tree_view_column_new_with_attributes ("CSS", cell, "text", 0, NULL );
+ //gtk_tree_view_column_pack_start (column, cell, FALSE);
+ gtk_tree_view_column_set_resizable (column, TRUE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW(fsel->style_treeview), column);
+
+ // Display Style name
+ cell = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Face"), cell, "text", 1, NULL );
+ //gtk_tree_view_column_pack_start (column, cell, FALSE);
gtk_tree_view_append_column (GTK_TREE_VIEW(fsel->style_treeview), column);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(fsel->style_treeview), FALSE);
+
+ //gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(fsel->style_treeview), 1);
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(fsel->style_treeview), TRUE);
gtk_container_add(GTK_CONTAINER(sw), fsel->style_treeview);
gtk_widget_show_all (sw);
@@ -306,13 +317,15 @@ static void sp_font_selector_family_select_row(GtkTreeSelection *selection,
// Create our own store of styles for selected font-family and find index of best style match
int path_index = 0;
int index = 0;
- GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING); // Where is this deleted?
+ GtkListStore *store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); // Where is this deleted?
for ( ; list ; list = list->next )
{
gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, (char*)list->data, -1);
-
- if( best.compare( (char*)list->data ) == 0 ) {
+ gtk_list_store_set (store, &iter,
+ 0, ((StyleNames*)list->data)->CssName.c_str(),
+ 1, ((StyleNames*)list->data)->DisplayName.c_str(),
+ -1);
+ if( best.compare( ((StyleNames*)list->data)->CssName ) == 0 ) {
path_index = index;
}
++index;
@@ -320,6 +333,7 @@ static void sp_font_selector_family_select_row(GtkTreeSelection *selection,
// Attach store to tree view. Can trigger style changed signal (but not FONT_SET):
gtk_tree_view_set_model (GTK_TREE_VIEW (fsel->style_treeview), GTK_TREE_MODEL (store));
+ //gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(fsel->style_treeview),1);
// Get path to best style
GtkTreePath *path = gtk_tree_path_new ();