41#include <drain/image/AlignAnchorSVG.h>
42#include <drain/util/EnumUtils.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),
93DRAIN_ENUM_DICT(image::FileSVG::IncludePolicy);
94DRAIN_ENUM_OSTREAM(image::FileSVG::IncludePolicy);
96DRAIN_ENUM_DICT(image::FileSVG::PathPolicy);
97DRAIN_ENUM_OSTREAM(image::FileSVG::PathPolicy);
103 typedef float coord_t;
106 UNDEFINED=XML::UNDEFINED,
107 COMMENT=XML::COMMENT,
111 STYLE_SELECT=XML::STYLE_SELECT,
113 CIRCLE, CLIP_PATH, DEFS, DESC, GROUP, IMAGE, LINE, LINEAR_GRADIENT, MASK, METADATA, PATH, POLYGON, RECT, TEXT, TITLE, TSPAN };
121typedef drain::UnorderedMultiTree<NodeSVG,false, NodeXML<>::path_t> TreeSVG;
132DRAIN_ENUM_DICT(image::svg::tag_t);
134DRAIN_ENUM_OSTREAM(image::svg::tag_t)
195 NodeSVG(svg::tag_t t = svg::UNDEFINED);
204 bool isAbstract()
const {
206 svg::tag_t::UNDEFINED,
208 svg::tag_t::CLIP_PATH,
211 svg::tag_t::METADATA,
229 setType(node.getType());
275 void setAttribute(
const std::string & key,
const std::string &value)
override;
279 void setAttribute(
const std::string & key,
const char *value)
override;
297 template <
typename T>
305 template <
typename T>
308 setViewBox(bb.x, bb.y, bb.width, bb.height);
313 template <
typename T>
315 void setViewBox(T & x, T & y, T & width, T & height){
320 template <
typename T>
331 template <
typename T>
334 box.setLocation(x, y);
337 template <
typename T>
340 box.width = frame.width;
341 box.height = frame.height;
348 template <
typename T>
359 template <
typename T>
366 svg::coord_t getWidth(){
374 template <
typename T>
377 link(
"data-margin", box.width);
395 template <
typename T>
398 if (typeIs(svg::TEXT)){
399 link(
"data-height", box.height);
405 svg::coord_t getHeight(){
410 void setFontSize(svg::coord_t size, svg::coord_t elemHeight = 0.0);
430 void handleType() override final;
434 void updateAlign() override;
463 std::stringstream sstr;
464 sstr <<
"<" << node.getTag();
465 if (::atoi(node.
getId().c_str())==0){
466 sstr <<
" id=" << node.
getId();
468 if (node.getName().isValid()){
469 sstr <<
" name=" << node.getName();
471 if (!node.getClasses().empty()){
472 sstr <<
" class=[" << node.getClasses() <<
']';
478 const std::string & str()
const {
516std::ostream & operator<<(std::ostream &ostr,
const drain::image::TreeSVG & tree){
544image::TreeSVG & image::TreeSVG::operator=(
const std::string & arg){
552image::TreeSVG & image::TreeSVG::operator=(std::initializer_list<std::pair<const char *,const Variable> > l){
559image::TreeSVG & image::TreeSVG::operator=(
const T & arg){
573image::TreeSVG & image::TreeSVG::operator()(
const image::svg::tag_t & type);
578bool image::TreeSVG::hasChild(
const image::svg::tag_t & type)
const;
583image::TreeSVG & image::TreeSVG::operator[](
const image::svg::tag_t & type);
590const image::TreeSVG & image::TreeSVG::operator[](
const image::svg::tag_t & type)
const ;
595bool image::TreeSVG::hasChild(
const ClassXML & cls)
const;
599image::TreeSVG & image::TreeSVG::operator[](
const ClassXML & cls);
604const image::TreeSVG & image::TreeSVG::operator[](
const ClassXML & cls)
const ;
626void image::TreeSVG::initChild(image::TreeSVG & child)
const {
627 UtilsXML::initChildWithDefaultType(*
this, child);
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:414
static std::ostream & docToStream(std::ostream &ostr, const V &tree)
Definition TreeXML.h:733
std::map< xml_tag_t, xml_tag_t > xml_default_elem_map_t
Helps creating child elements. Like children of HTML element UL should be LI.
Definition TreeXML.h:348
ref_t & link(const std::string &key, F &x)
Associates a map entry with a variable.
Definition ReferenceMap.h:84
Definition StringBuilder.h:58
static T & assign(T &dst, const T &src)
Assign another tree structure to another.
Definition UtilsXML.h:57
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:131
bool typeIsSet() const
Return true, if type is any of the arguments.
Definition XML.h:148
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:623
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:299
void setLocation(const T &x, const T &y)
Definition TreeSVG.h:333
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:220
const BBoxSVG & getBoundingBox() const
Get position (x,y), width and height of an object.
Definition TreeSVG.h:285
NodeSVG & operator=(const NodeSVG &node)
Copy data from a node. (Does not copy subtree.)
Definition TreeSVG.h:227
static std::string xlink
In opening SVG tag, referred to by attribute "xmlns:xlink".
Definition TreeSVG.h:183
void setMargin(T w)
Set margin of a TEXT element (non-standard).
Definition TreeSVG.h:376
void setWidth(T w)
Definition TreeSVG.h:361
NodeSVG & operator=(const std::initializer_list< Variable::init_pair_t > &l)
Copy data from a node. (Does not copy subtree.)
Definition TreeSVG.h:239
virtual void specificAttributesToStream(std::ostream &ostr) const override
Write transform, in addition to XML::ClassList.
Definition TreeSVG.cpp:323
svg::coord_t getMargin()
Get margin of a TEXT element (non-standard).
Definition TreeSVG.h:386
void setFontSize(svg::coord_t size, svg::coord_t elemHeight=0.0)
Sets font size and also text elem "height".
Definition TreeSVG.cpp:229
void setHeight(T h)
Definition TreeSVG.h:397
virtual bool isSingular() const override final
If true, render always as single elem (without child elems)
Definition TreeSVG.h:220
void setLocation(const drain::Point2D< T > &point)
Set position (x,y) of an object.
Definition TreeSVG.h:322
BBoxSVG & getBoundingBox()
Get position (x,y), width and height of an object.
Definition TreeSVG.h:292
void setFrame(const T &w, const T &h)
Definition TreeSVG.h:350
static std::string svg
In opening SVG tag, referred to by attributes "xmlns" and "xmlns:svg".
Definition TreeSVG.h:187
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:154
User-friendly programming interface for alignment considering two elements.
Definition AlignSVG.h:219