diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2014-05-30 13:38:31 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2014-05-30 13:38:31 +0000 |
| commit | f0b0773ecf0249c576e58059864f3a0ecbac64ec (patch) | |
| tree | 8f3176fc0f6d2533612c9e6edb8e7b4e862b70d6 /src/style.cpp | |
| parent | Use SPStyle value for 'font-family' rather than parse 'style' ourselves. (diff) | |
| download | inkscape-f0b0773ecf0249c576e58059864f3a0ecbac64ec.tar.gz inkscape-f0b0773ecf0249c576e58059864f3a0ecbac64ec.zip | |
Unquote names in 'font-family' lists. Partial fix for #1029080
(bzr r13341.1.42)
Diffstat (limited to 'src/style.cpp')
| -rw-r--r-- | src/style.cpp | 52 |
1 files changed, 33 insertions, 19 deletions
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 - * (& 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 |
