1 #ifndef __SP_MASK_H__
2 #define __SP_MASK_H__
4 /*
5 * SVG <mask> implementation
6 *
7 * Authors:
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 *
10 * Copyright (C) 2003 authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #define SP_TYPE_MASK (sp_mask_get_type ())
16 #define SP_MASK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_MASK, SPMask))
17 #define SP_MASK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_MASK, SPMaskClass))
18 #define SP_IS_MASK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_MASK))
19 #define SP_IS_MASK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_MASK))
21 class SPMask;
22 class SPMaskClass;
23 class SPMaskView;
25 #include "display/nr-arena-forward.h"
26 #include "libnr/nr-forward.h"
27 #include "sp-object-group.h"
28 #include "uri-references.h"
29 #include "xml/node.h"
31 struct SPMask : public SPObjectGroup {
32 unsigned int maskUnits_set : 1;
33 unsigned int maskUnits : 1;
35 unsigned int maskContentUnits_set : 1;
36 unsigned int maskContentUnits : 1;
38 SPMaskView *display;
39 };
41 struct SPMaskClass {
42 SPObjectGroupClass parent_class;
43 };
45 GType sp_mask_get_type (void);
47 class SPMaskReference : public Inkscape::URIReference {
48 public:
49 SPMaskReference(SPObject *obj) : URIReference(obj) {}
50 SPMask *getObject() const {
51 return (SPMask *)URIReference::getObject();
52 }
53 protected:
54 /**
55 * If the owner element of this reference (the element with <... mask="...">)
56 * is a child of the mask it refers to, return false.
57 * \return false if obj is not a mask or if obj is a parent of this
58 * reference's owner element. True otherwise.
59 */
60 virtual bool _acceptObject(SPObject *obj) const {
61 if (!SP_IS_MASK(obj)) {
62 return false;
63 }
64 SPObject * const owner = this->getOwner();
65 if (obj->isAncestorOf(owner)) {
66 Inkscape::XML::Node * const owner_repr = owner->repr;
67 Inkscape::XML::Node * const obj_repr = obj->repr;
68 gchar const * owner_name = NULL;
69 gchar const * owner_mask = NULL;
70 gchar const * obj_name = NULL;
71 gchar const * obj_id = NULL;
72 if (owner_repr != NULL) {
73 owner_name = owner_repr->name();
74 owner_mask = owner_repr->attribute("mask");
75 }
76 if (obj_repr != NULL) {
77 obj_name = obj_repr->name();
78 obj_id = obj_repr->attribute("id");
79 }
80 g_warning("Ignoring recursive mask reference "
81 "<%s mask=\"%s\"> in <%s id=\"%s\">",
82 owner_name, owner_mask,
83 obj_name, obj_id);
84 return false;
85 }
86 return true;
87 }
88 };
90 NRArenaItem *sp_mask_show (SPMask *mask, NRArena *arena, unsigned int key);
91 void sp_mask_hide (SPMask *mask, unsigned int key);
93 void sp_mask_set_bbox (SPMask *mask, unsigned int key, NRRect *bbox);
95 const gchar *sp_mask_create (GSList *reprs, SPDocument *document, Geom::Matrix const* applyTransform);
97 #endif