summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-06-05 16:28:15 +0000
committertavmjong-free <tavmjong@free.fr>2014-06-05 16:28:15 +0000
commit9b0db891ca0fc8ca0cfbfaa301c473f2ad3e6d68 (patch)
tree9e79bdf85977d200ee099809103b3bba31c81ddb
parentFix build failure with poppler 0.26 (Bug #1315142) (diff)
downloadinkscape-9b0db891ca0fc8ca0cfbfaa301c473f2ad3e6d68.tar.gz
inkscape-9b0db891ca0fc8ca0cfbfaa301c473f2ad3e6d68.zip
Make family-name comparisons case insensitive.
Fix UI bug when SVG file does not have -inkscape-font-specification properties (Style drop-down list not properly updated.) (bzr r13341.1.47)
-rw-r--r--src/ink-comboboxentry-action.cpp28
-rw-r--r--src/libnrtype/font-lister.cpp41
2 files changed, 46 insertions, 23 deletions
diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp
index 06ccc3739..ebd238edc 100644
--- a/src/ink-comboboxentry-action.cpp
+++ b/src/ink-comboboxentry-action.cpp
@@ -38,7 +38,7 @@ static GtkWidget* create_tool_item( GtkAction* action );
static GtkWidget* create_menu_item( GtkAction* action );
// Internal
-static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text, gboolean exclude = false );
+static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text, gboolean exclude = false, gboolean ignore_case = false );
static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* action );
// Callbacks
@@ -732,7 +732,8 @@ void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* actio
// use 3d colunm if available to exclude row from checking (useful to
// skip rows added for font-families included in doc and not on
// system)
-gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text, gboolean exclude ) {
+gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text,
+ gboolean exclude, gboolean ignore_case ) {
// Check if text in list
gint row = 0;
@@ -752,10 +753,23 @@ gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* ta
gchar* text = 0;
gtk_tree_model_get( action->model, &iter, 0, &text, -1 ); // Column 0
- // Check for match
- if( strcmp( target_text, text ) == 0 ){
- found = true;
- break;
+ if( !ignore_case ) {
+ // Case sensitive compare
+ if( strcmp( target_text, text ) == 0 ){
+ found = true;
+ break;
+ }
+ } else {
+ // Case insensitive compare
+ gchar* target_text_casefolded = g_utf8_casefold( target_text, -1 );
+ gchar* text_casefolded = g_utf8_casefold( text, -1 );
+ gboolean equal = (strcmp( target_text_casefolded, text_casefolded ) == 0 );
+ g_free( text_casefolded );
+ g_free( target_text_casefolded );
+ if( equal ) {
+ found = true;
+ break;
+ }
}
}
@@ -794,7 +808,7 @@ static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* actio
// Remove any surrounding white space.
g_strstrip( tokens[i] );
- if( get_active_row_from_text( action, tokens[i], true ) == -1 ) {
+ if( get_active_row_from_text( action, tokens[i], true, true ) == -1 ) {
missing += tokens[i];
missing += ", ";
}
diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp
index 333c4ef5b..8ce5eccfc 100644
--- a/src/libnrtype/font-lister.cpp
+++ b/src/libnrtype/font-lister.cpp
@@ -25,6 +25,13 @@
//#define DEBUG_FONT
+// CSS dictates that font family names are case insensitive.
+// This should really implement full Unicode case unfolding.
+bool familyNamesAreEqual( const Glib::ustring &a, const Glib::ustring &b ) {
+
+ return( a.casefold().compare( b.casefold() ) == 0 );
+}
+
namespace Inkscape
{
FontLister::FontLister ()
@@ -120,7 +127,7 @@ namespace Inkscape
Gtk::TreeModel::iterator iter2 = font_list_store->get_iter( "0" );
while( iter2 != font_list_store->children().end() ) {
Gtk::TreeModel::Row row = *iter2;
- if( row[FontList.onSystem] && tokens[0].compare( row[FontList.family] ) == 0 ) {
+ if( row[FontList.onSystem] && familyNamesAreEqual( tokens[0], row[FontList.family] ) ) {
styles = row[FontList.styles];
break;
}
@@ -197,7 +204,7 @@ namespace Inkscape
Gtk::TreeModel::iterator iter2 = font_list_store->get_iter( "0" );
while( iter2 != font_list_store->children().end() ) {
Gtk::TreeModel::Row row = *iter2;
- if( row[FontList.onSystem] && tokens[0].compare( row[FontList.family] ) == 0 ) {
+ if( row[FontList.onSystem] && familyNamesAreEqual( tokens[0], row[FontList.family] ) ) {
styles = row[FontList.styles];
break;
}
@@ -228,7 +235,7 @@ namespace Inkscape
path.push_back( row );
Gtk::TreeModel::iterator iter = font_list_store->get_iter( path );
if( iter ) {
- if( current_family.compare( (*iter)[FontList.family] ) == 0 ) {
+ if( familyNamesAreEqual( current_family, (*iter)[FontList.family] ) ) {
current_family_row = row;
break;
}
@@ -384,6 +391,7 @@ namespace Inkscape
std::pair<Glib::ustring, Glib::ustring> ui = ui_from_fontspec( current_fontspec );
set_font_family( ui.first );
+ set_font_style( ui.second );
#ifdef DEBUG_FONT
std::cout << " family_row: :" << current_family_row << ":" << std::endl;
@@ -424,7 +432,7 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
#endif
// No need to do anything if new family is same as old family.
- if ( new_family.compare( current_family ) == 0 ) {
+ if ( familyNamesAreEqual( new_family, current_family ) ) {
#ifdef DEBUG_FONT
std::cout << "FontLister::new_font_family: exit: no change in family." << std::endl;
std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" << std::endl;
@@ -443,7 +451,7 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
Gtk::TreeModel::Row row = *iter;
- if( new_family.compare( row[FontList.family] ) == 0 ) {
+ if( familyNamesAreEqual( new_family, row[FontList.family] ) ) {
styles = row[FontList.styles];
break;
}
@@ -688,18 +696,19 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
fontspec = style->font_family.value;
fontspec += ",";
+ // Use weight names as defined by Pango
switch (style->font_weight.computed) {
case SP_CSS_FONT_WEIGHT_100:
- fontspec += " 100";
+ fontspec += " Thin";
break;
case SP_CSS_FONT_WEIGHT_200:
- fontspec += " 200";
+ fontspec += " Ultra-Light";
break;
case SP_CSS_FONT_WEIGHT_300:
- fontspec += " 300";
+ fontspec += " Light";
break;
case SP_CSS_FONT_WEIGHT_400:
@@ -708,24 +717,24 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
break;
case SP_CSS_FONT_WEIGHT_500:
- fontspec += " 500";
+ fontspec += " Medium";
break;
case SP_CSS_FONT_WEIGHT_600:
- fontspec += " 600";
+ fontspec += " Semi-Bold";
break;
case SP_CSS_FONT_WEIGHT_700:
case SP_CSS_FONT_WEIGHT_BOLD:
- fontspec += " bold";
+ fontspec += " Bold";
break;
case SP_CSS_FONT_WEIGHT_800:
- fontspec += " 800";
+ fontspec += " Ultra-Bold";
break;
case SP_CSS_FONT_WEIGHT_900:
- fontspec += " 900";
+ fontspec += " Heavy";
break;
case SP_CSS_FONT_WEIGHT_LIGHTER:
@@ -821,7 +830,7 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
Gtk::TreeModel::Row row = *iter;
- if( family.compare( row[FontList.family] ) == 0 ) {
+ if( familyNamesAreEqual( family, row[FontList.family] ) ) {
return row;
}
@@ -847,7 +856,7 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::new_font_family (Glib::ustri
Gtk::TreeModel::Row row = *iter;
- if( style.compare( row[FontStyleList.styles] ) == 0 ) {
+ if( familyNamesAreEqual( style, row[FontStyleList.styles] ) ) {
return row;
}
@@ -1035,7 +1044,7 @@ void font_lister_cell_data_func(GtkCellLayout */*cell_layout*/,
valid = gtk_tree_model_iter_next( GTK_TREE_MODEL(model), &iter ) ) {
gtk_tree_model_get(model, &iter, 0, &family, 2, &onSystem, -1);
- if( onSystem && token.compare( family ) == 0 ) {
+ if( onSystem && familyNamesAreEqual( token, family ) ) {
found = true;
break;
}