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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/* libvisio
* Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
* Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301 USA
*/
#include <vector>
#include <map>
#include "VSDXStylesCollector.h"
libvisio::VSDXStylesCollector::VSDXStylesCollector(
std::vector<std::map<unsigned, XForm> > &groupXFormsSequence,
std::vector<std::map<unsigned, unsigned> > &groupMembershipsSequence,
std::vector<std::list<unsigned> > &documentPageShapeOrders
) :
m_currentLevel(0), m_isShapeStarted(false),
m_shadowOffsetX(0.0), m_shadowOffsetY(0.0),
m_currentShapeId(0), m_groupXForms(), m_groupMemberships(),
m_groupXFormsSequence(groupXFormsSequence),
m_groupMembershipsSequence(groupMembershipsSequence), m_pageShapeOrder(),
m_documentPageShapeOrders(documentPageShapeOrders),
m_shapeList(), m_currentStyleSheet(0), m_styles(),
m_lineStyle(), m_fillStyle(), m_textStyle(),
m_isStyleStarted(false)
{
m_groupXFormsSequence.clear();
m_groupMembershipsSequence.clear();
m_documentPageShapeOrders.clear();
}
void libvisio::VSDXStylesCollector::collectEllipticalArcTo(unsigned /* id */, unsigned level, double /* x3 */, double /* y3 */, double /* x2 */, double /* y2 */, double /* angle */, double /* ecc */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectForeignData(unsigned /* id */, unsigned level, const WPXBinaryData & /* binaryData */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectEllipse(unsigned /* id */, unsigned level, double /* cx */, double /* cy */, double /* xleft */, double /* yleft */, double /* xtop */, double /* ytop */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectLine(unsigned /* id */, unsigned level, double /* strokeWidth */, Colour /* c */, unsigned /* linePattern */, unsigned /* lineCap */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectFillAndShadow(unsigned /* id */, unsigned level, unsigned /* colourIndexFG */, unsigned /* colourIndexBG */, unsigned /* fillPattern */, unsigned /* fillFGTransparency */, unsigned /* fillBGTransparency */, unsigned /* shadowPattern */, Colour /* shfgc */, double /* shadowOffsetX */, double /* shadowOffsetY */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectFillAndShadow(unsigned /* id */, unsigned level, unsigned /* colourIndexFG */, unsigned /* colourIndexBG */, unsigned /* fillPattern */, unsigned /* fillFGTransparency */, unsigned /* fillBGTransparency */, unsigned /* shadowPattern */, Colour /* shfgc */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectGeomList(unsigned /* id */, unsigned level)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectCharList(unsigned /* id */, unsigned level)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectGeometry(unsigned /* id */, unsigned level, unsigned /* geomFlags */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectMoveTo(unsigned /* id */, unsigned level, double /* x */, double /* y */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectLineTo(unsigned /* id */, unsigned level, double /* x */, double /* y */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectArcTo(unsigned /* id */, unsigned level, double /* x2 */, double /* y2 */, double /* bow */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectNURBSTo(unsigned /* id */, unsigned level, double /* x2 */, double /* y2 */, unsigned /* xType */, unsigned /* yType */, unsigned /* degree */, std::vector<std::pair<double, double> > /* controlPoints */, std::vector<double> /* knotVector */, std::vector<double> /* weights */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectNURBSTo(unsigned /* id */, unsigned level, double /* x2 */, double /* y2 */, double /* knot */, double /* knotPrev */, double /* weight */, double /* weightPrev */, unsigned /* dataID */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectPolylineTo(unsigned /* id */, unsigned level, double /* x */, double /* y */, unsigned /* xType */, unsigned /* yType */, std::vector<std::pair<double, double> > & /* points */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectPolylineTo(unsigned /* id */, unsigned level, double /* x */, double /* y */, unsigned /* dataID */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectShapeData(unsigned /* id */, unsigned level, unsigned /* xType */, unsigned /* yType */, unsigned /* degree */, double /*lastKnot*/, std::vector<std::pair<double, double> > /* controlPoints */, std::vector<double> /* knotVector */, std::vector<double> /* weights */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectShapeData(unsigned /* id */, unsigned level, unsigned /* xType */, unsigned /* yType */, std::vector<std::pair<double, double> > /* points */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectXFormData(unsigned /* id */, unsigned level, const XForm &xform)
{
_handleLevelChange(level);
if (m_isShapeStarted)
m_groupXForms[m_currentShapeId] = xform;
}
void libvisio::VSDXStylesCollector::collectTxtXForm(unsigned /* id */, unsigned level, const XForm & /* txtxform */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectShapeId(unsigned /* id */, unsigned level, unsigned shapeId)
{
_handleLevelChange(level);
if (m_isShapeStarted)
m_groupMemberships[shapeId] = m_currentShapeId;
m_shapeList.push_back(shapeId);
}
void libvisio::VSDXStylesCollector::collectShapeList(unsigned /* id */, unsigned level)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectForeignDataType(unsigned /* id */, unsigned level, unsigned /* foreignType */, unsigned /* foreignFormat */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectPageProps(unsigned /* id */, unsigned level, double /* pageWidth */, double /* pageHeight */, double /* shadowOffsetX */, double /* shadowOffsetY */)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectShape(unsigned id, unsigned level, unsigned /*masterPage*/, unsigned /*masterShape*/, unsigned lineStyle, unsigned fillStyle, unsigned textStyle)
{
_handleLevelChange(level);
m_currentShapeId = id;
m_isShapeStarted = true;
}
void libvisio::VSDXStylesCollector::collectUnhandledChunk(unsigned /* id */, unsigned level)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectColours(const std::vector<Colour> & /* colours */)
{
}
void libvisio::VSDXStylesCollector::collectFont(unsigned short /* fontID */, const std::vector<unsigned char> & /* textStream */, TextFormat /* format */)
{
}
void libvisio::VSDXStylesCollector::collectText(unsigned /*id*/, unsigned level, const std::vector<unsigned char> & /*textStream*/, TextFormat /*format*/)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectCharFormat(unsigned /*id*/ , unsigned level, unsigned /*charCount*/, unsigned short /* fontID */, Colour /* fontColour */, unsigned /*langId*/, double /*fontSize*/, bool /*bold*/, bool /*italic*/, bool /*underline*/, WPXString /*fontFace*/)
{
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectStyleSheet(unsigned id, unsigned level, unsigned lineStyleParent, unsigned fillStyleParent, unsigned textStyleParent)
{
_handleLevelChange(level);
m_lineStyle = 0;
m_fillStyle = 0;
m_textStyle = 0;
m_currentStyleSheet = id;
m_styles.addLineStyleMaster(m_currentStyleSheet, lineStyleParent);
m_styles.addFillStyleMaster(m_currentStyleSheet, fillStyleParent);
m_styles.addTextStyleMaster(m_currentStyleSheet, textStyleParent);
m_isStyleStarted = true;
}
void libvisio::VSDXStylesCollector::collectLineStyle(unsigned /* id */, unsigned level, double strokeWidth, Colour c, unsigned linePattern, unsigned lineCap)
{
if (m_lineStyle == 0) m_lineStyle = new VSDXLineStyle();
m_lineStyle->width = strokeWidth;
m_lineStyle->colour = c;
m_lineStyle->pattern = linePattern;
m_lineStyle->cap = lineCap;
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectFillStyle(unsigned /*id*/, unsigned level, unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern, unsigned fillFGTransparency, unsigned fillBGTransparency, unsigned shadowPattern, Colour shfgc, double shadowOffsetX, double shadowOffsetY)
{
if (m_fillStyle == 0) m_fillStyle = new VSDXFillStyle();
m_fillStyle->fgColourId = colourIndexFG;
m_fillStyle->bgColourId = colourIndexBG;
m_fillStyle->pattern = fillPattern;
m_fillStyle->fgTransparency = fillFGTransparency;
m_fillStyle->bgTransparency = fillBGTransparency;
m_fillStyle->shadowPattern = shadowPattern;
m_fillStyle->shadowFgColour = shfgc;
m_fillStyle->shadowOffsetX = shadowOffsetX;
m_fillStyle->shadowOffsetY = shadowOffsetY;
_handleLevelChange(level);
}
void libvisio::VSDXStylesCollector::collectFillStyle(unsigned id, unsigned level, unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern, unsigned fillFGTransparency, unsigned fillBGTransparency, unsigned shadowPattern, Colour shfgc)
{
collectFillStyle(id, level, colourIndexFG, colourIndexBG, fillPattern, fillFGTransparency, fillBGTransparency, shadowPattern, shfgc, m_shadowOffsetX, m_shadowOffsetY);
}
void libvisio::VSDXStylesCollector::startPage()
{
m_groupXForms.clear();
m_groupMemberships.clear();
m_pageShapeOrder.clear();
m_groupShapeOrder.clear();
}
void libvisio::VSDXStylesCollector::endPage()
{
_handleLevelChange(0);
m_groupXFormsSequence.push_back(m_groupXForms);
m_groupMembershipsSequence.push_back(m_groupMemberships);
while (m_groupShapeOrder.size())
{
for (std::list<unsigned>::iterator j = m_pageShapeOrder.begin(); j != m_pageShapeOrder.end();)
{
std::map<unsigned, std::list<unsigned> >::iterator iter = m_groupShapeOrder.find(*j);
if (m_groupShapeOrder.end() != iter)
{
j++;
m_pageShapeOrder.splice(j, iter->second, iter->second.begin(), iter->second.end());
m_groupShapeOrder.erase(iter);
}
else
j++;
}
}
m_documentPageShapeOrders.push_back(m_pageShapeOrder);
}
void libvisio::VSDXStylesCollector::_handleLevelChange(unsigned level)
{
if (m_currentLevel == level)
return;
if (level < 3)
_flushShapeList();
if (level < 2)
{
m_isShapeStarted = false;
if (m_isStyleStarted)
{
m_isStyleStarted = false;
m_styles.addLineStyle(m_currentStyleSheet, m_lineStyle);
m_styles.addFillStyle(m_currentStyleSheet, m_fillStyle);
m_styles.addTextStyle(m_currentStyleSheet, m_textStyle);
if (m_lineStyle) delete m_lineStyle;
if (m_fillStyle) delete m_fillStyle;
if (m_textStyle) delete m_textStyle;
}
}
m_currentLevel = level;
}
void libvisio::VSDXStylesCollector::_flushShapeList()
{
if (!m_shapeList.size())
return;
if (m_isShapeStarted)
m_groupShapeOrder[m_currentShapeId] = m_shapeList;
else
m_pageShapeOrder = m_shapeList;
m_shapeList.clear();
}
|