sp-mask.cpp revision 5271cd656d5e935ca2f55b6b61a4f3aedee22fd5
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#define __SP_MASK_C__
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/*
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * SVG <mask> implementation
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Authors:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Lauris Kaplinski <lauris@kaplinski.com>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Copyright (C) 2003 authors
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Released under GNU GPL, read the file 'COPYING' for more information
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "display/nr-arena.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "display/nr-arena-group.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include <xml/repr.h>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "enums.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "attributes.h"
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd#include "document.h"
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd#include "document-private.h"
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd#include "sp-item.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
9bcfc3697a91b5215893a7d0206865b13fc72148nd#include "sp-mask.h"
9bcfc3697a91b5215893a7d0206865b13fc72148nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstruct SPMaskView {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPMaskView *next;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd unsigned int key;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NRArenaItem *arenaitem;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NRRect bbox;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd};
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_class_init (SPMaskClass *klass);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_init (SPMask *mask);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_release (SPObject * object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_set (SPObject *object, unsigned int key, const gchar *value);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_update (SPObject *object, SPCtx *ctx, guint flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void sp_mask_modified (SPObject *object, guint flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic Inkscape::XML::Node *sp_mask_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndSPMaskView *sp_mask_view_new_prepend (SPMaskView *list, unsigned int key, NRArenaItem *arenaitem);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndSPMaskView *sp_mask_view_list_remove (SPMaskView *list, SPMaskView *view);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic SPObjectGroupClass *parent_class;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndGType
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_get_type (void)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd static GType type = 0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (!type) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd GTypeInfo info = {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sizeof (SPMaskClass),
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NULL, NULL,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd (GClassInitFunc) sp_mask_class_init,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NULL, NULL,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sizeof (SPMask),
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd 16,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd (GInstanceInitFunc) sp_mask_init,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NULL, /* value_table */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd };
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd type = g_type_register_static (SP_TYPE_OBJECTGROUP, "SPMask", &info, (GTypeFlags)0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return type;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_class_init (SPMaskClass *klass)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd parent_class = (SPObjectGroupClass*) g_type_class_ref (SP_TYPE_OBJECTGROUP);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObjectClass *sp_object_class = (SPObjectClass *) klass;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_class->build = sp_mask_build;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_class->release = sp_mask_release;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_class->set = sp_mask_set;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_class->child_added = sp_mask_child_added;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_class->update = sp_mask_update;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_class->modified = sp_mask_modified;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_class->write = sp_mask_write;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_init (SPMask *mask)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskUnits_set = FALSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskUnits = SP_CONTENT_UNITS_OBJECTBOUNDINGBOX;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits_set = FALSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits = SP_CONTENT_UNITS_USERSPACEONUSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->display = NULL;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (((SPObjectClass *) parent_class)->build) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) parent_class)->build (object, document, repr);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_read_attr (object, "maskUnits");
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_object_read_attr (object, "maskContentUnits");
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Register ourselves */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_document_add_resource (document, "mask", object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_release (SPObject * object)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (SP_OBJECT_DOCUMENT (object)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Unregister ourselves */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_document_remove_resource (SP_OBJECT_DOCUMENT (object), "mask", object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPMask *cp = SP_MASK (object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd while (cp->display) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* We simply unref and let item manage this in handler */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd cp->display = sp_mask_view_list_remove (cp->display, cp->display);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (((SPObjectClass *) (parent_class))->release) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) parent_class)->release (object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_set (SPObject *object, unsigned int key, const gchar *value)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPMask *mask = SP_MASK (object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd switch (key) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd case SP_ATTR_MASKUNITS:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskUnits = SP_CONTENT_UNITS_OBJECTBOUNDINGBOX;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskUnits_set = FALSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (value) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (!strcmp (value, "userSpaceOnUse")) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskUnits = SP_CONTENT_UNITS_USERSPACEONUSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskUnits_set = TRUE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd } else if (!strcmp (value, "objectBoundingBox")) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskUnits_set = TRUE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd break;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd case SP_ATTR_MASKCONTENTUNITS:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits = SP_CONTENT_UNITS_USERSPACEONUSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits_set = FALSE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (value) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (!strcmp (value, "userSpaceOnUse")) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits_set = TRUE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd } else if (!strcmp (value, "objectBoundingBox")) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits = SP_CONTENT_UNITS_OBJECTBOUNDINGBOX;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->maskContentUnits_set = TRUE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd break;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd default:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (((SPObjectClass *) parent_class)->set)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) parent_class)->set (object, key, value);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd break;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Invoke SPObjectGroup implementation */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) (parent_class))->child_added (object, child, ref);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Show new object */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObject *ochild = SP_OBJECT_DOCUMENT (object)->getObjectByRepr(child);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (SP_IS_ITEM (ochild)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPMask *cp = SP_MASK (object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPMaskView *v = cp->display; v != NULL; v = v->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NRArenaItem *ac = sp_item_invoke_show (SP_ITEM (ochild),
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NR_ARENA_ITEM_ARENA (v->arenaitem),
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd v->key,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SP_ITEM_REFERENCE_FLAGS);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (ac) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_item_add_child (v->arenaitem, ac, NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_item_unref (ac);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_update (SPObject *object, SPCtx *ctx, guint flags)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (flags & SP_OBJECT_MODIFIED_FLAG) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd flags &= SP_OBJECT_MODIFIED_CASCADE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObjectGroup *og = SP_OBJECTGROUP (object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd GSList *l = NULL;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPObject *child = sp_object_first_child(SP_OBJECT(og)); child != NULL; child = SP_OBJECT_NEXT(child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_object_ref (G_OBJECT (child));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd l = g_slist_prepend (l, child);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd l = g_slist_reverse (l);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd while (l) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObject *child = SP_OBJECT (l->data);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd l = g_slist_remove (l, child);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd child->updateDisplay(ctx, flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_object_unref (G_OBJECT (child));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPMask *mask = SP_MASK (object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPMaskView *v = mask->display; v != NULL; v = v->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NRMatrix t;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_matrix_set_scale (&t, v->bbox.x1 - v->bbox.x0, v->bbox.y1 - v->bbox.y0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd t.c[4] = v->bbox.x0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd t.c[5] = v->bbox.y0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_group_set_child_transform (NR_ARENA_GROUP (v->arenaitem), &t);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd } else {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_group_set_child_transform (NR_ARENA_GROUP (v->arenaitem), NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_modified (SPObject *object, guint flags)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (flags & SP_OBJECT_MODIFIED_FLAG) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd flags &= SP_OBJECT_MODIFIED_CASCADE;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObjectGroup *og = SP_OBJECTGROUP (object);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd GSList *l = NULL;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPObject *child = sp_object_first_child(SP_OBJECT(og)); child != NULL; child = SP_OBJECT_NEXT(child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_object_ref (G_OBJECT (child));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd l = g_slist_prepend (l, child);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd l = g_slist_reverse (l);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd while (l) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObject *child = SP_OBJECT (l->data);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd l = g_slist_remove (l, child);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd child->emitModified(flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_object_unref (G_OBJECT (child));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic Inkscape::XML::Node *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd repr = sp_repr_new ("svg:mask");
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (((SPObjectClass *) (parent_class))->write)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ((SPObjectClass *) (parent_class))->write (object, repr, flags);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return repr;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd// Create a mask element (using passed elements), add it to <defs>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndconst gchar *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_create (GSList *reprs, SPDocument *document, NR::Matrix const* applyTransform)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Inkscape::XML::Node *defsrepr = SP_OBJECT_REPR (SP_DOCUMENT_DEFS (document));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Inkscape::XML::Node *repr = sp_repr_new ("svg:mask");
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd repr->setAttribute("maskUnits", "userSpaceOnUse");
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd defsrepr->appendChild(repr);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd const gchar *mask_id = repr->attribute("id");
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPObject *mask_object = document->getObjectById(mask_id);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (GSList *it = reprs; it != NULL; it = it->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPItem *item = SP_ITEM(mask_object->appendChildRepr(node));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (NULL != applyTransform) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NR::Matrix transform (item->transform);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd transform *= (*applyTransform);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_item_write_transform(item, SP_OBJECT_REPR(item), transform);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Inkscape::GC::release(repr);
71fccc298df6a1540d408151a26aa22beed55d0bnd return mask_id;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndNRArenaItem *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_show (SPMask *mask, NRArena *arena, unsigned int key)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_return_val_if_fail (mask != NULL, NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_return_val_if_fail (SP_IS_MASK (mask), NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_return_val_if_fail (arena != NULL, NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_return_val_if_fail (NR_IS_ARENA (arena), NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NRArenaItem *ai = NRArenaGroup::create(arena);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mask->display = sp_mask_view_new_prepend (mask->display, key, ai);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPObject *child = sp_object_first_child(SP_OBJECT(mask)) ; child != NULL; child = SP_OBJECT_NEXT(child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (SP_IS_ITEM (child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NRArenaItem *ac = sp_item_invoke_show (SP_ITEM (child), arena, key, SP_ITEM_REFERENCE_FLAGS);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (ac) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* The order is not important in mask */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_item_add_child (ai, ac, NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_item_unref (ac);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd NRMatrix t;
71fccc298df6a1540d408151a26aa22beed55d0bnd nr_matrix_set_scale (&t, mask->display->bbox.x1 - mask->display->bbox.x0, mask->display->bbox.y1 - mask->display->bbox.y0);
71fccc298df6a1540d408151a26aa22beed55d0bnd t.c[4] = mask->display->bbox.x0;
71fccc298df6a1540d408151a26aa22beed55d0bnd t.c[5] = mask->display->bbox.y0;
71fccc298df6a1540d408151a26aa22beed55d0bnd nr_arena_group_set_child_transform (NR_ARENA_GROUP (ai), &t);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return ai;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndvoid
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_hide (SPMask *cp, unsigned int key)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_return_if_fail (cp != NULL);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_return_if_fail (SP_IS_MASK (cp));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPObject *child = sp_object_first_child(SP_OBJECT(cp)); child != NULL; child = SP_OBJECT_NEXT(child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (SP_IS_ITEM (child)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sp_item_invoke_hide (SP_ITEM (child), key);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPMaskView *v = cp->display; v != NULL; v = v->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (v->key == key) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* We simply unref and let item to manage this in handler */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd cp->display = sp_mask_view_list_remove (cp->display, v);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
71fccc298df6a1540d408151a26aa22beed55d0bnd }
71fccc298df6a1540d408151a26aa22beed55d0bnd
71fccc298df6a1540d408151a26aa22beed55d0bnd g_assert_not_reached ();
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndvoid
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_set_bbox (SPMask *mask, unsigned int key, NRRect *bbox)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (SPMaskView *v = mask->display; v != NULL; v = v->next) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (v->key == key) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (!NR_DF_TEST_CLOSE (v->bbox.x0, bbox->x0, NR_EPSILON) ||
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd !NR_DF_TEST_CLOSE (v->bbox.y0, bbox->y0, NR_EPSILON) ||
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd !NR_DF_TEST_CLOSE (v->bbox.x1, bbox->x1, NR_EPSILON) ||
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd !NR_DF_TEST_CLOSE (v->bbox.y1, bbox->y1, NR_EPSILON)) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd v->bbox = *bbox;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd break;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* Mask views */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndSPMaskView *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_view_new_prepend (SPMaskView *list, unsigned int key, NRArenaItem *arenaitem)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPMaskView *new_mask_view = g_new (SPMaskView, 1);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd new_mask_view->next = list;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd new_mask_view->key = key;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd new_mask_view->arenaitem = nr_arena_item_ref(arenaitem);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd new_mask_view->bbox.x0 = new_mask_view->bbox.x1 = 0.0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd new_mask_view->bbox.y0 = new_mask_view->bbox.y1 = 0.0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return new_mask_view;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndSPMaskView *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndsp_mask_view_list_remove (SPMaskView *list, SPMaskView *view)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (view == list) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd list = list->next;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd } else {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd SPMaskView *prev;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd prev = list;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd while (prev->next != view) prev = prev->next;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd prev->next = view->next;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd nr_arena_item_unref (view->arenaitem);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd g_free (view);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return list;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/*
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Local Variables:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd mode:c++
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd c-file-style:"stroustrup"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd indent-tabs-mode:nil
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd fill-column:99
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd End:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd*/
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd