41#include <drain/image/AlignAnchorSVG.h>
42#include "drain/util/EnumFlags.h"
43#include "drain/util/FileInfo.h"
44#include "drain/util/Frame.h"
45#include "drain/util/SelectorXML.h"
46#include "drain/util/TreeXML.h"
47#include "TransformSVG.h"
55typedef drain::UnorderedMultiTree<NodeSVG,false, NodeXML<>::path_t> TreeSVG;
60 typedef float coord_t;
63 UNDEFINED=XML::UNDEFINED,
68 STYLE_SELECT=XML::STYLE_SELECT,
70 CIRCLE, DESC, GROUP, LINE, IMAGE, METADATA, PATH, POLYGON, RECT, TEXT, TITLE, TSPAN };
83DRAIN_ENUM_DICT(image::svg::tag_t);
85DRAIN_ENUM_OSTREAM(image::svg::tag_t)
145 NodeSVG(svg::tag_t t = svg::UNDEFINED);
154 bool isAbstract()
const {
158 svg::tag_t::METADATA,
176 setType(node.getType());
222 void setAttribute(
const std::string & key,
const std::string &value)
override;
226 void setAttribute(
const std::string & key,
const char *value)
override;
244 template <
typename T>
252 template <
typename T>
255 setViewBox(bb.x, bb.y, bb.width, bb.height);
260 template <
typename T>
262 void setViewBox(T & x, T & y, T & width, T & height){
267 template <
typename T>
278 template <
typename T>
281 box.setLocation(x, y);
284 template <
typename T>
287 box.width = frame.width;
288 box.height = frame.height;
295 template <
typename T>
306 template <
typename T>
313 svg::coord_t getWidth(){
321 template <
typename T>
324 link(
"data-margin", box.width);
342 template <
typename T>
345 if (typeIs(svg::TEXT)){
346 link(
"data-height", box.height);
352 svg::coord_t getHeight(){
357 void setFontSize(svg::coord_t size, svg::coord_t elemHeight = 0.0);
377 void handleType() override final;
381 void updateAlign() override;
410 std::stringstream sstr;
411 sstr <<
"<" << node.getTag();
412 if (::atoi(node.
getId().c_str())==0){
413 sstr <<
" id=" << node.
getId();
415 if (node.getName().isValid()){
416 sstr <<
" name=" << node.getName();
418 if (!node.getClasses().empty()){
419 sstr <<
" class=[" << node.getClasses() <<
']';
425 const std::string & str()
const {
453class NodeXML<image::svg::tag_t>::Elem<image::svg::tag_t::RECT>{
457 Elem(
image::NodeSVG & node) : node(node = image::svg::tag_t::RECT), x(node[
"x"]), y(node[
"y"]), width(node[
"width"]), height(node[
"height"]){
472class NodeXML<image::svg::tag_t>::Elem<image::svg::tag_t::CIRCLE>{
478 Elem(
image::NodeSVG & node) : node(node = image::svg::tag_t::CIRCLE), cx(node[
"cx"]), cy(node[
"cy"]), r(node[
"r"] = 0.0){
495class NodeXML<image::svg::tag_t>::Elem<image::svg::tag_t::POLYGON>{
499 Elem(
image::NodeSVG & node) : node(node = image::svg::tag_t::POLYGON), points(node[
"points"]), writablePoints(node[
"points"]){
513 writablePoints.clear();
516 template <
typename T>
518 void append(
const T &x,
const T &y){
519 writablePoints << x <<
',' << y <<
' ';
522 template <
typename T>
525 writablePoints << p.x <<
',' << p.y <<
' ';
542std::ostream & operator<<(std::ostream &ostr,
const drain::image::TreeSVG & tree){
555const NodeXML<image::svg::tag_t>::xml_default_elem_map_t NodeXML<image::svg::tag_t>::xml_default_elems;
572image::TreeSVG & image::TreeSVG::operator=(
const std::string & arg){
580image::TreeSVG & image::TreeSVG::operator=(std::initializer_list<std::pair<const char *,const Variable> > l){
588image::TreeSVG & image::TreeSVG::operator=(
const T & arg){
607image::TreeSVG & image::TreeSVG::operator()(
const image::svg::tag_t & type);
618image::TreeSVG & image::TreeSVG::operator[](
const image::svg::tag_t & type);
623const image::TreeSVG & image::TreeSVG::operator[](
const image::svg::tag_t & type)
const ;
628image::TreeSVG & image::TreeSVG::addChild(
const image::TreeSVG::key_t & key){
635bool image::TreeSVG::hasChild(
const image::svg::tag_t & type)
const;
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
Something that has width and height.
Definition Frame.h:55
A "handle" for specialized element classes, i.e. with members like width , height or radius .
Definition TreeXML.h:92
virtual std::ostream & nodeToStream(std::ostream &ostr, tag_display_mode mode=EMPTY_TAG) const override
Dumps info. Future option: outputs leading and ending tag.
Definition TreeXML.h:483
static std::ostream & docToStream(std::ostream &ostr, const V &tree)
Definition TreeXML.h:733
ref_t & link(const std::string &key, F &x)
Associates a map entry with a variable.
Definition ReferenceMap.h:84
Currently used only as CSS element selector.
Definition SelectorXML.h:50
Definition StringBuilder.h:58
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition VariableT.h:87
bool typeIsSet() const
Return true, if type is any of the arguments.
Definition XML.h:144
static T & xmlAssign(T &dst, const T &src)
Assign another tree structure to another.
Definition XML.h:616
const std::string & getId() const
Returns ID of this element. Hopefully a unique ID...
Definition TreeXML.h:142
static TX & xmlAssignString(TX &tree, const std::string &s)
When assigning a string, create new element unless the element itself is of type CTEXT.
Definition XML.h:732
static T & xmlAddChild(T &tree, const std::string &key)
Definition XML.h:782
static N & xmlAssignNode(N &dst, const N &src)
Assign tree node (data) to another.
Definition XML.h:661
std::string id
Some general-purpose.
Definition TreeXML.h:95
void setBoundingBox(const drain::Box< T > &b)
Set position (x,y), width and height of an object.
Definition TreeSVG.h:246
void setLocation(const T &x, const T &y)
Definition TreeSVG.h:280
virtual void setAttribute(const std::string &key, const std::string &value) override
Set attribute value, handling units in string arguments, like in "50%" or "640px".
Definition TreeSVG.cpp:241
const BBoxSVG & getBoundingBox() const
Get position (x,y), width and height of an object.
Definition TreeSVG.h:232
NodeSVG & operator=(const NodeSVG &node)
Copy data from a node. (Does not copy subtree.)
Definition TreeSVG.h:174
static std::string xlink
In opening SVG tag, referred to by attribute "xmlns:xlink".
Definition TreeSVG.h:134
void setMargin(T w)
Set margin of a TEXT element (non-standard).
Definition TreeSVG.h:323
void setWidth(T w)
Definition TreeSVG.h:308
NodeSVG & operator=(const std::initializer_list< Variable::init_pair_t > &l)
Copy data from a node. (Does not copy subtree.)
Definition TreeSVG.h:186
virtual void specificAttributesToStream(std::ostream &ostr) const override
Write transform, in addition to XML::ClassList.
Definition TreeSVG.cpp:344
svg::coord_t getMargin()
Get margin of a TEXT element (non-standard).
Definition TreeSVG.h:333
void setFontSize(svg::coord_t size, svg::coord_t elemHeight=0.0)
Sets font size and also text elem "height".
Definition TreeSVG.cpp:250
void setHeight(T h)
Definition TreeSVG.h:344
virtual bool isSingular() const override final
If true, render always as single elem (without child elems)
Definition TreeSVG.h:167
void setLocation(const drain::Point2D< T > &point)
Set position (x,y) of an object.
Definition TreeSVG.h:269
BBoxSVG & getBoundingBox()
Get position (x,y), width and height of an object.
Definition TreeSVG.h:239
void setFrame(const T &w, const T &h)
Definition TreeSVG.h:297
static std::string svg
In opening SVG tag, referred to by attributes "xmlns" and "xmlns:svg".
Definition TreeSVG.h:138
Definition DataSelector.cpp:1277
DRAIN_TYPENAME(void)
Add a specialization for each type of those you want to support.
Something that has coordinates (x,y) and dimensions (width, height).
Definition Frame.h:221
Adapter designed for NodeSVG.
Definition AlignAnchorSVG.h:161
User-friendly programming interface for alignment considering two elements.
Definition AlignSVG.h:222