summaryrefslogtreecommitdiffstats
path: root/src/sp-clippath.h
blob: f3894dc8fd64c03b86ec4fca1af84fe954cbf4ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef SEEN_SP_CLIPPATH_H
#define SEEN_SP_CLIPPATH_H

/*
 * SVG <clipPath> implementation
 *
 * Authors:
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *   Abhishek Sharma
 *   Jon A. Cruz <jon@joncruz.org>
 *
 * Copyright (C) 2001-2002 authors
 * Copyright (C) 2001 Ximian, Inc.
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#define SP_TYPE_CLIPPATH (sp_clippath_get_type())
#define SP_CLIPPATH(obj) ((SPClipPath*)obj)
#define SP_IS_CLIPPATH(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPClipPath)))

struct SPClipPathView;

#include "sp-object-group.h"
#include "uri-references.h"
#include "xml/node.h"

GType sp_clippath_get_type() G_GNUC_CONST;

namespace Inkscape {

class Drawing;
class DrawingItem;

} // namespace Inkscape

class CClipPath;

class SPClipPath : public SPObjectGroup {
public:
	CClipPath* cclippath;

    class Reference;

    unsigned int clipPathUnits_set : 1;
    unsigned int clipPathUnits : 1;

    SPClipPathView *display;
    static const gchar *create(GSList *reprs, SPDocument *document, Geom::Affine const* applyTransform);
    static GType sp_clippath_get_type(void);

    Inkscape::DrawingItem *show(Inkscape::Drawing &drawing, unsigned int key);
    void hide(unsigned int key);

    void setBBox(unsigned int key, Geom::OptRect const &bbox);
    Geom::OptRect geometricBounds(Geom::Affine const &transform);

private:
    friend class SPClipPathClass;
};

class SPClipPathClass {
public:
    SPObjectGroupClass parent_class;

private:
    friend class SPClipPath;
};


class CClipPath : public CObjectGroup {
public:
	CClipPath(SPClipPath* clippath);
	virtual ~CClipPath();

	virtual void build(SPDocument* doc, Inkscape::XML::Node* repr);
	virtual void release();

	virtual void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref);

	virtual void set(unsigned int key, const gchar* value);

	virtual void update(SPCtx* ctx, unsigned int flags);
	virtual void modified(unsigned int flags);

	virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags);

protected:
	SPClipPath* spclippath;
};


class SPClipPathReference : public Inkscape::URIReference {
public:
    SPClipPathReference(SPObject *obj) : URIReference(obj) {}
    SPClipPath *getObject() const {
        return static_cast<SPClipPath *>(URIReference::getObject());
    }

protected:
    /**
     * If the owner element of this reference (the element with <... clippath="...">)
     * is a child of the clippath it refers to, return false.
     * \return false if obj is not a clippath or if obj is a parent of this
     *         reference's owner element.  True otherwise.
     */
    virtual bool _acceptObject(SPObject *obj) const {
        if (!SP_IS_CLIPPATH(obj)) {
            return false;
        }
        SPObject * const owner = this->getOwner();
        if (obj->isAncestorOf(owner)) {
            //XML Tree being used directly here while it shouldn't be...
            Inkscape::XML::Node * const owner_repr = owner->getRepr();
            //XML Tree being used directly here while it shouldn't be...
            Inkscape::XML::Node * const obj_repr = obj->getRepr();
            gchar const * owner_name = NULL;
            gchar const * owner_clippath = NULL;
            gchar const * obj_name = NULL;
            gchar const * obj_id = NULL;
            if (owner_repr != NULL) {
                owner_name = owner_repr->name();
                owner_clippath = owner_repr->attribute("clippath");
            }
            if (obj_repr != NULL) {
                obj_name = obj_repr->name();
                obj_id = obj_repr->attribute("id");
            }
            g_warning("Ignoring recursive clippath reference "
                      "<%s clippath=\"%s\"> in <%s id=\"%s\">",
                      owner_name, owner_clippath,
                      obj_name, obj_id);
            return false;
        }
        return true;
    }
};

#endif // SEEN_SP_CLIPPATH_H

/*
  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:fileencoding=utf-8:textwidth=99 :