summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-01-16 16:18:45 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-01-16 16:18:45 +0000
commit03cb69220632b0c674efff5be3aab8be35d23eff (patch)
tree464a1f74c57b796604ceb38c1687d579d2891800 /src/display
parentupdate to trunk (diff)
parentTest implementation of 'shape-padding'. (diff)
downloadinkscape-03cb69220632b0c674efff5be3aab8be35d23eff.tar.gz
inkscape-03cb69220632b0c674efff5be3aab8be35d23eff.zip
update to trunk
(bzr r13708.1.7)
Diffstat (limited to 'src/display')
-rw-r--r--src/display/canvas-axonomgrid.cpp59
-rw-r--r--src/display/canvas-grid.cpp142
-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.cpp145
-rw-r--r--src/display/drawing-item.h13
-rw-r--r--src/display/drawing-pattern.h1
-rw-r--r--src/display/drawing-shape.cpp17
-rw-r--r--src/display/drawing-shape.h4
-rw-r--r--src/display/drawing-text.cpp20
-rw-r--r--src/display/drawing-text.h5
-rw-r--r--src/display/nr-filter-primitive.cpp10
-rw-r--r--src/display/nr-filter-turbulence.cpp6
-rw-r--r--src/display/nr-style.cpp82
-rw-r--r--src/display/nr-style.h3
-rw-r--r--src/display/snap-indicator.cpp12
18 files changed, 364 insertions, 181 deletions
diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp
index 592c962a6..05ba71a49 100644
--- a/src/display/canvas-axonomgrid.cpp
+++ b/src/display/canvas-axonomgrid.cpp
@@ -36,7 +36,7 @@
#include "ui/widget/registered-widget.h"
#include "desktop.h"
-#include "desktop-handles.h"
+
#include "display/cairo-utils.h"
#include "display/canvas-grid.h"
#include "display/sp-canvas-util.h"
@@ -46,6 +46,7 @@
#include "preferences.h"
#include "sp-namedview.h"
#include "sp-object.h"
+#include "sp-root.h"
#include "svg/svg-color.h"
#include "2geom/line.h"
#include "2geom/angle.h"
@@ -213,22 +214,53 @@ static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color)
void
CanvasAxonomGrid::readRepr()
{
+ SPRoot *root = doc->getRoot();
+ double scale_x = 1.0;
+ double scale_y = 1.0;
+ if( root->viewBox_set ) {
+ scale_x = root->width.computed / root->viewBox.width();
+ scale_y = root->height.computed / root->viewBox.height();
+ }
+
gchar const *value;
+
if ( (value = repr->attribute("originx")) ) {
+
Inkscape::Util::Quantity q = unit_table.parseQuantity(value);
- gridunit = q.unit;
- origin[Geom::X] = q.value("px");
+
+ if( q.unit->type == UNIT_TYPE_LINEAR ) {
+ // Legacy grid not in 'user units'
+ origin[Geom::X] = q.value("px");
+ } else {
+ // Grid in 'user units'
+ origin[Geom::X] = q.quantity * scale_x;
+ }
}
+
if ( (value = repr->attribute("originy")) ) {
+
Inkscape::Util::Quantity q = unit_table.parseQuantity(value);
- gridunit = q.unit;
- origin[Geom::Y] = q.value("px");
+
+ if( q.unit->type == UNIT_TYPE_LINEAR ) {
+ // Legacy grid not in 'user units'
+ origin[Geom::Y] = q.value("px");
+ } else {
+ // Grid in 'user units'
+ origin[Geom::Y] = q.quantity * scale_y;
+ }
}
if ( (value = repr->attribute("spacingy")) ) {
+
Inkscape::Util::Quantity q = unit_table.parseQuantity(value);
- gridunit = q.unit;
- lengthy = q.value("px");
+
+ if( q.unit->type == UNIT_TYPE_LINEAR ) {
+ // Legacy grid not in 'user units'
+ lengthy = q.value("px");
+ } else {
+ // Grid in 'user units'
+ lengthy = q.quantity * scale_y; // We do not handle scale_x != scale_y
+ }
if (lengthy < 0.0500) lengthy = 0.0500;
}
@@ -281,6 +313,10 @@ CanvasAxonomGrid::readRepr()
snapper->setSnapVisibleOnly(strcmp(value,"false") != 0 && strcmp(value, "0") != 0);
}
+ if ( (value = repr->attribute("units")) ) {
+ gridunit = unit_table.getUnit(value); // Display unit identifier in grid menu
+ }
+
for (GSList *l = canvasitems; l != NULL; l = l->next) {
sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) );
}
@@ -316,11 +352,14 @@ _wr.setUpdating (true);
Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu(
_("Grid _units:"), "units", _wr, repr, doc) );
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
- _("_Origin X:"), _("X coordinate of grid origin"), "originx", *_rumg, _wr, repr, doc) );
+ _("_Origin X:"), _("X coordinate of grid origin"), "originx",
+ *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_x) );
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
- _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", *_rumg, _wr, repr, doc) );
+ _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy",
+ *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_y) );
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
- _("Spacing _Y:"), _("Base length of z-axis"), "spacingy", *_rumg, _wr, repr, doc) );
+ _("Spacing _Y:"), _("Base length of z-axis"), "spacingy",
+ *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_y) );
Inkscape::UI::Widget::RegisteredScalar *_rsu_ax = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar(
_("Angle X:"), _("Angle of x-axis"), "gridanglex", _wr, repr, doc ) );
Inkscape::UI::Widget::RegisteredScalar *_rsu_az = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar(
diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp
index 2eeaa7006..1a284b46e 100644
--- a/src/display/canvas-grid.cpp
+++ b/src/display/canvas-grid.cpp
@@ -36,7 +36,7 @@
#include "desktop.h"
#include "sp-canvas-util.h"
#include "util/mathfns.h"
-#include "desktop-handles.h"
+
#include "display/cairo-utils.h"
#include "display/canvas-axonomgrid.h"
#include "display/canvas-grid.h"
@@ -47,6 +47,7 @@
#include "preferences.h"
#include "sp-namedview.h"
#include "sp-object.h"
+#include "sp-root.h"
#include "svg/svg-color.h"
#include "svg/stringstream.h"
#include "util/mathfns.h"
@@ -284,12 +285,12 @@ CanvasGrid::createCanvasItem(SPDesktop * desktop)
// check if there is already a canvasitem on this desktop linking to this grid
for (GSList *l = canvasitems; l != NULL; l = l->next) {
- if ( sp_desktop_gridgroup(desktop) == SP_CANVAS_GROUP(SP_CANVAS_ITEM(l->data)->parent) ) {
+ if ( desktop->getGridGroup() == SP_CANVAS_GROUP(SP_CANVAS_ITEM(l->data)->parent) ) {
return NULL;
}
}
- GridCanvasItem * item = INKSCAPE_GRID_CANVASITEM( sp_canvas_item_new(sp_desktop_gridgroup(desktop), INKSCAPE_TYPE_GRID_CANVASITEM, NULL) );
+ GridCanvasItem * item = INKSCAPE_GRID_CANVASITEM( sp_canvas_item_new(desktop->getGridGroup(), INKSCAPE_TYPE_GRID_CANVASITEM, NULL) );
item->grid = this;
sp_canvas_item_show(SP_CANVAS_ITEM(item));
@@ -367,17 +368,21 @@ bool CanvasGrid::isEnabled() const
return snapper->getEnabled();
}
+// Used to shift origin when page size changed to fit drawing.
void CanvasGrid::setOrigin(Geom::Point const &origin_px)
{
- Inkscape::SVGOStringStream os_x, os_y;
- gdouble val;
+ SPRoot *root = doc->getRoot();
+ double scale_x = 1.0;
+ double scale_y = 1.0;
+ if( root->viewBox_set ) {
+ scale_x = root->viewBox.width() / root->width.computed;
+ scale_y = root->viewBox.height() / root->height.computed;
+ }
- val = origin_px[Geom::X];
- val = Inkscape::Util::Quantity::convert(val, "px", gridunit);
- os_x << val << gridunit->abbr;
- val = origin_px[Geom::Y];
- val = Inkscape::Util::Quantity::convert(val, "px", gridunit);
- os_y << val << gridunit->abbr;
+ // Write out in 'user-units'
+ Inkscape::SVGOStringStream os_x, os_y;
+ os_x << origin_px[Geom::X] * scale_x;
+ os_y << origin_px[Geom::Y] * scale_y;
repr->setAttribute("originx", os_x.str().c_str());
repr->setAttribute("originy", os_y.str().c_str());
}
@@ -504,33 +509,6 @@ static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color)
return TRUE;
}
-/** If the passed scalar is invalid (<=0), then set the widget and the scalar
- to use the given old value.
-
- @param oldVal Old value to use if the new one is invalid.
- @param pTarget The scalar to validate.
- @param widget Widget associated with the scalar.
-*/
-static void validateScalar(double oldVal,
- double* pTarget)
-{
- // Avoid nullness.
- if ( pTarget == NULL )
- return;
-
- // Invalid new value?
- if ( *pTarget <= 0 ) {
- // If the old value is somehow invalid as well, then default to 1.
- if ( oldVal <= 0 )
- oldVal = 1;
-
- // Reset the scalar and associated widget to the old value.
- *pTarget = oldVal;
- } //if
-
-} //validateScalar
-
-
/** If the passed int is invalid (<=0), then set the widget and the int
to use the given old value.
@@ -560,34 +538,78 @@ static void validateInt(gint oldVal,
void
CanvasXYGrid::readRepr()
{
+ SPRoot *root = doc->getRoot();
+ double scale_x = 1.0;
+ double scale_y = 1.0;
+ if( root->viewBox_set ) {
+ scale_x = root->width.computed / root->viewBox.width();
+ scale_y = root->height.computed / root->viewBox.height();
+ }
+
gchar const *value;
+
if ( (value = repr->attribute("originx")) ) {
+
Inkscape::Util::Quantity q = unit_table.parseQuantity(value);
- gridunit = q.unit;
- origin[Geom::X] = q.value("px");
+
+ if( q.unit->type == UNIT_TYPE_LINEAR ) {
+ // Legacy grid not in 'user units'
+ origin[Geom::X] = q.value("px");
+ } else {
+ // Grid in 'user units'
+ origin[Geom::X] = q.quantity * scale_x;
+ }
}
if ( (value = repr->attribute("originy")) ) {
+
Inkscape::Util::Quantity q = unit_table.parseQuantity(value);
- gridunit = q.unit;
- origin[Geom::Y] = q.value("px");
+
+ if( q.unit->type == UNIT_TYPE_LINEAR ) {
+ // Legacy grid not in 'user units'
+ origin[Geom::Y] = q.value("px");
+ } else {
+ // Grid in 'user units'
+ origin[Geom::Y] = q.quantity * scale_y;
+ }
}
if ( (value = repr->attribute("spacingx")) ) {
- double oldVal = spacing[Geom::X];
+
+ // Ensure a valid default value
+ if( spacing[Geom::X] <= 0.0 )
+ spacing[Geom::X] = 1.0;
+
Inkscape::Util::Quantity q = unit_table.parseQuantity(value);
- gridunit = q.unit;
- spacing[Geom::X] = q.quantity;
- validateScalar(oldVal, &spacing[Geom::X]);
- spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], gridunit, "px");
+ // Ensure a valid new value
+ if( q.quantity > 0 ) {
+ if( q.unit->type == UNIT_TYPE_LINEAR ) {
+ // Legacy grid not in 'user units'
+ spacing[Geom::X] = q.value("px");
+ } else {
+ // Grid in 'user units'
+ spacing[Geom::X] = q.quantity * scale_x;
+ }
+ }
}
+
if ( (value = repr->attribute("spacingy")) ) {
- double oldVal = spacing[Geom::Y];
+
+ // Ensure a valid default value
+ if( spacing[Geom::Y] <= 0.0 )
+ spacing[Geom::Y] = 1.0;
+
Inkscape::Util::Quantity q = unit_table.parseQuantity(value);
- gridunit = q.unit;
- spacing[Geom::Y] = q.quantity;
- validateScalar(oldVal, &spacing[Geom::Y]);
- spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], gridunit, "px");
+ // Ensure a valid new value
+ if( q.quantity > 0 ) {
+ if( q.unit->type == UNIT_TYPE_LINEAR ) {
+ // Legacy grid not in 'user units'
+ spacing[Geom::Y] = q.value("px");
+ } else {
+ // Grid in 'user units'
+ spacing[Geom::Y] = q.quantity * scale_y;
+ }
+ }
}
if ( (value = repr->attribute("color")) ) {
@@ -629,6 +651,10 @@ CanvasXYGrid::readRepr()
snapper->setSnapVisibleOnly(strcmp(value,"false") != 0 && strcmp(value, "0") != 0);
}
+ if ( (value = repr->attribute("units")) ) {
+ gridunit = unit_table.getUnit(value); // Display unit identifier in grid menu
+ }
+
for (GSList *l = canvasitems; l != NULL; l = l->next) {
sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) );
}
@@ -666,13 +692,17 @@ CanvasXYGrid::newSpecificWidget()
Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu(
_("Grid _units:"), "units", _wr, repr, doc) );
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
- _("_Origin X:"), _("X coordinate of grid origin"), "originx", *_rumg, _wr, repr, doc) );
+ _("_Origin X:"), _("X coordinate of grid origin"), "originx",
+ *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_x) );
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
- _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", *_rumg, _wr, repr, doc) );
+ _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy",
+ *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_y) );
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
- _("Spacing _X:"), _("Distance between vertical grid lines"), "spacingx", *_rumg, _wr, repr, doc) );
+ _("Spacing _X:"), _("Distance between vertical grid lines"), "spacingx",
+ *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_x) );
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
- _("Spacing _Y:"), _("Distance between horizontal grid lines"), "spacingy", *_rumg, _wr, repr, doc) );
+ _("Spacing _Y:"), _("Distance between horizontal grid lines"), "spacingy",
+ *_rumg, _wr, repr, doc, Inkscape::UI::Widget::RSU_y) );
Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gcol = Gtk::manage(
new Inkscape::UI::Widget::RegisteredColorPicker(
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 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
diff --git a/src/display/drawing-item.h b/src/display/drawing-item.h
index 9b399e6e3..3c593ceaa 100644
--- a/src/display/drawing-item.h
+++ b/src/display/drawing-item.h
@@ -20,6 +20,10 @@
#include <exception>
#include <list>
+namespace Glib {
+class ustring;
+}
+
class SPStyle;
namespace Inkscape {
@@ -108,6 +112,8 @@ public:
bool cached() const { return _cached; }
void setCached(bool c, bool persistent = false);
+ virtual void setStyle(SPStyle *style, SPStyle *context_style = NULL);
+ virtual void setChildrenStyle(SPStyle *context_style);
void setOpacity(float opacity);
void setAntialiasing(bool a);
void setIsolation(unsigned isolation); // CSS Compositing and Blending
@@ -131,6 +137,9 @@ public:
void clip(DrawingContext &dc, Geom::IntRect const &area);
DrawingItem *pick(Geom::Point const &p, double delta, unsigned flags = 0);
+ virtual Glib::ustring name(); // For debugging
+ void recursivePrintTree(unsigned level = 0); // For debugging
+
protected:
enum ChildType {
CHILD_ORPHAN = 0, // no parent - implies _parent == NULL
@@ -149,7 +158,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*/,
@@ -176,6 +184,9 @@ 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
+ SPStyle *_context_style; // Used for 'context-fill', 'context-stroke'
+
float _opacity;
Geom::Affine *_transform; ///< Incremental transform from parent to this item's coords
diff --git a/src/display/drawing-pattern.h b/src/display/drawing-pattern.h
index 7483ba067..dc1f93ed1 100644
--- a/src/display/drawing-pattern.h
+++ b/src/display/drawing-pattern.h
@@ -15,7 +15,6 @@
#include "display/drawing-group.h"
typedef struct _cairo_pattern cairo_pattern_t;
-class SPStyle;
namespace Inkscape {
diff --git a/src/display/drawing-shape.cpp b/src/display/drawing-shape.cpp
index 66160638f..63efb3c0d 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();
}
@@ -65,10 +62,17 @@ DrawingShape::setPath(SPCurve *curve)
}
void
-DrawingShape::setStyle(SPStyle *style)
+DrawingShape::setStyle(SPStyle *style, SPStyle *context_style)
{
- _setStyleCommon(_style, style);
- _nrstyle.set(style);
+ DrawingItem::setStyle(style, context_style); // Must be first
+ _nrstyle.set(_style, _context_style);
+}
+
+void
+DrawingShape::setChildrenStyle(SPStyle* context_style)
+{
+ DrawingItem::setChildrenStyle( context_style );
+ _nrstyle.set(_style, _context_style);
}
unsigned
@@ -145,7 +149,6 @@ DrawingShape::_updateItem(Geom::IntRect const &area, UpdateContext const &ctx, u
_bbox.unionWith(i->geometricBounds());
}
}
-
return STATE_ALL;
}
diff --git a/src/display/drawing-shape.h b/src/display/drawing-shape.h
index 9d93a642f..1cdbc636e 100644
--- a/src/display/drawing-shape.h
+++ b/src/display/drawing-shape.h
@@ -28,7 +28,8 @@ public:
~DrawingShape();
void setPath(SPCurve *curve);
- void setStyle(SPStyle *style);
+ virtual void setStyle(SPStyle *style, SPStyle *context_style = NULL);
+ virtual void setChildrenStyle(SPStyle *context_style);
protected:
virtual unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx,
@@ -45,7 +46,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..e20a7ff2a 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*/, SPStyle * /*context_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);
@@ -216,10 +223,17 @@ DrawingText::addComponent(font_instance *font, int glyph, Geom::Affine const &tr
}
void
-DrawingText::setStyle(SPStyle *style)
+DrawingText::setStyle(SPStyle *style, SPStyle *context_style)
+{
+ DrawingGroup::setStyle(style, context_style); // Must be first
+ _nrstyle.set(_style, _context_style);
+}
+
+void
+DrawingText::setChildrenStyle(SPStyle* context_style)
{
- _nrstyle.set(style);
- DrawingGroup::setStyle(style);
+ DrawingGroup::setChildrenStyle( context_style );
+ _nrstyle.set(_style, _context_style);
}
unsigned
diff --git a/src/display/drawing-text.h b/src/display/drawing-text.h
index 4453a3db4..3d248df9b 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);
+ virtual void setStyle(SPStyle *style, SPStyle *context_style = NULL); // Not to be used
protected:
unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx,
@@ -56,8 +57,8 @@ public:
void clear();
bool addComponent(font_instance *font, int glyph, Geom::Affine const &trans,
float width, float ascent, float descent, float phase_length);
- void setStyle(SPStyle *style);
-
+ virtual void setStyle(SPStyle *style, SPStyle *context_style = NULL);
+ virtual void setChildrenStyle(SPStyle *context_style);
protected:
virtual unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx,
diff --git a/src/display/nr-filter-primitive.cpp b/src/display/nr-filter-primitive.cpp
index b065ac445..c8b569036 100644
--- a/src/display/nr-filter-primitive.cpp
+++ b/src/display/nr-filter-primitive.cpp
@@ -17,7 +17,7 @@
#include "inkscape.h"
#include "desktop.h"
-#include "desktop-handles.h"
+
#include "document.h"
#include "sp-root.h"
#include "style.h"
@@ -171,9 +171,11 @@ Geom::Rect FilterPrimitive::filter_primitive_area(FilterUnits const &units)
void FilterPrimitive::setStyle(SPStyle *style)
{
- 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;
+ }
}
diff --git a/src/display/nr-filter-turbulence.cpp b/src/display/nr-filter-turbulence.cpp
index a2a8c5756..19dedb67c 100644
--- a/src/display/nr-filter-turbulence.cpp
+++ b/src/display/nr-filter-turbulence.cpp
@@ -64,8 +64,10 @@ public:
for (i = 0; i < BSize; ++i) {
_latticeSelector[i] = i;
- _gradient[i][k][0] = static_cast<double>(_random() % (BSize*2) - BSize) / BSize;
- _gradient[i][k][1] = static_cast<double>(_random() % (BSize*2) - BSize) / BSize;
+ do {
+ _gradient[i][k][0] = static_cast<double>(_random() % (BSize*2) - BSize) / BSize;
+ _gradient[i][k][1] = static_cast<double>(_random() % (BSize*2) - BSize) / BSize;
+ } while(_gradient[i][k][0] == 0 && _gradient[i][k][1] == 0);
// normalize gradient
double s = hypot(_gradient[i][k][0], _gradient[i][k][1]);
diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp
index 96d16bf06..1740785e2 100644
--- a/src/display/nr-style.cpp
+++ b/src/display/nr-style.cpp
@@ -93,24 +93,47 @@ NRStyle::~NRStyle()
text_decoration_stroke.clear();
}
-void NRStyle::set(SPStyle *style)
+void NRStyle::set(SPStyle *style, SPStyle *context_style)
{
- if ( style->fill.isPaintserver() ) {
+ // Handle 'context-fill' and 'context-stroke': Work in progress
+ const SPIPaint *style_fill = &(style->fill);
+ if( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) {
+ if( context_style != NULL ) {
+ style_fill = &(context_style->fill);
+ } else {
+ // A marker in the defs section will result in ending up here.
+ //std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl;
+ }
+ } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) {
+ if( context_style != NULL ) {
+ style_fill = &(context_style->stroke);
+ } else {
+ //std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl;
+ }
+ }
+
+ if ( style_fill->isPaintserver() ) {
SPPaintServer* server = style->getFillPaintServer();
if ( server && server->isValid() ) {
fill.set(server);
- } else if ( style->fill.colorSet ) {
- fill.set(style->fill.value.color);
+ } else if ( style_fill->colorSet ) {
+ fill.set(style_fill->value.color);
} else {
fill.clear();
}
- } else if ( style->fill.isColor() ) {
- fill.set(style->fill.value.color);
- } else if ( style->fill.isNone() ) {
+ } else if ( style_fill->isColor() ) {
+ fill.set(style_fill->value.color);
+ } else if ( style_fill->isNone() ) {
fill.clear();
+ } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) {
+ // A marker in the defs section will result in ending up here.
+ //std::cerr << "NRStyle::set: fill: context-fill: Double" << std::endl;
+ } else if ( style_fill->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) {
+ //std::cerr << "NRStyle::set: fill: context-stroke: Double" << std::endl;
} else {
g_assert_not_reached();
}
+
fill.opacity = SP_SCALE24_TO_FLOAT(style->fill_opacity.value);
switch (style->fill_rule.computed) {
@@ -124,22 +147,42 @@ void NRStyle::set(SPStyle *style)
g_assert_not_reached();
}
- if ( style->stroke.isPaintserver() ) {
+ const SPIPaint *style_stroke = &(style->stroke);
+ if( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) {
+ if( context_style != NULL ) {
+ style_stroke = &(context_style->fill);
+ } else {
+ //std::cerr << "NRStyle::set: 'context-fill': 'context_style' is NULL" << std::endl;
+ }
+ } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) {
+ if( context_style != NULL ) {
+ style_stroke = &(context_style->stroke);
+ } else {
+ //std::cerr << "NRStyle::set: 'context-stroke': 'context_style' is NULL" << std::endl;
+ }
+ }
+
+ if ( style_stroke->isPaintserver() ) {
SPPaintServer* server = style->getStrokePaintServer();
if ( server && server->isValid() ) {
stroke.set(server);
- } else if ( style->stroke.isColor() ) {
- stroke.set(style->stroke.colorSet);
+ } else if ( style_stroke->isColor() ) {
+ stroke.set(style_stroke->colorSet);
} else {
stroke.clear();
}
- } else if ( style->stroke.isColor() ) {
- stroke.set(style->stroke.value.color);
- } else if ( style->stroke.isNone() ) {
+ } else if ( style_stroke->isColor() ) {
+ stroke.set(style_stroke->value.color);
+ } else if ( style_stroke->isNone() ) {
stroke.clear();
+ } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_FILL ) {
+ //std::cerr << "NRStyle::set: stroke: context-fill: Double" << std::endl;
+ } else if ( style_stroke->paintOrigin == SP_CSS_PAINT_ORIGIN_CONTEXT_STROKE ) {
+ //std::cerr << "NRStyle::set: stroke: context-stroke: Double" << std::endl;
} else {
g_assert_not_reached();
}
+
stroke.opacity = SP_SCALE24_TO_FLOAT(style->stroke_opacity.value);
stroke_width = style->stroke_width.computed;
switch (style->stroke_linecap.computed) {
@@ -266,7 +309,7 @@ void NRStyle::set(SPStyle *style)
} else if ( style_td->fill.isNone() ) {
text_decoration_fill.clear();
} else {
- g_assert_not_reached();
+ //g_assert_not_reached();
}
if ( style_td->stroke.isPaintserver() ) {
@@ -276,7 +319,7 @@ void NRStyle::set(SPStyle *style)
} else if ( style_td->stroke.isNone() ) {
text_decoration_stroke.clear();
} else {
- g_assert_not_reached();
+ //g_assert_not_reached();
}
}
@@ -310,13 +353,16 @@ bool NRStyle::prepareFill(Inkscape::DrawingContext &dc, Geom::OptRect const &pai
fill_pattern = pattern->renderPattern(fill.opacity);
} else {
fill_pattern = fill.server->pattern_new(dc.raw(), paintbox, fill.opacity);
- } break;
+ }
+ break;
case PAINT_COLOR: {
SPColor const &c = fill.color;
fill_pattern = cairo_pattern_create_rgba(
c.v.c[0], c.v.c[1], c.v.c[2], fill.opacity);
- } break;
- default: break;
+ }
+ break;
+ default:
+ break;
}
}
if (!fill_pattern) return false;
diff --git a/src/display/nr-style.h b/src/display/nr-style.h
index f324fdb56..5f78795d3 100644
--- a/src/display/nr-style.h
+++ b/src/display/nr-style.h
@@ -1,6 +1,7 @@
/**
* @file
* Style information for rendering.
+ * Only used by classes DrawingShape and DrawingText
*//*
* Authors:
* Krzysztof KosiƄski <tweenk.pl@gmail.com>
@@ -28,7 +29,7 @@ struct NRStyle {
NRStyle();
~NRStyle();
- void set(SPStyle *);
+ void set(SPStyle *style, SPStyle *context_style = NULL);
bool prepareFill(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern);
bool prepareStroke(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern);
bool prepareTextDecorationFill(Inkscape::DrawingContext &dc, Geom::OptRect const &paintbox, Inkscape::DrawingPattern *pattern);
diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp
index 2632d69db..bcce81f0b 100644
--- a/src/display/snap-indicator.cpp
+++ b/src/display/snap-indicator.cpp
@@ -14,7 +14,7 @@
#include "display/snap-indicator.h"
#include "desktop.h"
-#include "desktop-handles.h"
+
#include "display/sodipodi-ctrl.h"
#include "display/sodipodi-ctrlrect.h"
#include "display/canvas-text.h"
@@ -246,7 +246,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap
// Display the snap indicator (i.e. the cross)
SPCanvasItem * canvasitem = NULL;
- canvasitem = sp_canvas_item_new(sp_desktop_tempgroup (_desktop),
+ canvasitem = sp_canvas_item_new(_desktop->getTempGroup(),
SP_TYPE_CTRL,
"anchor", SP_ANCHOR_CENTER,
"size", 10.0,
@@ -280,7 +280,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap
tooltip_pos += _desktop->w2d(Geom::Point(0, -2*fontsize));
}
- SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(_desktop), _desktop, tooltip_pos, tooltip_str);
+ SPCanvasItem *canvas_tooltip = sp_canvastext_new(_desktop->getTempGroup(), _desktop, tooltip_pos, tooltip_str);
sp_canvastext_set_fontsize(SP_CANVASTEXT(canvas_tooltip), fontsize);
SP_CANVASTEXT(canvas_tooltip)->rgba = 0xffffffff;
SP_CANVASTEXT(canvas_tooltip)->outline = false;
@@ -299,7 +299,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap
// Display the bounding box, if we snapped to one
Geom::OptRect const bbox = p.getTargetBBox();
if (bbox) {
- SPCanvasItem* box = sp_canvas_item_new(sp_desktop_tempgroup (_desktop),
+ SPCanvasItem* box = sp_canvas_item_new(_desktop->getTempGroup(),
SP_TYPE_CTRLRECT,
NULL);
@@ -348,7 +348,7 @@ SnapIndicator::set_new_snapsource(Inkscape::SnapCandidatePoint const &p)
bool value = prefs->getBool("/options/snapindicator/value", true);
if (value) {
- SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop),
+ SPCanvasItem * canvasitem = sp_canvas_item_new( _desktop->getTempGroup(),
SP_TYPE_CTRL,
"anchor", SP_ANCHOR_CENTER,
"size", 6.0,
@@ -367,7 +367,7 @@ void
SnapIndicator::set_new_debugging_point(Geom::Point const &p)
{
g_assert(_desktop != NULL);
- SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop),
+ SPCanvasItem * canvasitem = sp_canvas_item_new( _desktop->getTempGroup(),
SP_TYPE_CTRL,
"anchor", SP_ANCHOR_CENTER,
"size", 10.0,