From 0533bf991e946b09053753566f209940f500d368 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 16 Dec 2014 15:05:47 +0100 Subject: Debugging routines to print out XML, SP Object, and Display Item trees. (bzr r13802) --- src/display/drawing-item.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/display/drawing-item.cpp') diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 8ed74b550..8a438e1c2 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -908,6 +908,30 @@ DrawingItem::pick(Geom::Point const &p, double delta, unsigned flags) return NULL; } + +// For debugging: Print drawing tree structure. +void +DrawingItem::recursivePrintTree( unsigned level ) +{ + if (level == 0) { + std::cout << "Display Item Tree" << std::endl; + } + std::cout << "DI: "; + for (unsigned i = 0; i < level; ++i) { + std::cout << " "; + } + SPObject *object = static_cast(_user_data); + if (object) { + std::cout << (object->getId()?object->getId():"No object id") << std::endl; + } else { + std::cout << "No associated object" << std::endl; + } + for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { + i->recursivePrintTree( level+1 ); + } +} + + /** * Marks the current visual bounding box of the item for redrawing. * This is called whenever the object changes its visible appearance. -- cgit v1.2.3 From 61f4ad6f7569805e50488d4af92756b310c51246 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 16 Dec 2014 17:45:03 +0100 Subject: Code rearrangement to make it clearer what is happening. (bzr r13803) --- src/display/drawing-item.cpp | 91 ++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 42 deletions(-) (limited to 'src/display/drawing-item.cpp') diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 8a438e1c2..407adc255 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -109,6 +109,7 @@ DrawingItem::DrawingItem(Drawing &drawing) : _drawing(drawing) , _parent(NULL) , _key(0) + , _style(NULL) , _opacity(1.0) , _transform(NULL) , _clip(NULL) @@ -188,6 +189,8 @@ DrawingItem::~DrawingItem() delete _clip; delete _mask; delete _filter; + if(_style) + sp_style_unref(_style); } DrawingItem * @@ -351,6 +354,52 @@ DrawingItem::setCached(bool cached, bool persistent) } } +/** + * Process information related to the new style. + * + * Note: _style is not used by DrawingGlyphs which uses its parent style. + */ +void +DrawingItem::setStyle(SPStyle *style) +{ + // std::cout << "DrawingItem::setStyle: "; + // SPObject *item = static_cast(_user_data); + // if( item ) { + // std::cout << (item->getId()?item->getId():"null") << std::endl; + // } else { + // std::cout << "No item" << std::endl; + // } + + if (style) sp_style_ref(style); + if (_style) sp_style_unref(_style); + _style = style; + + if (style && style->filter.set && style->getFilter()) { + if (!_filter) { + int primitives = sp_filter_primitive_count(SP_FILTER(style->getFilter())); + _filter = new Inkscape::Filters::Filter(primitives); + } + sp_filter_build_renderer(SP_FILTER(style->getFilter()), _filter); + } else { + // no filter set for this group + delete _filter; + _filter = NULL; + } + + if (style && style->enable_background.set) { + if (style->enable_background.value == SP_CSS_BACKGROUND_NEW && !_background_new) { + _background_new = true; + _markForUpdate(STATE_BACKGROUND, true); + } else if (style->enable_background.value == SP_CSS_BACKGROUND_ACCUMULATE && _background_new) { + _background_new = false; + _markForUpdate(STATE_BACKGROUND, true); + } + } + + _markForUpdate(STATE_ALL, false); +} + + void DrawingItem::setClip(DrawingItem *item) { @@ -1021,48 +1070,6 @@ DrawingItem::_markForUpdate(unsigned flags, bool propagate) } } -/** - * Process information related to the new style. - * - * This function is something of a hack to avoid creating an extra class in the hierarchy - * which would differ from DrawingItem only by having a _style member. - * This is mainly to the benefit of DrawingGlyphs, which use the style of their parent. - * This should probably be refactored some day, possibly by creating the relevant class - * or creating a more complex data model in DrawingText and removing DrawingGlyphs, - * which would cause every item to have a style. - */ -void -DrawingItem::_setStyleCommon(SPStyle *&_style, SPStyle *style) -{ - if (style) sp_style_ref(style); - if (_style) sp_style_unref(_style); - _style = style; - - if (style && style->filter.set && style->getFilter()) { - if (!_filter) { - int primitives = sp_filter_primitive_count(SP_FILTER(style->getFilter())); - _filter = new Inkscape::Filters::Filter(primitives); - } - sp_filter_build_renderer(SP_FILTER(style->getFilter()), _filter); - } else { - // no filter set for this group - delete _filter; - _filter = NULL; - } - - if (style && style->enable_background.set) { - if (style->enable_background.value == SP_CSS_BACKGROUND_NEW && !_background_new) { - _background_new = true; - _markForUpdate(STATE_BACKGROUND, true); - } else if (style->enable_background.value == SP_CSS_BACKGROUND_ACCUMULATE && _background_new) { - _background_new = false; - _markForUpdate(STATE_BACKGROUND, true); - } - } - - _markForUpdate(STATE_ALL, false); -} - /** * Compute the caching score. * -- cgit v1.2.3 From b6d303d11e572d8888d29c44e11d06d256821a03 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 21 Dec 2014 15:29:02 +0100 Subject: Implement rendering for 'context-fill' and 'context-stroke' (text not handled yet). (bzr r13807) --- src/display/drawing-item.cpp | 56 +++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'src/display/drawing-item.cpp') diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 407adc255..83d4744c9 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -110,6 +110,7 @@ DrawingItem::DrawingItem(Drawing &drawing) , _parent(NULL) , _key(0) , _style(NULL) + , _context_style(NULL) , _opacity(1.0) , _transform(NULL) , _clip(NULL) @@ -360,15 +361,10 @@ DrawingItem::setCached(bool cached, bool persistent) * Note: _style is not used by DrawingGlyphs which uses its parent style. */ void -DrawingItem::setStyle(SPStyle *style) +DrawingItem::setStyle(SPStyle *style, SPStyle *context_style) { - // std::cout << "DrawingItem::setStyle: "; - // SPObject *item = static_cast(_user_data); - // if( item ) { - // std::cout << (item->getId()?item->getId():"null") << std::endl; - // } else { - // std::cout << "No item" << std::endl; - // } + // std::cout << "DrawingItem::setStyle: " << name() << " " << style + // << " " << context_style << std::endl; if (style) sp_style_ref(style); if (_style) sp_style_unref(_style); @@ -396,10 +392,33 @@ DrawingItem::setStyle(SPStyle *style) } } + if (context_style != NULL) { + _context_style = context_style; + } else if (_parent != NULL) { + _context_style = _parent->_context_style; + } + _markForUpdate(STATE_ALL, false); } +/** + * Recursively update children style. + * The purpose of this call is to update fill and stroke for markers that have elements with + * fill/stroke property values of 'context-fill' or 'context-stroke'. Marker styling is not + * updated like other 'clones' as marker instances are not included the SP object tree. + * Note: this is a virtual function. + */ +void +DrawingItem::setChildrenStyle(SPStyle* context_style) +{ + _context_style = context_style; + for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { + i->setChildrenStyle( context_style ); + } +} + + void DrawingItem::setClip(DrawingItem *item) { @@ -957,6 +976,20 @@ DrawingItem::pick(Geom::Point const &p, double delta, unsigned flags) return NULL; } +// For debugging +Glib::ustring +DrawingItem::name() +{ + SPObject *object = static_cast(_user_data); + if (object) { + if(object->getId()) + return object->getId(); + else + return "No object id"; + } else { + return "No associated object"; + } +} // For debugging: Print drawing tree structure. void @@ -969,12 +1002,7 @@ DrawingItem::recursivePrintTree( unsigned level ) for (unsigned i = 0; i < level; ++i) { std::cout << " "; } - SPObject *object = static_cast(_user_data); - if (object) { - std::cout << (object->getId()?object->getId():"No object id") << std::endl; - } else { - std::cout << "No associated object" << std::endl; - } + std::cout << name() << std::endl; for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { i->recursivePrintTree( level+1 ); } -- 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/display/drawing-item.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/display/drawing-item.cpp') diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 83d4744c9..89ca66dc4 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -366,10 +366,12 @@ DrawingItem::setStyle(SPStyle *style, SPStyle *context_style) // std::cout << "DrawingItem::setStyle: " << name() << " " << style // << " " << context_style << std::endl; - if (style) sp_style_ref(style); - if (_style) sp_style_unref(_style); - _style = style; - + if( style != _style ) { + if (style) sp_style_ref(style); + if (_style) sp_style_unref(_style); + _style = style; + } + if (style && style->filter.set && style->getFilter()) { if (!_filter) { int primitives = sp_filter_primitive_count(SP_FILTER(style->getFilter())); -- cgit v1.2.3