sp-item.cpp revision 2f99f08590b9e75d4c4f33cc4374db3e8f97f15d
#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 "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 "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 "algorithms/find-last-if.h"
#include "util/reverse-list.h"
#include "extract-uri.h"
#define noSP_ITEM_DEBUG_IDLE
static Inkscape::XML::Node *sp_item_write(SPObject *object, 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
{
}
}
}
}
}
}
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 libavoid with item geometry (for connector routing).
}
{
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
{
NRRect r;
return r;
}
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, 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
{
}
{
}
{
/* Just the corners of the bounding box suffices given that we don't yet
support angled guide lines. */
if (bbox) {
*p = p1;
*p = p2;
}
}
{
if (item_class.snappoints) {
}
}
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;
}
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
}
/**
* A temporary wrapper for the next function accepting the NRMatrix
* instead of NR::Matrix
*/
void
sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, NRMatrix 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. */
}
}
/**
* \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;
}
}
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, 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;
}
/*
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 :