From 497b9890e0cb85fced32d6958b465d40212db482 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 24 Dec 2014 10:03:50 +0100 Subject: Remove sp_style_new_from_object() (bzr r13822.1.1) --- src/style.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index a7e50b17a..464c402fa 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -476,7 +476,7 @@ SPStyle::clear() { // (this->*(i->second)).clear(); // } - // Release connection to object, created in sp_style_new_from_object() + // Release connection to object, created in constructor. release_connection.disconnect(); // href->detach() called in fill->clear()... @@ -899,7 +899,7 @@ SPStyle::write( guint const flags, SPStyle const *const base ) const { // Corresponds to sp_style_merge_from_parent() void SPStyle::cascade( SPStyle const *const parent ) { - // std::cout << "SPStyle::cascade" << std::endl; + // std::cout << "SPStyle::cascade: " << (object->getId()?object->getId():"null") << std::endl; for(std::vector::size_type i = 0; i != _properties.size(); ++i) { _properties[i]->cascade( parent->_properties[i] ); } @@ -1157,20 +1157,6 @@ sp_style_new(SPDocument *document) return style; } -// Called in: sp-object.cpp -/** - * Creates a new SPStyle object, and attaches it to the specified SPObject. - */ -SPStyle * -sp_style_new_from_object(SPObject *object) -{ - g_return_val_if_fail(object != NULL, NULL); - g_return_val_if_fail(SP_IS_OBJECT(object), NULL); - - SPStyle *const style = new SPStyle( NULL, object ); - return style; -} - // Called in display/drawing-item.cpp, display/nr-filter-primitive.cpp, libnrtype/Layout-TNG-Input.cpp /** * Increase refcount of style. -- cgit v1.2.3 From f4cfff3d186fd61221b3f771bf2794725e619ff7 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 24 Dec 2014 11:09:33 +0100 Subject: Add missing SPStyle::readFromPrefs(), remove sp_style_read_from_prefs(). (bzr r13822.1.2) --- src/style.cpp | 62 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index 464c402fa..f677e4a76 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -591,6 +591,34 @@ SPStyle::readFromObject( SPObject *object ) { read( object, repr ); } +/** + * Read style properties from preferences. + * @param path Preferences directory from which the style should be read + */ +void +SPStyle::readFromPrefs(Glib::ustring const &path) { + + g_return_if_fail(!path.empty()); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + // not optimal: we reconstruct the node based on the prefs, then pass it to + // sp_style_read for actual processing. + Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument; + Inkscape::XML::Node *tempnode = tempdoc->createElement("prefs"); + + std::vector attrs = prefs->getAllEntries(path); + for (std::vector::iterator i = attrs.begin(); i != attrs.end(); ++i) { + tempnode->setAttribute(i->getEntryName().data(), i->getString().data()); + } + + read( NULL, tempnode ); + + Inkscape::GC::release(tempnode); + Inkscape::GC::release(tempdoc); + delete tempdoc; +} + // Matches sp_style_merge_property(SPStyle *style, gint id, gchar const *val) void SPStyle::readIfUnset( gint id, gchar const *val ) { @@ -1211,40 +1239,6 @@ sp_style_read_from_object(SPStyle *style, SPObject *object) style->read( object, repr ); } -// Called in: libnrtype/font-lister.cpp, widgets/dash-selector.cpp, widgets/text-toolbar.cpp, -// ui/dialog/text-edit.cpp -// Why is this called when draging a gradient handle? -/** - * Read style properties from preferences. - * @param style The style to write to - * @param path Preferences directory from which the style should be read - */ -void -sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path) -{ - g_return_if_fail(style != NULL); - g_return_if_fail(path != ""); - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - // not optimal: we reconstruct the node based on the prefs, then pass it to - // sp_style_read for actual processing. - Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument; - Inkscape::XML::Node *tempnode = tempdoc->createElement("prefs"); - - std::vector attrs = prefs->getAllEntries(path); - for (std::vector::iterator i = attrs.begin(); i != attrs.end(); ++i) { - tempnode->setAttribute(i->getEntryName().data(), i->getString().data()); - } - - style->read( NULL, tempnode ); - - Inkscape::GC::release(tempnode); - Inkscape::GC::release(tempdoc); - delete tempdoc; -} - - static CRSelEng * sp_repr_sel_eng() { -- cgit v1.2.3 From c10ae6598c095b0273672f764f0fe0e684c94b87 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 24 Dec 2014 11:27:30 +0100 Subject: Remove sp_style_read_from_object() (bzr r13822.1.3) --- src/style.cpp | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index f677e4a76..b91b3d774 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -576,7 +576,13 @@ SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) { } } -// Matches void sp_style_read_from_object(SPStyle *style, SPObject *object); +/** + * Read style properties from object's repr. + * + * 1. Reset existing object style + * 2. Load current effective object style + * 3. Load i attributes from immediate parent (which has to be up-to-date) + */ void SPStyle::readFromObject( SPObject *object ) { @@ -1215,30 +1221,6 @@ sp_style_unref(SPStyle *style) return style; } - - -// Called in: sp-clippath.cpp, sp-item.cpp (suspicious), sp-object.cpp, sp-style-elem.cpp -/** - * Read style properties from object's repr. - * - * 1. Reset existing object style - * 2. Load current effective object style - * 3. Load i attributes from immediate parent (which has to be up-to-date) - */ -void -sp_style_read_from_object(SPStyle *style, SPObject *object) -{ - // std::cout << "sp_style_read_from_object: " << (object->getId()?object->getId():"null") << std::endl; - g_return_if_fail(style != NULL); - g_return_if_fail(object != NULL); - g_return_if_fail(SP_IS_OBJECT(object)); - - Inkscape::XML::Node *repr = object->getRepr(); - g_return_if_fail(repr != NULL); - - style->read( object, repr ); -} - static CRSelEng * sp_repr_sel_eng() { -- cgit v1.2.3 From 9a8bd0c8c29161a2fd91ccb48a3a813d4a45ac99 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 25 Dec 2014 12:40:35 +0100 Subject: Remove sp_style_write_string() and sp_style_write_difference(). (bzr r13822.1.4) --- src/style.cpp | 94 +++++++++++++++++------------------------------------------ 1 file changed, 27 insertions(+), 67 deletions(-) (limited to 'src/style.cpp') 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") <_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; } -- cgit v1.2.3 From 3598d85ed64693808296324289a2d6e5284d486e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 25 Dec 2014 17:05:40 +0100 Subject: Remove sp_style_merge_from_parent() and sp_style_merge_from_dying_parent(). (bzr r13822.1.5) --- src/style.cpp | 81 +++++++++++++++++++++-------------------------------------- 1 file changed, 28 insertions(+), 53 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index a26c92e48..739c7bdb5 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -947,6 +947,17 @@ SPStyle::write( guint const flags, SPStyle const *const base ) const { } // Corresponds to sp_style_merge_from_parent() +/** + * Sets computed values in \a style, which may involve inheriting from (or in some other way + * calculating from) corresponding computed values of \a parent. + * + * References: http://www.w3.org/TR/SVG11/propidx.html shows what properties inherit by default. + * http://www.w3.org/TR/SVG11/styling.html#Inheritance gives general rules as to what it means to + * inherit a value. http://www.w3.org/TR/REC-CSS2/cascade.html#computed-value is more precise + * about what the computed value is (not obvious for lengths). + * + * \pre \a parent's computed values are already up-to-date. + */ void SPStyle::cascade( SPStyle const *const parent ) { // std::cout << "SPStyle::cascade: " << (object->getId()?object->getId():"null") << std::endl; @@ -959,6 +970,23 @@ SPStyle::cascade( SPStyle const *const parent ) { } // Corresponds to sp_style_merge_from_dying_parent() +/** + * Combine \a style and \a parent style specifications into a single style specification that + * preserves (as much as possible) the effect of the existing \a style being a child of \a parent. + * + * Called when the parent repr is to be removed (e.g. the parent is a \ element that is being + * unlinked), in which case we copy/adapt property values that are explicitly set in \a parent, + * trying to retain the same visual appearance once the parent is removed. Interesting cases are + * when there is unusual interaction with the parent's value (opacity, display) or when the value + * can be specified as relative to the parent computed value (font-size, font-weight etc.). + * + * Doesn't update computed values of \a style. For correctness, you should subsequently call + * sp_style_merge_from_parent against the new parent (presumably \a parent's parent) even if \a + * style was previously up-to-date wrt \a parent. + * + * \pre \a parent's computed values are already up-to-date. + * (\a style's computed values needn't be up-to-date.) + */ void SPStyle::merge( SPStyle const *const parent ) { // std::cout << "SPStyle::merge" << std::endl; @@ -1268,62 +1296,9 @@ sp_repr_sel_eng() return ret; } - -// Called in text-editting.cpp, ui/tools/frehand-base.cpp, ui/widget/style-swatch.cpp - /** 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}; -// Called in sp-object.cpp, sp-tref.cpp, sp-use.cpp -/** - * Sets computed values in \a style, which may involve inheriting from (or in some other way - * calculating from) corresponding computed values of \a parent. - * - * References: http://www.w3.org/TR/SVG11/propidx.html shows what properties inherit by default. - * http://www.w3.org/TR/SVG11/styling.html#Inheritance gives general rules as to what it means to - * inherit a value. http://www.w3.org/TR/REC-CSS2/cascade.html#computed-value is more precise - * about what the computed value is (not obvious for lengths). - * - * \pre \a parent's computed values are already up-to-date. - */ -void -sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent) -{ - // std::cout << "sp_style_merge_from_parent" << std::endl; - g_return_if_fail(style != NULL); - - if (!parent) - return; - - style->cascade( parent ); - return; -} - -// Called in: sp-use.cpp, sp-tref.cpp, sp-item.cpp -/** - * Combine \a style and \a parent style specifications into a single style specification that - * preserves (as much as possible) the effect of the existing \a style being a child of \a parent. - * - * Called when the parent repr is to be removed (e.g. the parent is a \ element that is being - * unlinked), in which case we copy/adapt property values that are explicitly set in \a parent, - * trying to retain the same visual appearance once the parent is removed. Interesting cases are - * when there is unusual interaction with the parent's value (opacity, display) or when the value - * can be specified as relative to the parent computed value (font-size, font-weight etc.). - * - * Doesn't update computed values of \a style. For correctness, you should subsequently call - * sp_style_merge_from_parent against the new parent (presumably \a parent's parent) even if \a - * style was previously up-to-date wrt \a parent. - * - * \pre \a parent's computed values are already up-to-date. - * (\a style's computed values needn't be up-to-date.) - */ -void -sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const parent) -{ - // std::cout << "sp_style_merge_from_dying_parent" << std::endl; - style->merge( parent ); -} - // The following functions should be incorporated into SPIPaint. FIXME // Called in: style.cpp, style-internal.cpp void -- cgit v1.2.3 From 05f2f043bdbadefa4ea435981e1a728420d6b93c Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 25 Dec 2014 20:30:29 +0100 Subject: Remove sp_style_new(). (bzr r13822.1.6) --- src/style.cpp | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index 739c7bdb5..1d08db4f8 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -1228,21 +1228,6 @@ sp_style_stroke_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPSty sp_style_paint_server_ref_modified(ref, 0, style); } -// Called in: desktop-style.cpp, gradient-chemistry.cpp, sp-object.cpp, sp-stop.cpp, style.cpp -// text-editing.cpp, libnrtype/font-lister.cpp, widgets/dash-selector.cpp, widgets/fill-style.cpp, -// widgets/stroke-style.cpp, widgets/text-toolbar.cpp, ui/dialog/glyphs.cpp, ui/dialog/swatches.cpp, -// ui/dialog/swatches.cpp, ui/dialog/text-edit.cpp. ui/tools/freehand-base.cpp, -// ui/widget/object-composite-settings.cpp, ui/widget/selected-style.cpp, ui/widget/style-swatch.cpp -/** - * Returns a new SPStyle object with default settings. - */ -SPStyle * -sp_style_new(SPDocument *document) -{ - SPStyle *const style = new SPStyle( document ); - return style; -} - // Called in display/drawing-item.cpp, display/nr-filter-primitive.cpp, libnrtype/Layout-TNG-Input.cpp /** * Increase refcount of style. @@ -1257,8 +1242,7 @@ sp_style_ref(SPStyle *style) return style; } -// Called in style.cpp, desktop-style.cpp, sp-object.cpp, sp-stop.cpp, text-editing.cpp -// display/drawing-group.cpp, ... +// Called in display/drawing-item.cpp, display/nr-filter-primitive.cpp, libnrtype/Layout-TNG-Input.cpp /** * Decrease refcount of style with possible destruction. */ -- cgit v1.2.3 From c784e87f3b53e823dfb303e296ede834accc9322 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 26 Dec 2014 15:44:07 +0100 Subject: SPStyle ref counting clean up. (bzr r13822.1.7) --- src/style.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/style.cpp') diff --git a/src/style.cpp b/src/style.cpp index 1d08db4f8..0772a4bce 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -458,6 +458,10 @@ SPStyle::~SPStyle() { _properties.clear(); + // Conjecture: all this SPStyle ref counting is not needed. SPObject creates an instance of + // SPStyle when it is constructed and deletes it when it is destructed. The refcount is + // incremented and decremented only in the files: display/drawing-item.cpp, + // display/nr-filter-primitive.cpp, and libnrtype/Layout-TNG-Input.cpp. if( _refcount > 1 ) { std::cerr << "SPStyle::~SPStyle: ref count greater than 1! " << _refcount << std::endl; } @@ -1237,7 +1241,7 @@ sp_style_ref(SPStyle *style) { g_return_val_if_fail(style != NULL, NULL); - style->ref(); // Increase ref count + style->style_ref(); // Increase ref count return style; } @@ -1250,7 +1254,7 @@ SPStyle * sp_style_unref(SPStyle *style) { g_return_val_if_fail(style != NULL, NULL); - if (style->unref() < 1) { + if (style->style_unref() < 1) { delete style; return NULL; } -- cgit v1.2.3