Start dx path support.

This commit is contained in:
jmsgrogan 2023-01-20 17:30:05 +00:00
parent f8a2ce3c59
commit a46477cdcf
5 changed files with 91 additions and 22 deletions

View file

@ -34,9 +34,15 @@ std::string Arc::toPostScriptString(std::size_t precision) const
{
sstr.precision(precision);
}
sstr << (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO) ? "a" : "A";
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);

View file

@ -11,6 +11,8 @@
#include "QuadraticBezierCurve.h"
#include "CubicBezierCurve.h"
#include "PointParser.h"
void PathPostScriptConverter::fromPostScript(GeometryPath* targetPath, const std::string& postScriptPath)
{
mCurrentPoint = Point();
@ -266,7 +268,7 @@ PathElementPtr PathPostScriptConverter::onQuadraticBezier()
double control_x = mPointBuffer[0];
double control_y = mPointBuffer[1];
double end_x = mPointBuffer[2];
bool end_y = mPointBuffer[3];
double end_y = mPointBuffer[3];
if (mPositionState == PositionState::RELATIVE)
{
const auto control_point = Point(mCurrentPoint.getX() + control_x, mCurrentPoint.getY() + control_y);
@ -286,14 +288,14 @@ PathElementPtr PathPostScriptConverter::onQuadraticBezier()
PathElementPtr PathPostScriptConverter::onCubicBezier()
{
PathElementPtr element;
if (mPointBuffer.size() == 4)
if (mPointBuffer.size() == 6)
{
double control0_x = mPointBuffer[0];
double control0_y = mPointBuffer[1];
double control1_x = mPointBuffer[0];
double control1_y = mPointBuffer[1];
double end_x = mPointBuffer[2];
bool end_y = mPointBuffer[3];
double control1_x = mPointBuffer[2];
double control1_y = mPointBuffer[3];
double end_x = mPointBuffer[4];
double end_y = mPointBuffer[5];
if (mPositionState == PositionState::RELATIVE)
{
const auto control_point0 = Point(mCurrentPoint.getX() + control0_x, mCurrentPoint.getY() + control0_y);
@ -318,11 +320,11 @@ std::string PathPostScriptConverter::toPostScript(const GeometryPath* targetPath
for (const auto& feature : targetPath->getFeatures())
{
auto start_loc = feature->getLocation();
path += "M " + std::to_string(start_loc.getX()) + " " + std::to_string(start_loc.getY());
path += "M" + PointParser::toString(start_loc, 2, " ", mPrecision);
for (const auto& path_element : feature->getElements())
{
path += " " + path_element->toPostScriptString(mPrecision);
path += path_element->toPostScriptString(mPrecision);
}
path += "Z ";
}