summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-05-30 13:29:49 +0000
committertavmjong-free <tavmjong@free.fr>2014-05-30 13:29:49 +0000
commite5004cc2ccb6d6554125552b4ef0e0b4cb23daf0 (patch)
tree8dbf4d54eb2e6c66d462653fd5e9a75855ef352f /src
parentUse SPStyle value for 'font-family' rather than parse 'style' ourselves. (diff)
downloadinkscape-e5004cc2ccb6d6554125552b4ef0e0b4cb23daf0.tar.gz
inkscape-e5004cc2ccb6d6554125552b4ef0e0b4cb23daf0.zip
Unquote names in 'font-family' lists. Partial fix for #1029080
(bzr r13402)
Diffstat (limited to 'src')
-rw-r--r--src/style-internal.cpp17
-rw-r--r--src/style.cpp52
-rw-r--r--src/style.h4
-rw-r--r--src/widgets/text-toolbar.cpp1
-rw-r--r--src/xml/repr-css.cpp20
5 files changed, 58 insertions, 36 deletions
diff --git a/src/style-internal.cpp b/src/style-internal.cpp
index b15892128..8b4f3c1cd 100644
--- a/src/style-internal.cpp
+++ b/src/style-internal.cpp
@@ -648,9 +648,6 @@ SPIString::read( gchar const *str ) {
if( !str ) return;
- // libcroco puts quotes around some strings... remove
- gchar *str_unquoted = attribute_unquote(str);
-
if (!strcmp(str, "inherit")) {
set = true;
inherit = true;
@@ -658,10 +655,18 @@ SPIString::read( gchar const *str ) {
} else {
set = true;
inherit = false;
- value = g_strdup(str_unquoted);
- }
- g_free( str_unquoted );
+ // libcroco puts quotes around some strings... remove
+ Glib::ustring str_unquoted(str);
+ css_unquote( str_unquoted );
+
+ // Unquote individual family names, Pango always uses unquoted names.
+ if( name.compare( "font-family" ) == 0 ) {
+ css_font_family_unquote( str_unquoted );
+ }
+
+ value = g_strdup(str_unquoted.c_str());
+ }
}
diff --git a/src/style.cpp b/src/style.cpp
index 11b1dc440..8e4c89839 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -58,6 +58,8 @@
#include <2geom/math-utils.h>
+#include <glibmm/regex.h>
+
using Inkscape::CSSOStringStream;
using std::vector;
@@ -1824,31 +1826,43 @@ sp_css_attr_scale(SPCSSAttr *css, double ex)
}
-// Called in style.cpp, xml/repr-css.cpp
+// Called in style-internal.cpp, xml/repr-css.cpp
/**
- * Remove quotes and escapes from a string. Returned value must be g_free'd.
+ * Remove paired single and double quotes from a string, changing string in place.
* Note: in CSS (in style= and in stylesheets), unquoting and unescaping is done
* by libcroco, our CSS parser, though it adds a new pair of "" quotes for the strings
- * it parsed for us. So this function is only used to remove those quotes and for
- * presentation attributes, without any unescaping. (XML unescaping
- * (&amp; etc) is done by XML parser.)
+ * it parsed for us.
*/
-gchar *
-attribute_unquote(gchar const *val)
+void
+css_unquote(Glib::ustring &val)
{
- if (val) {
- if (*val == '\'' || *val == '"') {
- int l = strlen(val);
- if (l >= 2) {
- if ( ( val[0] == '"' && val[l - 1] == '"' ) ||
- ( val[0] == '\'' && val[l - 1] == '\'' ) ) {
- return (g_strndup (val+1, l-2));
- }
- }
- }
- }
+ if( val.size() > 1 &&
+ ( (val[0] == '"' && val[val.size()-1] == '"' ) ||
+ (val[0] == '\'' && val[val.size()-1] == '\'' ) ) ) {
- return (val? g_strdup (val) : NULL);
+ val.erase( 0, 1 );
+ val.erase( val.size()-1 );
+ }
+}
+
+// Called in style-internal.cpp, text-toolbar.cpp
+/**
+ * Remove paired single and double quotes from font names in font-family lists,
+ * changing string in place.
+ * Pango expects unquoted font family names. We use unquoted names in interface.
+ */
+void
+css_font_family_unquote(Glib::ustring &val)
+{
+ std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("\\s*,\\s*", val );
+
+ val.erase();
+ for( unsigned i=0; i < tokens.size(); ++i ) {
+ css_unquote( tokens[i] );
+ val += tokens[i] + ", ";
+ }
+ if( val.size() > 1 )
+ val.erase( val.size() - 2 ); // Remove trailing ", "
}
// Called in style.cpp, xml/repr-css.cpp
diff --git a/src/style.h b/src/style.h
index 9e592b78f..506b90b44 100644
--- a/src/style.h
+++ b/src/style.h
@@ -292,7 +292,9 @@ void sp_style_unset_property_attrs(SPObject *o);
void sp_style_set_property_url (SPObject *item, gchar const *property, SPObject *linked, bool recursive);
-gchar *attribute_unquote(gchar const *val);
+void css_unquote( Glib::ustring &val ); // Remove quotes from CSS values (style-internal.cpp, xml/repr-css.cpp)
+void css_font_family_unquote( Glib::ustring &val ); // style-internal.cpp, text-toolbar.cpp
+
Glib::ustring css2_escape_quote(gchar const *val);
#endif // SEEN_SP_STYLE_H
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index 3a4f315da..64a7cd5e7 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -134,6 +134,7 @@ static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GOb
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
Glib::ustring new_family = ink_comboboxentry_action_get_active_text( act );
+ css_font_family_unquote( new_family ); // Remove quotes around font family names.
// TODO: Think about how to handle handle multiple selections. While
// the font-family may be the same for all, the styles might be different.
diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp
index 32a1e7f5d..e462f70da 100644
--- a/src/xml/repr-css.cpp
+++ b/src/xml/repr-css.cpp
@@ -12,7 +12,7 @@
* changing an item in the List. Utility functions are provided to go back and forth between the
* two ways of representing properties (by a string or by a list).
*
- * Use sp_repr_write_string to go from a property list to a style string.
+ * Use sp_repr_css_write_string to go from a property list to a style string.
*
*/
@@ -350,9 +350,10 @@ void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src)
static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *const decl)
{
guchar *const str_value_unsigned = cr_term_to_string(decl->value);
- gchar *const str_value = reinterpret_cast<gchar *>(str_value_unsigned);
- gchar *value_unquoted = attribute_unquote (str_value); // libcroco returns strings quoted in ""
- Glib::ustring value_unquoted2 = value_unquoted ? value_unquoted : Glib::ustring();
+
+ Glib::ustring value_unquoted( reinterpret_cast<gchar *>(str_value_unsigned ) );
+ css_unquote( value_unquoted ); // libcroco returns strings quoted in "", remove
+
Glib::ustring units;
/*
@@ -362,11 +363,11 @@ static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *con
*
* HACK for now is to strip off em and ex units and add them back at the end
*/
- int le = value_unquoted2.length();
+ int le = value_unquoted.length();
if (le > 2) {
- units = value_unquoted2.substr(le-2, 2);
+ units = value_unquoted.substr(le-2, 2);
if ((units == "em") || (units == "ex")) {
- value_unquoted2 = value_unquoted2.substr(0, le-2);
+ value_unquoted = value_unquoted.substr(0, le-2);
}
else {
units.clear();
@@ -377,7 +378,7 @@ static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *con
// CSSOStringStream is used here to write valid CSS (as in sp_style_write_string). This has
// the additional benefit of respecting the numerical precission set in the SVG Output
// preferences. We assume any numerical part comes first (if not, the whole string is copied).
- std::stringstream ss( value_unquoted2 );
+ std::stringstream ss( value_unquoted );
double number = 0;
std::string characters;
std::string temp;
@@ -399,8 +400,7 @@ static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *con
//g_message("sp_repr_css_merge_from_decl looks like em or ex units %s --> %s", str_value, os.str().c_str());
}
((Node *) css)->setAttribute(decl->property->stryng->str, os.str().c_str(), false);
- g_free(value_unquoted);
- g_free(str_value);
+ g_free(str_value_unsigned);
}
/**