Loading...
Searching...
No Matches
TreeUtilsSVG.h
1/*
2
3MIT License
4
5Copyright (c) 2023 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31/*
32 * TreeSVG.h
33 *
34 * Created on: Jun 24, 2012
35 * Author: mpeura
36 */
37
38#ifndef DRAIN_TREE_UTILS_SVG
39#define DRAIN_TREE_UTILS_SVG
40
41//
42
43#include <drain/Enum.h>
44
45#include "TreeSVG.h"
46
47namespace drain {
48
49namespace image {
50
51
53
59// TODO: separate TreeLayoutUtilsSVG
60
62
63public:
64
65 enum Roles {
66 MAIN,
67 };
68
70
73 /*
74 static
75 TreeSVG & getHeaderObject(TreeSVG & root, svg::tag_t, const std::string & key = "");
76 */
77
79
86};
87
88DRAIN_ENUM_DICT(TreeUtilsSVG::Roles);
89DRAIN_ENUM_OSTREAM(TreeUtilsSVG::Roles);
90
91
101
102public:
103
104 // Leading path, maybe partial, to be pruned
105 const std::string dir;
106
107 // String starting the modified path, for example "file://"
108 const std::string prefix;
109
110 inline
111 RelativePathSetterSVG(const drain::FilePath & filepath, const std::string & prefix = "") :
112 dir(filepath.dir.empty() ? "" : filepath.dir.str()+'/'),
113 prefix(prefix) {
114 }
115
116 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
117
118
119};
120
121
126
127public:
128
129 static
130 const std::string LOCAL;
131
132 static
133 const std::string SHARED;
134
135 /*
136 enum MetaDataType {
137 LOCAL,
138 SHARED
139 };
140 */
141
142 inline
143 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
144 // always continue
145 return 0;
146 }
147
148 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
149
150 // Also
151 //GraphicsContext::TitleFlagger titles;
152
153protected:
154
155 typedef std::map<std::string, unsigned short> variableStat_t;
156
157};
158
159
163class ClipperSVG : public drain::TreeVisitor<TreeSVG> {
164
165public:
166
167 static
168 const std::string CLIP;
169
170 /*
171 enum MyDataType {
172 FIRST,
173 SECOND
174 };
175 */
176
177 inline
178 ClipperSVG(TreeSVG & root) : root(root) {
179 }
180
181 ClipperSVG(const ClipperSVG & clipper) : root(clipper.root) { // ???
182 }
183
185
188 static
189 TreeSVG & getClippingRect(TreeSVG & root, size_t width, size_t height);
190
191 inline
192 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
193 // always continue
194 return 0;
195 }
196
197 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
198
199 TreeSVG & root;
200
201};
202
203
204
206
209class MaskerSVG : public drain::TreeVisitor<TreeSVG> {
210
211public:
212
213 static
214 const std::string MASK_ID;
215
216 static
217 const ClassXML COVER;
218
219 inline
220 MaskerSVG(){
221 }
222
223 MaskerSVG(const MaskerSVG & clipper){ // ???
224 }
225
226
228
231 static
232 const drain::FlexibleVariable & createMaskId(TreeSVG & group);
233
235 static
236 TreeSVG & getMask(TreeSVG & root, const std::string & maskId);
237
239
245 static
246 drain::image::TreeSVG & updateMask(TreeSVG & mask, int width, int height, const NodeSVG & contourNode);
247
248
250
253 static
254 TreeSVG & createMask(TreeSVG & root, TreeSVG & group, int width=0, int height=0, const NodeSVG & node = NodeSVG(svg::UNDEFINED));
255
257
264 static
265 void linkMask(const TreeSVG & mask, TreeSVG & obj);
266
267
269
276 inline
277 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
278 return 0;
279 }
280
281 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
282
283};
284
285
286
287// DRAIN_ENUM_DICT(MetaDataCollectorSVG::MetaDataType);
288
307} // image::
308
309} // drain::
310
311
312
313
314#endif // TREESVG_H_
315
A wrapper marking string an CSS effect.
Definition ClassXML.h:57
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:54
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:265
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition VariableT.h:87
Definition TreeUtilsSVG.h:163
static TreeSVG & getClippingRect(TreeSVG &root, size_t width, size_t height)
Ensures a clipping path o f type RECT of given size.
Definition TreeUtilsSVG.cpp:236
Tools for creating masks for graphic objects based on their contours.
Definition TreeUtilsSVG.h:209
static void linkMask(const TreeSVG &mask, TreeSVG &obj)
Finally, associate the object with a mask by assigning MASK elements ID to the mask attribute of obje...
Definition TreeUtilsSVG.cpp:392
static drain::image::TreeSVG & updateMask(TreeSVG &mask, int width, int height, const NodeSVG &contourNode)
Method for an object to copy its contour.
Definition TreeUtilsSVG.cpp:345
static TreeSVG & getMask(TreeSVG &root, const std::string &maskId)
From global document definitions (DEFS), retrieve the mask designed for this group.
Definition TreeUtilsSVG.cpp:310
static const drain::FlexibleVariable & createMaskId(TreeSVG &group)
Mark an overlay group "masked", meaning that at least one of its objects (also) creates a mask for th...
Definition TreeUtilsSVG.cpp:304
int visitPrefix(TreeSVG &tree, const TreeSVG::path_t &path) override
Ensures a clipping path o f type RECT of given size.
Definition TreeUtilsSVG.h:277
static TreeSVG & createMask(TreeSVG &root, TreeSVG &group, int width=0, int height=0, const NodeSVG &node=NodeSVG(svg::UNDEFINED))
Calls createMaskId(), getMask() and updateMask().
Definition TreeUtilsSVG.cpp:367
Definition TreeUtilsSVG.h:125
int visitPostfix(TreeSVG &tree, const TreeSVG::path_t &path) override
Iterate children and their attributes: check which attributes (key and value) are shared by all the c...
Definition TreeUtilsSVG.cpp:105
Definition TreeSVG.h:182
Definition TreeUtilsSVG.h:100
Definition DataSelector.cpp:1277
SVG classes marking requests of relative horizontal and vertical alignment.
Definition TreeUtilsSVG.h:61