diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index f94a5e404b2970629d14ccaef471df041bc0e9ef..d213ce2d7414688c0a2787367358a3aea68f99aa 100644 (file)
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
-#define __SP_ITEM_C__
-
/** \file
* Base class for visual SVG elements
*/
/** \file
* Base class for visual SVG elements
*/
#include "attributes.h"
#include "document.h"
#include "uri.h"
#include "attributes.h"
#include "document.h"
#include "uri.h"
+#include "inkscape.h"
+#include "desktop.h"
+#include "desktop-handles.h"
#include "style.h"
#include <glibmm/i18n.h>
#include "style.h"
#include <glibmm/i18n.h>
#include "sp-item-rm-unsatisfied-cns.h"
#include "sp-pattern.h"
#include "sp-switch.h"
#include "sp-item-rm-unsatisfied-cns.h"
#include "sp-pattern.h"
#include "sp-switch.h"
+#include "sp-guide-constraint.h"
#include "gradient-chemistry.h"
#include "gradient-chemistry.h"
-#include "prefs-utils.h"
+#include "preferences.h"
#include "conn-avoid-ref.h"
#include "conditions.h"
#include "conn-avoid-ref.h"
#include "conditions.h"
+#include "sp-filter-reference.h"
+#include "filter-chemistry.h"
+#include "sp-guide.h"
+#include "sp-title.h"
+#include "sp-desc.h"
-#include "libnr/nr-matrix-div.h"
#include "libnr/nr-matrix-fns.h"
#include "libnr/nr-matrix-scale-ops.h"
#include "libnr/nr-matrix-translate-ops.h"
#include "libnr/nr-scale-translate-ops.h"
#include "libnr/nr-translate-scale-ops.h"
#include "libnr/nr-matrix-fns.h"
#include "libnr/nr-matrix-scale-ops.h"
#include "libnr/nr-matrix-translate-ops.h"
#include "libnr/nr-scale-translate-ops.h"
#include "libnr/nr-translate-scale-ops.h"
-#include "algorithms/find-last-if.h"
+#include "libnr/nr-convert2geom.h"
+#include "util/find-last-if.h"
#include "util/reverse-list.h"
#include "util/reverse-list.h"
+#include <2geom/rect.h>
+#include <2geom/matrix.h>
+#include <2geom/transforms.h>
#include "xml/repr.h"
#include "xml/repr.h"
+#include "extract-uri.h"
+#include "helper/geom.h"
+
+#include "live_effects/lpeobject.h"
+#include "live_effects/effect.h"
+#include "live_effects/lpeobject-reference.h"
#define noSP_ITEM_DEBUG_IDLE
#define noSP_ITEM_DEBUG_IDLE
@@ -71,10 +87,10 @@ static void sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML:
static void sp_item_release(SPObject *object);
static void sp_item_set(SPObject *object, unsigned key, gchar const *value);
static void sp_item_update(SPObject *object, SPCtx *ctx, guint flags);
static void sp_item_release(SPObject *object);
static void sp_item_set(SPObject *object, unsigned key, gchar const *value);
static void sp_item_update(SPObject *object, SPCtx *ctx, guint flags);
-static Inkscape::XML::Node *sp_item_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
+static Inkscape::XML::Node *sp_item_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static gchar *sp_item_private_description(SPItem *item);
static gchar *sp_item_private_description(SPItem *item);
-static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p);
+static void sp_item_private_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
static SPItemView *sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem);
static SPItemView *sp_item_view_list_remove(SPItemView *list, SPItemView *view);
static SPItemView *sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem);
static SPItemView *sp_item_view_list_remove(SPItemView *list, SPItemView *view);
this->_is_evaluated = true;
this->_evaluated_status = StatusUnknown;
this->_is_evaluated = true;
this->_evaluated_status = StatusUnknown;
- this->transform = NR::identity();
+ this->transform = Geom::identity();
this->display = NULL;
this->clip_ref = new SPClipPathReference(this);
this->display = NULL;
this->clip_ref = new SPClipPathReference(this);
- sigc::signal<void, SPObject *, SPObject *> cs1=this->clip_ref->changedSignal();
- sigc::slot2<void,SPObject*, SPObject *> sl1=sigc::bind(sigc::ptr_fun(clip_ref_changed), this);
+ sigc::signal<void, SPObject *, SPObject *> cs1=this->clip_ref->changedSignal();
+ sigc::slot2<void,SPObject*, SPObject *> sl1=sigc::bind(sigc::ptr_fun(clip_ref_changed), this);
_clip_ref_connection = cs1.connect(sl1);
this->mask_ref = new SPMaskReference(this);
_clip_ref_connection = cs1.connect(sl1);
this->mask_ref = new SPMaskReference(this);
- sigc::signal<void, SPObject *, SPObject *> cs2=this->mask_ref->changedSignal();
- sigc::slot2<void,SPObject*, SPObject *> sl2=sigc::bind(sigc::ptr_fun(mask_ref_changed), this);
+ sigc::signal<void, SPObject *, SPObject *> cs2=this->mask_ref->changedSignal();
+ sigc::slot2<void,SPObject*, SPObject *> sl2=sigc::bind(sigc::ptr_fun(mask_ref_changed), this);
_mask_ref_connection = cs2.connect(sl2);
_mask_ref_connection = cs2.connect(sl2);
- if (!this->style) this->style = sp_style_new_from_object(this);
-
this->avoidRef = new SPAvoidRef(this);
this->avoidRef = new SPAvoidRef(this);
- new (&this->_transformed_signal) sigc::signal<void, NR::Matrix const *, SPItem *>();
+ new (&this->constraints) std::vector<SPGuideConstraint>();
+
+ new (&this->_transformed_signal) sigc::signal<void, Geom::Matrix const *, SPItem *>();
}
bool SPItem::isVisibleAndUnlocked() const {
}
bool SPItem::isVisibleAndUnlocked() const {
}
bool SPItem::isLocked() const {
}
bool SPItem::isLocked() const {
- for (SPObject *o = SP_OBJECT(this); o != NULL; o = SP_OBJECT_PARENT(o)) {
- if (SP_IS_ITEM(o) && !(SP_ITEM(o)->sensitive))
+ for (SPObject const *o = this; o != NULL; o = o->parent) {
+ if (SP_IS_ITEM(o) && !(SP_ITEM(o)->sensitive)) {
return true;
return true;
+ }
}
return false;
}
void SPItem::setLocked(bool locked) {
}
return false;
}
void SPItem::setLocked(bool locked) {
- SP_OBJECT_REPR(this)->setAttribute("sodipodi:insensitive",
- ( locked ? "1" : NULL ));
+ this->repr->setAttribute("sodipodi:insensitive",
+ ( locked ? "1" : NULL ));
updateRepr();
}
updateRepr();
}
requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
}
} if ( StatusSet == _evaluated_status ) {
requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
}
} if ( StatusSet == _evaluated_status ) {
- SPObject const *const parent = SP_OBJECT_PARENT(this);
+ SPObject const *const parent = this->parent;
if (SP_IS_SWITCH(parent)) {
SP_SWITCH(parent)->resetChildEvaluated();
}
if (SP_IS_SWITCH(parent)) {
SP_SWITCH(parent)->resetChildEvaluated();
}
SPItem::isExplicitlyHidden() const
{
return (this->style->display.set
SPItem::isExplicitlyHidden() const
{
return (this->style->display.set
- && this->style->display.value == SP_CSS_DISPLAY_NONE);
+ && this->style->display.value == SP_CSS_DISPLAY_NONE);
}
/**
}
/**
* Sets the transform_center_x and transform_center_y properties to retain the rotation centre
*/
void
* Sets the transform_center_x and transform_center_y properties to retain the rotation centre
*/
void
-SPItem::setCenter(NR::Point object_centre) {
- NR::Rect bbox = invokeBbox(sp_item_i2d_affine(this));
- if (!bbox.isEmpty()) {
- transform_center_x = object_centre[NR::X] - bbox.midpoint()[NR::X];
+SPItem::setCenter(Geom::Point object_centre) {
+ // for getBounds() to work
+ sp_document_ensure_up_to_date( this->document );
+
+ Geom::OptRect bbox = getBounds(sp_item_i2d_affine(this));
+ if (bbox) {
+ transform_center_x = object_centre[Geom::X] - bbox->midpoint()[Geom::X];
if (fabs(transform_center_x) < 1e-5) // rounding error
transform_center_x = 0;
if (fabs(transform_center_x) < 1e-5) // rounding error
transform_center_x = 0;
- transform_center_y = object_centre[NR::Y] - bbox.midpoint()[NR::Y];
+ transform_center_y = object_centre[Geom::Y] - bbox->midpoint()[Geom::Y];
if (fabs(transform_center_y) < 1e-5) // rounding error
transform_center_y = 0;
}
if (fabs(transform_center_y) < 1e-5) // rounding error
transform_center_y = 0;
}
return (transform_center_x != 0 || transform_center_y != 0);
}
return (transform_center_x != 0 || transform_center_y != 0);
}
-NR::Point SPItem::getCenter() {
- NR::Rect bbox = invokeBbox(sp_item_i2d_affine(this));
- if (!bbox.isEmpty()) {
- return bbox.midpoint() + NR::Point (this->transform_center_x, this->transform_center_y);
+Geom::Point SPItem::getCenter() const {
+ // for getBounds() to work
+ sp_document_ensure_up_to_date( this->document );
+
+ Geom::OptRect bbox = getBounds(sp_item_i2d_affine(this));
+ if (bbox) {
+ return to_2geom(bbox->midpoint()) + Geom::Point (this->transform_center_x, this->transform_center_y);
} else {
} else {
- return NR::Point (0, 0); // something's wrong!
+ return Geom::Point (0, 0); // something's wrong!
}
}
}
}
using Inkscape::Algorithms::find_last_if;
SPObject *topmost=find_last_if<SPObject::SiblingIterator>(
using Inkscape::Algorithms::find_last_if;
SPObject *topmost=find_last_if<SPObject::SiblingIterator>(
- SP_OBJECT_NEXT(this), NULL, &is_item
+ this->next, NULL, &is_item
);
if (topmost) {
);
if (topmost) {
- Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
- sp_repr_parent(repr)->changeOrder(repr, SP_OBJECT_REPR(topmost));
+ Inkscape::XML::Node *repr = this->repr;
+ sp_repr_parent(repr)->changeOrder( repr, topmost->repr );
}
}
void SPItem::raiseOne() {
SPObject *next_higher=std::find_if<SPObject::SiblingIterator>(
}
}
void SPItem::raiseOne() {
SPObject *next_higher=std::find_if<SPObject::SiblingIterator>(
- SP_OBJECT_NEXT(this), NULL, &is_item
+ this->next, NULL, &is_item
);
if (next_higher) {
);
if (next_higher) {
- Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
- Inkscape::XML::Node *ref=SP_OBJECT_REPR(next_higher);
+ Inkscape::XML::Node *repr = this->repr;
+ Inkscape::XML::Node *ref = next_higher->repr;
sp_repr_parent(repr)->changeOrder(repr, ref);
}
}
sp_repr_parent(repr)->changeOrder(repr, ref);
}
}
MutableList<SPObject &> next_lower=std::find_if(
reverse_list<SPObject::SiblingIterator>(
MutableList<SPObject &> next_lower=std::find_if(
reverse_list<SPObject::SiblingIterator>(
- SP_OBJECT_PARENT(this)->firstChild(), this
+ this->parent->firstChild(), this
),
MutableList<SPObject &>(),
&is_item
);
if (next_lower) {
++next_lower;
),
MutableList<SPObject &>(),
&is_item
);
if (next_lower) {
++next_lower;
- Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
- Inkscape::XML::Node *ref=( next_lower ? SP_OBJECT_REPR(&*next_lower) : NULL );
+ Inkscape::XML::Node *repr = this->repr;
+ Inkscape::XML::Node *ref = ( next_lower ? next_lower->repr : NULL );
sp_repr_parent(repr)->changeOrder(repr, ref);
}
}
sp_repr_parent(repr)->changeOrder(repr, ref);
}
}
MutableList<SPObject &> bottom=find_last_if(
reverse_list<SPObject::SiblingIterator>(
MutableList<SPObject &> bottom=find_last_if(
reverse_list<SPObject::SiblingIterator>(
- SP_OBJECT_PARENT(this)->firstChild(), this
+ this->parent->firstChild(), this
),
MutableList<SPObject &>(),
&is_item
);
if (bottom) {
++bottom;
),
MutableList<SPObject &>(),
&is_item
);
if (bottom) {
++bottom;
- Inkscape::XML::Node *repr=SP_OBJECT_REPR(this);
- Inkscape::XML::Node *ref=( bottom ? SP_OBJECT_REPR(&*bottom) : NULL );
+ Inkscape::XML::Node *repr = this->repr;
+ Inkscape::XML::Node *ref = ( bottom ? bottom->repr : NULL );
sp_repr_parent(repr)->changeOrder(repr, ref);
}
}
sp_repr_parent(repr)->changeOrder(repr, ref);
}
}
@@ -390,6 +413,7 @@ sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
sp_object_read_attr(object, "inkscape:transform-center-x");
sp_object_read_attr(object, "inkscape:transform-center-y");
sp_object_read_attr(object, "inkscape:connector-avoid");
sp_object_read_attr(object, "inkscape:transform-center-x");
sp_object_read_attr(object, "inkscape:transform-center-y");
sp_object_read_attr(object, "inkscape:connector-avoid");
+ sp_object_read_attr(object, "inkscape:connection-points");
if (((SPObjectClass *) (parent_class))->build) {
(* ((SPObjectClass *) (parent_class))->build)(object, document, repr);
if (((SPObjectClass *) (parent_class))->build) {
(* ((SPObjectClass *) (parent_class))->build)(object, document, repr);
item->_clip_ref_connection.disconnect();
item->_mask_ref_connection.disconnect();
item->_clip_ref_connection.disconnect();
item->_mask_ref_connection.disconnect();
+ // Note: do this here before the clip_ref is deleted, since calling
+ // sp_document_ensure_up_to_date for triggered routing may reference
+ // the deleted clip_ref.
+ if (item->avoidRef) {
+ delete item->avoidRef;
+ item->avoidRef = NULL;
+ }
+
if (item->clip_ref) {
item->clip_ref->detach();
delete item->clip_ref;
if (item->clip_ref) {
item->clip_ref->detach();
delete item->clip_ref;
item->mask_ref = NULL;
}
item->mask_ref = NULL;
}
- if (item->avoidRef) {
- delete item->avoidRef;
- item->avoidRef = NULL;
- }
-
if (((SPObjectClass *) (parent_class))->release) {
((SPObjectClass *) parent_class)->release(object);
}
if (((SPObjectClass *) (parent_class))->release) {
((SPObjectClass *) parent_class)->release(object);
}
switch (key) {
case SP_ATTR_TRANSFORM: {
switch (key) {
case SP_ATTR_TRANSFORM: {
- NR::Matrix t;
+ Geom::Matrix t;
if (value && sp_svg_transform_read(value, &t)) {
sp_item_set_item_transform(item, t);
} else {
if (value && sp_svg_transform_read(value, &t)) {
sp_item_set_item_transform(item, t);
} else {
- sp_item_set_item_transform(item, NR::identity());
+ sp_item_set_item_transform(item, Geom::identity());
}
break;
}
case SP_PROP_CLIP_PATH: {
}
break;
}
case SP_PROP_CLIP_PATH: {
- gchar *uri = Inkscape::parse_css_url(value);
+ gchar *uri = extract_uri(value);
if (uri) {
try {
item->clip_ref->attach(Inkscape::URI(uri));
if (uri) {
try {
item->clip_ref->attach(Inkscape::URI(uri));
break;
}
case SP_PROP_MASK: {
break;
}
case SP_PROP_MASK: {
- gchar *uri=Inkscape::parse_css_url(value);
+ gchar *uri = extract_uri(value);
if (uri) {
try {
item->mask_ref->attach(Inkscape::URI(uri));
if (uri) {
try {
item->mask_ref->attach(Inkscape::URI(uri));
nr_arena_item_set_sensitive(v->arenaitem, item->sensitive);
}
break;
nr_arena_item_set_sensitive(v->arenaitem, item->sensitive);
}
break;
- case SP_ATTR_STYLE:
- sp_style_read_from_object(object->style, object);
- object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
- break;
case SP_ATTR_CONNECTOR_AVOID:
item->avoidRef->setAvoid(value);
break;
case SP_ATTR_CONNECTOR_AVOID:
item->avoidRef->setAvoid(value);
break;
+ case SP_ATTR_CONNECTION_POINTS:
+ item->avoidRef->setConnectionPoints(value);
+ break;
case SP_ATTR_TRANSFORM_CENTER_X:
if (value) {
item->transform_center_x = g_strtod(value, NULL);
} else {
item->transform_center_x = 0;
}
case SP_ATTR_TRANSFORM_CENTER_X:
if (value) {
item->transform_center_x = g_strtod(value, NULL);
} else {
item->transform_center_x = 0;
}
+ object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_ATTR_TRANSFORM_CENTER_Y:
if (value) {
break;
case SP_ATTR_TRANSFORM_CENTER_Y:
if (value) {
} else {
item->transform_center_y = 0;
}
} else {
item->transform_center_y = 0;
}
+ object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
break;
case SP_PROP_SYSTEM_LANGUAGE:
case SP_PROP_REQUIRED_FEATURES:
break;
case SP_PROP_SYSTEM_LANGUAGE:
case SP_PROP_REQUIRED_FEATURES:
}
if (SP_IS_CLIPPATH(clip)) {
NRRect bbox;
}
if (SP_IS_CLIPPATH(clip)) {
NRRect bbox;
- sp_item_invoke_bbox(item, &bbox, NR::identity(), TRUE);
+ sp_item_invoke_bbox(item, &bbox, Geom::identity(), TRUE);
for (SPItemView *v = item->display; v != NULL; v = v->next) {
if (!v->arenaitem->key) {
NR_ARENA_ITEM_SET_KEY(v->arenaitem, sp_item_display_key_new(3));
for (SPItemView *v = item->display; v != NULL; v = v->next) {
if (!v->arenaitem->key) {
NR_ARENA_ITEM_SET_KEY(v->arenaitem, sp_item_display_key_new(3));
nr_arena_item_set_clip(v->arenaitem, ai);
nr_arena_item_unref(ai);
sp_clippath_set_bbox(SP_CLIPPATH(clip), NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
nr_arena_item_set_clip(v->arenaitem, ai);
nr_arena_item_unref(ai);
sp_clippath_set_bbox(SP_CLIPPATH(clip), NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
- SP_OBJECT(clip)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ clip->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
}
}
}
}
}
}
if (SP_IS_MASK(mask)) {
NRRect bbox;
}
if (SP_IS_MASK(mask)) {
NRRect bbox;
- sp_item_invoke_bbox(item, &bbox, NR::identity(), TRUE);
+ sp_item_invoke_bbox(item, &bbox, Geom::identity(), TRUE);
for (SPItemView *v = item->display; v != NULL; v = v->next) {
if (!v->arenaitem->key) {
NR_ARENA_ITEM_SET_KEY(v->arenaitem, sp_item_display_key_new(3));
for (SPItemView *v = item->display; v != NULL; v = v->next) {
if (!v->arenaitem->key) {
NR_ARENA_ITEM_SET_KEY(v->arenaitem, sp_item_display_key_new(3));
nr_arena_item_set_mask(v->arenaitem, ai);
nr_arena_item_unref(ai);
sp_mask_set_bbox(SP_MASK(mask), NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
nr_arena_item_set_mask(v->arenaitem, ai);
nr_arena_item_unref(ai);
sp_mask_set_bbox(SP_MASK(mask), NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
- SP_OBJECT(mask)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ mask->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
}
}
}
}
}
}
}
}
}
- SPClipPath *clip_path = item->clip_ref->getObject();
- SPMask *mask = item->mask_ref->getObject();
+ SPClipPath *clip_path = item->clip_ref ? item->clip_ref->getObject() : NULL;
+ SPMask *mask = item->mask_ref ? item->mask_ref->getObject() : NULL;
if ( clip_path || mask ) {
NRRect bbox;
if ( clip_path || mask ) {
NRRect bbox;
- sp_item_invoke_bbox(item, &bbox, NR::identity(), TRUE);
+ sp_item_invoke_bbox(item, &bbox, Geom::identity(), TRUE);
if (clip_path) {
for (SPItemView *v = item->display; v != NULL; v = v->next) {
sp_clippath_set_bbox(clip_path, NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
if (clip_path) {
for (SPItemView *v = item->display; v != NULL; v = v->next) {
sp_clippath_set_bbox(clip_path, NR_ARENA_ITEM_GET_KEY(v->arenaitem), &bbox);
}
}
}
}
+ /* Update bounding box data used by filters */
+ if (item->style->filter.set && item->display) {
+ Geom::OptRect item_bbox;
+ sp_item_invoke_bbox(item, item_bbox, Geom::identity(), TRUE, SPItem::GEOMETRIC_BBOX);
+
+ SPItemView *itemview = item->display;
+ do {
+ if (itemview->arenaitem)
+ nr_arena_item_set_item_bbox(itemview->arenaitem, item_bbox);
+ } while ( (itemview = itemview->next) );
+ }
+
// Update libavoid with item geometry (for connector routing).
// Update libavoid with item geometry (for connector routing).
- item->avoidRef->handleSettingChange();
+ if (item->avoidRef)
+ item->avoidRef->handleSettingChange();
}
static Inkscape::XML::Node *
}
static Inkscape::XML::Node *
-sp_item_write(SPObject *const object, Inkscape::XML::Node *repr, guint flags)
+sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
{
+ SPObject *child;
SPItem *item = SP_ITEM(object);
SPItem *item = SP_ITEM(object);
- gchar c[256];
- if (sp_svg_transform_write(c, 256, item->transform)) {
- repr->setAttribute("transform", c);
+ // in the case of SP_OBJECT_WRITE_BUILD, the item should always be newly created,
+ // so we need to add any children from the underlying object to the new repr
+ if (flags & SP_OBJECT_WRITE_BUILD) {
+ Inkscape::XML::Node *crepr;
+ GSList *l;
+ l = NULL;
+ for (child = sp_object_first_child(object); child != NULL; child = child->next ) {
+ if (!SP_IS_TITLE(child) && !SP_IS_DESC(child)) continue;
+ crepr = child->updateRepr(xml_doc, NULL, flags);
+ if (crepr) l = g_slist_prepend (l, crepr);
+ }
+ while (l) {
+ repr->addChild((Inkscape::XML::Node *) l->data, NULL);
+ Inkscape::GC::release((Inkscape::XML::Node *) l->data);
+ l = g_slist_remove (l, l->data);
+ }
} else {
} else {
- repr->setAttribute("transform", NULL);
- }
-
- SPObject const *const parent = SP_OBJECT_PARENT(object);
- /** \todo Can someone please document why this is conditional on having
- * a parent? The only parentless thing I can think of is the top-level
- * <svg> element (SPRoot). SPRoot is derived from SPGroup, and can have
- * style. I haven't looked at callers.
- */
- if (parent) {
- SPStyle const *const obj_style = SP_OBJECT_STYLE(object);
- if (obj_style) {
- gchar *s = sp_style_write_string(obj_style, SP_STYLE_FLAG_IFSET);
- repr->setAttribute("style", ( *s ? s : NULL ));
- g_free(s);
- } else {
- /** \todo I'm not sure what to do in this case. Bug #1165868
- * suggests that it can arise, but the submitter doesn't know
- * how to do so reliably. The main two options are either
- * leave repr's style attribute unchanged, or explicitly clear it.
- * Must also consider what to do with property attributes for
- * the element; see below.
- */
- char const *style_str = repr->attribute("style");
- if (!style_str) {
- style_str = "NULL";
- }
- g_warning("Item's style is NULL; repr style attribute is %s", style_str);
+ for (child = sp_object_first_child(object) ; child != NULL; child = child->next ) {
+ if (!SP_IS_TITLE(child) && !SP_IS_DESC(child)) continue;
+ child->updateRepr(flags);
}
}
-
- /** \note We treat object->style as authoritative. Its effects have
- * been written to the style attribute above; any properties that are
- * unset we take to be deliberately unset (e.g. so that clones can
- * override the property).
- *
- * Note that the below has an undesirable consequence of changing the
- * appearance on renderers that lack CSS support (e.g. SVG tiny);
- * possibly we should write property attributes instead of a style
- * attribute.
- */
- sp_style_unset_property_attrs (object);
}
}
+ gchar *c = sp_svg_transform_write(item->transform);
+ repr->setAttribute("transform", c);
+ g_free(c);
+
if (flags & SP_OBJECT_WRITE_EXT) {
repr->setAttribute("sodipodi:insensitive", ( item->sensitive ? NULL : "true" ));
if (item->transform_center_x != 0)
if (flags & SP_OBJECT_WRITE_EXT) {
repr->setAttribute("sodipodi:insensitive", ( item->sensitive ? NULL : "true" ));
if (item->transform_center_x != 0)
@@ -705,44 +727,155 @@ sp_item_write(SPObject *const object, Inkscape::XML::Node *repr, guint flags)
}
if (((SPObjectClass *) (parent_class))->write) {
}
if (((SPObjectClass *) (parent_class))->write) {
- ((SPObjectClass *) (parent_class))->write(object, repr, flags);
+ ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
}
return repr;
}
}
return repr;
}
-NR::Rect SPItem::invokeBbox(NR::Matrix const &transform) const
+/**
+ * \return There is no guarantee that the return value will contain a rectangle.
+ If this item does not have a boundingbox, it might well be empty.
+ */
+Geom::OptRect SPItem::getBounds(Geom::Matrix const &transform,
+ SPItem::BBoxType type,
+ unsigned int /*dkey*/) const
{
{
- NRRect r;
- sp_item_invoke_bbox_full(this, &r, transform, 0, TRUE);
- return NR::Rect(r);
+ Geom::OptRect r;
+ sp_item_invoke_bbox_full(this, r, transform, type, TRUE);
+ return r;
}
}
-NR::Maybe<NR::Rect> SPItem::getBBox(NR::Matrix const &transform,
- SPItem::BBoxType type,
- unsigned int dkey) const
+void
+sp_item_invoke_bbox(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
{
{
- NRRect r;
- sp_item_invoke_bbox_full(this, &r, transform, 0, TRUE);
- if (nr_rect_d_test_empty(&r)) {
- return NR::Nothing();
- } else {
- return NR::Rect(r);
- }
+ sp_item_invoke_bbox_full(item, bbox, transform, type, clear);
}
}
+// DEPRECATED to phase out the use of NRRect in favor of Geom::OptRect
void
void
-sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear)
+sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
{
{
- sp_item_invoke_bbox_full(item, bbox, transform, 0, clear);
+ sp_item_invoke_bbox_full(item, bbox, transform, type, clear);
}
}
+/** Calls \a item's subclass' bounding box method; clips it by the bbox of clippath, if any; and
+ * unions the resulting bbox with \a bbox. If \a clear is true, empties \a bbox first. Passes the
+ * transform and the flags to the actual bbox methods. Note that many of subclasses (e.g. groups,
+ * clones), in turn, call this function in their bbox methods.
+ * \retval bbox Note that there is no guarantee that bbox will contain a rectangle when the
+ * function returns. If this item does not have a boundingbox, this might well be empty.
+ */
+void
+sp_item_invoke_bbox_full(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear)
+{
+ g_assert(item != NULL);
+ g_assert(SP_IS_ITEM(item));
+
+ if (clear) {
+ bbox = Geom::OptRect();
+ }
+
+ // TODO: replace NRRect by Geom::Rect, for all SPItemClasses, and for SP_CLIPPATH
+
+ NRRect temp_bbox;
+ temp_bbox.x0 = temp_bbox.y0 = NR_HUGE;
+ temp_bbox.x1 = temp_bbox.y1 = -NR_HUGE;
+
+ // call the subclass method
+ if (((SPItemClass *) G_OBJECT_GET_CLASS(item))->bbox) {
+ ((SPItemClass *) G_OBJECT_GET_CLASS(item))->bbox(item, &temp_bbox, transform, flags);
+ }
+
+ // unless this is geometric bbox, extend by filter area and crop the bbox by clip path, if any
+ if ((SPItem::BBoxType) flags != SPItem::GEOMETRIC_BBOX) {
+ if ( item->style && item->style->filter.href ) {
+ SPObject *filter = item->style->getFilter();
+ if (filter && SP_IS_FILTER(filter)) {
+ // default filer area per the SVG spec:
+ double x = -0.1;
+ double y = -0.1;
+ double w = 1.2;
+ double h = 1.2;
+
+ // if area is explicitly set, override:
+ if (SP_FILTER(filter)->x._set)
+ x = SP_FILTER(filter)->x.computed;
+ if (SP_FILTER(filter)->y._set)
+ y = SP_FILTER(filter)->y.computed;
+ if (SP_FILTER(filter)->width._set)
+ w = SP_FILTER(filter)->width.computed;
+ if (SP_FILTER(filter)->height._set)
+ h = SP_FILTER(filter)->height.computed;
+
+ double dx0 = 0;
+ double dx1 = 0;
+ double dy0 = 0;
+ double dy1 = 0;
+ if (filter_is_single_gaussian_blur(SP_FILTER(filter))) {
+ // if this is a single blur, use 2.4*radius
+ // which may be smaller than the default area;
+ // see set_filter_area for why it's 2.4
+ double r = get_single_gaussian_blur_radius (SP_FILTER(filter));
+ dx0 = -2.4 * r;
+ dx1 = 2.4 * r;
+ dy0 = -2.4 * r;
+ dy1 = 2.4 * r;
+ } else {
+ // otherwise, calculate expansion from relative to absolute units:
+ dx0 = x * (temp_bbox.x1 - temp_bbox.x0);
+ dx1 = (w + x - 1) * (temp_bbox.x1 - temp_bbox.x0);
+ dy0 = y * (temp_bbox.y1 - temp_bbox.y0);
+ dy1 = (h + y - 1) * (temp_bbox.y1 - temp_bbox.y0);
+ }
+
+ // transform the expansions by the item's transform:
+ Geom::Matrix i2d(sp_item_i2d_affine (item));
+ dx0 *= i2d.expansionX();
+ dx1 *= i2d.expansionX();
+ dy0 *= i2d.expansionY();
+ dy1 *= i2d.expansionY();
+
+ // expand the bbox
+ temp_bbox.x0 += dx0;
+ temp_bbox.x1 += dx1;
+ temp_bbox.y0 += dy0;
+ temp_bbox.y1 += dy1;
+ }
+ }
+ if (item->clip_ref->getObject()) {
+ NRRect b;
+ sp_clippath_get_bbox(SP_CLIPPATH(item->clip_ref->getObject()), &b, transform, flags);
+ nr_rect_d_intersect (&temp_bbox, &temp_bbox, &b);
+ }
+ }
+
+ if (temp_bbox.x0 > temp_bbox.x1 || temp_bbox.y0 > temp_bbox.y1) {
+ // Either the bbox hasn't been touched by the SPItemClass' bbox method
+ // (it still has its initial values, see above: x0 = y0 = NR_HUGE and x1 = y1 = -NR_HUGE)
+ // or it has explicitely been set to be like this (e.g. in sp_shape_bbox)
+
+ // When x0 > x1 or y0 > y1, the bbox is considered to be "nothing", although it has not been
+ // explicitely defined this way for NRRects (as opposed to Geom::OptRect)
+ // So union bbox with nothing = do nothing, just return
+ return;
+ }
+
+ // Do not use temp_bbox.upgrade() here, because it uses a test that returns an empty Geom::OptRect()
+ // for any rectangle with zero area. The geometrical bbox of for example a vertical line
+ // would therefore be translated into empty Geom::OptRect() (see bug https://bugs.launchpad.net/inkscape/+bug/168684)
+ Geom::OptRect temp_bbox_new = Geom::Rect(Geom::Point(temp_bbox.x0, temp_bbox.y0), Geom::Point(temp_bbox.x1, temp_bbox.y1));
+
+ bbox = Geom::unify(bbox, temp_bbox_new);
+}
+
+// DEPRECATED to phase out the use of NRRect in favor of Geom::OptRect
/** Calls \a item's subclass' bounding box method; clips it by the bbox of clippath, if any; and
* unions the resulting bbox with \a bbox. If \a clear is true, empties \a bbox first. Passes the
* transform and the flags to the actual bbox methods. Note that many of subclasses (e.g. groups,
* clones), in turn, call this function in their bbox methods. */
void
/** Calls \a item's subclass' bounding box method; clips it by the bbox of clippath, if any; and
* unions the resulting bbox with \a bbox. If \a clear is true, empties \a bbox first. Passes the
* transform and the flags to the actual bbox methods. Note that many of subclasses (e.g. groups,
* clones), in turn, call this function in their bbox methods. */
void
-sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear)
+sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear)
{
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
{
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
@@ -762,8 +895,8 @@ sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, NR::Matrix const &tra
((SPItemClass *) G_OBJECT_GET_CLASS(item))->bbox(item, &this_bbox, transform, flags);
}
((SPItemClass *) G_OBJECT_GET_CLASS(item))->bbox(item, &this_bbox, transform, flags);
}
- // crop the bbox by clip path, if any
- if (item->clip_ref->getObject()) {
+ // unless this is geometric bbox, crop the bbox by clip path, if any
+ if ((SPItem::BBoxType) flags != SPItem::GEOMETRIC_BBOX && item->clip_ref->getObject()) {
NRRect b;
sp_clippath_get_bbox(SP_CLIPPATH(item->clip_ref->getObject()), &b, transform, flags);
nr_rect_d_intersect (&this_bbox, &this_bbox, &b);
NRRect b;
sp_clippath_get_bbox(SP_CLIPPATH(item->clip_ref->getObject()), &b, transform, flags);
nr_rect_d_intersect (&this_bbox, &this_bbox, &b);
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
- SPObject *parent = SP_OBJECT_PARENT(item);
+ SPObject *parent = item->parent;
g_assert(parent != NULL);
g_assert(SP_IS_OBJECT(parent));
g_assert(parent != NULL);
g_assert(SP_IS_OBJECT(parent));
- SPObject *object = SP_OBJECT(item);
+ SPObject *object = item;
- unsigned pos=0;
- for ( SPObject *iter = sp_object_first_child(parent) ; iter ; iter = SP_OBJECT_NEXT(iter)) {
+ unsigned pos = 0;
+ for ( SPObject *iter = sp_object_first_child(parent) ; iter ; iter = iter->next) {
if ( iter == object ) {
return pos;
}
if ( iter == object ) {
return pos;
}
}
void
}
void
-sp_item_bbox_desktop(SPItem *item, NRRect *bbox)
+sp_item_bbox_desktop(SPItem *item, NRRect *bbox, SPItem::BBoxType type)
{
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
g_assert(bbox != NULL);
{
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
g_assert(bbox != NULL);
- sp_item_invoke_bbox(item, bbox, sp_item_i2d_affine(item), TRUE);
+ sp_item_invoke_bbox(item, bbox, sp_item_i2d_affine(item), TRUE, type);
}
}
-NR::Rect sp_item_bbox_desktop(SPItem *item)
+Geom::OptRect sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type)
{
{
- NRRect ret;
- sp_item_invoke_bbox(item, &ret, sp_item_i2d_affine(item), TRUE);
- return NR::Rect(ret);
+ Geom::OptRect rect = Geom::OptRect();
+ sp_item_invoke_bbox(item, rect, sp_item_i2d_affine(item), TRUE, type);
+ return rect;
}
}
-static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p)
+static void sp_item_private_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const */*snapprefs*/)
{
{
- NR::Rect const bbox = item->invokeBbox(sp_item_i2d_affine(item));
- /* Just a pair of opposite corners of the bounding box suffices given that we don't yet
- support angled guide lines. */
+ /* This will only be called if the derived class doesn't override this.
+ * see for example sp_genericellipse_snappoints in sp-ellipse.cpp
+ * We don't know what shape we could be dealing with here, so we'll just
+ * return the corners of the bounding box */
+
+ Geom::OptRect bbox = item->getBounds(sp_item_i2d_affine(item));
+
+ if (bbox) {
+ Geom::Point p1, p2;
+ p1 = bbox->min();
+ p2 = bbox->max();
+ p.push_back(Inkscape::SnapCandidatePoint(p1, Inkscape::SNAPSOURCE_BBOX_CORNER, Inkscape::SNAPTARGET_BBOX_CORNER));
+ p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(p1[Geom::X], p2[Geom::Y]), Inkscape::SNAPSOURCE_BBOX_CORNER, Inkscape::SNAPTARGET_BBOX_CORNER));
+ p.push_back(Inkscape::SnapCandidatePoint(p2, Inkscape::SNAPSOURCE_BBOX_CORNER, Inkscape::SNAPTARGET_BBOX_CORNER));
+ p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(p2[Geom::X], p1[Geom::Y]), Inkscape::SNAPSOURCE_BBOX_CORNER, Inkscape::SNAPTARGET_BBOX_CORNER));
+ }
- *p = bbox.min();
- *p = bbox.max();
}
}
-void sp_item_snappoints(SPItem const *item, SnapPointsIter p)
+void sp_item_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs)
{
{
- g_assert (item != NULL);
- g_assert (SP_IS_ITEM(item));
+ if (item == NULL) {
+ g_warning("sp_item_snappoints: cannot snap because no item is being provided");
+ return;
+ }
+
+ if (!SP_IS_ITEM(item)) {
+ g_warning("sp_item_snappoints: cannot snap because this is not a SP_ITEM");
+ return;
+ }
+ // Get the snappoints of the item
SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(item);
if (item_class.snappoints) {
SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(item);
if (item_class.snappoints) {
- item_class.snappoints(item, p);
+ item_class.snappoints(item, p, snapprefs);
+ }
+
+ // Get the snappoints at the item's center
+ if (snapprefs != NULL && snapprefs->getIncludeItemCenter()) {
+ p.push_back(Inkscape::SnapCandidatePoint(item->getCenter(), Inkscape::SNAPSOURCE_ROTATION_CENTER, Inkscape::SNAPTARGET_ROTATION_CENTER));
+ }
+
+ // Get the snappoints of clipping paths and mask, if any
+ std::list<SPObject const *> clips_and_masks;
+
+ clips_and_masks.push_back(item->clip_ref->getObject());
+ clips_and_masks.push_back(item->mask_ref->getObject());
+
+ SPDesktop *desktop = inkscape_active_desktop();
+ for (std::list<SPObject const *>::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); o++) {
+ if (*o) {
+ // obj is a group object, the children are the actual clippers
+ for (SPObject *child = (*o)->children ; child ; child = child->next) {
+ if (SP_IS_ITEM(child)) {
+ std::vector<Inkscape::SnapCandidatePoint> p_clip_or_mask;
+ // Please note the recursive call here!
+ sp_item_snappoints(SP_ITEM(child), p_clip_or_mask, snapprefs);
+ // Take into account the transformation of the item being clipped or masked
+ for (std::vector<Inkscape::SnapCandidatePoint>::const_iterator p_orig = p_clip_or_mask.begin(); p_orig != p_clip_or_mask.end(); p_orig++) {
+ // All snappoints are in desktop coordinates, but the item's transformation is
+ // in document coordinates. Hence the awkward construction below
+ Geom::Point pt = desktop->dt2doc((*p_orig).getPoint()) * sp_item_i2d_affine(item);
+ p.push_back(Inkscape::SnapCandidatePoint(pt, (*p_orig).getSourceType(), (*p_orig).getTargetType()));
+ }
+ }
+ }
+ }
}
}
}
}
{
if (!item->isHidden()) {
if (((SPItemClass *) G_OBJECT_GET_CLASS(item))->print) {
{
if (!item->isHidden()) {
if (((SPItemClass *) G_OBJECT_GET_CLASS(item))->print) {
- if (!item->transform.test_identity()
- || SP_OBJECT_STYLE(item)->opacity.value != SP_SCALE24_MAX)
+ if (!item->transform.isIdentity()
+ || item->style->opacity.value != SP_SCALE24_MAX)
{
{
- sp_print_bind(ctx, item->transform, SP_SCALE24_TO_FLOAT(SP_OBJECT_STYLE(item)->opacity.value));
+ sp_print_bind(ctx, item->transform, SP_SCALE24_TO_FLOAT(item->style->opacity.value));
((SPItemClass *) G_OBJECT_GET_CLASS(item))->print(item, ctx);
sp_print_release(ctx);
} else {
((SPItemClass *) G_OBJECT_GET_CLASS(item))->print(item, ctx);
sp_print_release(ctx);
} else {
}
static gchar *
}
static gchar *
-sp_item_private_description(SPItem *item)
+sp_item_private_description(SPItem */*item*/)
{
return g_strdup(_("Object"));
}
{
return g_strdup(_("Object"));
}
g_free (s);
s = snew;
}
g_free (s);
s = snew;
}
+ if ( item->style && item->style->filter.href && item->style->filter.href->getObject() ) {
+ const gchar *label = item->style->filter.href->getObject()->label();
+ gchar *snew;
+ if (label) {
+ snew = g_strdup_printf (_("%s; <i>filtered (%s)</i>"), s, _(label));
+ } else {
+ snew = g_strdup_printf (_("%s; <i>filtered</i>"), s);
+ }
+ g_free (s);
+ s = snew;
+ }
return s;
}
return s;
}
@@ -924,7 +1119,7 @@ sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags)
if (ai != NULL) {
item->display = sp_item_view_new_prepend(item->display, item, flags, key, ai);
nr_arena_item_set_transform(ai, item->transform);
if (ai != NULL) {
item->display = sp_item_view_new_prepend(item->display, item, flags, key, ai);
nr_arena_item_set_transform(ai, item->transform);
- nr_arena_item_set_opacity(ai, SP_SCALE24_TO_FLOAT(SP_OBJECT_STYLE(item)->opacity.value));
+ nr_arena_item_set_opacity(ai, SP_SCALE24_TO_FLOAT(item->style->opacity.value));
nr_arena_item_set_visible(ai, !item->isHidden());
nr_arena_item_set_sensitive(ai, item->sensitive);
if (item->clip_ref->getObject()) {
nr_arena_item_set_visible(ai, !item->isHidden());
nr_arena_item_set_sensitive(ai, item->sensitive);
if (item->clip_ref->getObject()) {
@@ -942,9 +1137,9 @@ sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags)
// Update bbox, in case the clip uses bbox units
NRRect bbox;
// Update bbox, in case the clip uses bbox units
NRRect bbox;
- sp_item_invoke_bbox(item, &bbox, NR::identity(), TRUE);
+ sp_item_invoke_bbox(item, &bbox, Geom::identity(), TRUE);
sp_clippath_set_bbox(SP_CLIPPATH(cp), clip_key, &bbox);
sp_clippath_set_bbox(SP_CLIPPATH(cp), clip_key, &bbox);
- SP_OBJECT(cp)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ cp->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
if (item->mask_ref->getObject()) {
SPMask *mask = item->mask_ref->getObject();
}
if (item->mask_ref->getObject()) {
SPMask *mask = item->mask_ref->getObject();
@@ -961,11 +1156,14 @@ sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags)
// Update bbox, in case the mask uses bbox units
NRRect bbox;
// Update bbox, in case the mask uses bbox units
NRRect bbox;
- sp_item_invoke_bbox(item, &bbox, NR::identity(), TRUE);
+ sp_item_invoke_bbox(item, &bbox, Geom::identity(), TRUE);
sp_mask_set_bbox(SP_MASK(mask), mask_key, &bbox);
sp_mask_set_bbox(SP_MASK(mask), mask_key, &bbox);
- SP_OBJECT(mask)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ mask->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
NR_ARENA_ITEM_SET_DATA(ai, item);
}
NR_ARENA_ITEM_SET_DATA(ai, item);
+ Geom::OptRect item_bbox;
+ sp_item_invoke_bbox(item, item_bbox, Geom::identity(), TRUE, SPItem::GEOMETRIC_BBOX);
+ nr_arena_item_set_item_bbox(ai, item_bbox);
}
return ai;
}
return ai;
// Adjusters
void
// Adjusters
void
-sp_item_adjust_pattern (SPItem *item, NR::Matrix const &postmul, bool set)
+sp_item_adjust_pattern (SPItem *item, Geom::Matrix const &postmul, bool set)
{
{
- SPStyle *style = SP_OBJECT_STYLE (item);
+ SPStyle *style = item->style;
- if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) {
- SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item);
- if (SP_IS_PATTERN (server)) {
- SPPattern *pattern = sp_pattern_clone_if_necessary (item, SP_PATTERN (server), "fill");
- sp_pattern_transform_multiply (pattern, postmul, set);
+ if ( style && style->fill.isPaintserver() ) {
+ SPPaintServer *server = item->style->getFillPaintServer();
+ if ( SP_IS_PATTERN(server) ) {
+ SPPattern *pattern = sp_pattern_clone_if_necessary(item, SP_PATTERN(server), "fill");
+ sp_pattern_transform_multiply(pattern, postmul, set);
}
}
}
}
- if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) {
- SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item);
- if (SP_IS_PATTERN (server)) {
- SPPattern *pattern = sp_pattern_clone_if_necessary (item, SP_PATTERN (server), "stroke");
- sp_pattern_transform_multiply (pattern, postmul, set);
+ if ( style && style->stroke.isPaintserver() ) {
+ SPPaintServer *server = item->style->getStrokePaintServer();
+ if ( SP_IS_PATTERN(server) ) {
+ SPPattern *pattern = sp_pattern_clone_if_necessary(item, SP_PATTERN(server), "stroke");
+ sp_pattern_transform_multiply(pattern, postmul, set);
}
}
}
}
-
}
}
-void
-sp_item_adjust_gradient (SPItem *item, NR::Matrix const &postmul, bool set)
+void sp_item_adjust_gradient( SPItem *item, Geom::Matrix const &postmul, bool set )
{
{
- SPStyle *style = SP_OBJECT_STYLE (item);
+ SPStyle *style = item->style;
- if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) {
- SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(item);
- if (SP_IS_GRADIENT (server)) {
+ if ( style && style->fill.isPaintserver() ) {
+ SPPaintServer *server = item->style->getFillPaintServer();
+ if ( SP_IS_GRADIENT(server) ) {
/**
* \note Bbox units for a gradient are generally a bad idea because
/**
* \note Bbox units for a gradient are generally a bad idea because
* \todo FIXME: convert back to bbox units after transforming with
* the item, so as to preserve the original units.
*/
* \todo FIXME: convert back to bbox units after transforming with
* the item, so as to preserve the original units.
*/
- SPGradient *gradient = sp_gradient_convert_to_userspace (SP_GRADIENT (server), item, "fill");
+ SPGradient *gradient = sp_gradient_convert_to_userspace( SP_GRADIENT(server), item, "fill" );
- sp_gradient_transform_multiply (gradient, postmul, set);
+ sp_gradient_transform_multiply( gradient, postmul, set );
}
}
}
}
- if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) {
- SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER(item);
- if (SP_IS_GRADIENT (server)) {
- SPGradient *gradient = sp_gradient_convert_to_userspace (SP_GRADIENT (server), item, "stroke");
- sp_gradient_transform_multiply (gradient, postmul, set);
+ if ( style && style->stroke.isPaintserver() ) {
+ SPPaintServer *server = item->style->getStrokePaintServer();
+ if ( SP_IS_GRADIENT(server) ) {
+ SPGradient *gradient = sp_gradient_convert_to_userspace( SP_GRADIENT(server), item, "stroke" );
+ sp_gradient_transform_multiply( gradient, postmul, set );
}
}
}
}
}
}
-void
-sp_item_adjust_stroke (SPItem *item, gdouble ex)
+void sp_item_adjust_stroke( SPItem *item, gdouble ex )
{
{
- SPStyle *style = SP_OBJECT_STYLE (item);
-
- if (style && style->stroke.type != SP_PAINT_TYPE_NONE && !NR_DF_TEST_CLOSE (ex, 1.0, NR_EPSILON)) {
+ SPStyle *style = item->style;
+ if ( style && !style->stroke.isNone() && !NR_DF_TEST_CLOSE(ex, 1.0, NR_EPSILON) ) {
style->stroke_width.computed *= ex;
style->stroke_width.set = TRUE;
style->stroke_width.computed *= ex;
style->stroke_width.set = TRUE;
- if (style->stroke_dash.n_dash != 0) {
- int i;
- for (i = 0; i < style->stroke_dash.n_dash; i++) {
+ if ( style->stroke_dash.n_dash != 0 ) {
+ for (int i = 0; i < style->stroke_dash.n_dash; i++) {
style->stroke_dash.dash[i] *= ex;
}
style->stroke_dash.offset *= ex;
}
style->stroke_dash.dash[i] *= ex;
}
style->stroke_dash.offset *= ex;
}
- SP_OBJECT(item)->updateRepr();
+ item->updateRepr();
}
}
/**
* Find out the inverse of previous transform of an item (from its repr)
*/
}
}
/**
* Find out the inverse of previous transform of an item (from its repr)
*/
-NR::Matrix
+Geom::Matrix
sp_item_transform_repr (SPItem *item)
{
sp_item_transform_repr (SPItem *item)
{
- NR::Matrix t_old(NR::identity());
- gchar const *t_attr = SP_OBJECT_REPR(item)->attribute("transform");
+ Geom::Matrix t_old(Geom::identity());
+ gchar const *t_attr = item->repr->attribute("transform");
if (t_attr) {
if (t_attr) {
- NR::Matrix t;
+ Geom::Matrix t;
if (sp_svg_transform_read(t_attr, &t)) {
t_old = t;
}
if (sp_svg_transform_read(t_attr, &t)) {
t_old = t;
}
{
sp_item_adjust_stroke (item, expansion);
{
sp_item_adjust_stroke (item, expansion);
- for (SPObject *o = SP_OBJECT(item)->children; o != NULL; o = o->next) {
+// A clone's child is the ghost of its original - we must not touch it, skip recursion
+ if (item && SP_IS_USE(item))
+ return;
+
+ for (SPObject *o = item->children; o != NULL; o = o->next) {
if (SP_IS_ITEM(o))
sp_item_adjust_stroke_width_recursive(SP_ITEM(o), expansion);
}
if (SP_IS_ITEM(o))
sp_item_adjust_stroke_width_recursive(SP_ITEM(o), expansion);
}
* Recursively adjust rx and ry of rects.
*/
void
* Recursively adjust rx and ry of rects.
*/
void
-sp_item_adjust_rects_recursive(SPItem *item, NR::Matrix advertized_transform)
+sp_item_adjust_rects_recursive(SPItem *item, Geom::Matrix advertized_transform)
{
if (SP_IS_RECT (item)) {
sp_rect_compensate_rxry (SP_RECT(item), advertized_transform);
}
{
if (SP_IS_RECT (item)) {
sp_rect_compensate_rxry (SP_RECT(item), advertized_transform);
}
- for (SPObject *o = SP_OBJECT(item)->children; o != NULL; o = o->next) {
+ for (SPObject *o = item->children; o != NULL; o = o->next) {
if (SP_IS_ITEM(o))
sp_item_adjust_rects_recursive(SP_ITEM(o), advertized_transform);
}
if (SP_IS_ITEM(o))
sp_item_adjust_rects_recursive(SP_ITEM(o), advertized_transform);
}
@@ -1142,47 +1339,60 @@ sp_item_adjust_rects_recursive(SPItem *item, NR::Matrix advertized_transform)
* Recursively compensate pattern or gradient transform.
*/
void
* Recursively compensate pattern or gradient transform.
*/
void
-sp_item_adjust_paint_recursive (SPItem *item, NR::Matrix advertized_transform, NR::Matrix t_ancestors, bool is_pattern)
+sp_item_adjust_paint_recursive (SPItem *item, Geom::Matrix advertized_transform, Geom::Matrix t_ancestors, bool is_pattern)
{
{
-// A clone must not touch the style (it's that of its parent!) and has no children, so quit now
- if (item && SP_IS_USE(item))
- return;
-
// _Before_ full pattern/gradient transform: t_paint * t_item * t_ancestors
// _After_ full pattern/gradient transform: t_paint_new * t_item * t_ancestors * advertised_transform
// By equating these two expressions we get t_paint_new = t_paint * paint_delta, where:
// _Before_ full pattern/gradient transform: t_paint * t_item * t_ancestors
// _After_ full pattern/gradient transform: t_paint_new * t_item * t_ancestors * advertised_transform
// By equating these two expressions we get t_paint_new = t_paint * paint_delta, where:
- NR::Matrix t_item = sp_item_transform_repr (item);
- NR::Matrix paint_delta = t_item * t_ancestors * advertized_transform * t_ancestors.inverse() * t_item.inverse();
+ Geom::Matrix t_item = sp_item_transform_repr (item);
+ Geom::Matrix paint_delta = t_item * t_ancestors * advertized_transform * t_ancestors.inverse() * t_item.inverse();
+
+// Within text, we do not fork gradients, and so must not recurse to avoid double compensation;
+// also we do not recurse into clones, because a clone's child is the ghost of its original -
+// we must not touch it
+ if (!(item && (SP_IS_TEXT(item) || SP_IS_USE(item)))) {
+ for (SPObject *o = item->children; o != NULL; o = o->next) {
+ if (SP_IS_ITEM(o)) {
+// At the level of the transformed item, t_ancestors is identity;
+// below it, it is the accmmulated chain of transforms from this level to the top level
+ sp_item_adjust_paint_recursive (SP_ITEM(o), advertized_transform, t_item * t_ancestors, is_pattern);
+ }
+ }
+ }
+
+// We recursed into children first, and are now adjusting this object second;
+// this is so that adjustments in a tree are done from leaves up to the root,
+// and paintservers on leaves inheriting their values from ancestors could adjust themselves properly
+// before ancestors themselves are adjusted, probably differently (bug 1286535)
if (is_pattern)
sp_item_adjust_pattern (item, paint_delta);
else
sp_item_adjust_gradient (item, paint_delta);
if (is_pattern)
sp_item_adjust_pattern (item, paint_delta);
else
sp_item_adjust_gradient (item, paint_delta);
-// Within text, we do not fork gradients, and so must not recurse to avoid double compensation
- if (item && SP_IS_TEXT(item))
- return;
-
- for (SPObject *o = SP_OBJECT(item)->children; o != NULL; o = o->next) {
- if (SP_IS_ITEM(o)) {
-// At the level of the transformed item, t_ancestors is identity;
-// below it, it is the accmmulated chain of transforms from this level to the top level
- sp_item_adjust_paint_recursive (SP_ITEM(o), advertized_transform, t_item * t_ancestors, is_pattern);
- }
- }
}
}
-/**
- * A temporary wrapper for the next function accepting the NRMatrix
- * instead of NR::Matrix
- */
void
void
-sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NRMatrix const *transform, NR::Matrix const *adv)
+sp_item_adjust_livepatheffect (SPItem *item, Geom::Matrix const &postmul, bool set)
{
{
- if (transform == NULL)
- sp_item_write_transform(item, repr, NR::identity(), adv);
- else
- sp_item_write_transform(item, repr, NR::Matrix (transform), adv);
+ if ( !SP_IS_LPE_ITEM(item) )
+ return;
+
+ SPLPEItem *lpeitem = SP_LPE_ITEM (item);
+ if ( sp_lpe_item_has_path_effect(lpeitem) ) {
+ sp_lpe_item_fork_path_effects_if_necessary(lpeitem);
+
+ // now that all LPEs are forked_if_necessary, we can apply the transform
+ PathEffectList effect_list = sp_lpe_item_get_effect_list(lpeitem);
+ for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); it++)
+ {
+ LivePathEffectObject *lpeobj = (*it)->lpeobject;
+ if (lpeobj && lpeobj->get_lpe()) {
+ Inkscape::LivePathEffect::Effect * effect = lpeobj->get_lpe();
+ effect->transform_multiply(postmul, set);
+ }
+ }
+ }
}
/**
}
/**
@@ -1194,57 +1404,58 @@ sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NRMatrix const
* the repr is updated with the new transform.
*/
void
* the repr is updated with the new transform.
*/
void
-sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix const &transform, NR::Matrix const *adv, bool compensate)
+sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, Geom::Matrix const &transform, Geom::Matrix const *adv, bool compensate)
{
g_return_if_fail(item != NULL);
g_return_if_fail(SP_IS_ITEM(item));
g_return_if_fail(repr != NULL);
// calculate the relative transform, if not given by the adv attribute
{
g_return_if_fail(item != NULL);
g_return_if_fail(SP_IS_ITEM(item));
g_return_if_fail(repr != NULL);
// calculate the relative transform, if not given by the adv attribute
- NR::Matrix advertized_transform;
+ Geom::Matrix advertized_transform;
if (adv != NULL) {
advertized_transform = *adv;
} else {
advertized_transform = sp_item_transform_repr (item).inverse() * transform;
}
if (adv != NULL) {
advertized_transform = *adv;
} else {
advertized_transform = sp_item_transform_repr (item).inverse() * transform;
}
-
+
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (compensate) {
if (compensate) {
-
+
// recursively compensate for stroke scaling, depending on user preference
// recursively compensate for stroke scaling, depending on user preference
- if (prefs_get_int_attribute("options.transform", "stroke", 1) == 0) {
- double const expansion = 1. / NR::expansion(advertized_transform);
+ if (!prefs->getBool("/options/transform/stroke", true)) {
+ double const expansion = 1. / advertized_transform.descrim();
sp_item_adjust_stroke_width_recursive(item, expansion);
}
sp_item_adjust_stroke_width_recursive(item, expansion);
}
-
+
// recursively compensate rx/ry of a rect if requested
// recursively compensate rx/ry of a rect if requested
- if (prefs_get_int_attribute("options.transform", "rectcorners", 1) == 0) {
+ if (!prefs->getBool("/options/transform/rectcorners", true)) {
sp_item_adjust_rects_recursive(item, advertized_transform);
}
sp_item_adjust_rects_recursive(item, advertized_transform);
}
-
+
// recursively compensate pattern fill if it's not to be transformed
// recursively compensate pattern fill if it's not to be transformed
- if (prefs_get_int_attribute("options.transform", "pattern", 1) == 0) {
- sp_item_adjust_paint_recursive (item, advertized_transform.inverse(), NR::identity(), true);
+ if (!prefs->getBool("/options/transform/pattern", true)) {
+ sp_item_adjust_paint_recursive (item, advertized_transform.inverse(), Geom::identity(), true);
}
/// \todo FIXME: add the same else branch as for gradients below, to convert patterns to userSpaceOnUse as well
/// recursively compensate gradient fill if it's not to be transformed
}
/// \todo FIXME: add the same else branch as for gradients below, to convert patterns to userSpaceOnUse as well
/// recursively compensate gradient fill if it's not to be transformed
- if (prefs_get_int_attribute("options.transform", "gradient", 1) == 0) {
- sp_item_adjust_paint_recursive (item, advertized_transform.inverse(), NR::identity(), false);
+ if (!prefs->getBool("/options/transform/gradient", true)) {
+ sp_item_adjust_paint_recursive (item, advertized_transform.inverse(), Geom::identity(), false);
} else {
// this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do
// it here _before_ the new transform is set, so as to use the pre-transform bbox
} else {
// this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do
// it here _before_ the new transform is set, so as to use the pre-transform bbox
- sp_item_adjust_paint_recursive (item, NR::identity(), NR::identity(), false);
- }
-
+ sp_item_adjust_paint_recursive (item, Geom::identity(), Geom::identity(), false);
+ }
+
} // endif(compensate)
} // endif(compensate)
- gint preserve = prefs_get_int_attribute("options.preservetransform", "value", 0);
- NR::Matrix transform_attr (transform);
+ gint preserve = prefs->getBool("/options/preservetransform/value", 0);
+ Geom::Matrix transform_attr (transform);
if ( // run the object's set_transform (i.e. embed transform) only if:
((SPItemClass *) G_OBJECT_GET_CLASS(item))->set_transform && // it does have a set_transform method
!preserve && // user did not chose to preserve all transforms
!item->clip_ref->getObject() && // the object does not have a clippath
!item->mask_ref->getObject() && // the object does not have a mask
if ( // run the object's set_transform (i.e. embed transform) only if:
((SPItemClass *) G_OBJECT_GET_CLASS(item))->set_transform && // it does have a set_transform method
!preserve && // user did not chose to preserve all transforms
!item->clip_ref->getObject() && // the object does not have a clippath
!item->mask_ref->getObject() && // the object does not have a mask
- !(!transform.is_translation() && SP_OBJECT_STYLE(item) && SP_OBJECT_STYLE(item)->filter.filter)
+ !(!transform.isTranslation() && item->style && item->style->getFilter())
// the object does not have a filter, or the transform is translation (which is supposed to not affect filters)
) {
transform_attr = ((SPItemClass *) G_OBJECT_GET_CLASS(item))->set_transform(item, transform);
// the object does not have a filter, or the transform is translation (which is supposed to not affect filters)
) {
transform_attr = ((SPItemClass *) G_OBJECT_GET_CLASS(item))->set_transform(item, transform);
@@ -1255,7 +1466,7 @@ sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix cons
// it causes clone SPUse's copy of the original object to brought up to
// date with the original. Otherwise, sp_use_bbox returns incorrect
// values if called in code handling the transformed signal.
// it causes clone SPUse's copy of the original object to brought up to
// date with the original. Otherwise, sp_use_bbox returns incorrect
// values if called in code handling the transformed signal.
- SP_OBJECT(item)->updateRepr();
+ item->updateRepr();
// send the relative transform with a _transformed_signal
item->_transformed_signal.emit(&advertized_transform, item);
// send the relative transform with a _transformed_signal
item->_transformed_signal.emit(&advertized_transform, item);
* gradients, patterns as sp_item_write_transform does.
*/
void
* gradients, patterns as sp_item_write_transform does.
*/
void
-sp_item_set_item_transform(SPItem *item, NR::Matrix const &transform)
+sp_item_set_item_transform(SPItem *item, Geom::Matrix const &transform)
{
g_return_if_fail(item != NULL);
g_return_if_fail(SP_IS_ITEM(item));
{
g_return_if_fail(item != NULL);
g_return_if_fail(SP_IS_ITEM(item));
}
}
}
}
+void
+sp_item_convert_item_to_guides(SPItem *item) {
+ g_return_if_fail(item != NULL);
+ g_return_if_fail(SP_IS_ITEM(item));
+
+ /* Use derived method if present ... */
+ if (((SPItemClass *) G_OBJECT_GET_CLASS(item))->convert_to_guides) {
+ (*((SPItemClass *) G_OBJECT_GET_CLASS(item))->convert_to_guides)(item);
+ return;
+ }
+
+ /* .. otherwise simply place the guides around the item's bounding box */
+
+ sp_item_convert_to_guides(item);
+}
+
/**
* \pre \a ancestor really is an ancestor (\>=) of \a object, or NULL.
* ("Ancestor (\>=)" here includes as far as \a object itself.)
*/
/**
* \pre \a ancestor really is an ancestor (\>=) of \a object, or NULL.
* ("Ancestor (\>=)" here includes as far as \a object itself.)
*/
-NR::Matrix
+Geom::Matrix
i2anc_affine(SPObject const *object, SPObject const *const ancestor) {
i2anc_affine(SPObject const *object, SPObject const *const ancestor) {
- NR::Matrix ret(NR::identity());
+ Geom::Matrix ret(Geom::identity());
g_return_val_if_fail(object != NULL, ret);
/* stop at first non-renderable ancestor */
while ( object != ancestor && SP_IS_ITEM(object) ) {
if (SP_IS_ROOT(object)) {
ret *= SP_ROOT(object)->c2p;
g_return_val_if_fail(object != NULL, ret);
/* stop at first non-renderable ancestor */
while ( object != ancestor && SP_IS_ITEM(object) ) {
if (SP_IS_ROOT(object)) {
ret *= SP_ROOT(object)->c2p;
+ } else {
+ ret *= SP_ITEM(object)->transform;
}
}
- ret *= SP_ITEM(object)->transform;
- object = SP_OBJECT_PARENT(object);
+ object = object->parent;
}
return ret;
}
}
return ret;
}
-NR::Matrix
+Geom::Matrix
i2i_affine(SPObject const *src, SPObject const *dest) {
i2i_affine(SPObject const *src, SPObject const *dest) {
- g_return_val_if_fail(src != NULL && dest != NULL, NR::identity());
+ g_return_val_if_fail(src != NULL && dest != NULL, Geom::identity());
SPObject const *ancestor = src->nearestCommonAncestor(dest);
SPObject const *ancestor = src->nearestCommonAncestor(dest);
- return i2anc_affine(src, ancestor) / i2anc_affine(dest, ancestor);
+ return i2anc_affine(src, ancestor) * i2anc_affine(dest, ancestor).inverse();
}
}
-NR::Matrix SPItem::getRelativeTransform(SPObject const *dest) const {
+Geom::Matrix SPItem::getRelativeTransform(SPObject const *dest) const {
return i2i_affine(this, dest);
}
return i2i_affine(this, dest);
}
* Returns the accumulated transformation of the item and all its ancestors, including root's viewport.
* \pre (item != NULL) and SP_IS_ITEM(item).
*/
* Returns the accumulated transformation of the item and all its ancestors, including root's viewport.
* \pre (item != NULL) and SP_IS_ITEM(item).
*/
-NR::Matrix sp_item_i2doc_affine(SPItem const *item)
+Geom::Matrix sp_item_i2doc_affine(SPItem const *item)
{
return i2anc_affine(item, NULL);
}
/**
{
return i2anc_affine(item, NULL);
}
/**
- * Returns the accumulated transformation of the item and all its ancestors, but excluding root's viewport.
- * Used in path operations mostly.
- * \pre (item != NULL) and SP_IS_ITEM(item).
+ * Returns the transformation from item to desktop coords
*/
*/
-NR::Matrix sp_item_i2root_affine(SPItem const *item)
-{
- g_assert(item != NULL);
- g_assert(SP_IS_ITEM(item));
-
- NR::Matrix ret(NR::identity());
- g_assert(ret.test_identity());
- while ( NULL != SP_OBJECT_PARENT(item) ) {
- ret *= item->transform;
- item = SP_ITEM(SP_OBJECT_PARENT(item));
- }
- g_assert(SP_IS_ROOT(item));
-
- ret *= item->transform;
-
- return ret;
-}
-
-/* fixme: This is EVIL!!! */
-
-NR::Matrix sp_item_i2d_affine(SPItem const *item)
+Geom::Matrix sp_item_i2d_affine(SPItem const *item)
{
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
{
g_assert(item != NULL);
g_assert(SP_IS_ITEM(item));
- NR::Matrix const ret( sp_item_i2doc_affine(item)
- * NR::scale(1, -1)
- * NR::translate(0, sp_document_height(SP_OBJECT_DOCUMENT(item))) );
+ Geom::Matrix const ret( sp_item_i2doc_affine(item)
+ * Geom::Scale(1, -1)
+ * Geom::Translate(0, sp_document_height(item->document)) );
return ret;
}
return ret;
}
-// same as i2d but with i2root instead of i2doc
-NR::Matrix sp_item_i2r_affine(SPItem const *item)
-{
- g_assert(item != NULL);
- g_assert(SP_IS_ITEM(item));
-
- NR::Matrix const ret( sp_item_i2root_affine(item)
- * NR::scale(1, -1)
- * NR::translate(0, sp_document_height(SP_OBJECT_DOCUMENT(item))) );
- return ret;
-}
-
-/**
- * Converts a matrix \a m into the desktop coords of the \a item.
- * Will become a noop when we eliminate the coordinate flipping.
- */
-NR::Matrix matrix_to_desktop(NR::Matrix const m, SPItem const *item)
-{
- NR::Matrix const ret(m
- * NR::translate(0, -sp_document_height(SP_OBJECT_DOCUMENT(item)))
- * NR::scale(1, -1));
- return ret;
-}
-
-/**
- * Converts a matrix \a m from the desktop coords of the \a item.
- * Will become a noop when we eliminate the coordinate flipping.
- */
-NR::Matrix matrix_from_desktop(NR::Matrix const m, SPItem const *item)
-{
- NR::Matrix const ret(NR::scale(1, -1)
- * NR::translate(0, sp_document_height(SP_OBJECT_DOCUMENT(item)))
- * m);
- return ret;
-}
-
-void sp_item_set_i2d_affine(SPItem *item, NR::Matrix const &i2dt)
+void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &i2dt)
{
g_return_if_fail( item != NULL );
g_return_if_fail( SP_IS_ITEM(item) );
{
g_return_if_fail( item != NULL );
g_return_if_fail( SP_IS_ITEM(item) );
- NR::Matrix dt2p; /* desktop to item parent transform */
- if (SP_OBJECT_PARENT(item)) {
- dt2p = sp_item_i2d_affine((SPItem *) SP_OBJECT_PARENT(item)).inverse();
+ Geom::Matrix dt2p; /* desktop to item parent transform */
+ if (item->parent) {
+ dt2p = sp_item_i2d_affine(static_cast<SPItem *>(item->parent)).inverse();
} else {
} else {
- dt2p = ( NR::translate(0, -sp_document_height(SP_OBJECT_DOCUMENT(item)))
- * NR::scale(1, -1) );
+ dt2p = ( Geom::Translate(0, -sp_document_height(item->document))
+ * Geom::Scale(1, -1) );
}
}
- NR::Matrix const i2p( i2dt * dt2p );
+ Geom::Matrix const i2p( i2dt * dt2p );
sp_item_set_item_transform(item, i2p);
}
sp_item_set_item_transform(item, i2p);
}
-NR::Matrix
+/**
+ * should rather be named "sp_item_d2i_affine" to match "sp_item_i2d_affine" (or vice versa)
+ */
+Geom::Matrix
sp_item_dt2i_affine(SPItem const *item)
{
/* fixme: Implement the right way (Lauris) */
sp_item_dt2i_affine(SPItem const *item)
{
/* fixme: Implement the right way (Lauris) */
@@ -1448,7 +1621,7 @@ sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigne
new_view->next = list;
new_view->flags = flags;
new_view->key = key;
new_view->next = list;
new_view->flags = flags;
new_view->key = key;
- new_view->arenaitem = nr_arena_item_ref(arenaitem);
+ new_view->arenaitem = arenaitem;
return new_view;
}
return new_view;
}
int
sp_item_repr_compare_position(SPItem *first, SPItem *second)
{
int
sp_item_repr_compare_position(SPItem *first, SPItem *second)
{
- return sp_repr_compare_position(SP_OBJECT_REPR(first),
- SP_OBJECT_REPR(second));
+ return sp_repr_compare_position(first->repr,
+ second->repr);
}
SPItem *
sp_item_first_item_child (SPObject *obj)
{
}
SPItem *
sp_item_first_item_child (SPObject *obj)
{
- for ( SPObject *iter = sp_object_first_child(obj) ; iter ; iter = SP_OBJECT_NEXT(iter)) {
- if (SP_IS_ITEM (iter))
+ for ( SPObject *iter = sp_object_first_child(obj) ; iter ; iter = iter->next) {
+ if ( SP_IS_ITEM(iter) ) {
return SP_ITEM (iter);
return SP_ITEM (iter);
+ }
}
return NULL;
}
}
return NULL;
}
+void
+sp_item_convert_to_guides(SPItem *item) {
+ SPDesktop *dt = inkscape_active_desktop();
+ SPNamedView *nv = sp_desktop_namedview(dt);
+ (void)nv;
+
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ int prefs_bbox = prefs->getInt("/tools/bounding_box", 0);
+ SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
+ SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
+
+ Geom::OptRect bbox = sp_item_bbox_desktop(item, bbox_type);
+ if (!bbox) {
+ g_warning ("Cannot determine item's bounding box during conversion to guides.\n");
+ return;
+ }
+
+ std::list<std::pair<Geom::Point, Geom::Point> > pts;
+
+ Geom::Point A((*bbox).min());
+ Geom::Point C((*bbox).max());
+ Geom::Point B(A[Geom::X], C[Geom::Y]);
+ Geom::Point D(C[Geom::X], A[Geom::Y]);
+
+ pts.push_back(std::make_pair(A, B));
+ pts.push_back(std::make_pair(B, C));
+ pts.push_back(std::make_pair(C, D));
+ pts.push_back(std::make_pair(D, A));
+
+ sp_guide_pt_pairs_to_guides(dt, pts);
+}
/*
Local Variables:
/*
Local Variables: