X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsp-item.cpp;h=65d8b997c729130a31a37a8b2130f05e51052a29;hb=76b503bd0b736746080408a83b83f99da06be85b;hp=eb3abce16b618d40e8d098b401f5343ffbc5b901;hpb=6e3576be211b59b7d8a9e7afe3493d961c053b75;p=inkscape.git diff --git a/src/sp-item.cpp b/src/sp-item.cpp index eb3abce16..65d8b997c 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -34,6 +34,8 @@ #include "attributes.h" #include "document.h" #include "uri.h" +#include "inkscape.h" +#include "desktop-handles.h" #include "style.h" #include @@ -50,6 +52,8 @@ #include "prefs-utils.h" #include "conn-avoid-ref.h" #include "conditions.h" +#include "sp-filter-reference.h" +#include "sp-guide.h" #include "libnr/nr-matrix-div.h" #include "libnr/nr-matrix-fns.h" @@ -57,10 +61,15 @@ #include "libnr/nr-matrix-translate-ops.h" #include "libnr/nr-scale-translate-ops.h" #include "libnr/nr-translate-scale-ops.h" +#include "libnr/nr-convert2geom.h" #include "algorithms/find-last-if.h" #include "util/reverse-list.h" #include "xml/repr.h" +#include "extract-uri.h" + +#include "live_effects/lpeobject.h" +#include "live_effects/effect.h" #define noSP_ITEM_DEBUG_IDLE @@ -159,8 +168,6 @@ void SPItem::init() { sigc::slot2 sl2=sigc::bind(sigc::ptr_fun(mask_ref_changed), this); _mask_ref_connection = cs2.connect(sl2); - if (!this->style) this->style = sp_style_new_from_object(this); - this->avoidRef = new SPAvoidRef(this); new (&this->_transformed_signal) sigc::signal(); @@ -298,7 +305,7 @@ bool SPItem::isCenterSet() { return (transform_center_x != 0 || transform_center_y != 0); } -NR::Point SPItem::getCenter() { +NR::Point SPItem::getCenter() const { NR::Maybe bbox = getBounds(sp_item_i2d_affine(this)); if (bbox) { return bbox->midpoint() + NR::Point (this->transform_center_x, this->transform_center_y); @@ -404,6 +411,14 @@ sp_item_release(SPObject *object) 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; @@ -416,11 +431,6 @@ sp_item_release(SPObject *object) item->mask_ref = NULL; } - if (item->avoidRef) { - delete item->avoidRef; - item->avoidRef = NULL; - } - if (((SPObjectClass *) (parent_class))->release) { ((SPObjectClass *) parent_class)->release(object); } @@ -449,7 +459,7 @@ sp_item_set(SPObject *object, unsigned key, gchar const *value) 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)); @@ -465,7 +475,7 @@ sp_item_set(SPObject *object, unsigned key, gchar const *value) 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)); @@ -486,10 +496,6 @@ sp_item_set(SPObject *object, unsigned key, gchar const *value) 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; @@ -601,8 +607,8 @@ sp_item_update(SPObject *object, SPCtx *ctx, guint flags) } } - 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; @@ -627,8 +633,22 @@ sp_item_update(SPObject *object, SPCtx *ctx, guint flags) } } + /* Update bounding box data used by filters */ + if (item->style->filter.set && item->display) { + NRRect item_bbox; + sp_item_invoke_bbox(item, &item_bbox, NR::identity(), TRUE, SPItem::GEOMETRIC_BBOX); + NR::Maybe i_bbox = item_bbox; + + SPItemView *itemview = item->display; + do { + if (itemview->arenaitem) + nr_arena_item_set_item_bbox(itemview->arenaitem, i_bbox); + } while ( (itemview = itemview->next) ); + } + // Update libavoid with item geometry (for connector routing). - item->avoidRef->handleSettingChange(); + if (item->avoidRef) + item->avoidRef->handleSettingChange(); } static Inkscape::XML::Node * @@ -640,46 +660,6 @@ sp_item_write(SPObject *const object, Inkscape::XML::Node *repr, guint flags) repr->setAttribute("transform", c); g_free(c); - 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 - * 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); - } - - /** \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); - } - if (flags & SP_OBJECT_WRITE_EXT) { repr->setAttribute("sodipodi:insensitive", ( item->sensitive ? NULL : "true" )); if (item->transform_center_x != 0) @@ -712,19 +692,83 @@ sp_item_write(SPObject *const object, Inkscape::XML::Node *repr, guint flags) NR::Maybe SPItem::getBounds(NR::Matrix const &transform, SPItem::BBoxType type, - unsigned int dkey) const + unsigned int /*dkey*/) const { - NRRect r; + NR::Maybe r = NR::Nothing(); sp_item_invoke_bbox_full(this, &r, transform, type, TRUE); return r; } void -sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear) +sp_item_invoke_bbox(SPItem const *item, NR::Maybe *bbox, NR::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); +} + +// DEPRECATED to phase out the use of NRRect in favor of NR::Maybe +void +sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type) +{ + 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. */ +void +sp_item_invoke_bbox_full(SPItem const *item, NR::Maybe *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear) +{ + g_assert(item != NULL); + g_assert(SP_IS_ITEM(item)); + g_assert(bbox != NULL); + + if (clear) { + *bbox = NR::Nothing(); + } + + // TODO: replace NRRect by NR::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, 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 (&temp_bbox, &temp_bbox, &b); + } + + if (temp_bbox.x0 > temp_bbox.x1 || temp_bbox.y0 > temp_bbox.y1) { + // We'll assume here that when x0 > x1 or y0 > y1, the bbox is "nothing" + // However it has never been explicitely defined this way for NRRects + // (as opposed to NR::Maybe) + *bbox = NR::Nothing(); + return; + } + + if (temp_bbox.x0 == temp_bbox.y0 == NR_HUGE && temp_bbox.x1 == temp_bbox.y1 == -NR_HUGE) { + // The bbox hasn't been touched by the SPItemClass' bbox method + // or it has explicitely been set to be like this (e.g. in sp_shape_bbox) + *bbox = NR::Nothing(); + return; + } + + // Do not use temp_bbox.upgrade() here, because it uses a test that returns NR::Nothing + // for any rectangle with zero area. The geometrical bbox of for example a vertical line + // would therefore be translated into NR::Nothing (see bug https://bugs.launchpad.net/inkscape/+bug/168684) + NR::Maybe temp_bbox_new = NR::Rect(NR::Point(temp_bbox.x0, temp_bbox.y0), NR::Point(temp_bbox.x1, temp_bbox.y1)); + + *bbox = NR::union_bounds(*bbox, temp_bbox_new); +} + +// DEPRECATED to phase out the use of NRRect in favor of NR::Maybe /** 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, @@ -750,8 +794,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); } - // 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); @@ -789,35 +833,40 @@ unsigned sp_item_pos_in_parent(SPItem *item) } 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); - 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::Maybe sp_item_bbox_desktop(SPItem *item) +NR::Maybe sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type) { - NRRect ret; - sp_item_invoke_bbox(item, &ret, sp_item_i2d_affine(item), TRUE); - return ret.upgrade(); + NR::Maybe rect = NR::Nothing(); + 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) { NR::Maybe bbox = item->getBounds(sp_item_i2d_affine(item)); - /* Just a pair of opposite corners of the bounding box suffices given that we don't yet + /* Just the corners of the bounding box suffices given that we don't yet support angled guide lines. */ if (bbox) { - *p = bbox->min(); - *p = bbox->max(); + NR::Point p1, p2; + p1 = bbox->min(); + p2 = bbox->max(); + *p = p1; + *p = NR::Point(p1[NR::X], p2[NR::Y]); + *p = p2; + *p = NR::Point(p1[NR::Y], p2[NR::X]); } } -void sp_item_snappoints(SPItem const *item, SnapPointsIter p) +void sp_item_snappoints(SPItem const *item, bool includeItemCenter, SnapPointsIter p) { g_assert (item != NULL); g_assert (SP_IS_ITEM(item)); @@ -826,6 +875,10 @@ void sp_item_snappoints(SPItem const *item, SnapPointsIter p) if (item_class.snappoints) { item_class.snappoints(item, p); } + + if (includeItemCenter) { + *p = item->getCenter(); + } } void @@ -847,7 +900,7 @@ sp_item_invoke_print(SPItem *item, SPPrintContext *ctx) } static gchar * -sp_item_private_description(SPItem *item) +sp_item_private_description(SPItem */*item*/) { return g_strdup(_("Object")); } @@ -956,6 +1009,10 @@ sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags) SP_OBJECT(mask)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } NR_ARENA_ITEM_SET_DATA(ai, item); + NRRect item_bbox; + sp_item_invoke_bbox(item, &item_bbox, NR::identity(), TRUE, SPItem::GEOMETRIC_BBOX); + NR::Maybe i_bbox = item_bbox; + nr_arena_item_set_item_bbox(ai, i_bbox); } return ai; @@ -1006,7 +1063,7 @@ sp_item_adjust_pattern (SPItem *item, NR::Matrix const &postmul, bool set) { SPStyle *style = SP_OBJECT_STYLE (item); - if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) { + if (style && (style->fill.isPaintserver())) { 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"); @@ -1014,7 +1071,7 @@ sp_item_adjust_pattern (SPItem *item, NR::Matrix const &postmul, bool set) } } - if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) { + if (style && (style->stroke.isPaintserver())) { 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"); @@ -1029,7 +1086,7 @@ sp_item_adjust_gradient (SPItem *item, NR::Matrix const &postmul, bool set) { SPStyle *style = SP_OBJECT_STYLE (item); - if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) { + if (style && (style->fill.isPaintserver())) { SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(item); if (SP_IS_GRADIENT (server)) { @@ -1048,7 +1105,7 @@ sp_item_adjust_gradient (SPItem *item, NR::Matrix const &postmul, bool set) } } - if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) { + if (style && (style->stroke.isPaintserver())) { 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"); @@ -1062,7 +1119,7 @@ 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)) { + if (style && !style->stroke.isNone() && !NR_DF_TEST_CLOSE (ex, 1.0, NR_EPSILON)) { style->stroke_width.computed *= ex; style->stroke_width.set = TRUE; @@ -1106,6 +1163,10 @@ sp_item_adjust_stroke_width_recursive(SPItem *item, double expansion) { sp_item_adjust_stroke (item, expansion); +// 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 = SP_OBJECT(item)->children; o != NULL; o = o->next) { if (SP_IS_ITEM(o)) sp_item_adjust_stroke_width_recursive(SP_ITEM(o), expansion); @@ -1134,30 +1195,54 @@ sp_item_adjust_rects_recursive(SPItem *item, NR::Matrix advertized_transform) void sp_item_adjust_paint_recursive (SPItem *item, NR::Matrix advertized_transform, NR::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: 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(); +// 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 = 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); + } + } + } + +// 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); -// Within text, we do not fork gradients, and so must not recurse to avoid double compensation - if (item && SP_IS_TEXT(item)) +} + +void +sp_item_adjust_livepatheffect (SPItem *item, NR::Matrix const &postmul, bool set) +{ + if ( !SP_IS_SHAPE(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); + SPShape *shape = SP_SHAPE (item); + if ( sp_shape_has_path_effect(shape) ) { + LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(shape); + LivePathEffectObject *new_lpeobj = lpeobj->fork_private_if_necessary(); + if (new_lpeobj != lpeobj) { + sp_shape_set_path_effect(shape, new_lpeobj); + } + + Inkscape::LivePathEffect::Effect * effect = sp_shape_get_livepatheffect(shape); + if (effect) { + effect->transform_multiply (to_2geom(postmul), set); } } } @@ -1197,20 +1282,20 @@ sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix cons } else { advertized_transform = sp_item_transform_repr (item).inverse() * transform; } - + if (compensate) { - + // 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); sp_item_adjust_stroke_width_recursive(item, expansion); } - + // recursively compensate rx/ry of a rect if requested if (prefs_get_int_attribute("options.transform", "rectcorners", 1) == 0) { sp_item_adjust_rects_recursive(item, advertized_transform); } - + // 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); @@ -1223,8 +1308,8 @@ sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix cons // 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); - } - + } + } // endif(compensate) gint preserve = prefs_get_int_attribute("options.preservetransform", "value", 0); @@ -1234,7 +1319,7 @@ sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix cons !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.is_translation() && SP_OBJECT_STYLE(item) && SP_OBJECT_STYLE(item)->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); @@ -1283,6 +1368,22 @@ sp_item_set_item_transform(SPItem *item, NR::Matrix const &transform) } } +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. @@ -1494,6 +1595,35 @@ sp_item_first_item_child (SPObject *obj) return NULL; } +void +sp_item_convert_to_guides(SPItem *item) { + SPDesktop *dt = inkscape_active_desktop(); + SPNamedView *nv = sp_desktop_namedview(dt); + (void)nv; + + gchar const *prefs_bbox = prefs_get_string_attribute("tools", "bounding_box"); + SPItem::BBoxType bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::RENDERING_BBOX; + + NR::Maybe 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 > pts; + + NR::Point A((*bbox).min()); + NR::Point C((*bbox).max()); + NR::Point B(A[NR::X], C[NR::Y]); + NR::Point D(C[NR::X], A[NR::Y]); + + pts.push_back(std::make_pair(A.to_2geom(), B.to_2geom())); + pts.push_back(std::make_pair(B.to_2geom(), C.to_2geom())); + pts.push_back(std::make_pair(C.to_2geom(), D.to_2geom())); + pts.push_back(std::make_pair(D.to_2geom(), A.to_2geom())); + + sp_guide_pt_pairs_to_guides(SP_OBJECT_DOCUMENT(item), pts); +} /* Local Variables: