summaryrefslogtreecommitdiffstats
path: root/src/display/drawing-item.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/display/drawing-item.cpp')
-rw-r--r--src/display/drawing-item.cpp145
1 files changed, 103 insertions, 42 deletions
diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp
index 8ed74b550..89ca66dc4 100644
--- a/src/display/drawing-item.cpp
+++ b/src/display/drawing-item.cpp
@@ -109,6 +109,8 @@ DrawingItem::DrawingItem(Drawing &drawing)
: _drawing(drawing)
, _parent(NULL)
, _key(0)
+ , _style(NULL)
+ , _context_style(NULL)
, _opacity(1.0)
, _transform(NULL)
, _clip(NULL)
@@ -188,6 +190,8 @@ DrawingItem::~DrawingItem()
delete _clip;
delete _mask;
delete _filter;
+ if(_style)
+ sp_style_unref(_style);
}
DrawingItem *
@@ -351,6 +355,72 @@ 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, SPStyle *context_style)
+{
+ // std::cout << "DrawingItem::setStyle: " << name() << " " << style
+ // << " " << context_style << std::endl;
+
+ 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()));
+ _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);
+ }
+ }
+
+ 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)
{
@@ -908,6 +978,39 @@ DrawingItem::pick(Geom::Point const &p, double delta, unsigned flags)
return NULL;
}
+// For debugging
+Glib::ustring
+DrawingItem::name()
+{
+ SPObject *object = static_cast<SPObject *>(_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
+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 << " ";
+ }
+ std::cout << name() << 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.
@@ -998,48 +1101,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.
*
* Higher scores mean the item is more aggresively prioritized for automatic