summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
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/libnrtype
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/libnrtype')
-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
4 files changed, 69 insertions, 34 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;