sp-item.cpp revision 15e3dcef1404b66dcfd4658e63d2323fc41b98f0
#define __SP_ITEM_C__
/** \file
* Base class for visual SVG elements
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
*
* Copyright (C) 2001-2006 authors
* Copyright (C) 2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/** \class SPItem
*
* SPItem is an abstract base class for all graphic (visible) SVG nodes. It
* is a subclass of SPObject, with great deal of specific functionality.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "sp-item.h"
#include "print.h"
#include "display/nr-arena.h"
#include "display/nr-arena-item.h"
#include "attributes.h"
#include "document.h"
#include "uri.h"
#include "inkscape.h"
#include "desktop-handles.h"
#include "style.h"
#include "sp-root.h"
#include "sp-clippath.h"
#include "sp-mask.h"
#include "sp-rect.h"
#include "sp-use.h"
#include "sp-text.h"
#include "sp-item-rm-unsatisfied-cns.h"
#include "sp-pattern.h"
#include "sp-switch.h"
#include "gradient-chemistry.h"
#include "prefs-utils.h"
#include "conn-avoid-ref.h"
#include "conditions.h"
#include "sp-filter-reference.h"
#include "filter-chemistry.h"
#include "sp-guide.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-convert2geom.h"
#include "algorithms/find-last-if.h"
#include "util/reverse-list.h"
#include "extract-uri.h"
#include "live_effects/lpeobject.h"
#include "live_effects/effect.h"
#include "live_effects/lpeobject-reference.h"
#define noSP_ITEM_DEBUG_IDLE
static Inkscape::XML::Node *sp_item_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static SPItemView *sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem);
static SPObjectClass *parent_class;
/**
* Registers SPItem class and returns its type number.
*/
sp_item_get_type(void)
{
if (!type) {
sizeof(SPItemClass),
sizeof(SPItem),
16,
NULL, /* value_table */
};
}
return type;
}
/**
* SPItem vtable initialization.
*/
static void
{
}
/**
* Callback for SPItem object initialization.
*/
static void
{
}
this->transform_center_x = 0;
this->transform_center_y = 0;
this->_is_evaluated = true;
this->_evaluated_status = StatusUnknown;
this->clip_ref = new SPClipPathReference(this);
this->mask_ref = new SPMaskReference(this);
this->avoidRef = new SPAvoidRef(this);
}
bool SPItem::isVisibleAndUnlocked() const {
}
}
return true;
}
return false;
}
updateRepr();
}
if (!isEvaluated())
return true;
}
updateRepr();
}
if (!isEvaluated())
return true;
{
return true;
}
}
return false;
}
}
return true;
}
}
void SPItem::resetEvaluated() {
if ( StatusCalculated == _evaluated_status ) {
bool oldValue = _is_evaluated;
if ( oldValue != isEvaluated() ) {
}
} if ( StatusSet == _evaluated_status ) {
if (SP_IS_SWITCH(parent)) {
}
}
}
bool SPItem::isEvaluated() const {
if ( StatusUnknown == _evaluated_status ) {
_is_evaluated = sp_item_evaluate(this);
}
return _is_evaluated;
}
/**
* Returns something suitable for the `Hide' checkbox in the Object Properties dialog box.
* Corresponds to setExplicitlyHidden.
*/
bool
SPItem::isExplicitlyHidden() const
{
}
/**
* Sets the display CSS property to `hidden' if \a val is true,
* otherwise makes it unset
*/
void
this->updateRepr();
}
/**
* Sets the transform_center_x and transform_center_y properties to retain the rotation centre
*/
void
if (bbox) {
transform_center_x = 0;
transform_center_y = 0;
}
}
void
SPItem::unsetCenter() {
transform_center_x = 0;
transform_center_y = 0;
}
bool SPItem::isCenterSet() {
return (transform_center_x != 0 || transform_center_y != 0);
}
if (bbox) {
} else {
}
}
namespace {
return SP_IS_ITEM(&object);
}
}
void SPItem::raiseToTop() {
);
if (topmost) {
}
}
);
if (next_higher) {
}
}
SP_OBJECT_PARENT(this)->firstChild(), this
),
MutableList<SPObject &>(),
);
if (next_lower) {
++next_lower;
}
}
void SPItem::lowerToBottom() {
SP_OBJECT_PARENT(this)->firstChild(), this
),
MutableList<SPObject &>(),
);
if (bottom) {
++bottom;
}
}
static void
{
}
}
static void
{
// 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.
}
}
}
}
}
}
static void
{
switch (key) {
case SP_ATTR_TRANSFORM: {
} else {
}
break;
}
case SP_PROP_CLIP_PATH: {
if (uri) {
try {
} catch (Inkscape::BadURIException &e) {
}
} else {
}
break;
}
case SP_PROP_MASK: {
if (uri) {
try {
} catch (Inkscape::BadURIException &e) {
}
} else {
}
break;
}
}
break;
case SP_ATTR_CONNECTOR_AVOID:
break;
if (value) {
} else {
item->transform_center_x = 0;
}
break;
if (value) {
} else {
item->transform_center_y = 0;
}
break;
case SP_PROP_SYSTEM_LANGUAGE:
{
item->resetEvaluated();
// pass to default handler
}
default:
if (SP_ATTRIBUTE_IS_CSS(key)) {
} else {
}
}
break;
}
}
static void
{
if (old_clip) {
SPItemView *v;
/* Hide clippath */
}
}
if (SP_IS_CLIPPATH(clip)) {
}
}
}
}
static void
{
if (old_mask) {
/* Hide mask */
}
}
if (SP_IS_MASK(mask)) {
}
}
}
}
static void
{
if (flags & (SP_OBJECT_CHILD_MODIFIED_FLAG | SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG)) {
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
}
if (clip_path) {
}
}
if (mask) {
}
}
}
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
}
}
}
/* Update bounding box data used by filters */
do {
}
// Update libavoid with item geometry (for connector routing).
}
sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
g_free(c);
if (flags & SP_OBJECT_WRITE_EXT) {
if (item->transform_center_x != 0)
else
if (item->transform_center_y != 0)
else
}
}
}
}
return repr;
}
unsigned int /*dkey*/) const
{
return r;
}
const
{
}
void
sp_item_invoke_bbox(SPItem const *item, NR::Maybe<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
{
}
// DEPRECATED to phase out the use of NRRect in favor of NR::Maybe<NR::Rect>
void
sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
{
}
/** 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<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear)
{
if (clear) {
}
// TODO: replace NRRect by NR::Rect, for all SPItemClasses, and for SP_CLIPPATH
// call the subclass method
}
// unless this is geometric bbox, extend by filter area and crop the bbox by clip path, if any
// 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:
double dx0 = 0;
double dx1 = 0;
double dy0 = 0;
double dy1 = 0;
// 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
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:
}
// transform the expansions by the item's transform:
// expand the bbox
}
}
NRRect b;
}
}
// 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 NR::Maybe<NR::Rect>)
// So union bbox with nothing = do nothing, just return
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<NR::Rect> temp_bbox_new = NR::Rect(NR::Point(temp_bbox.x0, temp_bbox.y0), NR::Point(temp_bbox.x1, temp_bbox.y1));
}
// DEPRECATED to phase out the use of NRRect in favor of NR::Maybe<NR::Rect>
/** 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)
{
if (clear) {
}
// call the subclass method
}
// unless this is geometric bbox, crop the bbox by clip path, if any
NRRect b;
}
// if non-empty (with some tolerance - ?) union this_bbox with the bbox we've got passed
}
}
{
unsigned pos=0;
return pos;
}
if (SP_IS_ITEM(iter)) {
pos++;
}
}
return 0;
}
void
{
}
{
return rect;
}
{
/* Just the corners of the bounding box suffices given that we don't yet
support angled guide lines. */
if (bbox) {
*p = p1;
*p = p2;
}
}
{
// Get the snappoints of the item
if (item_class.snappoints) {
}
// Get the snappoints at the item's center
if (includeItemCenter) {
}
// Get the snappoints of clipping paths and mask, if any
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
if (SP_IS_ITEM(child)) {
// Please note the recursive call here!
// Take into account the transformation of the item being clipped or masked
for (std::vector<NR::Point>::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
*p = (*p_orig) * from_2geom(matrix_to_desktop (matrix_from_desktop (to_2geom(item->transform), item), item));
}
}
}
}
}
}
void
{
{
} else {
}
}
}
}
static gchar *
{
return g_strdup(_("Object"));
}
/**
* Returns a string suitable for status bar, formatted in pango markup language.
*
* Must be freed by caller.
*/
gchar *
{
g_free (s);
s = snew;
}
g_free (s);
s = snew;
}
g_free (s);
s = snew;
}
return s;
}
return NULL;
}
/**
* Allocates unique integer keys.
* \param numkeys Number of keys required.
* \return First allocated key; hence if the returned key is n
* you can use n, n + 1, ..., n + (numkeys - 1)
*/
unsigned
sp_item_display_key_new(unsigned numkeys)
{
static unsigned dkey = 0;
}
{
}
}
// Show and set clip
// Update bbox, in case the clip uses bbox units
}
}
// Show and set mask
// Update bbox, in case the mask uses bbox units
}
}
return ai;
}
void
{
}
while (v != NULL) {
}
}
if (!ref) {
} else {
}
g_free(v);
} else {
ref = v;
}
v = next;
}
}
// Adjusters
void
{
if (SP_IS_PATTERN (server)) {
}
}
if (SP_IS_PATTERN (server)) {
}
}
}
void
{
if (SP_IS_GRADIENT (server)) {
/**
* \note Bbox units for a gradient are generally a bad idea because
* with them, you cannot preserve the relative position of the
* object and its gradient after rotation or skew. So now we
* convert them to userspace units which are easy to keep in sync
* just by adding the object's transform to gradientTransform.
* \todo FIXME: convert back to bbox units after transforming with
* the item, so as to preserve the original units.
*/
}
}
if (SP_IS_GRADIENT (server)) {
}
}
}
void
{
int i;
}
}
}
}
/**
* Find out the inverse of previous transform of an item (from its repr)
*/
{
if (t_attr) {
if (sp_svg_transform_read(t_attr, &t)) {
t_old = t;
}
}
return t_old;
}
/**
* Recursively scale stroke width in \a item and its children by \a expansion.
*/
void
{
// A clone's child is the ghost of its original - we must not touch it, skip recursion
return;
if (SP_IS_ITEM(o))
}
}
/**
* Recursively adjust rx and ry of rects.
*/
void
{
if (SP_IS_RECT (item)) {
}
if (SP_IS_ITEM(o))
}
}
/**
* 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)
{
// _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 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 (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)
else
}
void
{
if ( !SP_IS_LPE_ITEM(item) )
return;
if ( sp_lpe_item_has_path_effect(lpeitem) ) {
{
// If the path effect is used by 2 or more items, fork it
// so that each object has its own independent copy of the effect
if (lpeobj) {
if (new_lpeobj != lpeobj) {
}
}
}
}
}
}
/**
* A temporary wrapper for the next function accepting the NR::Matrix
* instead of NR::Matrix
*/
void
sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NR::Matrix const *transform, NR::Matrix const *adv)
{
else
}
/**
* Set a new transform on an object.
*
* necessary. Call the object's set_transform method if transforms are
* stored optimized. Send _transformed_signal. Invoke _write method so that
* 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)
{
// calculate the relative transform, if not given by the adv attribute
} else {
}
if (compensate) {
// recursively compensate for stroke scaling, depending on user preference
}
}
// recursively compensate pattern 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
} else {
// it here _before_ the new transform is set, so as to use the pre-transform bbox
}
} // endif(compensate)
if ( // run the object's set_transform (i.e. embed transform) only if:
!preserve && // user did not chose to preserve all transforms
// the object does not have a filter, or the transform is translation (which is supposed to not affect filters)
) {
}
// Note: updateRepr comes before emitting the transformed signal since
// 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.
// send the relative transform with a _transformed_signal
}
{
return FALSE;
}
/**
* Sets item private transform (not propagated to repr), without compensating stroke widths,
* gradients, patterns as sp_item_write_transform does.
*/
void
{
/* The SP_OBJECT_USER_MODIFIED_FLAG_B is used to mark the fact that it's only a
transformation. It's apparently not used anywhere else. */
}
}
void
/* Use derived method if present ... */
return;
}
/* .. otherwise simply place the guides around the item's bounding box */
}
/**
* \pre \a ancestor really is an ancestor (\>=) of \a object, or NULL.
* ("Ancestor (\>=)" here includes as far as \a object itself.)
*/
/* stop at first non-renderable ancestor */
if (SP_IS_ROOT(object)) {
}
}
return ret;
}
}
}
/**
* 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, but excluding root's viewport.
* Used in path operations mostly.
* \pre (item != NULL) and SP_IS_ITEM(item).
*/
{
}
return ret;
}
/* fixme: This is EVIL!!! */
{
return ret;
}
// same as i2d but with i2root instead of i2doc
{
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.
*/
{
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.
*/
{
* m);
return ret;
}
{
if (SP_OBJECT_PARENT(item)) {
} else {
}
}
{
/* fixme: Implement the right way (Lauris) */
}
/* Item views */
static SPItemView *
sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem)
{
return new_view;
}
static SPItemView *
{
} else {
}
return list;
}
/**
* Return the arenaitem corresponding to the given item in the display
* with the given key
*/
{
}
}
return NULL;
}
int
{
}
SPItem *
{
if (SP_IS_ITEM (iter))
}
return NULL;
}
void
(void)nv;
if (!bbox) {
g_warning ("Cannot determine item's bounding box during conversion to guides.\n");
return;
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :