summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-12-16 16:45:03 +0000
committertavmjong-free <tavmjong@free.fr>2014-12-16 16:45:03 +0000
commit61f4ad6f7569805e50488d4af92756b310c51246 (patch)
tree45f8df080a1b5e63a856e6fd3a99a468fd3b9f1c /src/display
parentDebugging routines to print out XML, SP Object, and Display Item trees. (diff)
downloadinkscape-61f4ad6f7569805e50488d4af92756b310c51246.tar.gz
inkscape-61f4ad6f7569805e50488d4af92756b310c51246.zip
Code rearrangement to make it clearer what is happening.
(bzr r13803)
Diffstat (limited to 'src/display')
-rw-r--r--src/display/drawing-group.cpp9
-rw-r--r--src/display/drawing-group.h4
-rw-r--r--src/display/drawing-image.cpp11
-rw-r--r--src/display/drawing-image.h2
-rw-r--r--src/display/drawing-item.cpp91
-rw-r--r--src/display/drawing-item.h3
-rw-r--r--src/display/drawing-shape.cpp5
-rw-r--r--src/display/drawing-shape.h3
-rw-r--r--src/display/drawing-text.cpp7
-rw-r--r--src/display/drawing-text.h1
10 files changed, 61 insertions, 75 deletions
diff --git a/src/display/drawing-group.cpp b/src/display/drawing-group.cpp
index bce89d70e..1a9cbfdcc 100644
--- a/src/display/drawing-group.cpp
+++ b/src/display/drawing-group.cpp
@@ -21,14 +21,11 @@ namespace Inkscape {
DrawingGroup::DrawingGroup(Drawing &drawing)
: DrawingItem(drawing)
- , _style(NULL)
, _child_transform(NULL)
{}
DrawingGroup::~DrawingGroup()
{
- if (_style)
- sp_style_unref(_style);
delete _child_transform; // delete NULL; is safe
}
@@ -42,12 +39,6 @@ DrawingGroup::setPickChildren(bool p)
_pick_children = p;
}
-void
-DrawingGroup::setStyle(SPStyle *style)
-{
- _setStyleCommon(_style, style);
-}
-
/**
* Set additional transform for the group.
* This is applied after the normal transform and mainly useful for
diff --git a/src/display/drawing-group.h b/src/display/drawing-group.h
index ab1f9895d..0c985b43f 100644
--- a/src/display/drawing-group.h
+++ b/src/display/drawing-group.h
@@ -14,8 +14,6 @@
#include "display/drawing-item.h"
-class SPStyle;
-
namespace Inkscape {
class DrawingGroup
@@ -28,7 +26,6 @@ public:
bool pickChildren() { return _pick_children; }
void setPickChildren(bool p);
- void setStyle(SPStyle *style);
void setChildTransform(Geom::Affine const &new_trans);
protected:
@@ -40,7 +37,6 @@ protected:
virtual DrawingItem *_pickItem(Geom::Point const &p, double delta, unsigned flags);
virtual bool _canClip();
- SPStyle *_style;
Geom::Affine *_child_transform;
};
diff --git a/src/display/drawing-image.cpp b/src/display/drawing-image.cpp
index e56f3e58b..8fe337959 100644
--- a/src/display/drawing-image.cpp
+++ b/src/display/drawing-image.cpp
@@ -24,15 +24,10 @@ namespace Inkscape {
DrawingImage::DrawingImage(Drawing &drawing)
: DrawingItem(drawing)
, _pixbuf(NULL)
- , _style(NULL)
{}
DrawingImage::~DrawingImage()
{
- if (_style) {
- sp_style_unref(_style);
- }
-
// _pixbuf is owned by SPImage - do not delete it
}
@@ -45,12 +40,6 @@ DrawingImage::setPixbuf(Inkscape::Pixbuf *pb)
}
void
-DrawingImage::setStyle(SPStyle *style)
-{
- _setStyleCommon(_style, style);
-}
-
-void
DrawingImage::setScale(double sx, double sy)
{
_scale = Geom::Scale(sx, sy);
diff --git a/src/display/drawing-image.h b/src/display/drawing-image.h
index 64e4517b0..7511768c9 100644
--- a/src/display/drawing-image.h
+++ b/src/display/drawing-image.h
@@ -29,7 +29,6 @@ public:
~DrawingImage();
void setPixbuf(Inkscape::Pixbuf *pb);
- void setStyle(SPStyle *style);
void setScale(double sx, double sy);
void setOrigin(Geom::Point const &o);
void setClipbox(Geom::Rect const &box);
@@ -43,7 +42,6 @@ protected:
virtual DrawingItem *_pickItem(Geom::Point const &p, double delta, unsigned flags);
Inkscape::Pixbuf *_pixbuf;
- SPStyle *_style;
// TODO: the following three should probably be merged into a new Geom::Viewbox object
Geom::Rect _clipbox; ///< for preserveAspectRatio
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<SPObject *>(_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)
{
@@ -1022,48 +1071,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
diff --git a/src/display/drawing-item.h b/src/display/drawing-item.h
index 585f3811f..89331c13d 100644
--- a/src/display/drawing-item.h
+++ b/src/display/drawing-item.h
@@ -108,6 +108,7 @@ public:
bool cached() const { return _cached; }
void setCached(bool c, bool persistent = false);
+ virtual void setStyle(SPStyle *style);
void setOpacity(float opacity);
void setAntialiasing(bool a);
void setIsolation(unsigned isolation); // CSS Compositing and Blending
@@ -151,7 +152,6 @@ protected:
void _markForUpdate(unsigned state, bool propagate);
void _markForRendering();
void _invalidateFilterBackground(Geom::IntRect const &area);
- void _setStyleCommon(SPStyle *&_style, SPStyle *style);
double _cacheScore();
Geom::OptIntRect _cacheRect();
virtual unsigned _updateItem(Geom::IntRect const &/*area*/, UpdateContext const &/*ctx*/,
@@ -178,6 +178,7 @@ protected:
unsigned _key; ///< Some SPItems can have more than one DrawingItem;
/// this value is a hack used to distinguish between them
+ SPStyle *_style; // Not used by DrawingGlyphs
float _opacity;
Geom::Affine *_transform; ///< Incremental transform from parent to this item's coords
diff --git a/src/display/drawing-shape.cpp b/src/display/drawing-shape.cpp
index 66160638f..5bdc7a323 100644
--- a/src/display/drawing-shape.cpp
+++ b/src/display/drawing-shape.cpp
@@ -34,15 +34,12 @@ namespace Inkscape {
DrawingShape::DrawingShape(Drawing &drawing)
: DrawingItem(drawing)
, _curve(NULL)
- , _style(NULL)
, _last_pick(NULL)
, _repick_after(0)
{}
DrawingShape::~DrawingShape()
{
- if (_style)
- sp_style_unref(_style);
if (_curve)
_curve->unref();
}
@@ -67,8 +64,8 @@ DrawingShape::setPath(SPCurve *curve)
void
DrawingShape::setStyle(SPStyle *style)
{
- _setStyleCommon(_style, style);
_nrstyle.set(style);
+ DrawingItem::setStyle(style);
}
unsigned
diff --git a/src/display/drawing-shape.h b/src/display/drawing-shape.h
index 9d93a642f..1c921b21f 100644
--- a/src/display/drawing-shape.h
+++ b/src/display/drawing-shape.h
@@ -28,7 +28,7 @@ public:
~DrawingShape();
void setPath(SPCurve *curve);
- void setStyle(SPStyle *style);
+ virtual void setStyle(SPStyle *style);
protected:
virtual unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx,
@@ -45,7 +45,6 @@ protected:
DrawingItem *stop_at);
SPCurve *_curve;
- SPStyle *_style;
NRStyle _nrstyle;
DrawingItem *_last_pick;
diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp
index afe661b2e..58305477b 100644
--- a/src/display/drawing-text.cpp
+++ b/src/display/drawing-text.cpp
@@ -55,6 +55,13 @@ DrawingGlyphs::setGlyph(font_instance *font, int glyph, Geom::Affine const &tran
_markForUpdate(STATE_ALL, false);
}
+void
+DrawingGlyphs::setStyle(SPStyle *style)
+{
+ std::cerr << "DrawingGlyphs: Use parent style" << std::endl;
+}
+
+
unsigned DrawingGlyphs::_updateItem(Geom::IntRect const &/*area*/, UpdateContext const &ctx, unsigned /*flags*/, unsigned /*reset*/)
{
DrawingText *ggroup = dynamic_cast<DrawingText *>(_parent);
diff --git a/src/display/drawing-text.h b/src/display/drawing-text.h
index 4453a3db4..37c1e81c7 100644
--- a/src/display/drawing-text.h
+++ b/src/display/drawing-text.h
@@ -28,6 +28,7 @@ public:
~DrawingGlyphs();
void setGlyph(font_instance *font, int glyph, Geom::Affine const &trans);
+ void setStyle(SPStyle *style); // Not to be used, prints error message.
protected:
unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx,