Improve node to svg conversion.
This commit is contained in:
parent
64f0b3e77a
commit
26ecae46b3
22 changed files with 403 additions and 126 deletions
|
@ -27,6 +27,11 @@ list(APPEND web_LIB_INCLUDES
|
|||
html/elements/HtmlHeadElement.cpp
|
||||
html/elements/HtmlBodyElement.cpp
|
||||
html/elements/HtmlParagraphElement.cpp
|
||||
svg/SvgDocument.h
|
||||
svg/SvgWriter.h
|
||||
svg/SvgShapeElement.h
|
||||
svg/SvgElement.h
|
||||
svg/elements/SvgShapeElements.h
|
||||
svg/SvgDocument.cpp
|
||||
svg/SvgWriter.cpp
|
||||
svg/SvgShapeElement.cpp
|
||||
|
|
|
@ -10,6 +10,20 @@ SvgShapeElement::SvgShapeElement(const std::string& tagName)
|
|||
|
||||
}
|
||||
|
||||
void SvgShapeElement::setNoFill()
|
||||
{
|
||||
auto attr = std::make_unique<XmlAttribute>("fill");
|
||||
attr->setValue("none");
|
||||
addAttribute(std::move(attr));
|
||||
}
|
||||
|
||||
void SvgShapeElement::setNoStroke()
|
||||
{
|
||||
auto attr = std::make_unique<XmlAttribute>("stroke");
|
||||
attr->setValue("none");
|
||||
addAttribute(std::move(attr));
|
||||
}
|
||||
|
||||
void SvgShapeElement::setFill(const Color& fill)
|
||||
{
|
||||
auto attr = std::make_unique<XmlAttribute>("fill");
|
||||
|
|
|
@ -10,8 +10,11 @@ public:
|
|||
|
||||
void setFill(const Color& fill);
|
||||
|
||||
void setNoFill();
|
||||
|
||||
void setStrokeWidth(double width);
|
||||
|
||||
void setStrokeColor(const Color& stroke);
|
||||
|
||||
void setNoStroke();
|
||||
};
|
||||
|
|
|
@ -8,19 +8,19 @@ SvgCircle::SvgCircle()
|
|||
|
||||
}
|
||||
|
||||
void SvgCircle::setLocation(const DiscretePoint& loc)
|
||||
void SvgCircle::setLocation(const Point& loc)
|
||||
{
|
||||
auto cx = std::make_unique<XmlAttribute>("cx");
|
||||
auto cy = std::make_unique<XmlAttribute>("cy");
|
||||
|
||||
cx->setValue(std::to_string(loc.GetX()));
|
||||
cy->setValue(std::to_string(loc.GetY()));
|
||||
cx->setValue(std::to_string(loc.getX()));
|
||||
cy->setValue(std::to_string(loc.getY()));
|
||||
|
||||
addAttribute(std::move(cx));
|
||||
addAttribute(std::move(cy));
|
||||
}
|
||||
|
||||
void SvgCircle::setRadius(unsigned rad)
|
||||
void SvgCircle::setRadius(double rad)
|
||||
{
|
||||
auto r = std::make_unique<XmlAttribute>("r");
|
||||
r->setValue(std::to_string(rad));
|
||||
|
@ -33,19 +33,19 @@ SvgRectangle::SvgRectangle()
|
|||
|
||||
}
|
||||
|
||||
void SvgRectangle::setLocation(const DiscretePoint& loc)
|
||||
void SvgRectangle::setLocation(const Point& loc)
|
||||
{
|
||||
auto x = std::make_unique<XmlAttribute>("x");
|
||||
auto y = std::make_unique<XmlAttribute>("y");
|
||||
|
||||
x->setValue(std::to_string(loc.GetX()));
|
||||
y->setValue(std::to_string(loc.GetY()));
|
||||
x->setValue(std::to_string(loc.getX()));
|
||||
y->setValue(std::to_string(loc.getY()));
|
||||
|
||||
addAttribute(std::move(x));
|
||||
addAttribute(std::move(y));
|
||||
}
|
||||
|
||||
void SvgRectangle::setWidth(unsigned w)
|
||||
void SvgRectangle::setWidth(double w)
|
||||
{
|
||||
auto width = std::make_unique<XmlAttribute>("width");
|
||||
|
||||
|
@ -54,7 +54,7 @@ void SvgRectangle::setWidth(unsigned w)
|
|||
addAttribute(std::move(width));
|
||||
}
|
||||
|
||||
void SvgRectangle::setHeight(unsigned h)
|
||||
void SvgRectangle::setHeight(double h)
|
||||
{
|
||||
auto height = std::make_unique<XmlAttribute>("height");
|
||||
|
||||
|
@ -70,14 +70,14 @@ SvgPolygon::SvgPolygon()
|
|||
|
||||
}
|
||||
|
||||
void SvgPolygon::setPoints(const std::vector<DiscretePoint>& locs)
|
||||
void SvgPolygon::setPoints(const std::vector<Point>& locs)
|
||||
{
|
||||
auto points = std::make_unique<XmlAttribute>("points");
|
||||
|
||||
std::stringstream sstr;
|
||||
for (const auto& loc : locs)
|
||||
{
|
||||
sstr << loc.GetX() << "," << loc.GetY() << " ";
|
||||
sstr << loc.getX() << "," << loc.getY() << " ";
|
||||
}
|
||||
points->setValue(sstr.str());
|
||||
addAttribute(std::move(points));
|
||||
|
@ -91,14 +91,14 @@ SvgPolyline::SvgPolyline()
|
|||
addAttribute(std::move(fill));
|
||||
}
|
||||
|
||||
void SvgPolyline::setPoints(const std::vector<DiscretePoint>& locs)
|
||||
void SvgPolyline::setPoints(const std::vector<Point>& locs)
|
||||
{
|
||||
auto points = std::make_unique<XmlAttribute>("points");
|
||||
|
||||
std::stringstream sstr;
|
||||
for (const auto& loc : locs)
|
||||
{
|
||||
sstr << loc.GetX() << "," << loc.GetY() << " ";
|
||||
sstr << loc.getX() << "," << loc.getY() << " ";
|
||||
}
|
||||
points->setValue(sstr.str());
|
||||
addAttribute(std::move(points));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "SvgShapeElement.h"
|
||||
#include "DiscretePoint.h"
|
||||
#include "Point.h"
|
||||
|
||||
#include "XmlAttribute.h"
|
||||
|
||||
|
@ -10,9 +10,9 @@ class SvgCircle : public SvgShapeElement
|
|||
public:
|
||||
SvgCircle();
|
||||
|
||||
void setLocation(const DiscretePoint& loc);
|
||||
void setLocation(const Point& loc);
|
||||
|
||||
void setRadius(unsigned rad);
|
||||
void setRadius(double rad);
|
||||
};
|
||||
|
||||
class SvgRectangle : public SvgShapeElement
|
||||
|
@ -20,11 +20,11 @@ class SvgRectangle : public SvgShapeElement
|
|||
public:
|
||||
SvgRectangle();
|
||||
|
||||
void setLocation(const DiscretePoint& loc);
|
||||
void setLocation(const Point& loc);
|
||||
|
||||
void setWidth(unsigned width);
|
||||
void setWidth(double width);
|
||||
|
||||
void setHeight(unsigned height);
|
||||
void setHeight(double height);
|
||||
};
|
||||
|
||||
class SvgPolygon : public SvgShapeElement
|
||||
|
@ -32,7 +32,7 @@ class SvgPolygon : public SvgShapeElement
|
|||
public:
|
||||
SvgPolygon();
|
||||
|
||||
void setPoints(const std::vector<DiscretePoint>& loc);
|
||||
void setPoints(const std::vector<Point>& loc);
|
||||
};
|
||||
|
||||
class SvgPolyline : public SvgShapeElement
|
||||
|
@ -40,7 +40,7 @@ class SvgPolyline : public SvgShapeElement
|
|||
public:
|
||||
SvgPolyline();
|
||||
|
||||
void setPoints(const std::vector<DiscretePoint>& loc);
|
||||
void setPoints(const std::vector<Point>& loc);
|
||||
};
|
||||
|
||||
class SvgPath : public SvgShapeElement
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue