Add path rendering and svg line output.

This commit is contained in:
jmsgrogan 2023-01-24 11:04:47 +00:00
parent 73051a5f27
commit 6274c41a80
15 changed files with 281 additions and 79 deletions

View file

@ -3,78 +3,105 @@
#include "PointParser.h"
#include <sstream>
Arc::Arc(const Point& startPoint, const Point& endPoint, double rX, double rY, double rotation, bool largeArc, bool sweep)
: mStartPoint(startPoint),
mEndPoint(endPoint),
mRx(rX),
mRy(rY),
mRotation(rotation),
mLargeArc(largeArc),
mSweep(sweep)
{
}
Point Arc::getFirstPoint() const
{
return mStartPoint;
}
Point Arc::getEndPoint() const
{
return mEndPoint;
}
std::string Arc::toPostScriptString(std::size_t precision) const
{
const auto large = mLargeArc ? "1" : "0";
const auto sweep = mSweep ? "1" : "0";
std::stringstream sstr;
if (precision > 0)
namespace ntk {
Arc::Arc(const Point& startPoint, const Point& endPoint, double rX, double rY, double rotation, bool largeArc, bool sweep)
: mStartPoint(startPoint),
mEndPoint(endPoint),
mRx(rX),
mRy(rY),
mRotation(rotation),
mLargeArc(largeArc),
mSweep(sweep)
{
sstr.precision(precision);
}
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
Point Arc::getFirstPoint() const
{
sstr << "a";
return mStartPoint;
}
else
Point Arc::getEndPoint() const
{
sstr << "A";
return mEndPoint;
}
sstr << mRx << " " << mRy << " " << mRotation << " " << large << " " << sweep << " ";
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
std::string Arc::toPostScriptString(std::size_t precision) const
{
sstr << PointParser::toStringRelative(mEndPoint, mStartPoint, 2, " ", precision);
const auto large = mLargeArc ? "1" : "0";
const auto sweep = mSweep ? "1" : "0";
std::stringstream sstr;
if (precision > 0)
{
sstr.precision(precision);
}
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
{
sstr << "a";
}
else
{
sstr << "A";
}
sstr << mRx << " " << mRy << " " << mRotation << " " << large << " " << sweep << " ";
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
{
sstr << PointParser::toStringRelative(mEndPoint, mStartPoint, 2, " ", precision);
}
else
{
sstr << PointParser::toString(mEndPoint, 2, " ", precision);
}
return sstr.str();
}
else
Bounds Arc::getBounds() const
{
sstr << PointParser::toString(mEndPoint, 2, " ", precision);
return {};
}
return sstr.str();
}
Bounds Arc::getBounds() const
{
return {};
}
const Point& Arc::getLocation() const
{
return mStartPoint;
}
const Point& Arc::getLocation() const
{
return mStartPoint;
}
void Arc::sample(SparseGrid<bool>*) const
{
void Arc::sample(SparseGrid<bool>*) const
{
}
}
Arc::Type Arc::getType() const
{
return Type::CURVE;
}
Arc::Type Arc::getType() const
{
return Type::CURVE;
}
Arc::CurveType Arc::getCurveType() const
{
return CurveType::ARC;
}
Arc::CurveType Arc::getCurveType() const
{
return CurveType::ARC;
double Arc::getRx() const
{
return mRx;
}
double Arc::getRy() const
{
return mRy;
}
double Arc::getRotation() const
{
return mRotation;
}
bool Arc::getUseLargeArc() const
{
return mLargeArc;
}
bool Arc::getSweepParam() const
{
return mSweep;
}
}

View file

@ -3,6 +3,7 @@
#include "Curve.h"
#include "Point.h"
namespace ntk{
class Arc : public Curve
{
public:
@ -20,6 +21,16 @@ public:
CurveType getCurveType() const override;
double getRx() const;
double getRy() const;
double getRotation() const;
bool getUseLargeArc() const;
bool getSweepParam() const;
void sample(SparseGrid<bool>*) const override;
std::string toPostScriptString(std::size_t precision = 0) const override;
@ -33,3 +44,4 @@ private:
bool mLargeArc{ false };
bool mSweep{ false };
};
}

View file

@ -21,6 +21,16 @@ Point CubicBezierCurve::getEndPoint() const
return mEndPoint;
}
const Point& CubicBezierCurve::getStartControlPoint() const
{
return mStartControlPoint;
}
const Point& CubicBezierCurve::getEndControlPoint() const
{
return mEndControlPoint;
}
std::string CubicBezierCurve::toPostScriptString(std::size_t precision) const
{
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)

View file

@ -12,6 +12,10 @@ public:
Point getEndPoint() const override;
const Point& getStartControlPoint() const;
const Point& getEndControlPoint() const;
Bounds getBounds() const override;
const Point& getLocation() const override;

View file

@ -249,12 +249,12 @@ PathElementPtr PathPostScriptConverter::onArc()
if (mPositionState == PositionState::RELATIVE)
{
const auto end_point = Point(mCurrentPoint.getX() + mPointBuffer[5], mCurrentPoint.getY() + mPointBuffer[6]);
element = std::make_unique<Arc>(mCurrentPoint, end_point, rx, ry, rotation, large_arc, sweep);
element = std::make_unique<ntk::Arc>(mCurrentPoint, end_point, rx, ry, rotation, large_arc, sweep);
}
else
{
const auto end_point = Point(mPointBuffer[5], mPointBuffer[6]);
element = std::make_unique<Arc>(mCurrentPoint, end_point, rx, ry, rotation, large_arc, sweep);
element = std::make_unique<ntk::Arc>(mCurrentPoint, end_point, rx, ry, rotation, large_arc, sweep);
}
}
return element;

View file

@ -20,6 +20,11 @@ Point QuadraticBezierCurve::getEndPoint() const
return mEndPoint;
}
Point QuadraticBezierCurve::getControlPoint() const
{
return mControlPoint;
}
std::string QuadraticBezierCurve::toPostScriptString(std::size_t precision) const
{
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)

View file

@ -10,6 +10,8 @@ public:
Point getFirstPoint() const override;
Point getControlPoint() const;
Point getEndPoint() const override;
Bounds getBounds() const override;