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
92
100class RelativePathSetterSVG : public drain::TreeVisitor<TreeSVG> {
101
102public:
103
104 // Leading path, maybe partial, to be pruned
105 // const std::string dir;
106 const FilePath removePath;
107
108 // String starting the modified path, for example "file://"
109 const std::string prefixNew;
110
111 inline
112 RelativePathSetterSVG(const drain::FilePath & filepath, const std::string & prefixNew = "") :
113 //dir(filepath.dir.empty() ? "" : filepath.dir.str()), // +'/'
114 removePath(filepath),
115 prefixNew(prefixNew) {
116 /*
117 drain::Logger mout( __FILE__, __FUNCTION__);
118 drain::FilePath checkPath(dir);
119 mout.warn("checking prefix: ", dir, " to ", checkPath);
120 if (checkPath.str() != dir){
121 mout.warn("consider pruning prefix: ", dir, " to ", checkPath);
122 }
123 */
124
125
126 }
127
128 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
129
130
131};
132
133
138
139public:
140
141 static
142 const std::string LOCAL;
143
144 static
145 const std::string SHARED;
146
147 /*
148 enum MetaDataType {
149 LOCAL,
150 SHARED
151 };
152 */
153
154 inline
155 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
156 // always continue
157 return 0;
158 }
159
160 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
161
162 // Also
163 //GraphicsContext::TitleFlagger titles;
164
165protected:
166
167 typedef std::map<std::string, unsigned short> variableStat_t;
168
169};
170
171
173
176class FloaterSVG : public drain::TreeVisitor<TreeSVG> {
177public:
178
179 static
180 const std::string FLOATING;
181
182 inline // TreeSVG & root
183 FloaterSVG(){
184 }
185
186 inline
187 FloaterSVG(const FloaterSVG & floatLifter){ // : root(clipper.root) { // ???
188 }
189
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
204
207class OverlayMoverSVG : public drain::TreeVisitor<TreeSVG> {
208public:
209
210 static
211 const std::string OVERLAY;
212
213 inline // TreeSVG & root
215 }
216
217 inline
218 OverlayMoverSVG(const OverlayMoverSVG & floatLifter){ // : root(clipper.root) { // ???
219 }
220
221 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
222 /*
223 inline
224 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
225 // always continue
226 return 0;
227 }
228 */
229
230 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
231
232 // TreeSVG & root;
233
234};
235
236
240class ClipperSVG : public drain::TreeVisitor<TreeSVG> {
241
242public:
243
244 static
245 const std::string CLIPPED;
246
247
248 inline
249 ClipperSVG(){ // : root(root) {
250 }
251
252 ClipperSVG(const ClipperSVG & clipper){ // : root(clipper.root) { // ???
253 }
254
256
259 static
260 TreeSVG & getClippingRect(TreeSVG & root, size_t width, size_t height);
261
262 inline
263 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
264 // always continue
265 return 0;
266 }
267
268 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
269
270 // TreeSVG & root;
271
272};
273
274
275
277
280class MaskerSVG : public drain::TreeVisitor<TreeSVG> {
281
282public:
283
284 static
285 const std::string MASK_ID;
286
287 static
288 const std::string MASK_POS;
289
290 static
291 const ClassXML COVER;
292
293
294 enum MaskPosition {
295 NONE=0, // alias "false", No mask applied
296 TOP=1, // alias "true", Highest (last) element in a group, added by TreeSVG::addChild(COVER)
297 BOTTOM=2, // Lowest (first) element in a group, added by TreeSVG::prependChild(COVER)
298 // Note: also "false" and "true" supported, see Enum dict
299 };
300
301 inline
302 MaskerSVG(){
303 }
304
305 MaskerSVG(const MaskerSVG & masker){ // ???
306 }
307
308
310
313 static
314 const drain::FlexibleVariable & ensureMaskId(TreeSVG & group);
315
317 static
318 TreeSVG & getMask(TreeSVG & root, const std::string & maskId);
319
321
327 static
328 drain::image::TreeSVG & updateMask(TreeSVG & mask, int width, int height, const NodeSVG & contourNode);
329
330
332
337 static
338 TreeSVG & createMask(TreeSVG & root, TreeSVG & group, int width=0, int height=0, const NodeSVG & node = NodeSVG(svg::UNDEFINED),
339 MaskerSVG::MaskPosition pos=MaskerSVG::MaskPosition::BOTTOM);
340
342 // static
343 //void linkMask(const TreeSVG & mask, TreeSVG & obj);
344
346
353 static
354 void addCoverRect(const TreeSVG & mask, TreeSVG & group, MaskPosition pos=TOP);
355
356
358
365 inline
366 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
367 return 0;
368 }
369
370 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
371
372};
373
374
376
382class TransformerSVG : public drain::TreeVisitor<TreeSVG> {
383public:
384
385 inline // TreeSVG & root
387 }
388
389 inline
390 TransformerSVG(const TransformerSVG & transformer) : transform(transformer.transform){
391 }
392
393 inline // TreeSVG & root
394 TransformerSVG(const TransformSVG & transform) : transform(transform) {
395 }
396
397 inline
398 void set(const TransformSVG & tr){
399 transform = tr;
400 }
401
402
403 inline
404 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
405 if (tree.data.typeIs(svg::SVG, svg::GROUP)){
406 return 0;
407 }
408 else {
409 return 1;
410 }
411 }
412
413 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
414
415protected:
416
417 TransformSVG transform;
418
419};
420
421
422// DRAIN_ENUM_DICT(MetaDataCollectorSVG::MetaDataType);
423
442} // image::
443
444
445
446DRAIN_ENUM_DICT(image::MaskerSVG::MaskPosition);
447DRAIN_ENUM_OSTREAM(image::MaskerSVG::MaskPosition)
448
449//DRAIN_GETKEY_ENUM(image::TreeSVG, rack::RackSVG::ElemClass);
450
451
452} // drain::
453
454
455
456
457#endif // TREESVG_H_
458
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:253
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition VariableT.h:87
Definition TreeUtilsSVG.h:240
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:379
Raises FLOATING elements on the top.
Definition TreeUtilsSVG.h:176
Tools for creating masks for graphic objects based on their contours.
Definition TreeUtilsSVG.h:280
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:477
static TreeSVG & getMask(TreeSVG &root, const std::string &maskId)
From global document definitions (DEFS), retrieve the mask designed for this group.
Definition TreeUtilsSVG.cpp:444
static void addCoverRect(const TreeSVG &mask, TreeSVG &group, MaskPosition pos=TOP)
Finally, associate the object with a mask by assigning MASK elements ID to the mask attribute of obje...
Definition TreeUtilsSVG.cpp:513
static const drain::FlexibleVariable & ensureMaskId(TreeSVG &group)
Mark an overlay group "masked", meaning that at least one of its objects (also) creates a mask for th...
Definition TreeUtilsSVG.cpp:432
static TreeSVG & createMask(TreeSVG &root, TreeSVG &group, int width=0, int height=0, const NodeSVG &node=NodeSVG(svg::UNDEFINED), MaskerSVG::MaskPosition pos=MaskerSVG::MaskPosition::BOTTOM)
Calls createMaskId(), getMask() and updateMask().
Definition TreeUtilsSVG.cpp:497
int visitPrefix(TreeSVG &tree, const TreeSVG::path_t &path) override
Ensures a clipping path o f type RECT of given size.
Definition TreeUtilsSVG.h:366
Definition TreeUtilsSVG.h:137
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:127
Definition TreeSVG.h:135
Within a group, moves elements of class OVERLAY to the subgroup.
Definition TreeUtilsSVG.h:207
Definition TreeUtilsSVG.h:100
Definition TransformSVG.h:103
Applies transformation.
Definition TreeUtilsSVG.h:382
Definition Data.h:1473
SVG classes marking requests of relative horizontal and vertical alignment.
Definition TreeUtilsSVG.h:61