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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBSVGSUBSETADAPTOR_H_
#define UBSVGSUBSETADAPTOR_H_
#include <QtGui>
#include <QtXml>
#include "frameworks/UBGeometryUtils.h"
class UBGraphicsSvgItem;
class UBGraphicsPolygonItem;
class UBGraphicsPixmapItem;
class UBGraphicsPDFItem;
class UBGraphicsWidgetItem;
class UBGraphicsVideoItem;
class UBGraphicsAudioItem;
class UBGraphicsAppleWidgetItem;
class UBGraphicsW3CWidgetItem;
class UBGraphicsTextItem;
class UBGraphicsCurtainItem;
class UBGraphicsRuler;
class UBGraphicsCompass;
class UBGraphicsProtractor;
class UBGraphicsScene;
class UBDocumentProxy;
class UBGraphicsStroke;
class UBPersistenceManager;
class UBGraphicsTriangle;
class UBGraphicsCache;
class UBSvgSubsetAdaptor
{
private:
UBSvgSubsetAdaptor() {;}
virtual ~UBSvgSubsetAdaptor() {;}
public:
static UBGraphicsScene* loadScene(UBDocumentProxy* proxy, const int pageIndex);
static void persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex);
static void upgradeScene(UBDocumentProxy* proxy, const int pageIndex);
static QUuid sceneUuid(UBDocumentProxy* proxy, const int pageIndex);
static void setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid);
static void convertPDFObjectsToImages(UBDocumentProxy* proxy);
static void convertSvgImagesToImages(UBDocumentProxy* proxy);
static const QString nsSvg;
static const QString nsXLink;
static const QString nsXHtml;
static const QString nsUb;
static const QString xmlTrue;
static const QString xmlFalse;
static const QString sFontSizePrefix;
static const QString sPixelUnit;
static const QString sFontWeightPrefix;
static const QString sFontStylePrefix;
private:
static UBGraphicsScene* loadScene(UBDocumentProxy* proxy, const QByteArray& pArray);
static QDomDocument loadSceneDocument(UBDocumentProxy* proxy, const int pPageIndex);
static QString uniboardDocumentNamespaceUriFromVersion(int fileVersion);
static const QString sFormerUniboardDocumentNamespaceUri;
static QString toSvgTransform(const QMatrix& matrix);
static QMatrix fromSvgTransform(const QString& transform);
class UBSvgSubsetReader
{
public:
UBSvgSubsetReader(UBDocumentProxy* proxy, const QByteArray& pXmlData);
virtual ~UBSvgSubsetReader(){}
UBGraphicsScene* loadScene();
private:
UBGraphicsPolygonItem* polygonItemFromLineSvg(const QColor& pDefaultBrushColor);
UBGraphicsPolygonItem* polygonItemFromPolygonSvg(const QColor& pDefaultBrushColor);
QList<UBGraphicsPolygonItem*> polygonItemsFromPolylineSvg(const QColor& pDefaultColor);
UBGraphicsPixmapItem* pixmapItemFromSvg();
UBGraphicsSvgItem* svgItemFromSvg();
UBGraphicsPDFItem* pdfItemFromPDF();
UBGraphicsVideoItem* videoItemFromSvg();
UBGraphicsAudioItem* audioItemFromSvg();
UBGraphicsAppleWidgetItem* graphicsAppleWidgetFromSvg();
UBGraphicsW3CWidgetItem* graphicsW3CWidgetFromSvg();
UBGraphicsTextItem* textItemFromSvg();
UBGraphicsCurtainItem* curtainItemFromSvg();
UBGraphicsRuler* rulerFromSvg();
UBGraphicsCompass* compassFromSvg();
UBGraphicsProtractor* protractorFromSvg();
UBGraphicsTriangle* triangleFromSvg();
UBGraphicsCache* cacheFromSvg();
void graphicsItemFromSvg(QGraphicsItem* gItem);
QXmlStreamReader mXmlReader;
int mFileVersion;
UBDocumentProxy *mProxy;
QString mDocumentPath;
QColor mGroupDarkBackgroundColor;
QColor mGroupLightBackgroundColor;
qreal mGroupZIndex;
bool mGroupHasInfo;
QString mNamespaceUri;
};
class UBSvgSubsetWriter
{
public:
UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex);
bool persistScene();
virtual ~UBSvgSubsetWriter(){}
private:
void polygonItemToSvgPolygon(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo);
void polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo);
void strokeToSvgPolyline(UBGraphicsStroke* stroke, bool groupHoldsInfo);
void strokeToSvgPolygon(UBGraphicsStroke* stroke, bool groupHoldsInfo);
inline QString pointsToSvgPointsAttribute(QVector<QPointF> points)
{
UBGeometryUtils::crashPointList(points);
int pointsCount = points.size();
QString svgPoints;
int length = 0;
QString sBuf;
for(int j = 0; j < pointsCount; j++)
{
sBuf = "%1,%2 ";
const QPointF & point = points.at(j);
QString temp1 = "%1", temp2 = "%2";
temp1 = temp1.arg(point.x());
temp2 = temp2.arg(point.y());
QLocale loc(QLocale::C);
sBuf = sBuf.arg(loc.toFloat(temp1)).arg(loc.toFloat(temp2));
svgPoints.insert(length, sBuf);
length += sBuf.length();
}
return svgPoints;
}
inline qreal trickAlpha(qreal alpha)
{
qreal trickAlpha = alpha;
if(trickAlpha >= 0.2 && trickAlpha < 0.6){
trickAlpha /= 5;
}else if (trickAlpha < 0.8)
trickAlpha /= 3;
return trickAlpha;
}
void pixmapItemToLinkedImage(UBGraphicsPixmapItem *pixmapItem);
void svgItemToLinkedSvg(UBGraphicsSvgItem *svgItem);
void pdfItemToLinkedPDF(UBGraphicsPDFItem *pdfItem);
void videoItemToLinkedVideo(UBGraphicsVideoItem *videoItem);
void audioItemToLinkedAudio(UBGraphicsAudioItem* audioItem);
void graphicsItemToSvg(QGraphicsItem *item);
void graphicsAppleWidgetToSvg(UBGraphicsAppleWidgetItem *item);
void graphicsW3CWidgetToSvg(UBGraphicsW3CWidgetItem *item);
void graphicsWidgetToSvg(UBGraphicsWidgetItem *item);
void textItemToSvg(UBGraphicsTextItem *item);
void curtainItemToSvg(UBGraphicsCurtainItem *item);
void rulerToSvg(UBGraphicsRuler *item);
void compassToSvg(UBGraphicsCompass *item);
void protractorToSvg(UBGraphicsProtractor *item);
void cacheToSvg(UBGraphicsCache* item);
void triangleToSvg(UBGraphicsTriangle *item);
void writeSvgElement();
private:
UBGraphicsScene* mScene;
QXmlStreamWriter mXmlWriter;
QString mDocumentPath;
int mPageIndex;
};
};
#endif /* UBSVGSUBSETADAPTOR_H_ */