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#include <drain/util/Frame.h>
45#include <drain/util/Rectangle.h>
46
47#include "AlignAnchorSVG.h"
48#include "LayoutSVG.h"
49#include "TreeSVG.h"
50
51namespace drain {
52
53namespace image {
54
55
57
63// TODO: separate TreeLayoutUtilsSVG
64
66
67public:
68
69 enum Roles {
70 MAIN,
71 };
72
74
77 /*
78 static
79 TreeSVG & getHeaderObject(TreeSVG & root, svg::tag_t, const std::string & key = "");
80 */
81
83
90};
91
92DRAIN_ENUM_DICT(TreeUtilsSVG::Roles);
93DRAIN_ENUM_OSTREAM(TreeUtilsSVG::Roles);
94
95
96
98
99public:
100
101 // Leading path, maybe partial, to be pruned
102 const std::string dir;
103
104 // String starting the modified path, for example "file://"
105 const std::string prefix;
106
107 inline
108 RelativePathSetterSVG(const drain::FilePath & filepath, const std::string & prefix = "") :
109 dir(filepath.dir.empty() ? "" : filepath.dir.str()+'/'),
110 prefix(prefix) {
111 }
112
113 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
114
115
116};
117
118
123
124public:
125
126 static
127 const std::string LOCAL;
128
129 static
130 const std::string SHARED;
131
132 /*
133 enum MetaDataType {
134 LOCAL,
135 SHARED
136 };
137 */
138
139 inline
140 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
141 // always continue
142 return 0;
143 }
144
145 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
146
147 // Also
148 //GraphicsContext::TitleFlagger titles;
149
150protected:
151
152 typedef std::map<std::string, unsigned short> variableStat_t;
153
154};
155
156
160class ClipperSVG : public drain::TreeVisitor<TreeSVG> {
161
162public:
163
164 static
165 const std::string CLIP;
166
167 /*
168 enum MyDataType {
169 FIRST,
170 SECOND
171 };
172 */
173
174 inline
175 ClipperSVG(TreeSVG & root) : root(root) {
176 }
177
178 ClipperSVG(const ClipperSVG & clipper) : root(clipper.root) { // ???
179 }
180
182
185 static
186 TreeSVG & getClippingRect(TreeSVG & root, size_t width, size_t height);
187
188 inline
189 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
190 // always continue
191 return 0;
192 }
193
194 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
195
196 TreeSVG & root;
197
198};
199
200
201
203
206class MaskerSVG : public drain::TreeVisitor<TreeSVG> {
207
208public:
209
210 static
211 const std::string MASK_ID;
212
213 static
214 const ClassXML COVER;
215
216 inline
217 MaskerSVG(){
218 }
219
220 MaskerSVG(const MaskerSVG & clipper){ // ???
221 }
222
223
225
228 static
229 const drain::FlexibleVariable & createMaskId(TreeSVG & group);
230
232 static
233 TreeSVG & getMask(TreeSVG & root, const std::string & maskId);
234
236
242 static
243 drain::image::TreeSVG & updateMask(TreeSVG & mask, int width, int height, const NodeSVG & contourNode);
244
245
247
250 static
251 TreeSVG & createMask(TreeSVG & root, TreeSVG & group, int width=0, int height=0, const NodeSVG & node = NodeSVG(svg::UNDEFINED));
252
254
261 static
262 void linkMask(const TreeSVG & mask, TreeSVG & obj);
263
264
266
273 inline
274 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
275 return 0;
276 }
277
278 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
279
280};
281
282
283
284// DRAIN_ENUM_DICT(MetaDataCollectorSVG::MetaDataType);
285
304} // image::
305
306} // drain::
307
308
309
310
311#endif // TREESVG_H_
312
A wrapper marking string an CSS effect.
Definition ClassXML.h:57
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:58
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:270
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition VariableT.h:87
Definition TreeUtilsSVG.h:160
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:286
Tools for creating masks for graphic objects based on their contours.
Definition TreeUtilsSVG.h:206
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:440
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:395
static TreeSVG & getMask(TreeSVG &root, const std::string &maskId)
From global document definitions (DEFS), retrieve the mask designed for this group.
Definition TreeUtilsSVG.cpp:360
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:354
int visitPrefix(TreeSVG &tree, const TreeSVG::path_t &path) override
Ensures a clipping path o f type RECT of given size.
Definition TreeUtilsSVG.h:274
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:416
Definition TreeUtilsSVG.h:122
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:155
Definition TreeSVG.h:182
Definition TreeUtilsSVG.h:97
int visitPrefix(TreeSVG &tree, const TreeSVG::path_t &path) override
Create a new entry, unless already defined.
Definition TreeUtilsSVG.cpp:122
Definition DataSelector.cpp:1277
SVG classes marking requests of relative horizontal and vertical alignment.
Definition TreeUtilsSVG.h:65