Compare commits
2 Commits
dcb882fb86
...
11bed6c706
Author | SHA1 | Date |
---|---|---|
白封羽 | 11bed6c706 | |
白封羽 | 25bc2fb280 |
|
@ -31,7 +31,7 @@
|
||||||
<Import Project="$(QtMsBuild)\qt_defaults.props" />
|
<Import Project="$(QtMsBuild)\qt_defaults.props" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
|
<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>
|
<QtModules>core;gui;widgets</QtModules>
|
||||||
<QtBuildConfig>debug</QtBuildConfig>
|
<QtBuildConfig>debug</QtBuildConfig>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,140 +1,173 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "Line.h"
|
#include "Line.h"
|
||||||
namespace SVGParser {
|
#include <cmath>
|
||||||
enum SVGCommandType {
|
#include <string>
|
||||||
SVG_INVALID = -1,
|
using namespace std;
|
||||||
//SVG_MOVE_TO_REL, SVG_LINE_TO_REL, SVG_QUADRATIC_CURVE_TO_REL, SVG_CUBIC_CURVE_TO_REL,
|
namespace SVGParser
|
||||||
//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,
|
enum SVGCommandType
|
||||||
SVG_LINE_TO_REL, SVG_LINE_TO_ABS,
|
{
|
||||||
SVG_HORIZONTAL_LINE_TO_REL, SVG_HORIZONTAL_LINE_TO_ABS,
|
SVG_INVALID = -1,
|
||||||
SVG_VERTICAL_LINE_TO_REL, SVG_VERTICAL_LINE_TO_ABS,
|
// SVG_MOVE_TO_REL, SVG_LINE_TO_REL, SVG_QUADRATIC_CURVE_TO_REL, SVG_CUBIC_CURVE_TO_REL,
|
||||||
SVG_QUADRATIC_CURVE_TO_REL, SVG_QUADRATIC_CURVE_TO_ABS,
|
// SVG_MOVE_TO_ABS, SVG_LINE_TO_ABS, SVG_QUADRATIC_CURVE_TO_ABS, SVG_CUBIC_CURVE_TO_ABS,
|
||||||
SVG_CUBIC_CURVE_TO_REL, SVG_CUBIC_CURVE_TO_ABS,
|
SVG_MOVE_TO_REL,
|
||||||
SVG_SMOOTH_CUBIC_CURVE_TO_REL, SVG_SMOOTH_CUBIC_CURVE_TO_ABS,
|
SVG_MOVE_TO_ABS,
|
||||||
SVG_SMOOTH_QUADRATIC_CURVE_TO_REL, SVG_SMOOTH_QUADRATIC_CURVE_TO_ABS,
|
SVG_LINE_TO_REL,
|
||||||
SVG_ARC_TO_REL, SVG_ARC_TO_ABS,
|
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
|
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*);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
class SvgParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SvgParser(const std::string path, const double width, const double height) ;
|
SvgParser(const std::string path, const double width, const double height);
|
||||||
vector<vector<Point>> parse();
|
vector<vector<Point>> parse();
|
||||||
private:
|
|
||||||
const std::string path;
|
|
||||||
const double width;
|
|
||||||
const double height;
|
|
||||||
|
|
||||||
Point convertPoint(double x, double y);
|
private:
|
||||||
Point clampPoint(Point p);
|
static constexpr const double eps = 1e-6;
|
||||||
Point convertAbsPoint(double x, double y);
|
static constexpr const double PI = 3.14159265358979323846;
|
||||||
Point convertRelPoint(Point pointBegin, double x, double y);
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue