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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <test/bootstrapfixture.hxx>
#include <test/primitive2dxmldump.hxx>
#include <test/xmltesttools.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/seqstream.hxx>
#include <comphelper/sequence.hxx>
#include <com/sun/star/graphic/SvgTools.hpp>
#include <com/sun/star/graphic/Primitive2DTools.hpp>
#include <com/sun/star/graphic/XPrimitive2D.hpp>
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
#include <memory>
namespace
{
using namespace css::uno;
using namespace css::io;
using namespace css::graphic;
using drawinglayer::primitive2d::Primitive2DSequence;
using drawinglayer::primitive2d::Primitive2DContainer;
class Test : public test::BootstrapFixture, public XmlTestTools
{
void checkRectPrimitive(Primitive2DSequence& rPrimitive);
void testStyles();
void testTdf87309();
void testFontsizeKeywords();
void testFontsizePercentage();
void testFontsizeRelative();
void testTdf45771();
void testTdf97941();
void testTdf85770();
void testTdf79163();
void testTdf97542_1();
void testTdf97542_2();
void testTdf97543();
void testRGBColor();
void testRGBAColor();
void testTdf97936();
Primitive2DSequence parseSvg(const char* aSource);
public:
virtual void setUp() override;
virtual void tearDown() override;
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testStyles);
CPPUNIT_TEST(testTdf87309);
CPPUNIT_TEST(testFontsizeKeywords);
CPPUNIT_TEST(testFontsizePercentage);
CPPUNIT_TEST(testFontsizeRelative);
CPPUNIT_TEST(testTdf45771);
CPPUNIT_TEST(testTdf97941);
CPPUNIT_TEST(testTdf85770);
CPPUNIT_TEST(testTdf79163);
CPPUNIT_TEST(testTdf97542_1);
CPPUNIT_TEST(testTdf97542_2);
CPPUNIT_TEST(testTdf97543);
CPPUNIT_TEST(testRGBColor);
CPPUNIT_TEST(testRGBAColor);
CPPUNIT_TEST(testTdf97936);
CPPUNIT_TEST_SUITE_END();
};
Primitive2DSequence Test::parseSvg(const char* aSource)
{
const Reference<XSvgParser> xSvgParser = SvgTools::create(m_xContext);
OUString aUrl = getURLFromSrc(aSource);
OUString aPath = getPathFromSrc(aSource);
SvFileStream aFileStream(aUrl, StreamMode::READ);
sal_Size nSize = aFileStream.remainingSize();
std::unique_ptr<sal_Int8[]> pBuffer(new sal_Int8[nSize + 1]);
aFileStream.Read(pBuffer.get(), nSize);
pBuffer[nSize] = 0;
Sequence<sal_Int8> aData(pBuffer.get(), nSize + 1);
Reference<XInputStream> aInputStream(new comphelper::SequenceInputStream(aData));
return xSvgParser->getDecomposition(aInputStream, aPath);
}
void Test::setUp()
{
BootstrapFixture::setUp();
}
void Test::tearDown()
{
BootstrapFixture::tearDown();
}
void Test::checkRectPrimitive(Primitive2DSequence& rPrimitive)
{
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(rPrimitive));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00"); // rect background color
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "height", "100"); // rect background height
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "width", "100"); // rect background width
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "minx", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "miny", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "maxx", "110");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "maxy", "110");
assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "color", "#ff0000"); // rect stroke color
assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "width", "3"); // rect stroke width
}
static bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB)
{
const sal_Int32 nCount(rA.getLength());
if(nCount != rB.getLength())
return false;
for(sal_Int32 a(0L); a < nCount; a++) {
if(!drawinglayer::primitive2d::arePrimitive2DReferencesEqual(rA[a], rB[a]))
return false;
}
return true;
}
// Attributes for an object (like rect as in this case) can be defined
// in different ways (directly with xml attributes, or with CSS styles),
// however the end result should be the same.
void Test::testStyles()
{
Primitive2DSequence aSequenceRect = parseSvg("/svgio/qa/cppunit/data/Rect.svg");
CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRect.getLength());
checkRectPrimitive(aSequenceRect);
Primitive2DSequence aSequenceRectWithStyle = parseSvg("/svgio/qa/cppunit/data/RectWithStyles.svg");
CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStyle.getLength());
checkRectPrimitive(aSequenceRectWithStyle);
Primitive2DSequence aSequenceRectWithParentStyle = parseSvg("/svgio/qa/cppunit/data/RectWithParentStyles.svg");
CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithParentStyle.getLength());
checkRectPrimitive(aSequenceRectWithParentStyle);
Primitive2DSequence aSequenceRectWithStylesByGroup = parseSvg("/svgio/qa/cppunit/data/RectWithStylesByGroup.svg");
CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStylesByGroup.getLength());
checkRectPrimitive(aSequenceRectWithStylesByGroup);
CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithStyle));
CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithParentStyle));
CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithStylesByGroup));
}
void Test::testTdf87309()
{
Primitive2DSequence aSequenceTdf87309 = parseSvg("/svgio/qa/cppunit/data/tdf87309.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf87309.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf87309));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#000000");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "height", "100");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "width", "100");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "minx", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "miny", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "maxx", "110");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "maxy", "110");
}
void Test::testFontsizeKeywords()
{
Primitive2DSequence aSequenceFontsizeKeywords = parseSvg("/svgio/qa/cppunit/data/FontsizeKeywords.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceFontsizeKeywords.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceFontsizeKeywords));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "height", "9");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "height", "11");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "height", "13");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]", "height", "16");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]", "height", "19");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[6]", "height", "23");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[7]", "height", "27");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[8]", "height", "13");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[9]", "height", "19");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[10]", "height", "16");
}
void Test::testFontsizePercentage()
{
//Check when font-size uses percentage and defined globally
Primitive2DSequence aSequenceFontsizePercentage = parseSvg("/svgio/qa/cppunit/data/FontsizePercentage.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceFontsizePercentage.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceFontsizePercentage));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "height", "16");
}
void Test::testFontsizeRelative()
{
//Check when font-size uses relative units (em,ex) and it's based on its parent's font-size
Primitive2DSequence aSequenceFontsizeRelative = parseSvg("/svgio/qa/cppunit/data/FontsizeRelative.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceFontsizeRelative.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceFontsizeRelative));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "height", "50");
}
void Test::testTdf45771()
{
//Check text fontsize when using relative units
Primitive2DSequence aSequenceTdf45771 = parseSvg("/svgio/qa/cppunit/data/tdf45771.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf45771.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf45771));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "height", "32");
}
void Test::testTdf97941()
{
//Check tspan fontsize when using relative units
Primitive2DSequence aSequenceTdf97941 = parseSvg("/svgio/qa/cppunit/data/tdf97941.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97941.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf97941));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "height", "48");
}
void Test::testTdf85770()
{
Primitive2DSequence aSequenceTdf85770 = parseSvg("/svgio/qa/cppunit/data/tdf85770.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf85770.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf85770));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "text", "Start Middle End");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "text", "Start ");
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "text", "End");
}
void Test::testTdf79163()
{
//Check Opacity
Primitive2DSequence aSequenceTdf79163 = parseSvg("/svgio/qa/cppunit/data/tdf79163.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf79163.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf79163));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence", "transparence", "0");
}
void Test::testTdf97542_1()
{
Primitive2DSequence aSequenceTdf97542_1 = parseSvg("/svgio/qa/cppunit/data/tdf97542_1.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97542_1.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf97542_1));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/objectinfo/textsimpleportion", "fontcolor", "#ffff00");
}
void Test::testTdf97542_2()
{
Primitive2DSequence aSequenceTdf97542_2 = parseSvg("/svgio/qa/cppunit/data/tdf97542_2.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97542_2.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf97542_2));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "x", "1");
assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "y", "1");
assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "radius", "3");
}
void Test::testTdf97543()
{
// check visibility="inherit"
Primitive2DSequence aSequenceTdf97543 = parseSvg("/svgio/qa/cppunit/data/tdf97543.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97543.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf97543));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "height", "100");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "width", "100");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "minx", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "miny", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "maxx", "110");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "maxy", "110");
}
void Test::testRGBColor()
{
Primitive2DSequence aSequenceRGBColor = parseSvg("/svgio/qa/cppunit/data/RGBColor.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceRGBColor.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceRGBColor));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#646464");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "height", "100");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "width", "100");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "minx", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "miny", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "maxx", "110");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "maxy", "110");
}
void Test::testRGBAColor()
{
Primitive2DSequence aSequenceRGBAColor = parseSvg("/svgio/qa/cppunit/data/RGBAColor.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceRGBAColor.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceRGBAColor));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence", "transparence", "0");
}
void Test::testTdf97936()
{
// check that both rectangles are rendered in the viewBox
Primitive2DSequence aSequenceTdf97936 = parseSvg("/svgio/qa/cppunit/data/tdf97936.svg");
CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97936.getLength());
Primitive2dXmlDump dumper;
xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf97936));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "height", "50");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "width", "50");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "minx", "70");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "miny", "50");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "maxx", "120");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "maxy", "100");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "height", "50");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "width", "50");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "minx", "10");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "miny", "50");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "maxx", "60");
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "maxy", "100");
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|