From ac296d6ff2208225570199ee779177477b0d45fc Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 15 Aug 2012 12:50:53 +0900 Subject: Fix for 1036010 : Cant read styles with 'em' units (bzr r11605) --- src/xml/repr-css.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/xml/repr-css.cpp') diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 19f3f1d6c..679ec73cb 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -360,6 +360,21 @@ 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(str_value_unsigned); gchar *value_unquoted = attribute_unquote (str_value); // libcroco returns strings quoted in "" + gchar *units = NULL; + + /* + * 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 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); + } // 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 @@ -379,6 +394,11 @@ 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) { + 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); g_free(str_value); -- cgit v1.2.3 From ce4e3c231102682e1cc263054c727ad687634523 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 2 Sep 2012 17:59:13 +0200 Subject: performance: ?? (bzr r11645) --- src/xml/repr-css.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/xml/repr-css.cpp') diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 679ec73cb..594ac83c6 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -286,8 +286,6 @@ gchar *sp_repr_css_write_string(SPCSSAttr *css) 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); -- cgit v1.2.3 From fd0a5dfa4cb237f8e5232c785693cc3e676336e8 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 2 Sep 2012 21:32:59 +0200 Subject: converted some c-string usage to c++ string class usage: should fix some memory leaks (bzr r11646) --- src/xml/repr-css.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/xml/repr-css.cpp') diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 594ac83c6..88f85f8de 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -270,10 +270,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 iter = css->attributeList() ; iter ; ++iter ) { @@ -281,26 +280,24 @@ 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 *val_quoted = css2_escape_quote (iter->value); if (val_quoted) { - buffer.append(val_quoted); + str.append(val_quoted); g_free (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())); } /** @@ -312,7 +309,8 @@ 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 @@ -320,9 +318,7 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr) * SPObject::sp_object_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()); } /** -- cgit v1.2.3 From d4f5006264e2e19a9fe50968a2e422b83785821c Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 3 Sep 2012 08:35:01 +0200 Subject: revert rev 11646: build issue with dbus (forgot to adapt some more, dbus was not enabled) and other issues (bzr r11649) --- src/xml/repr-css.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/xml/repr-css.cpp') diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 88f85f8de..594ac83c6 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -270,9 +270,10 @@ 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. */ -void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str) +gchar *sp_repr_css_write_string(SPCSSAttr *css) { - str.clear(); + Glib::ustring buffer; + for ( List iter = css->attributeList() ; iter ; ++iter ) { @@ -280,24 +281,26 @@ void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str) continue; } - str.append(g_quark_to_string(iter->key)); - str.push_back(':'); + buffer.append(g_quark_to_string(iter->key)); + buffer.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 *val_quoted = css2_escape_quote (iter->value); if (val_quoted) { - str.append(val_quoted); + buffer.append(val_quoted); g_free (val_quoted); } } else { - str.append(iter->value); // unquoted + buffer.append(iter->value); // unquoted } if (rest(iter)) { - str.push_back(';'); + buffer.push_back(';'); } } + + return (buffer.empty() ? NULL : g_strdup (buffer.c_str())); } /** @@ -309,8 +312,7 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr) g_assert(css != NULL); g_assert(attr != NULL); - Glib::ustring value; - sp_repr_css_write_string(css, value); + gchar *value = sp_repr_css_write_string(css); /* * If the new value is different from the old value, this will sometimes send a signal via @@ -318,7 +320,9 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr) * SPObject::sp_object_repr_attr_changed and thus updates the object's SPStyle. This update * results in another call to repr->setAttribute(). */ - repr->setAttribute(attr, value.c_str()); + repr->setAttribute(attr, value); + + if (value) g_free (value); } /** -- cgit v1.2.3 From bac4df147de363a0774548acd63d367a09ab50d3 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 20 Sep 2012 22:40:55 +0200 Subject: some memleak fixes (Bug #1043571) (bzr r11686) --- src/xml/repr-css.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'src/xml/repr-css.cpp') diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 594ac83c6..7fba4d7c6 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -270,10 +270,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 iter = css->attributeList() ; iter ; ++iter ) { @@ -281,26 +280,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 *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())); } /** @@ -312,7 +306,8 @@ 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 @@ -320,9 +315,7 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr) * SPObject::sp_object_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()); } /** -- cgit v1.2.3 From edf55384619442eed0ffee95e0eaa9b565477b86 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Tue, 9 Oct 2012 20:44:34 +0200 Subject: fix memory leak and access error in sp_repr_css_merge_from_decl (Bug #1061157) (bzr r11771) --- src/xml/repr-css.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/xml/repr-css.cpp') diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 7fba4d7c6..f554d314d 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -351,7 +351,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(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" @@ -360,18 +361,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; @@ -385,10 +390,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); -- cgit v1.2.3 From f2907ae896ed8688e800519310b61754550f27f6 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 11 Nov 2012 14:17:53 +0000 Subject: SPObject: drop sp_object_ prefix on class members (bzr r11869) --- src/xml/repr-css.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xml/repr-css.cpp') diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index f554d314d..4c339ad5a 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -312,7 +312,7 @@ void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr) /* * 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.c_str()); -- cgit v1.2.3 From c8a761256b40300761c7ff6a0d642ac75b6f541a Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 11 Feb 2013 23:34:59 +0000 Subject: A couple of forward declarations (bzr r12119) --- src/xml/repr-css.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/xml/repr-css.cpp') diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 4c339ad5a..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" -- cgit v1.2.3