-
Notifications
You must be signed in to change notification settings - Fork 849
/
Copy pathfsvgrenderer.h
120 lines (99 loc) · 4.43 KB
/
fsvgrenderer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*******************************************************************
Part of the Fritzing project - http://fritzing.org
Copyright (c) 2007-2019 Fritzing
Fritzing is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fritzing is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
********************************************************************/
#ifndef FSVGRENDERER_H
#define FSVGRENDERER_H
#include <QHash>
#include <QSvgRenderer>
#include <QXmlStreamReader>
#include <QDomDocument>
#include <QMatrix>
#include <QStringList>
#include "viewlayer.h"
struct ConnectorInfo {
bool gotCircle;
double radius;
double strokeWidth;
QMatrix matrix;
//QRectF cbounds;
QMatrix terminalMatrix;
QMatrix legMatrix;
QString legColor;
QLineF legLine;
double legStrokeWidth;
bool gotPath;
};
typedef QHash<ViewLayer::ViewLayerID, class FSvgRenderer *> RendererHash;
struct LoadInfo {
QString filename;
QStringList connectorIDs;
QStringList terminalIDs;
QStringList legIDs;
QString setColor;
QString colorElementID;
bool findNonConnectors = false;
bool parsePaths = false;;
LoadInfo() = default;
LoadInfo(const QString& file, bool _findNonConnector = false) : filename(file), findNonConnectors(_findNonConnector) { }
};
class FSvgRenderer : public QSvgRenderer
{
Q_OBJECT
public:
FSvgRenderer(QObject * parent = 0);
~FSvgRenderer();
QByteArray loadSvg(const LoadInfo &);
QByteArray loadSvg(const QString & filename);
QByteArray loadSvg(const QByteArray & contents, const LoadInfo &); // for SvgSplitter loads
QByteArray loadSvg(const QByteArray & contents, const QString & filename, bool findNonConnectors); // for SvgSplitter loads
bool loadSvgString(const QString & svg);
bool loadSvgString(const QString & svg, QString & newSvg);
bool fastLoad(const QByteArray & contents);
QByteArray finalLoad(QByteArray & cleanContents, const QString & filename);
constexpr const QString & filename() const noexcept { return m_filename; }
QSizeF defaultSizeF();
bool setUpConnector(class SvgIdLayer * svgIdLayer, bool ignoreTerminalPoint, ViewLayer::ViewLayerPlacement);
QList<SvgIdLayer *> setUpNonConnectors(ViewLayer::ViewLayerPlacement);
public:
static void cleanup();
static QSizeF parseForWidthAndHeight(QXmlStreamReader &);
static QPixmap * getPixmap(QSvgRenderer * renderer, QSize size);
static void initNames();
protected:
bool determineDefaultSize(QXmlStreamReader &);
QByteArray loadAux (const QByteArray & contents, const LoadInfo &);
bool initConnectorInfo(QDomDocument &, const LoadInfo &);
ConnectorInfo * initConnectorInfoStruct(QDomElement & connectorElement, const QString & filename, bool parsePaths);
bool initConnectorInfoStructAux(QDomElement &, ConnectorInfo * connectorInfo, const QString & filename, bool parsePaths);
bool initConnectorInfoCircle(QDomElement & element, ConnectorInfo * connectorInfo, const QString & filename);
bool initConnectorInfoPath(QDomElement & element, ConnectorInfo * connectorInfo, const QString & filename);
void initNonConnectorInfo(QDomDocument & domDocument, const QString & filename);
void initNonConnectorInfoAux(QDomElement & element, const QString & filename);
void initTerminalInfoAux(QDomElement & element, const LoadInfo &);
void initLegInfoAux(QDomElement & element, const LoadInfo &, bool & gotOne);
void initConnectorInfoAux(QDomElement & element, const LoadInfo &);
QPointF calcTerminalPoint(const QString & terminalId, const QRectF & connectorRect, bool ignoreTerminalPoint, const QRectF & viewBox, QMatrix & terminalMatrix);
bool initLegInfoAux(QDomElement & element, ConnectorInfo * connectorInfo);
void calcLeg(SvgIdLayer *, const QRectF & viewBox, ConnectorInfo * connectorInfo);
ConnectorInfo * getConnectorInfo(const QString & connectorID);
void clearConnectorInfoHash(QHash<QString, ConnectorInfo *> & hash);
protected:
QString m_filename;
QSizeF m_defaultSizeF;
QHash<QString, ConnectorInfo *> m_connectorInfoHash;
QHash<QString, ConnectorInfo *> m_nonConnectorInfoHash;
public:
static QString NonConnectorName;
};
#endif