1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <test/bootstrapfixture.hxx>
13 #include <test/primitive2dxmldump.hxx>
14 #include <test/xmltesttools.hxx>
16 #include <comphelper/seqstream.hxx>
17 #include <comphelper/sequence.hxx>
19 #include <com/sun/star/graphic/SvgTools.hpp>
20 #include <com/sun/star/graphic/Primitive2DTools.hpp>
21 #include <com/sun/star/graphic/XPrimitive2D.hpp>
23 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
31 using namespace css::uno
;
32 using namespace css::io
;
33 using namespace css::graphic
;
34 using drawinglayer::primitive2d::Primitive2DSequence
;
35 using drawinglayer::primitive2d::Primitive2DContainer
;
36 using drawinglayer::primitive2d::Primitive2DReference
;
38 class Test
: public test::BootstrapFixture
, public XmlTestTools
40 void checkRectPrimitive(Primitive2DSequence
const & rPrimitive
);
44 void testFontsizeKeywords();
45 void testFontsizePercentage();
46 void testFontsizeRelative();
51 void testTdf97542_1();
52 void testTdf97542_2();
57 void testClipPathAndParentStyle();
58 void testClipPathAndStyle();
60 void testMaskingPath07b();
67 void testBehaviourWhenWidthAndHeightIsOrIsNotSet();
69 Primitive2DSequence
parseSvg(const OUString
& aSource
);
72 CPPUNIT_TEST_SUITE(Test
);
73 CPPUNIT_TEST(testStyles
);
74 CPPUNIT_TEST(testTdf87309
);
75 CPPUNIT_TEST(testFontsizeKeywords
);
76 CPPUNIT_TEST(testFontsizePercentage
);
77 CPPUNIT_TEST(testFontsizeRelative
);
78 CPPUNIT_TEST(testTdf45771
);
79 CPPUNIT_TEST(testTdf97941
);
80 CPPUNIT_TEST(testTdf85770
);
81 CPPUNIT_TEST(testTdf79163
);
82 CPPUNIT_TEST(testTdf97542_1
);
83 CPPUNIT_TEST(testTdf97542_2
);
84 CPPUNIT_TEST(testTdf97543
);
85 CPPUNIT_TEST(testRGBColor
);
86 CPPUNIT_TEST(testRGBAColor
);
87 CPPUNIT_TEST(testTdf97936
);
88 CPPUNIT_TEST(testClipPathAndParentStyle
);
89 CPPUNIT_TEST(testClipPathAndStyle
);
90 CPPUNIT_TEST(testi125329
);
91 CPPUNIT_TEST(testMaskingPath07b
);
92 CPPUNIT_TEST(test47446
);
93 CPPUNIT_TEST(test47446b
);
94 CPPUNIT_TEST(testMaskText
);
95 CPPUNIT_TEST(testTdf99994
);
96 CPPUNIT_TEST(testTdf99115
);
97 CPPUNIT_TEST(testTdf101237
);
98 CPPUNIT_TEST(testBehaviourWhenWidthAndHeightIsOrIsNotSet
);
99 CPPUNIT_TEST_SUITE_END();
102 Primitive2DSequence
Test::parseSvg(const OUString
& aSource
)
104 const Reference
<XSvgParser
> xSvgParser
= SvgTools::create(m_xContext
);
106 OUString aUrl
= m_directories
.getURLFromSrc(aSource
);
107 OUString aPath
= m_directories
.getPathFromSrc(aSource
);
109 SvFileStream
aFileStream(aUrl
, StreamMode::READ
);
110 std::size_t nSize
= aFileStream
.remainingSize();
111 std::unique_ptr
<sal_Int8
[]> pBuffer(new sal_Int8
[nSize
+ 1]);
112 aFileStream
.ReadBytes(pBuffer
.get(), nSize
);
115 Sequence
<sal_Int8
> aData(pBuffer
.get(), nSize
+ 1);
116 Reference
<XInputStream
> aInputStream(new comphelper::SequenceInputStream(aData
));
118 return xSvgParser
->getDecomposition(aInputStream
, aPath
);
121 void Test::checkRectPrimitive(Primitive2DSequence
const & rPrimitive
)
123 Primitive2dXmlDump dumper
;
124 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(rPrimitive
));
126 CPPUNIT_ASSERT (pDocument
);
128 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00"); // rect background color
129 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "height", "100"); // rect background height
130 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "width", "100"); // rect background width
131 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "minx", "10");
132 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "miny", "10");
133 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "maxx", "110");
134 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "maxy", "110");
135 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "color", "#ff0000"); // rect stroke color
136 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "width", "3"); // rect stroke width
141 bool arePrimitive2DSequencesEqual(const Primitive2DSequence
& rA
, const Primitive2DSequence
& rB
)
143 const sal_Int32
nCount(rA
.getLength());
145 if(nCount
!= rB
.getLength())
148 for(sal_Int32
a(0); a
< nCount
; a
++) {
149 if(!drawinglayer::primitive2d::arePrimitive2DReferencesEqual(rA
[a
], rB
[a
]))
156 // Attributes for an object (like rect as in this case) can be defined
157 // in different ways (directly with xml attributes, or with CSS styles),
158 // however the end result should be the same.
159 void Test::testStyles()
161 Primitive2DSequence aSequenceRect
= parseSvg("/svgio/qa/cppunit/data/Rect.svg");
162 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceRect
.getLength()));
163 checkRectPrimitive(aSequenceRect
);
165 Primitive2DSequence aSequenceRectWithStyle
= parseSvg("/svgio/qa/cppunit/data/RectWithStyles.svg");
166 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceRectWithStyle
.getLength()));
167 checkRectPrimitive(aSequenceRectWithStyle
);
169 Primitive2DSequence aSequenceRectWithParentStyle
= parseSvg("/svgio/qa/cppunit/data/RectWithParentStyles.svg");
170 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceRectWithParentStyle
.getLength()));
171 checkRectPrimitive(aSequenceRectWithParentStyle
);
173 Primitive2DSequence aSequenceRectWithStylesByGroup
= parseSvg("/svgio/qa/cppunit/data/RectWithStylesByGroup.svg");
174 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceRectWithStylesByGroup
.getLength()));
175 checkRectPrimitive(aSequenceRectWithStylesByGroup
);
177 CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect
, aSequenceRectWithStyle
));
178 CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect
, aSequenceRectWithParentStyle
));
179 CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect
, aSequenceRectWithStylesByGroup
));
182 void Test::testTdf87309()
184 Primitive2DSequence aSequenceTdf87309
= parseSvg("/svgio/qa/cppunit/data/tdf87309.svg");
185 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf87309
.getLength()));
187 Primitive2dXmlDump dumper
;
188 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf87309
));
190 CPPUNIT_ASSERT (pDocument
);
192 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "color", "#000000");
193 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "height", "100");
194 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "width", "100");
195 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "minx", "10");
196 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "miny", "10");
197 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "maxx", "110");
198 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "maxy", "110");
201 void Test::testFontsizeKeywords()
203 Primitive2DSequence aSequenceFontsizeKeywords
= parseSvg("/svgio/qa/cppunit/data/FontsizeKeywords.svg");
204 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceFontsizeKeywords
.getLength()));
206 Primitive2dXmlDump dumper
;
207 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceFontsizeKeywords
));
209 CPPUNIT_ASSERT (pDocument
);
211 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#000000");
212 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "text", "Sample");
213 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "height", "9");
214 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Times New Roman");
216 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "fontcolor", "#ffffff");
217 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "text", "Sample");
218 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "height", "11");
219 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "familyname", "Times New Roman");
221 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "fontcolor", "#ffd700");
222 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "text", "Sample");
223 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "height", "13");
224 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "familyname", "Times New Roman");
226 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[4]", "fontcolor", "#ff0000");
227 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[4]", "text", "Sample");
228 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[4]", "height", "16");
229 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[4]", "familyname", "Times New Roman");
231 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[5]", "fontcolor", "#ffff00");
232 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[5]", "text", "Sample");
233 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[5]", "height", "19");
234 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[5]", "familyname", "Times New Roman");
236 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[6]", "fontcolor", "#0000ff");
237 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[6]", "text", "Sample");
238 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[6]", "height", "23");
239 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[6]", "familyname", "Times New Roman");
241 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[7]", "fontcolor", "#008000");
242 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[7]", "text", "Sample");
243 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[7]", "height", "27");
244 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[7]", "familyname", "Times New Roman");
246 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[8]", "fontcolor", "#ff7f50");
247 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[8]", "text", "Sample");
248 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[8]", "height", "13");
249 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[8]", "familyname", "Times New Roman");
251 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[9]", "fontcolor", "#ffc0cb");
252 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[9]", "text", "Sample");
253 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[9]", "height", "19");
254 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[9]", "familyname", "Times New Roman");
256 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[10]", "fontcolor", "#fffff0");
257 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[10]", "text", "Sample");
258 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[10]", "height", "16");
259 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[9]", "familyname", "Times New Roman");
263 void Test::testFontsizePercentage()
265 //Check when font-size uses percentage and defined globally
266 Primitive2DSequence aSequenceFontsizePercentage
= parseSvg("/svgio/qa/cppunit/data/FontsizePercentage.svg");
267 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceFontsizePercentage
.getLength()));
269 Primitive2dXmlDump dumper
;
270 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceFontsizePercentage
));
272 CPPUNIT_ASSERT (pDocument
);
274 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#000000");
275 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "text", "Sample");
276 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "height", "16");
277 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Times New Roman");
280 void Test::testFontsizeRelative()
282 //Check when font-size uses relative units (em,ex) and it's based on its parent's font-size
283 Primitive2DSequence aSequenceFontsizeRelative
= parseSvg("/svgio/qa/cppunit/data/FontsizeRelative.svg");
284 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceFontsizeRelative
.getLength()));
286 Primitive2dXmlDump dumper
;
287 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceFontsizeRelative
));
289 CPPUNIT_ASSERT (pDocument
);
291 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#000000");
292 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "text", "Sample");
293 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "height", "50");
294 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "familyname", "serif");
296 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "fontcolor", "#000000");
297 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "text", "Sample");
298 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "height", "50");
299 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "familyname", "serif");
302 void Test::testTdf45771()
304 //Check text fontsize when using relative units
305 Primitive2DSequence aSequenceTdf45771
= parseSvg("/svgio/qa/cppunit/data/tdf45771.svg");
306 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf45771
.getLength()));
308 Primitive2dXmlDump dumper
;
309 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf45771
));
311 CPPUNIT_ASSERT (pDocument
);
313 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#000000");
314 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "text", "Sample");
315 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "height", "32");
316 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Times New Roman");
319 void Test::testTdf97941()
321 //Check tspan fontsize when using relative units
322 Primitive2DSequence aSequenceTdf97941
= parseSvg("/svgio/qa/cppunit/data/tdf97941.svg");
323 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf97941
.getLength()));
325 Primitive2dXmlDump dumper
;
326 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf97941
));
328 CPPUNIT_ASSERT (pDocument
);
330 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#000000");
331 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "text", "Sample");
332 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "height", "48");
333 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Times New Roman");
336 void Test::testTdf85770()
338 Primitive2DSequence aSequenceTdf85770
= parseSvg("/svgio/qa/cppunit/data/tdf85770.svg");
339 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf85770
.getLength()));
341 Primitive2dXmlDump dumper
;
342 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf85770
));
344 CPPUNIT_ASSERT (pDocument
);
346 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#000000");
347 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "text", "Start Middle End");
348 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "height", "11");
349 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Times New Roman");
350 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "fontcolor", "#000000");
351 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "text", "Start ");
352 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "height", "11");
353 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "familyname", "Times New Roman");
354 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "fontcolor", "#000000");
355 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "text", "End");
356 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "height", "11");
357 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "familyname", "Times New Roman");
361 void Test::testTdf79163()
364 Primitive2DSequence aSequenceTdf79163
= parseSvg("/svgio/qa/cppunit/data/tdf79163.svg");
365 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf79163
.getLength()));
367 Primitive2dXmlDump dumper
;
368 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf79163
));
370 CPPUNIT_ASSERT (pDocument
);
372 assertXPath(pDocument
, "/primitive2D/transform/unifiedtransparence", "transparence", "0.5");
375 void Test::testTdf97542_1()
377 Primitive2DSequence aSequenceTdf97542_1
= parseSvg("/svgio/qa/cppunit/data/tdf97542_1.svg");
378 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf97542_1
.getLength()));
380 Primitive2dXmlDump dumper
;
381 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf97542_1
));
383 CPPUNIT_ASSERT (pDocument
);
385 assertXPath(pDocument
, "/primitive2D/transform/objectinfo/textsimpleportion", "fontcolor", "#ffff00");
386 assertXPath(pDocument
, "/primitive2D/transform/objectinfo/textsimpleportion", "text", "Text");
387 assertXPath(pDocument
, "/primitive2D/transform/objectinfo/textsimpleportion", "height", "48");
388 assertXPath(pDocument
, "/primitive2D/transform/objectinfo/textsimpleportion", "familyname", "serif");
391 void Test::testTdf97542_2()
393 Primitive2DSequence aSequenceTdf97542_2
= parseSvg("/svgio/qa/cppunit/data/tdf97542_2.svg");
394 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf97542_2
.getLength()));
396 Primitive2dXmlDump dumper
;
397 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf97542_2
));
399 CPPUNIT_ASSERT (pDocument
);
401 assertXPath(pDocument
, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "x", "1");
402 assertXPath(pDocument
, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "y", "1");
403 assertXPath(pDocument
, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "radius", "3");
406 void Test::testTdf97543()
408 // check visibility="inherit"
409 Primitive2DSequence aSequenceTdf97543
= parseSvg("/svgio/qa/cppunit/data/tdf97543.svg");
410 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf97543
.getLength()));
412 Primitive2dXmlDump dumper
;
413 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf97543
));
415 CPPUNIT_ASSERT (pDocument
);
417 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00");
418 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "height", "100");
419 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "width", "100");
420 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "minx", "10");
421 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "miny", "10");
422 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "maxx", "110");
423 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "maxy", "110");
426 void Test::testRGBColor()
428 Primitive2DSequence aSequenceRGBColor
= parseSvg("/svgio/qa/cppunit/data/RGBColor.svg");
429 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceRGBColor
.getLength()));
431 Primitive2dXmlDump dumper
;
432 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceRGBColor
));
434 CPPUNIT_ASSERT (pDocument
);
436 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "color", "#646464");
437 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "height", "100");
438 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "width", "100");
439 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "minx", "10");
440 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "miny", "10");
441 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "maxx", "110");
442 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "maxy", "110");
445 void Test::testRGBAColor()
447 Primitive2DSequence aSequenceRGBAColor
= parseSvg("/svgio/qa/cppunit/data/RGBAColor.svg");
448 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceRGBAColor
.getLength()));
450 Primitive2dXmlDump dumper
;
451 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceRGBAColor
));
453 CPPUNIT_ASSERT (pDocument
);
455 assertXPath(pDocument
, "/primitive2D/transform/unifiedtransparence", "transparence", "0.5");
458 void Test::testTdf97936()
460 // check that both rectangles are rendered in the viewBox
461 Primitive2DSequence aSequenceTdf97936
= parseSvg("/svgio/qa/cppunit/data/tdf97936.svg");
462 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf97936
.getLength()));
464 Primitive2dXmlDump dumper
;
465 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf97936
));
467 CPPUNIT_ASSERT (pDocument
);
469 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[1]");
470 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[1]", "height", "50");
471 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[1]", "width", "50");
472 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[1]", "minx", "70");
473 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[1]", "miny", "50");
474 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[1]", "maxx", "120");
475 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[1]", "maxy", "100");
476 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[2]");
477 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[2]", "height", "50");
478 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[2]", "width", "50");
479 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[2]", "minx", "10");
480 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[2]", "miny", "50");
481 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[2]", "maxx", "60");
482 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor[2]", "maxy", "100");
485 void Test::testClipPathAndParentStyle()
487 //Check that fill color, stroke color and stroke-width are inherited from use element
488 //when the element is within a clipPath element
489 Primitive2DSequence aSequenceClipPathAndParentStyle
= parseSvg("/svgio/qa/cppunit/data/ClipPathAndParentStyle.svg");
490 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceClipPathAndParentStyle
.getLength()));
492 Primitive2dXmlDump dumper
;
493 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceClipPathAndParentStyle
));
495 CPPUNIT_ASSERT (pDocument
);
497 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "color", "#ff0000");
498 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "color", "#000000");
499 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "width", "5");
503 void Test::testClipPathAndStyle()
505 //Check that fill color, stroke color and stroke-width are inherited from use element
506 //when the element is within a clipPath element
507 Primitive2DSequence aSequenceClipPathAndStyle
= parseSvg("/svgio/qa/cppunit/data/ClipPathAndStyle.svg");
508 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceClipPathAndStyle
.getLength()));
510 Primitive2dXmlDump dumper
;
511 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceClipPathAndStyle
));
513 CPPUNIT_ASSERT (pDocument
);
515 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "color", "#ccccff");
516 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "color", "#0000cc");
517 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "width", "2");
521 void Test::testi125329()
523 //Check style inherit from * css element
524 Primitive2DSequence aSequencei125329
= parseSvg("/svgio/qa/cppunit/data/i125329.svg");
525 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequencei125329
.getLength()));
527 Primitive2dXmlDump dumper
;
528 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequencei125329
));
530 CPPUNIT_ASSERT (pDocument
);
532 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygoncolor", "color", "#c0c0c0"); // rect background color
533 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygoncolor", "height", "30"); // rect background height
534 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygoncolor", "width", "50"); // rect background width
535 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygoncolor", "minx", "15");
536 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygoncolor", "miny", "15");
537 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygoncolor", "maxx", "65");
538 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygoncolor", "maxy", "45");
539 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygonstroke/line", "color", "#008000"); // rect stroke color
540 assertXPath(pDocument
, "/primitive2D/transform/transform/objectinfo/polypolygonstroke/line", "width", "1"); // rect stroke width
543 void Test::testMaskingPath07b()
545 //For the time being, check that masking-path-07-b.svg can be imported and it doesn't hang on loading
546 //it used to hang after d5649ae7b76278cb3155f951d6327157c7c92b65
547 Primitive2DSequence aSequenceMaskingPath07b
= parseSvg("/svgio/qa/cppunit/data/masking-path-07-b.svg");
548 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceMaskingPath07b
.getLength()));
550 Primitive2dXmlDump dumper
;
551 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceMaskingPath07b
));
553 CPPUNIT_ASSERT (pDocument
);
557 void Test::test47446()
559 //Check that marker's fill attribute is black is not set
560 Primitive2DSequence aSequence47446
= parseSvg("/svgio/qa/cppunit/data/47446.svg");
561 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence47446
.getLength()));
563 Primitive2dXmlDump dumper
;
564 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequence47446
));
566 CPPUNIT_ASSERT (pDocument
);
568 assertXPath(pDocument
, "/primitive2D/transform/transform/transform/polypolygoncolor", "color", "#000000");
572 void Test::test47446b()
574 //Check that marker's fill attribute is inherit from def
575 Primitive2DSequence aSequence47446b
= parseSvg("/svgio/qa/cppunit/data/47446b.svg");
576 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence47446b
.getLength()));
578 Primitive2dXmlDump dumper
;
579 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequence47446b
));
581 CPPUNIT_ASSERT (pDocument
);
583 assertXPath(pDocument
, "/primitive2D/transform/transform/transform/polypolygoncolor", "color", "#ffff00");
587 void Test::testMaskText()
589 //Check that mask is applied on text
590 Primitive2DSequence aSequenceMaskText
= parseSvg("/svgio/qa/cppunit/data/maskText.svg");
591 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceMaskText
.getLength()));
593 Primitive2dXmlDump dumper
;
594 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceMaskText
));
596 CPPUNIT_ASSERT (pDocument
);
598 assertXPath(pDocument
, "/primitive2D/transform/transform/polypolygoncolor", "color", "#000000");
599 assertXPath(pDocument
, "/primitive2D/transform/transform/textsimpleportion", "fontcolor", "#ffffff");
600 assertXPath(pDocument
, "/primitive2D/transform/transform/textsimpleportion", "text", "Black White");
601 assertXPath(pDocument
, "/primitive2D/transform/transform/textsimpleportion", "height", "26");
602 assertXPath(pDocument
, "/primitive2D/transform/transform/textsimpleportion", "familyname", "Times New Roman");
605 void Test::testTdf99994()
607 //Check text fontsize when using relative units
608 Primitive2DSequence aSequenceTdf99994
= parseSvg("/svgio/qa/cppunit/data/tdf99994.svg");
609 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf99994
.getLength()));
611 Primitive2dXmlDump dumper
;
612 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf99994
));
614 CPPUNIT_ASSERT (pDocument
);
616 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#0000ff");
617 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "height", "16");
618 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "text", "test");
619 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Sans");
622 void Test::testTdf99115()
624 //Check that styles are resolved correctly where there is a * css selector
625 Primitive2DSequence aSequenceTdf99115
= parseSvg("/svgio/qa/cppunit/data/tdf99115.svg");
626 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf99115
.getLength()));
628 Primitive2dXmlDump dumper
;
629 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf99115
) );
631 CPPUNIT_ASSERT (pDocument
);
633 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "text", "red 1");
634 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#ff0000");
635 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[1]", "height", "18");
637 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "text", "red 2");
638 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "fontcolor", "#ff0000");
639 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[2]", "height", "18");
641 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "text", "red 3");
642 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "fontcolor", "#ff0000");
643 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[3]", "height", "18");
645 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[4]", "text", "blue 4");
646 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[4]", "fontcolor", "#0000ff");
647 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[4]", "height", "18");
649 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[5]", "text", "blue 5");
650 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[5]", "fontcolor", "#0000ff");
651 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[5]", "height", "18");
653 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[6]", "text", "blue 6");
654 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[6]", "fontcolor", "#0000ff");
655 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[6]", "height", "18");
657 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[7]", "text", "green 7");
658 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[7]", "fontcolor", "#008000");
659 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[7]", "height", "18");
661 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[8]", "text", "green 8");
662 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[8]", "fontcolor", "#008000");
663 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[8]", "height", "18");
665 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[9]", "text", "green 9");
666 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[9]", "fontcolor", "#008000");
667 assertXPath(pDocument
, "/primitive2D/transform/textsimpleportion[9]", "height", "18");
670 void Test::testTdf101237()
672 //Check that fill color, stroke color and stroke-width are inherited from use element
673 //when the element is within a clipPath element
674 Primitive2DSequence aSequenceTdf101237
= parseSvg("/svgio/qa/cppunit/data/tdf101237.svg");
675 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf101237
.getLength()));
677 Primitive2dXmlDump dumper
;
678 xmlDocPtr pDocument
= dumper
.dumpAndParse(comphelper::sequenceToContainer
<Primitive2DContainer
>(aSequenceTdf101237
));
680 CPPUNIT_ASSERT (pDocument
);
682 assertXPath(pDocument
, "/primitive2D/transform/polypolygoncolor", "color", "#ff0000");
683 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "color", "#000000");
684 assertXPath(pDocument
, "/primitive2D/transform/polypolygonstroke/line", "width", "5");
687 void Test::testBehaviourWhenWidthAndHeightIsOrIsNotSet()
689 // This test checks the behaviour when width and height attributes
690 // are and are not set. In both cases the result must be the same,
691 // however if the width / height are set, then the size of the image
692 // is enforced, but this isn't really possible in LibreOffice (or
693 // maybe we could lock the size in this case).
694 // The behaviour in browsers is that when a SVG image has width / height
695 // attributes set, then the image is shown with that size, but if it
696 // isn't set then it is shown as scalable image which is the size of
700 Primitive2DSequence aSequence
= parseSvg("svgio/qa/cppunit/data/Drawing_WithWidthHeight.svg");
701 CPPUNIT_ASSERT(aSequence
.hasElements());
703 geometry::RealRectangle2D aRealRect
;
704 basegfx::B2DRange aRange
;
705 uno::Sequence
<beans::PropertyValue
> aViewParameters
;
707 for (Primitive2DReference
const & xReference
: aSequence
)
711 aRealRect
= xReference
->getRange(aViewParameters
);
712 aRange
.expand(basegfx::B2DRange(aRealRect
.X1
, aRealRect
.Y1
, aRealRect
.X2
, aRealRect
.Y2
));
716 double fWidth
= (aRange
.getWidth() / 2540.0) * 96.0;
717 double fHeight
= (aRange
.getHeight() / 2540.0) * 96.0;
719 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, fWidth
, 1E-12);
720 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, fHeight
, 1E-12);
724 Primitive2DSequence aSequence
= parseSvg("svgio/qa/cppunit/data/Drawing_NoWidthHeight.svg");
725 CPPUNIT_ASSERT(aSequence
.hasElements());
728 geometry::RealRectangle2D aRealRect
;
729 basegfx::B2DRange aRange
;
730 uno::Sequence
<beans::PropertyValue
> aViewParameters
;
732 for (Primitive2DReference
const & xReference
: aSequence
)
736 aRealRect
= xReference
->getRange(aViewParameters
);
737 aRange
.expand(basegfx::B2DRange(aRealRect
.X1
, aRealRect
.Y1
, aRealRect
.X2
, aRealRect
.Y2
));
741 double fWidth
= (aRange
.getWidth() / 2540.0) * 96.0;
742 double fHeight
= (aRange
.getHeight() / 2540.0) * 96.0;
744 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, fWidth
, 1E-12);
745 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, fHeight
, 1E-12);
749 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
753 CPPUNIT_PLUGIN_IMPLEMENT();
755 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */