summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
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 /src/libnrtype
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)
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/font-lister.cpp41
1 files changed, 25 insertions, 16 deletions
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;
}