sp-item.cpp revision 0f7095989c2fb9df2c85f07d5c30e32fb22b7878
#define __SP_ITEM_C__
/** \file
* Base class for visual SVG elements
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 2001-2005 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 "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 "gradient-chemistry.h"
#include "prefs-utils.h"
#include "conn-avoid-ref.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"
#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
{
item->transform_center_x = 0;
item->transform_center_y = 0;
{
}
}
bool SPItem::isVisibleAndUnlocked() const {
}
}
return true;
}
return false;
}
updateRepr();
}
}
updateRepr();
}
{
return true;
}
}
return false;
}
}
return true;
}
/**
* 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
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);
}
} 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_STYLE:
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;
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).
}
{
gchar c[256];
} else {
}
/** \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) {
if (obj_style) {
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.
*/
if (!style_str) {
style_str = "NULL";
}
}
/** \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.
*/
}
if (flags & SP_OBJECT_WRITE_EXT) {
if (item->transform_center_x != 0)
else
if (item->transform_center_y != 0)
else
}
}
return repr;
}
{
NRRect r;
}
void
sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const clear)
{
}
void
sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags, unsigned const clear)
{
if (clear) {
}
}
// crop the bbox by clip path, if any
NRRect b;
}
}
{
unsigned pos=0;
return pos;
}
if (SP_IS_ITEM(iter)) {
pos++;
}
}
return 0;
}
void
{
}
{
}
{
/* Just a pair of opposite corners of the bounding box suffices given that we don't yet
support angled guide lines. */
}
{
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 *
{
}
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;
}
{
}
if (!item->display->arenaitem->key) NR_ARENA_ITEM_SET_KEY(item->display->arenaitem, sp_item_display_key_new(3));
ac = sp_clippath_show(item->clip_ref->getObject(), arena, NR_ARENA_ITEM_GET_KEY(item->display->arenaitem));
}
if (!item->display->arenaitem->key) NR_ARENA_ITEM_SET_KEY(item->display->arenaitem, sp_item_display_key_new(3));
ac = sp_mask_show(item->mask_ref->getObject(), arena, NR_ARENA_ITEM_GET_KEY(item->display->arenaitem));
}
}
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
{
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)
{
// A clone must not touch the style (it's that of its parent!) and has no children, so quit now
return;
// _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();
if (is_pattern)
else
// Within text, we do not fork gradients, and so must not recurse to avoid double compensation
return;
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
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)
{
// calculate the relative transform, if not given by the adv attribute
} else {
}
// 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
}
// run the object's set_transform if transforms are stored optimized
}
// 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 :