diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
| commit | a168040d5a452544328a1e6ad35aaac351f94d44 (patch) | |
| tree | fae1ba829f543a473da281bd5fa6e4deabbf6912 /src/xml/repr-css.cpp | |
| parent | Removed function pointers from SPObject and subclasses. (diff) | |
| parent | Dutch translation update (diff) | |
| download | inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.tar.gz inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.zip | |
merged from trunk
(bzr r11608.1.56)
Diffstat (limited to 'src/xml/repr-css.cpp')
| -rw-r--r-- | src/xml/repr-css.cpp | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 679ec73cb..24e2db9e1 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -27,6 +27,7 @@ #include "xml/repr.h" #include "xml/simple-document.h" #include "xml/simple-node.h" +#include "xml/sp-css-attr.h" #include "style.h" #include "libcroco/cr-sel-eng.h" @@ -270,10 +271,9 @@ double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double def /** * Write a style attribute string from a list of properties stored in an SPCSAttr object. */ -gchar *sp_repr_css_write_string(SPCSSAttr *css) +void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str) { - Glib::ustring buffer; - + str.clear(); for ( List<AttributeRecord const> iter = css->attributeList() ; iter ; ++iter ) { @@ -281,28 +281,21 @@ gchar *sp_repr_css_write_string(SPCSSAttr *css) continue; } - buffer.append(g_quark_to_string(iter->key)); - buffer.push_back(':'); + 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 - gchar *t = g_strdup (iter->value); - g_free (t); - gchar *val_quoted = css2_escape_quote (iter->value); - if (val_quoted) { - buffer.append(val_quoted); - g_free (val_quoted); - } + Glib::ustring val_quoted = css2_escape_quote (iter->value); + str.append(val_quoted); } else { - buffer.append(iter->value); // unquoted + str.append(iter->value); // unquoted } if (rest(iter)) { - buffer.push_back(';'); + str.push_back(';'); } } - - return (buffer.empty() ? NULL : g_strdup (buffer.c_str())); } /** @@ -314,17 +307,16 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr) g_assert(css != NULL); g_assert(attr != NULL); - gchar *value = sp_repr_css_write_string(css); + Glib::ustring value; + sp_repr_css_write_string(css, value); /* * If the new value is different from the old value, this will sometimes send a signal via * CompositeNodeObserver::notiftyAttributeChanged() which results in calling - * SPObject::sp_object_repr_attr_changed and thus updates the object's SPStyle. This update + * SPObject::repr_attr_changed and thus updates the object's SPStyle. This update * results in another call to repr->setAttribute(). */ - repr->setAttribute(attr, value); - - if (value) g_free (value); + repr->setAttribute(attr, value.c_str()); } /** @@ -360,7 +352,8 @@ static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *con 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 "" - gchar *units = NULL; + Glib::ustring value_unquoted2 = value_unquoted ? value_unquoted : Glib::ustring(); + Glib::ustring units; /* * Problem with parsing of units em and ex, like font-size "1.2em" and "3.4ex" @@ -369,18 +362,22 @@ 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 l = strlen(value_unquoted); - if (!strncmp(&value_unquoted[l-2], "em", 2) || - !strncmp(&value_unquoted[l-2], "ex", 2)) { - units = g_strndup(&value_unquoted[l-2], 2); - value_unquoted = g_strndup(value_unquoted, l-2); + int le = value_unquoted2.length(); + if (le > 2) { + units = value_unquoted2.substr(le-2, 2); + if ((units == "em") || (units == "ex")) { + value_unquoted2 = value_unquoted2.substr(0, le-2); + } + else { + units.clear(); + } } // libcroco uses %.17f for formatting... leading to trailing zeros or small rounding errors. // 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_unquoted2 ); double number = 0; std::string characters; std::string temp; @@ -394,10 +391,9 @@ static void sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *con Inkscape::CSSOStringStream os; if( number_valid ) os << number; os << characters; - if (units) { + if (!units.empty()) { os << units; //g_message("sp_repr_css_merge_from_decl looks like em or ex units %s --> %s", str_value, os.str().c_str()); - g_free(units); } ((Node *) css)->setAttribute(decl->property->stryng->str, os.str().c_str(), false); g_free(value_unquoted); |
