41#include <drain/Enum.h>
42#include <drain/image/AlignAnchorSVG.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 "drain/util/UtilsXML.h"
48#include "TransformSVG.h"
83 ALL = ON|(PNG|SVG|TXT),
90 int radialBezierResolution;
96DRAIN_ENUM_DICT(image::FileSVG::IncludePolicy);
97DRAIN_ENUM_OSTREAM(image::FileSVG::IncludePolicy);
99DRAIN_ENUM_DICT(image::FileSVG::PathPolicy);
100DRAIN_ENUM_OSTREAM(image::FileSVG::PathPolicy);
106 typedef float coord_t;
109 UNDEFINED=XML::UNDEFINED,
110 COMMENT=XML::COMMENT,
114 STYLE_SELECT=XML::STYLE_SELECT,
115 JAVASCRIPT_SCOPE=XML::JAVASCRIPT_SCOPE,
117 CIRCLE, CLIP_PATH, DEFS, DESC, GROUP, IMAGE, LINE, LINEAR_GRADIENT, MASK, METADATA, PATH, POLYGON, RECT, TEXT, TITLE, TSPAN };
125typedef drain::UnorderedMultiTree<NodeSVG,false, NodeXML<>::path_t> TreeSVG;
136DRAIN_ENUM_DICT(image::svg::tag_t);
138DRAIN_ENUM_OSTREAM(image::svg::tag_t)
185 typedef svg::tag_t tag_t;
201 NodeSVG(svg::tag_t t = svg::UNDEFINED);
210 bool isAbstract()
const {
212 svg::tag_t::UNDEFINED,
214 svg::tag_t::CLIP_PATH,
217 svg::tag_t::METADATA,
235 setType(node.getType());
281 void setAttribute(
const std::string & key,
const std::string &value)
override;
285 void setAttribute(
const std::string & key,
const char *value)
override;
303 template <
typename T>
311 template <
typename T>
314 setViewBox(bb.x, bb.y, bb.width, bb.height);
319 template <
typename T>
321 void setViewBox(T & x, T & y, T & width, T & height){
326 template <
typename T>
337 template <
typename T>
340 box.setLocation(x, y);
343 template <
typename T>
346 box.width = frame.width;
347 box.height = frame.height;
354 template <
typename T>
365 template <
typename T>
372 svg::coord_t getWidth(){
380 template <
typename T>
383 getMap()[
"data-margin"].
link(box.width = w);
402 template <
typename T>
405 if (typeIs(svg::TEXT)){
407 getMap()[
"data-height"].
link(box.height = h);
413 svg::coord_t getHeight(){
418 void setFontSize(svg::coord_t size, svg::coord_t elemHeight = 0.0);
438 void handleType() override final;
442 void updateAlign() override;
471 std::stringstream sstr;
472 sstr <<
"<" << node.getTag();
473 if (::atoi(node.
getId().c_str())==0){
474 sstr <<
" id=" << node.
getId();
476 if (node.getName().isValid()){
477 sstr <<
" name=" << node.getName();
479 if (!node.getClasses().empty()){
480 sstr <<
" class=[" << node.getClasses() <<
']';
486 const std::string & str()
const {
524std::ostream & operator<<(std::ostream &ostr,
const drain::image::TreeSVG & tree){
552image::TreeSVG & image::TreeSVG::operator=(
const std::string & arg){
560image::TreeSVG & image::TreeSVG::operator=(std::initializer_list<std::pair<const char *,const Variable> > l){
567image::TreeSVG & image::TreeSVG::operator=(
const T & arg){
584DRAIN_XML_EASY_TYPE(image::TreeSVG);
586DRAIN_XML_ENUM_KEY(image::TreeSVG, image::svg::tag_t);
601const image::TreeSVG::key_t & image::TreeSVG::getKey(
const ClassXML & cls){
602 return image::TreeSVG::getKey(cls.strPrefixed());
609 return image::TreeSVG::getKey(sel.str());
622template <> // for T (Tree class)
623template <> // for K (path elem arg)
624image::TreeSVG & image::TreeSVG::operator[](const image::svg::tag_t & type);
629template <> // for T (Tree class)
630template <> // for K (path elem arg)
631const image::TreeSVG & image::TreeSVG::operator[](const image::svg::tag_t & type) const ;
634template <> // for T (Tree class)
635template <> // for K (path elem arg)
636bool image::TreeSVG::hasChild(const ClassXML & cls) const;
638template <> // for T (Tree class)
639template <> // for K (path elem arg)
640image::TreeSVG & image::TreeSVG::operator[](const ClassXML & cls);
643template <> // for T (Tree class)
644template <> // for K (path elem arg)
645const image::TreeSVG & image::TreeSVG::operator[](const ClassXML & cls) const ;
658DRAIN_XML_DEFAULT_ELEMS(image::TreeSVG);
667DRAIN_XML_DEFAULT_INIT(image::TreeSVG);
A wrapper marking string an CSS effect.
Definition ClassXML.h:57
Something that has width and height.
Definition Frame.h:55
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:416
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
Definition SelectorXML.h:73
Definition StringBuilder.h:58
static T & assign(T &dst, const T &src)
Assign another tree structure to another.
Definition UtilsXML.h:60
static TX & assignString(TX &tree, const std::string &s)
When assigning a string, create new element unless the element itself is of type CTEXT.
Definition UtilsXML.h:134
bool typeIsSet() const
Return true, if type is any of the arguments.
Definition XML.h:165
const std::string & getId() const
Returns ID of this element. Hopefully a unique ID...
Definition TreeXML.h:142
static N & xmlAssignNode(N &dst, const N &src)
Assign tree node (data) to another.
Definition XML.h:664
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:305
void setLocation(const T &x, const T &y)
Definition TreeSVG.h:339
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:223
const BBoxSVG & getBoundingBox() const
Get position (x,y), width and height of an object.
Definition TreeSVG.h:291
NodeSVG & operator=(const NodeSVG &node)
Copy data from a node. (Does not copy subtree.)
Definition TreeSVG.h:233
static std::string xlink
In opening SVG tag, referred to by attribute "xmlns:xlink".
Definition TreeSVG.h:189
void setMargin(T w)
Set margin of a TEXT element (non-standard).
Definition TreeSVG.h:382
void setWidth(T w)
Definition TreeSVG.h:367
NodeSVG & operator=(const std::initializer_list< Variable::init_pair_t > &l)
Copy data from a node. (Does not copy subtree.)
Definition TreeSVG.h:245
virtual void specificAttributesToStream(std::ostream &ostr) const override
Write transform, in addition to XML::ClassList.
Definition TreeSVG.cpp:326
svg::coord_t getMargin()
Get margin of a TEXT element (non-standard).
Definition TreeSVG.h:393
void setFontSize(svg::coord_t size, svg::coord_t elemHeight=0.0)
Sets font size and also text elem "height".
Definition TreeSVG.cpp:232
void setHeight(T h)
Definition TreeSVG.h:404
virtual bool isSingular() const override final
If true, render always as single elem (without child elems)
Definition TreeSVG.h:226
void setLocation(const drain::Point2D< T > &point)
Set position (x,y) of an object.
Definition TreeSVG.h:328
BBoxSVG & getBoundingBox()
Get position (x,y), width and height of an object.
Definition TreeSVG.h:298
static std::string svg_decl
In opening SVG tag, referred to by attributes "xmlns" and "xmlns:svg".
Definition TreeSVG.h:193
void setFrame(const T &w, const T &h)
Definition TreeSVG.h:356
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:155
User-friendly programming interface for alignment considering two elements.
Definition AlignSVG.h:230