diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
| commit | 5a4fb2325f60d292b47330f540b26a3279341c90 (patch) | |
| tree | d2aa7967be25450b83e625025366c618101ae49f /src/xml/repr-css.cpp | |
| parent | The Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff) | |
| parent | Remove Snap menu item and improve grid menu item text (diff) | |
| download | inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip | |
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/xml/repr-css.cpp')
| -rw-r--r-- | src/xml/repr-css.cpp | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 19f3f1d6c..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,12 +352,32 @@ 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 "" + 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" + * stringstream thinks they are in scientific "e" notation and fails + * Must be a better way using std::fixed, precision etc + * + * HACK for now is to strip off em and ex units and add them back at the end + */ + 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; @@ -379,6 +391,10 @@ 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.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()); + } ((Node *) css)->setAttribute(decl->property->stryng->str, os.str().c_str(), false); g_free(value_unquoted); g_free(str_value); |
