Compare commits

...

2 Commits

Author SHA1 Message Date
白封羽 11bed6c706 Merge branch 'main' of http://101.34.228.45:3000/BigC/ArchitectureColoredPainting 2022-10-11 19:57:38 +08:00
白封羽 25bc2fb280 实现了椭圆转换 2022-10-11 19:57:30 +08:00
3 changed files with 881 additions and 689 deletions

View File

@ -31,7 +31,7 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>5.15.2_msvc2019_64</QtInstall>
<QtInstall>5.15.0_msvc2019_64</QtInstall>
<QtModules>core;gui;widgets</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>

File diff suppressed because it is too large Load Diff

View File

@ -1,140 +1,173 @@
#pragma once
#include <string>
#include "Line.h"
namespace SVGParser {
enum SVGCommandType {
SVG_INVALID = -1,
//SVG_MOVE_TO_REL, SVG_LINE_TO_REL, SVG_QUADRATIC_CURVE_TO_REL, SVG_CUBIC_CURVE_TO_REL,
//SVG_MOVE_TO_ABS, SVG_LINE_TO_ABS, SVG_QUADRATIC_CURVE_TO_ABS, SVG_CUBIC_CURVE_TO_ABS,
SVG_MOVE_TO_REL, SVG_MOVE_TO_ABS,
SVG_LINE_TO_REL, SVG_LINE_TO_ABS,
SVG_HORIZONTAL_LINE_TO_REL, SVG_HORIZONTAL_LINE_TO_ABS,
SVG_VERTICAL_LINE_TO_REL, SVG_VERTICAL_LINE_TO_ABS,
SVG_QUADRATIC_CURVE_TO_REL, SVG_QUADRATIC_CURVE_TO_ABS,
SVG_CUBIC_CURVE_TO_REL, SVG_CUBIC_CURVE_TO_ABS,
SVG_SMOOTH_CUBIC_CURVE_TO_REL, SVG_SMOOTH_CUBIC_CURVE_TO_ABS,
SVG_SMOOTH_QUADRATIC_CURVE_TO_REL, SVG_SMOOTH_QUADRATIC_CURVE_TO_ABS,
SVG_ARC_TO_REL, SVG_ARC_TO_ABS,
#include <cmath>
#include <string>
using namespace std;
namespace SVGParser
{
enum SVGCommandType
{
SVG_INVALID = -1,
// SVG_MOVE_TO_REL, SVG_LINE_TO_REL, SVG_QUADRATIC_CURVE_TO_REL, SVG_CUBIC_CURVE_TO_REL,
// SVG_MOVE_TO_ABS, SVG_LINE_TO_ABS, SVG_QUADRATIC_CURVE_TO_ABS, SVG_CUBIC_CURVE_TO_ABS,
SVG_MOVE_TO_REL,
SVG_MOVE_TO_ABS,
SVG_LINE_TO_REL,
SVG_LINE_TO_ABS,
SVG_HORIZONTAL_LINE_TO_REL,
SVG_HORIZONTAL_LINE_TO_ABS,
SVG_VERTICAL_LINE_TO_REL,
SVG_VERTICAL_LINE_TO_ABS,
SVG_QUADRATIC_CURVE_TO_REL,
SVG_QUADRATIC_CURVE_TO_ABS,
SVG_CUBIC_CURVE_TO_REL,
SVG_CUBIC_CURVE_TO_ABS,
SVG_SMOOTH_CUBIC_CURVE_TO_REL,
SVG_SMOOTH_CUBIC_CURVE_TO_ABS,
SVG_SMOOTH_QUADRATIC_CURVE_TO_REL,
SVG_SMOOTH_QUADRATIC_CURVE_TO_ABS,
SVG_ARC_TO_REL,
SVG_ARC_TO_ABS,
SVG_CLOSE_PATH
};
bool isAbsolute(SVGCommandType);
class SVGCommand {
public:
SVGCommand(double, double, bool = false);
static const int length;
double x, y;
bool absolute;
virtual const std::string toString() const = 0;
virtual SVGCommandType getType() = 0;
virtual std::string toString2() = 0;
};
class SVGMoveTo : public SVGCommand {
public:
static const int length = 2;
SVGMoveTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGLineTo : public SVGCommand {
public:
static const int length = 2;
SVGLineTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGHLineTo : public SVGCommand {
public:
static const int length = 1;
SVGHLineTo(double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGVLineTo : public SVGCommand {
public:
static const int length = 1;
SVGVLineTo(double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGQuadraticCurveTo : public SVGCommand {
public:
SVGQuadraticCurveTo(double, double, double, double, bool = false);
double x0, y0;
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGCubicCurveTo : public SVGCommand {
public:
double x0, y0, x1, y1;
SVGCubicCurveTo(double, double, double, double, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGSmoothQuadraticCurveTo : public SVGCommand {
public:
SVGSmoothQuadraticCurveTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGSmoothCubicCurveTo : public SVGCommand {
public:
double x1, y1;
SVGSmoothCubicCurveTo(double, double, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGArcTo : public SVGCommand {
public:
double rx, ry, rot;
bool large, sweep;
SVGArcTo(double, double, double, bool, bool, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGClosePath : public SVGCommand {
public:
SVGClosePath(bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
typedef vector<std::shared_ptr<SVGCommand>> SVGPath;
SVGPath parsePath(std::istream&);
std::ostream& operator<< (std::ostream&, const SVGParser::SVGPath&);
std::ostream& operator<< (std::ostream&, const SVGParser::SVGCommand*);
SVG_CLOSE_PATH
};
bool isAbsolute(SVGCommandType);
class SVGCommand
{
public:
SVGCommand(double, double, bool = false);
static const int length;
double x, y;
bool absolute;
virtual const std::string toString() const = 0;
virtual SVGCommandType getType() = 0;
virtual std::string toString2() = 0;
};
class SVGMoveTo : public SVGCommand
{
public:
static const int length = 2;
SVGMoveTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGLineTo : public SVGCommand
{
public:
static const int length = 2;
SVGLineTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGHLineTo : public SVGCommand
{
public:
static const int length = 1;
SVGHLineTo(double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGVLineTo : public SVGCommand
{
public:
static const int length = 1;
SVGVLineTo(double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGQuadraticCurveTo : public SVGCommand
{
public:
SVGQuadraticCurveTo(double, double, double, double, bool = false);
double x0, y0;
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGCubicCurveTo : public SVGCommand
{
public:
double x0, y0, x1, y1;
SVGCubicCurveTo(double, double, double, double, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGSmoothQuadraticCurveTo : public SVGCommand
{
public:
SVGSmoothQuadraticCurveTo(double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGSmoothCubicCurveTo : public SVGCommand
{
public:
double x1, y1;
SVGSmoothCubicCurveTo(double, double, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGArcTo : public SVGCommand
{
public:
double rx, ry, rot;
bool large, sweep;
SVGArcTo(double, double, double, bool, bool, double, double, bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
class SVGClosePath : public SVGCommand
{
public:
SVGClosePath(bool = false);
virtual const std::string toString() const;
virtual SVGCommandType getType();
virtual std::string toString2();
};
typedef vector<std::shared_ptr<SVGCommand>> SVGPath;
SVGPath parsePath(std::istream &);
std::ostream &operator<<(std::ostream &, const SVGParser::SVGPath &);
std::ostream &operator<<(std::ostream &, const SVGParser::SVGCommand *);
}; // namespace SVGParser
class SvgParser
{
public:
SvgParser(const std::string path, const double width, const double height) ;
vector<vector<Point>> parse();
private:
const std::string path;
const double width;
const double height;
public:
SvgParser(const std::string path, const double width, const double height);
vector<vector<Point>> parse();
Point convertPoint(double x, double y);
Point clampPoint(Point p);
Point convertAbsPoint(double x, double y);
Point convertRelPoint(Point pointBegin, double x, double y);
private:
static constexpr const double eps = 1e-6;
static constexpr const double PI = 3.14159265358979323846;
const std::string path;
const double width;
const double height;
Point convertPoint(double x, double y);
Point clampPoint(Point p);
Point convertAbsPoint(double x, double y);
Point convertRelPoint(Point pointBegin, double x, double y);
void ellipticalArcConverter(Point beginPoint, double radiusX, double radiusY, double phi, bool flagA,
bool flagS, Point endPoint,vector<vector<Point>>& lines);
vector<double> centerConverter(Point beginPoint, double radiusX, double radiusY, double phi, bool flagA, bool flagS,
Point endPoint);
double angleConverter(Point u, Point v);
Point eConverter(Point c, Point r, double cosPhi, double sinPhi, double t);
Point e2Converter(Point c, Point r, double cosPhi, double sinPhi, double t);
};