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/util/EnumUtils.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
73 static
74 TreeSVG & getDefaultObject(TreeSVG & root, svg::tag_t);
75
77 static
78 TreeSVG & ensureStyle(TreeSVG & root, const SelectXML<svg::tag_t> & selector, const std::initializer_list<std::pair<const char *,const Variable> > & styleDef);
79
80
81};
82
83DRAIN_ENUM_DICT(TreeUtilsSVG::Roles);
84DRAIN_ENUM_OSTREAM(TreeUtilsSVG::Roles);
85
86
87
89
90public:
91
92 // Leading path, maybe partial, to be pruned
93 const std::string dir;
94
95 // String starting the modified path, for example "file://"
96 const std::string prefix;
97
98 inline
99 RelativePathSetterSVG(const drain::FilePath & filepath, const std::string & prefix = "") :
100 dir(filepath.dir.empty() ? "" : filepath.dir.str()+'/'),
101 prefix(prefix) {
102 }
103
104 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override;
105
106
107};
108
109
114
115public:
116
117 static
118 const std::string LOCAL;
119
120 static
121 const std::string SHARED;
122
123 /*
124 enum MetaDataType {
125 LOCAL,
126 SHARED
127 };
128 */
129
130 inline
131 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
132 // always continue
133 return 0;
134 }
135
136 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
137
138 // Also
139 //GraphicsContext::TitleFlagger titles;
140
141protected:
142
143 typedef std::map<std::string, unsigned short> variableStat_t;
144
145};
146
147
151class ClipperSVG : public drain::TreeVisitor<TreeSVG> {
152
153public:
154
155 static
156 const std::string CLIP;
157
158 /*
159 enum MyDataType {
160 FIRST,
161 SECOND
162 };
163 */
164
165 inline
166 ClipperSVG(TreeSVG & root) : root(root) {
167 }
168
169 ClipperSVG(const ClipperSVG & clipper) : root(clipper.root) { // ???
170 }
171
173
176 static
177 TreeSVG & getClippingRect(TreeSVG & root, size_t width, size_t height);
178
179 inline
180 int visitPrefix(TreeSVG & tree, const TreeSVG::path_t & path) override {
181 // always continue
182 return 0;
183 }
184
185 int visitPostfix(TreeSVG & tree, const TreeSVG::path_t & path) override;
186
187 TreeSVG & root;
188
189};
190
191
192// DRAIN_ENUM_DICT(MetaDataCollectorSVG::MetaDataType);
193
212} // image::
213
214} // drain::
215
216
217
218
219#endif // TREESVG_H_
220
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:58
Definition SelectorXML.h:89
Default implementation of a tree visitor (concept) compatible TreeUtils::traverser()
Definition TreeUtils.h:270
Definition TreeUtilsSVG.h:151
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:289
Definition TreeUtilsSVG.h:113
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:158
Definition TreeUtilsSVG.h:88
Definition DataSelector.cpp:1277
SVG classes marking requests of relative horizontal and vertical alignment.
Definition TreeUtilsSVG.h:65
static TreeSVG & ensureStyle(TreeSVG &root, const SelectXML< svg::tag_t > &selector, const std::initializer_list< std::pair< const char *, const Variable > > &styleDef)
Create a new entry, unless already defined.
Definition TreeUtilsSVG.cpp:65