diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2014-06-10 09:29:58 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2014-06-10 09:29:58 +0000 |
| commit | 30add35428dda0b2ba699612148d4627994add79 (patch) | |
| tree | 0c1d423712898fc508d9af3dd25a14e61c232331 /src/xml/repr-css.cpp | |
| parent | Display name of face from font file in Text and Font dialog (as well as CSS/P... (diff) | |
| download | inkscape-30add35428dda0b2ba699612148d4627994add79.tar.gz inkscape-30add35428dda0b2ba699612148d4627994add79.zip | |
Proper quoting of CSS 'font-family' fallback lists.
(bzr r13415)
Diffstat (limited to 'src/xml/repr-css.cpp')
| -rw-r--r-- | src/xml/repr-css.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index e462f70da..c043904a7 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -283,14 +283,7 @@ void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str) str.append(g_quark_to_string(iter->key)); str.push_back(':'); - if (!strcmp(g_quark_to_string(iter->key), "font-family") - || !strcmp(g_quark_to_string(iter->key), "-inkscape-font-specification")) { - // we only quote font-family/font-specification, as SPStyle does - Glib::ustring val_quoted = css2_escape_quote (iter->value); - str.append(val_quoted); - } else { - str.append(iter->value); // unquoted - } + str.append(iter->value); // Any necessary quoting to be done by calling routine. if (rest(iter)) { str.push_back(';'); @@ -346,13 +339,23 @@ void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src) /** * Merges style properties as parsed by libcroco into an existing SPCSSAttr. + * libcroco converts all single quotes to double quotes, which needs to be + * undone as we always use single quotes inside our 'style' strings since + * double quotes are used outside: e.g.: + * style="font-family:'DejaVu Sans'" */ 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); - Glib::ustring value_unquoted( reinterpret_cast<gchar *>(str_value_unsigned ) ); - css_unquote( value_unquoted ); // libcroco returns strings quoted in "", remove + Glib::ustring value( reinterpret_cast<gchar *>(str_value_unsigned ) ); + g_free(str_value_unsigned); + + Glib::ustring::size_type pos = 0; + while( (pos=value.find("\"",pos)) != Glib::ustring::npos) { + value.replace(pos,1,"'"); + ++pos; + } Glib::ustring units; @@ -363,11 +366,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_unquoted.length(); + int le = value.length(); if (le > 2) { - units = value_unquoted.substr(le-2, 2); + units = value.substr(le-2, 2); if ((units == "em") || (units == "ex")) { - value_unquoted = value_unquoted.substr(0, le-2); + value = value.substr(0, le-2); } else { units.clear(); @@ -378,7 +381,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_unquoted ); + std::stringstream ss( value ); double number = 0; std::string characters; std::string temp; @@ -400,7 +403,6 @@ 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(str_value_unsigned); } /** |
