1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /** \file 3 * SVG <filter> element 4 *//* 5 * Authors: 6 * Hugo Rodrigues <haa.rodrigues@gmail.com> 7 * Niko Kiirala <niko@kiirala.com> 8 * 9 * Copyright (C) 2006,2007 Authors 10 * 11 * Released under GNU GPL v2+, read the file 'COPYING' for more information. 12 */ 13 #ifndef SP_FILTER_H_SEEN 14 #define SP_FILTER_H_SEEN 15 16 #include <glibmm/ustring.h> 17 #include <map> 18 19 #include "number-opt-number.h" 20 #include "sp-dimensions.h" 21 #include "sp-object.h" 22 #include "sp-item.h" 23 #include "sp-filter-units.h" 24 #include "svg/svg-length.h" 25 26 #define SP_FILTER(obj) (dynamic_cast<SPFilter*>((SPObject*)obj)) 27 #define SP_IS_FILTER(obj) (dynamic_cast<const SPFilter*>((SPObject*)obj) != NULL) 28 29 #define SP_FILTER_FILTER_UNITS(f) (SP_FILTER(f)->filterUnits) 30 #define SP_FILTER_PRIMITIVE_UNITS(f) (SP_FILTER(f)->primitiveUnits) 31 32 namespace Inkscape { 33 namespace Filters { 34 class Filter; 35 } } 36 37 class SPFilterReference; 38 class SPFilterPrimitive; 39 40 struct ltstr { 41 bool operator()(const char* s1, const char* s2) const; 42 }; 43 44 class SPFilter : public SPObject, public SPDimensions { 45 public: 46 SPFilter(); 47 ~SPFilter() override; 48 49 /* Initializes the given Inkscape::Filters::Filter object as a renderer for this 50 * SPFilter object. */ 51 void build_renderer(Inkscape::Filters::Filter *nr_filter); 52 53 /// Returns the number of filter primitives in this SPFilter object. 54 int primitive_count() const; 55 56 /// Returns a slot number for given image name, or -1 for unknown name. 57 int get_image_name(char const *name) const; 58 59 /// Returns slot number for given image name, even if it's unknown. 60 int set_image_name(char const *name); 61 62 void update_filter_all_regions(); 63 void update_filter_region(SPItem *item); 64 void set_filter_region(double x, double y, double width, double height); 65 Geom::Rect get_automatic_filter_region(SPItem *item); 66 67 // Checks each filter primative to make sure the object won't cause issues 68 bool valid_for(SPObject const *obj) const; 69 70 /** Finds image name based on it's slot number. Returns 0 for unknown slot 71 * numbers. */ 72 char const *name_for_image(int const image) const; 73 74 /// Returns a result image name that is not in use inside this filter. 75 Glib::ustring get_new_result_name() const; 76 77 SPFilterUnits filterUnits; 78 unsigned int filterUnits_set : 1; 79 SPFilterUnits primitiveUnits; 80 unsigned int primitiveUnits_set : 1; 81 NumberOptNumber filterRes; 82 SPFilterReference *href; 83 bool auto_region; 84 85 sigc::connection modified_connection; 86 87 guint getRefCount(); 88 guint _refcount; 89 90 Inkscape::Filters::Filter *_renderer; 91 92 std::map<gchar *, int, ltstr>* _image_name; 93 int _image_number_next; 94 95 protected: 96 void build(SPDocument* doc, Inkscape::XML::Node* repr) override; 97 void release() override; 98 99 void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) override; 100 void remove_child(Inkscape::XML::Node* child) override; 101 102 void set(SPAttr key, const char* value) override; 103 104 void modified(unsigned int flags) override; 105 void update(SPCtx* ctx, unsigned int flags) override; 106 107 Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, unsigned int flags) override; 108 }; 109 110 #endif /* !SP_FILTER_H_SEEN */ 111 112 /* 113 Local Variables: 114 mode:c++ 115 c-file-style:"stroustrup" 116 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 117 indent-tabs-mode:nil 118 fill-column:99 119 End: 120 */ 121 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 122