Code

add default unit to grid preferences.
[inkscape.git] / src / display / nr-filter.h
1 #ifndef __NR_FILTER_H__
2 #define __NR_FILTER_H__
4 /*
5  * SVG filters rendering
6  *
7  * Author:
8  *   Niko Kiirala <niko@kiirala.com>
9  *
10  * Copyright (C) 2006 Niko Kiirala
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 //#include "display/nr-arena-item.h"
16 #include "display/nr-filter-primitive.h"
17 #include "display/nr-filter-types.h"
18 #include "libnr/nr-pixblock.h"
19 #include "libnr/nr-matrix.h"
20 #include "libnr/nr-rect.h"
21 #include "svg/svg-length.h"
22 #include "sp-filter-units.h"
23 #include "gc-managed.h"
25 struct NRArenaItem;
27 namespace NR {
29 class Filter : public Inkscape::GC::Managed<> {
30 public:
31     int render(NRArenaItem const *item, NRPixBlock *pb);
33     /**
34      * Creates a new filter primitive under this filter object.
35      * New primitive is placed so that it will be executed after all filter
36      * primitives defined beforehand for this filter object.
37      * Should this filter not have enough space for a new primitive, the filter
38      * is enlarged to accomodate the new filter element. It may be enlarged by
39      * more that one element.
40      * Returns a handle (non-negative integer) to the filter primitive created.
41      * Returns -1, if type is not valid filter primitive type or filter
42      * primitive of such type cannot be created.
43      */
44     int add_primitive(FilterPrimitiveType type);
45     /**
46      * Removes all filter primitives from this filter.
47      * All pointers to filter primitives inside this filter should be
48      * considered invalid after calling this function.
49      */
50     void clear_primitives();
51     /**
52      * Replaces filter primitive pointed by 'target' with a new filter
53      * primitive of type 'type'
54      * If 'target' does not correspond to any primitive inside this filter OR
55      * 'type' is not a valid filter primitive type OR
56      * filter primitive of such type cannot be created,
57      * this function returns -1 and doesn't change the internal state of this
58      * filter.
59      * Otherwise, a new filter primitive is created. Any pointers to filter
60      * primitive 'target' should be considered invalid. A handle to the
61      * newly created primitive is returned.
62      */
63     int replace_primitive(int primitive, FilterPrimitiveType type);
65     /**
66      * Returns a pointer to the primitive, which the handle corrensponds to.
67      * If the handle is not valid, returns NULL.
68      */
69     FilterPrimitive *get_primitive(int handle);
71     /**
72      * Sets the slot number 'slot' to be used as result from this filter.
73      * If output is not set, the output from last filter primitive is used as
74      * output from the filter.
75      * It is an error to specify a pre-defined slot as 'slot'. Such call does
76      * not have any effect to the state of filter or its primitives.
77      */
78     void set_output(int slot);
80     void set_x(SVGLength const &length);
81     void set_y(SVGLength const &length);
82     void set_width(SVGLength const &length);
83     void set_height(SVGLength const &length);
85     /**
86      * Sets the filter effects region.
87      * Passing an unset length (length._set == false) as any of the parameters
88      * results in that parameter not being changed.
89      * Filter will not hold any references to the passed SVGLength object after
90      * function returns.
91      * If any of these parameters does not get set, the default value, as
92      * defined in SVG standard, for that parameter is used instead.
93      */
94     void set_region(SVGLength &x, SVGLength &y,
95                     SVGLength &width, SVGLength &height);
97     /**
98      * Resets the filter effects region to its default value as defined
99      * in SVG standard.
100      */
101     void reset_region();
103     /**
104      * Sets the width of intermediate images in pixels. If not set, suitable
105      * resolution is determined automatically. If x_pixels is less than zero,
106      * calling this function results in no changes to filter state.
107      */
108     void set_resolution(double const x_pixels);
110     /**
111      * Sets the width and height of intermediate images in pixels. If not set,
112      * suitable resolution is determined automatically. If either parameter is
113      * less than zero, calling this function results in no changes to filter
114      * state.
115      */
116     void set_resolution(double const x_pixels, double const y_pixels);
118     /**
119      * Resets the filter resolution to its default value, i.e. automatically
120      * determined.
121      */
122     void reset_resolution();
124     /**
125      * Set the filterUnits-property. If not set, the default value of 
126      * objectBoundingBox is used. If the parameter value is not a
127      * valid enumeration value from SPFilterUnits, no changes to filter state
128      * are made.
129      */
130     void set_filter_units(SPFilterUnits unit);
132     /**
133      * Set the primitiveUnits-properterty. If not set, the default value of
134      * userSpaceOnUse is used. If the parameter value is not a valid
135      * enumeration value from SPFilterUnits, no changes to filter state
136      * are made.
137      */
138     void set_primitive_units(SPFilterUnits unit);
140     /** 
141      * Modifies the given area to accommodate for filters needing pixels
142      * outside the rendered area.
143      * When this function returns, area contains the area that needs
144      * to be rendered so that after filtering, the original area is
145      * drawn correctly.
146      */
147     void area_enlarge(NRRectL &area, Matrix const &m);
148     /**
149      * Given an object bounding box, this function enlarges it so that
150      * it contains the filter effect area.
151      */
152     void bbox_enlarge(NRRectL &bbox);
153     /**
154      * Returns the filter effects area in user coordinate system.
155      * The given bounding box should be a bounding box as specified in
156      * SVG standard and in user coordinate system.
157      */
158     Rect filter_effect_area(Rect const &bbox);
160     /** Creates a new filter with space for one filter element */
161     Filter();
162     /** 
163      * Creates a new filter with space for n filter elements. If number of
164      * filter elements is known beforehand, it's better to use this
165      * constructor.
166      */
167     Filter(int n);
168     /** Destroys the filter and all its primitives */
169     virtual ~Filter();
171 private:
172     int _primitive_count;
173     int _primitive_table_size;
175     /** Amount of image slots used, when this filter was rendered last time */
176     int _slot_count;
178     /** Image slot, from which filter output should be read.
179      * Negative values mean 'not set' */
180     int _output_slot;
182     SVGLength _region_x;
183     SVGLength _region_y;
184     SVGLength _region_width;
185     SVGLength _region_height;
187     /* x- and y-resolutions for filter rendering.
188      * Negative values mean 'not set'.
189      * If _y_pixels is set, _x_pixels should be set, too. */
190     double _x_pixels;
191     double _y_pixels;
193     SPFilterUnits _filter_units;
194     SPFilterUnits _primitive_units;
196     FilterPrimitive ** _primitive;
198     void _create_constructor_table();
199     void _enlarge_primitive_table();
200     void _common_init();
201 };
204 } /* namespace NR */
209 #endif /* __NR_FILTER_H__ */
210 /*
211   Local Variables:
212   mode:c++
213   c-file-style:"stroustrup"
214   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
215   indent-tabs-mode:nil
216   fill-column:99
217   End:
218 */
219 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :