diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2014-12-25 11:40:35 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2014-12-25 11:40:35 +0000 |
| commit | 9a8bd0c8c29161a2fd91ccb48a3a813d4a45ac99 (patch) | |
| tree | ff76ccc40eff6789fba245ff1c8ee15d5b5303da /src | |
| parent | Remove sp_style_read_from_object() (diff) | |
| download | inkscape-9a8bd0c8c29161a2fd91ccb48a3a813d4a45ac99.tar.gz inkscape-9a8bd0c8c29161a2fd91ccb48a3a813d4a45ac99.zip | |
Remove sp_style_write_string() and sp_style_write_difference().
(bzr r13822.1.4)
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop-style.cpp | 7 | ||||
| -rw-r--r-- | src/path-chemistry.cpp | 28 | ||||
| -rw-r--r-- | src/sp-flowtext.cpp | 8 | ||||
| -rw-r--r-- | src/sp-object.cpp | 14 | ||||
| -rw-r--r-- | src/style-test.h | 123 | ||||
| -rw-r--r-- | src/style.cpp | 94 | ||||
| -rw-r--r-- | src/style.h | 18 | ||||
| -rw-r--r-- | src/text-editing.cpp | 39 | ||||
| -rw-r--r-- | src/ui/tools/freehand-base.cpp | 19 | ||||
| -rw-r--r-- | src/ui/widget/style-swatch.cpp | 9 |
10 files changed, 138 insertions, 221 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 3eb11bea6..ee9fa39ec 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -428,10 +428,9 @@ sp_desktop_get_font_size_tool(SPDesktop *desktop) double ret = 12; if (!style_str.empty()) { - SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT); - sp_style_merge_from_style_string(style, style_str.data()); - ret = style->font_size.computed; - sp_style_unref(style); + SPStyle style(SP_ACTIVE_DOCUMENT); + style.mergeString(style_str.data()); + ret = style.font_size.computed; } return ret; } diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 238527465..5f6e1495b 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -500,11 +500,12 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) /* Rotation center */ g_repr->setAttribute("inkscape:transform-center-x", item->getRepr()->attribute("inkscape:transform-center-x"), false); g_repr->setAttribute("inkscape:transform-center-y", item->getRepr()->attribute("inkscape:transform-center-y"), false); + /* Whole text's style */ - gchar *style_str = sp_style_write_difference(item->style, - item->parent ? item->parent->style : NULL); // TODO investigate posibility - g_repr->setAttribute("style", style_str); - g_free(style_str); + Glib::ustring style_str = + item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + g_repr->setAttribute("style", style_str.c_str()); + Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); do { Inkscape::Text::Layout::iterator iter_next = iter; @@ -522,19 +523,17 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) while (dynamic_cast<SPString const *>(pos_obj) && pos_obj->parent) { pos_obj = pos_obj->parent; // SPStrings don't have style } - gchar *style_str = sp_style_write_difference(pos_obj->style, - pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility + Glib::ustring style_str = + pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility // get path from iter to iter_next: SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); iter = iter_next; // shift to next glyph if (!curve) { // error converting this glyph - g_free (style_str); continue; } if (curve->is_empty()) { // whitespace glyph? curve->unref(); - g_free (style_str); continue; } @@ -545,8 +544,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) g_free(def_str); curve->unref(); - p_repr->setAttribute("style", style_str); - g_free(style_str); + p_repr->setAttribute("style", style_str.c_str()); g_repr->appendChild(p_repr); Inkscape::GC::release(p_repr); @@ -565,7 +563,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) if (shape) { curve = shape->getCurve(); } - } + } if (!curve) return NULL; @@ -581,11 +579,11 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); /* Transformation */ repr->setAttribute("transform", item->getRepr()->attribute("transform")); + /* Style */ - gchar *style_str = sp_style_write_difference(item->style, - item->parent ? item->parent->style : NULL); // TODO investigate posibility - repr->setAttribute("style", style_str); - g_free(style_str); + Glib::ustring style_str = + item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + repr->setAttribute("style", style_str.c_str()); /* Mask */ gchar *mask_str = (gchar *) item->getRepr()->attribute("mask"); diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 8d9f87037..6d2385aff 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -525,10 +525,10 @@ Inkscape::XML::Node *SPFlowtext::getAsText() Glib::ustring::iterator span_text_start_iter; this->layout.getSourceOfCharacter(it, &rawptr, &span_text_start_iter); SPObject *source_obj = reinterpret_cast<SPObject *>(rawptr); - gchar *style_text = sp_style_write_difference((dynamic_cast<SPString *>(source_obj) ? source_obj->parent : source_obj)->style, this->style); - if (style_text && *style_text) { - span_tspan->setAttribute("style", style_text); - g_free(style_text); + + Glib::ustring style_text = (dynamic_cast<SPString *>(source_obj) ? source_obj->parent : source_obj)->style->write( SP_STYLE_FLAG_IFDIFF, this->style); + if (!style_text.empty()) { + span_tspan->setAttribute("style", style_text.c_str()); } SPString *str = dynamic_cast<SPString *>(source_obj); diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 124471545..d492e7817 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1007,9 +1007,8 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML repr->setAttribute("inkscape:collect", NULL); } - SPStyle const *const obj_style = this->style; - if (obj_style) { - gchar *s = sp_style_write_string(obj_style, SP_STYLE_FLAG_IFSET); + if (style) { + Glib::ustring s = style->write(SP_STYLE_FLAG_IFSET); // Check for valid attributes. This may be time consuming. // It is useful, though, for debugging Inkscape code. @@ -1017,17 +1016,14 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML if( prefs->getBool("/options/svgoutput/check_on_editing") ) { unsigned int flags = sp_attribute_clean_get_prefs(); - Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s, flags ); - g_free( s ); - s = (s_cleaned.empty() ? NULL : g_strdup (s_cleaned.c_str())); + Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s.c_str(), flags ); } - if( s == NULL || strcmp(s,"") == 0 ) { + if( s.empty() ) { repr->setAttribute("style", NULL); } else { - repr->setAttribute("style", s); + repr->setAttribute("style", s.c_str()); } - g_free(s); } else { /** \todo I'm not sure what to do in this case. Bug #1165868 diff --git a/src/style-test.h b/src/style-test.h index e14ed4db7..cd6769b24 100644 --- a/src/style-test.h +++ b/src/style-test.h @@ -214,32 +214,25 @@ public: for ( gint i = 0; cases[i].src; i++ ) { // std::cout << "Test one: " << i << std::endl; - SPStyle *style = sp_style_new(_doc); - TS_ASSERT(style); - if ( style ) { - sp_style_merge_from_style_string( style, cases[i].src ); - - if ( cases[i].uri ) { - TSM_ASSERT( cases[i].src, style->fill.value.href ); - if ( style->fill.value.href ) { - TS_ASSERT_EQUALS( style->fill.value.href->getURI()->toString(), std::string(cases[i].uri) ); - } - } else { - TS_ASSERT( !style->fill.value.href || !style->fill.value.href->getObject() ); + SPStyle style(_doc); + style.mergeString( cases[i].src ); + if ( cases[i].uri ) { + TSM_ASSERT( cases[i].src, style.fill.value.href ); + if ( style.fill.value.href ) { + TS_ASSERT_EQUALS( style.fill.value.href->getURI()->toString(), std::string(cases[i].uri) ); } + } else { + TS_ASSERT( !style.fill.value.href || !style.fill.value.href->getObject() ); + } - gchar *str0_set = sp_style_write_string( style, SP_STYLE_FLAG_IFSET ); - //printf("<<%s>>\n", str0_set); - if ( cases[i].dst ) { - // std::cout << " " << std::string(str0_set) << " " << std::string(cases[i].dst) << std::endl; - TS_ASSERT_EQUALS( std::string(str0_set), std::string(cases[i].dst) ); - } else { - // std::cout << " " << std::string(str0_set) << " " << std::string(cases[i].src) << std::endl; - TS_ASSERT_EQUALS( std::string(str0_set), std::string(cases[i].src) ); - } + std::string str0_set = style.write(SP_STYLE_FLAG_IFSET ); - g_free(str0_set); - sp_style_unref(style); + if ( cases[i].dst ) { + // std::cout << " " << str0_set << " " << std::string(cases[i].dst) << std::endl; + TS_ASSERT_EQUALS( str0_set, std::string(cases[i].dst) ); + } else { + // std::cout << " " << str0_set << " " << std::string(cases[i].src) << std::endl; + TS_ASSERT_EQUALS( str0_set, std::string(cases[i].src) ); } } } @@ -366,26 +359,22 @@ public: }; for ( gint i = 0; cases[i].src; i++ ) { // std::cout << "Test two: " << i << std::endl; - SPStyle *style_src = sp_style_new(_doc); - TS_ASSERT(style_src); - SPStyle *style_dst = sp_style_new(_doc); - TS_ASSERT(style_dst); - - if ( style_src && style_dst ) { - sp_style_merge_from_style_string( style_src, cases[i].src ); - sp_style_merge_from_style_string( style_dst, cases[i].dst ); - // std::cout << "Test:" << std::endl; - // std::cout << " C: |" << cases[i].src << "| |" << cases[i].dst << "|" << std::endl; - // std::cout << " S: |" << style_src->write( SP_STYLE_FLAG_IFSET, NULL ) << "| |" - // << style_dst->write( SP_STYLE_FLAG_IFSET, NULL ) << "|" <<std::endl; - TS_ASSERT( (*style_src == *style_dst) == cases[i].match ); - sp_style_unref(style_src); - sp_style_unref(style_dst); - // std::cout << "End Test\n" << std::endl; - } + SPStyle style_src(_doc); + SPStyle style_dst(_doc); + + style_src.mergeString( cases[i].src ); + style_dst.mergeString( cases[i].dst ); + + // std::cout << "Test:" << std::endl; + // std::cout << " C: |" << cases[i].src << "| |" << cases[i].dst << "|" << std::endl; + // std::cout << " S: |" << style_src.write( SP_STYLE_FLAG_IFSET, NULL ) << "| |" + // << style_dst.write( SP_STYLE_FLAG_IFSET, NULL ) << "|" <<std::endl; + TS_ASSERT( (style_src == style_dst) == cases[i].match ); + // std::cout << "End Test\n" << std::endl; } } + // Test of cascade void testThree() { @@ -477,37 +466,29 @@ public: }; for ( gint i = 0; cases[i].parent; i++ ) { // std::cout << "Test three: " << i << std::endl; - SPStyle *style_parent = sp_style_new(_doc); - TS_ASSERT(style_parent); - SPStyle *style_child = sp_style_new(_doc); - TS_ASSERT(style_child); - SPStyle *style_result = sp_style_new(_doc); - TS_ASSERT(style_result); - - if ( style_parent && style_child && style_result ) { - sp_style_merge_from_style_string( style_parent, cases[i].parent ); - sp_style_merge_from_style_string( style_child, cases[i].child ); - sp_style_merge_from_style_string( style_result, cases[i].result ); - // std::cout << "Test:" << std::endl; - // std::cout << " Input: "; - // std::cout << " Parent: " << cases[i].parent - // << " Child: " << cases[i].child - // << " Result: " << cases[i].result << std::endl; - // std::cout << " Write: "; - // std::cout << " Parent: " << style_parent->write( SP_STYLE_FLAG_IFSET ) - // << " Child: " << style_child->write( SP_STYLE_FLAG_IFSET ) - // << " Result: " << style_result->write( SP_STYLE_FLAG_IFSET ) << std::endl; - - //sp_style_merge_from_parent( style_child, style_parent ); - style_child->cascade( style_parent ); - - TS_ASSERT(*style_child == *style_result ); - - sp_style_unref(style_child); - sp_style_unref(style_parent); - sp_style_unref(style_result); - // std::cout << "End Test: *************\n" << std::endl; - } + SPStyle style_parent(_doc); + SPStyle style_child( _doc); + SPStyle style_result(_doc); + + style_parent.mergeString( cases[i].parent ); + style_child.mergeString( cases[i].child ); + style_result.mergeString( cases[i].result ); + + // std::cout << "Test:" << std::endl; + // std::cout << " Input: "; + // std::cout << " Parent: " << cases[i].parent + // << " Child: " << cases[i].child + // << " Result: " << cases[i].result << std::endl; + // std::cout << " Write: "; + // std::cout << " Parent: " << style_parent.write( SP_STYLE_FLAG_IFSET ) + // << " Child: " << style_child.write( SP_STYLE_FLAG_IFSET ) + // << " Result: " << style_result.write( SP_STYLE_FLAG_IFSET ) << std::endl; + + style_child.cascade( &style_parent ); + + TS_ASSERT(style_child == style_result ); + + // std::cout << "End Test: *************\n" << std::endl; } } diff --git a/src/style.cpp b/src/style.cpp index b91b3d774..a26c92e48 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -458,7 +458,10 @@ SPStyle::~SPStyle() { _properties.clear(); - // std::cout << "SPStyle::~SPstyle(): Exit\n" << std::endl; + if( _refcount > 1 ) { + std::cerr << "SPStyle::~SPStyle: ref count greater than 1! " << _refcount << std::endl; + } + // std::cout << "SPStyle::~SPStyle(): Exit\n" << std::endl; } // Used in SPStyle::clear() @@ -902,6 +905,19 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { } } +/** + * Outputs the style to a CSS string. + * + * Use with SP_STYLE_FLAG_ALWAYS for copying an object's complete cascaded style to + * style_clipboard. + * + * Use with SP_STYLE_FLAG_IFDIFF and a pointer to the parent class when you need a CSS string for + * an object in the document tree. + * + * \pre flags in {IFSET, ALWAYS, IFDIFF}. + * \pre base. + * \post ret != NULL. + */ Glib::ustring SPStyle::write( guint const flags, SPStyle const *const base ) const { @@ -954,6 +970,14 @@ SPStyle::merge( SPStyle const *const parent ) { // } } +/** + * Parses a style="..." string and merges it with an existing SPStyle. + */ +void +SPStyle::mergeString( gchar const *const p ) { + _mergeString( p ); +} + // Mostly for unit testing bool SPStyle::operator==(const SPStyle& rhs) { @@ -1246,25 +1270,6 @@ sp_repr_sel_eng() // Called in text-editting.cpp, ui/tools/frehand-base.cpp, ui/widget/style-swatch.cpp -/** - * Parses a style="..." string and merges it with an existing SPStyle. - */ -void -sp_style_merge_from_style_string(SPStyle *const style, gchar const *const p) -{ - // std::cout << "sp_style_merge_from_style_string: " << (p?p:"null") <<std::endl; - /* - * Reference: http://www.w3.org/TR/SVG11/styling.html#StyleAttribute: - * ``When CSS styling is used, CSS inline style is specified by including - * semicolon-separated property declarations of the form "name : value" - * within the style attribute''. - * - * That's fairly ambiguous. Is a `value' allowed to contain semicolons? - * Why does it say "including", what else is allowed in the style - * attribute value? - */ - style->_mergeString( p ); -} /** Indexed by SP_CSS_FONT_SIZE_blah. These seem a bit small */ static float const font_size_table[] = {6.0, 8.0, 10.0, 12.0, 14.0, 18.0, 24.0}; @@ -1435,50 +1440,6 @@ sp_style_css_size_units_to_px(double size, int unit) return size * (size / sp_style_css_size_px_to_units(size, unit));; } -// Called in style.cpp, text-editing.cpp -/** - * Dumps the style to a CSS string, with either SP_STYLE_FLAG_IFSET or - * SP_STYLE_FLAG_ALWAYS flags. Used with Always for copying an object's - * complete cascaded style to style_clipboard. When you need a CSS string - * for an object in the document tree, you normally call - * sp_style_write_difference instead to take into account the object's parent. - * - * \pre style != NULL. - * \pre flags in {IFSET, ALWAYS}. - * \post ret != NULL. - */ -gchar * -sp_style_write_string(SPStyle const *const style, guint const flags) -{ - /** \todo - * Merge with write_difference, much duplicate code! - */ - g_return_val_if_fail(style != NULL, NULL); - g_return_val_if_fail(((flags == SP_STYLE_FLAG_IFSET) || - (flags == SP_STYLE_FLAG_ALWAYS) ), - NULL); - - return g_strdup( style->write( flags ).c_str() ); -} - - -// Called in style.cpp, path-chemistry, NOT in text-editting.cpp (because of bug) -/** - * Dumps style to CSS string, see sp_style_write_string() - * - * \pre from != NULL. - * \pre to != NULL. - * \post ret != NULL. - */ -gchar * -sp_style_write_difference(SPStyle const *const from, SPStyle const *const to) -{ - g_return_val_if_fail(from != NULL, NULL); - g_return_val_if_fail(to != NULL, NULL); - - return g_strdup( from->write( SP_STYLE_FLAG_IFDIFF, to ).c_str() ); -} - // FIXME: Everything below this line belongs in a different file - css-chemistry? @@ -1639,10 +1600,9 @@ sp_css_attr_from_style(SPStyle const *const style, guint const flags) g_return_val_if_fail(((flags == SP_STYLE_FLAG_IFSET) || (flags == SP_STYLE_FLAG_ALWAYS) ), NULL); - gchar *style_str = sp_style_write_string(style, flags); + Glib::ustring style_str = style->write(flags); SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, style_str); - g_free(style_str); + sp_repr_css_attr_add_from_string(css, style_str.c_str()); return css; } diff --git a/src/style.h b/src/style.h index 5884f2459..324b30523 100644 --- a/src/style.h +++ b/src/style.h @@ -51,18 +51,18 @@ public: void readFromObject(SPObject *object); void readFromPrefs(Glib::ustring const &path); void readIfUnset( int id, char const *val ); - Glib::ustring write( unsigned int const flags, SPStyle const *const base = NULL ) const; + Glib::ustring write( unsigned int const flags = SP_STYLE_FLAG_IFSET, + SPStyle const *const base = NULL ) const; void cascade( SPStyle const *const parent ); void merge( SPStyle const *const parent ); + void mergeString( char const *const p ); bool operator==(const SPStyle& rhs); int ref() { ++_refcount; return _refcount; } int unref() { --_refcount; return _refcount; } -//FIXME: Make private -public: - void _mergeString( char const *const p ); // Rename to readFromString? private: + void _mergeString( char const *const p ); void _mergeDeclList( CRDeclaration const *const decl_list ); void _mergeDecl( CRDeclaration const *const decl ); void _mergeProps( CRPropList *const props ); @@ -288,20 +288,10 @@ SPStyle *sp_style_ref(SPStyle *style); // SPStyle::ref(); SPStyle *sp_style_unref(SPStyle *style); // SPStyle::unref(); -void sp_style_read_from_object(SPStyle *style, SPObject *object); //SPStyle::read( SPObject * object); - -void sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path); // SPStyle::read( ... ); - -void sp_style_merge_from_style_string(SPStyle *style, char const *p); // SPStyle::merge( ... );? - void sp_style_merge_from_parent(SPStyle *style, SPStyle const *parent); // SPStyle::cascade( ... ); void sp_style_merge_from_dying_parent(SPStyle *style, SPStyle const *parent); // SPStyle::merge( ... ) -char *sp_style_write_string(SPStyle const *style, unsigned int flags = SP_STYLE_FLAG_IFSET);//SPStyle::write - -char *sp_style_write_difference(SPStyle const *from, SPStyle const *to); // SPStyle::write - void sp_style_set_to_uri_string (SPStyle *style, bool isfill, const char *uri); // ? char const *sp_style_get_css_unit_string(int unit); // No change? diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 47964880c..4a962ab4c 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -1321,23 +1321,23 @@ static unsigned char_index_of_iterator(Glib::ustring const &string, Glib::ustrin return n; } +// Move to style.h? /** applies the given style string on top of the existing styles for \a item, as opposed to sp_style_merge_from_style_string which merges its parameter underneath the existing styles (ie ignoring already set properties). */ static void overwrite_style_with_string(SPObject *item, gchar const *style_string) { - SPStyle *new_style = sp_style_new(item->document); - sp_style_merge_from_style_string(new_style, style_string); + SPStyle style(item->document); + style.mergeString(style_string); gchar const *item_style_string = item->getRepr()->attribute("style"); if (item_style_string && *item_style_string) { - sp_style_merge_from_style_string(new_style, item_style_string); + style.mergeString(item_style_string); } - gchar *new_style_string = sp_style_write_string(new_style); - sp_style_unref(new_style); - item->getRepr()->setAttribute("style", new_style_string && *new_style_string ? new_style_string : NULL); - g_free(new_style_string); + Glib::ustring new_style_string = style.write(); + item->getRepr()->setAttribute("style", new_style_string.empty() ? NULL : new_style_string.c_str()); } +// Move to style.h? /** Returns true if the style of \a parent and the style of \a child are equivalent (and hence the children of both will appear the same). It is a limitation of the current implementation that \a parent must be a (not @@ -1349,14 +1349,14 @@ static bool objects_have_equal_style(SPObject const *parent, SPObject const *chi // implications too large for me to feel safe fixing, but mainly because the css spec // requires that the computed value is inherited, not the specified value. g_assert(parent->isAncestorOf(child)); - gchar *parent_style = sp_style_write_string(parent->style, SP_STYLE_FLAG_ALWAYS); + + Glib::ustring parent_style = parent->style->write( SP_STYLE_FLAG_ALWAYS ); + // we have to write parent_style then read it again, because some properties format their values // differently depending on whether they're set or not (*cough*dash-offset*cough*) - SPStyle *parent_spstyle = sp_style_new(parent->document); - sp_style_merge_from_style_string(parent_spstyle, parent_style); - g_free(parent_style); - parent_style = sp_style_write_string(parent_spstyle, SP_STYLE_FLAG_ALWAYS); - sp_style_unref(parent_spstyle); + SPStyle parent_spstyle(parent->document); + parent_spstyle.mergeString(parent_style.c_str()); + parent_style = parent_spstyle.write(SP_STYLE_FLAG_ALWAYS); Glib::ustring child_style_construction; while (child != parent) { @@ -1369,13 +1369,12 @@ static bool objects_have_equal_style(SPObject const *parent, SPObject const *chi child = child->parent; } child_style_construction.insert(0, parent_style); - SPStyle *child_spstyle = sp_style_new(parent->document); - sp_style_merge_from_style_string(child_spstyle, child_style_construction.c_str()); - gchar *child_style = sp_style_write_string(child_spstyle, SP_STYLE_FLAG_ALWAYS); - sp_style_unref(child_spstyle); - bool equal = !strcmp(child_style, parent_style); - g_free(child_style); - g_free(parent_style); + + SPStyle child_spstyle(parent->document); + child_spstyle.mergeString(child_style_construction.c_str()); + Glib::ustring child_style = child_spstyle.write(SP_STYLE_FLAG_ALWAYS); + + bool equal = (child_style == parent_style); // Glib::ustring overloads == operator return equal; } diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index c9fe37135..0f14d7534 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -247,11 +247,9 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points char const *style_str = NULL; style_str = repr->attribute("style"); if (style_str) { - SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT); - sp_style_merge_from_style_string(style, style_str); - stroke_width = style->stroke_width.computed; - style->stroke_width.computed = 0; - sp_style_unref(style); + SPStyle style(SP_ACTIVE_DOCUMENT); + style.mergeString(style_str); + stroke_width = style.stroke_width.computed; } std::ostringstream s; @@ -821,14 +819,11 @@ void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *too // find out stroke width (TODO: is there an easier way??) double stroke_width = 3.0; - gchar const *style_str = NULL; - style_str = repr->attribute("style"); + gchar const *style_str = repr->attribute("style"); if (style_str) { - SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT); - sp_style_merge_from_style_string(style, style_str); - stroke_width = style->stroke_width.computed; - style->stroke_width.computed = 0; - sp_style_unref(style); + SPStyle style(SP_ACTIVE_DOCUMENT); + style.mergeString(style_str); + stroke_width = style.stroke_width.computed; } // unset stroke and set fill color to former stroke color diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 157fd2ad9..fa8543c46 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -260,13 +260,12 @@ void StyleSwatch::setStyle(SPCSSAttr *css) Glib::ustring css_string; sp_repr_css_write_string (_css, css_string); - SPStyle *temp_spstyle = sp_style_new(SP_ACTIVE_DOCUMENT); + + SPStyle style(SP_ACTIVE_DOCUMENT); if (!css_string.empty()) { - sp_style_merge_from_style_string (temp_spstyle, css_string.c_str()); + style.mergeString(css_string.c_str()); } - - setStyle (temp_spstyle); - sp_style_unref (temp_spstyle); + setStyle (&style); } void StyleSwatch::setStyle(SPStyle *query) |
