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/.
11 #include <sal/config.h>
13 #include <string_view>
15 #include <osl/endian.h>
16 #include <test/bootstrapfixture.hxx>
17 #include <test/xmltesttools.hxx>
18 #include <vcl/gdimtf.hxx>
19 #include <vcl/gradient.hxx>
20 #include <vcl/hatch.hxx>
21 #include <vcl/lineinfo.hxx>
22 #include <vcl/virdev.hxx>
23 #include <vcl/filter/PngImageWriter.hxx>
24 #include <tools/fract.hxx>
25 #include <vcl/metaact.hxx>
26 #include <vcl/filter/SvmReader.hxx>
27 #include <vcl/filter/SvmWriter.hxx>
28 #include <salhelper/simplereferenceobject.hxx>
30 #include <bitmap/BitmapWriteAccess.hxx>
32 #include <basegfx/polygon/b2dpolypolygon.hxx>
34 #include <config_features.h>
35 #include <config_fonts.h>
36 #include <vcl/skia/SkiaHelper.hxx>
40 class SvmTest
: public test::BootstrapFixture
, public XmlTestTools
44 OUString
getFullUrl(std::u16string_view sFileName
)
46 return m_directories
.getURLFromSrc(maDataUrl
) + sFileName
;
49 void checkRendering(ScopedVclPtrInstance
<VirtualDevice
> const & pVirtualDev
, const GDIMetaFile
& rMetaFile
);
51 // write GDI Metafile to a file in data directory
52 // only use this for new tests to create the svm file
53 void writeToFile(GDIMetaFile
& rMetaFile
, std::u16string_view rName
);
55 GDIMetaFile
writeAndReadStream(
56 GDIMetaFile
& rMetaFile
, std::u16string_view rName
= std::u16string_view());
58 GDIMetaFile
readFile(std::u16string_view sName
);
60 xmlDocUniquePtr
dumpMeta(const GDIMetaFile
& rMetaFile
);
62 void checkVirtualDevice(const xmlDocUniquePtr
& pDoc
);
63 void checkErase(const xmlDocUniquePtr
& pDoc
);
65 void checkPixel(const GDIMetaFile
& rMetaFile
);
68 void checkPoint(const GDIMetaFile
& rMetaFile
);
71 void checkLine(const GDIMetaFile
& rMetaFile
);
74 void checkRect(const GDIMetaFile
& rMetaFile
);
77 void checkRoundRect(const GDIMetaFile
& rMetaFile
);
80 void checkEllipse(const GDIMetaFile
& rMetaFile
);
83 void checkArc(const GDIMetaFile
& rMetaFile
);
86 void checkPie(const GDIMetaFile
& rMetaFile
);
89 void checkChord(const GDIMetaFile
& rMetaFile
);
92 void checkPolyLine(const GDIMetaFile
& rMetaFile
);
95 void checkPolygon(const GDIMetaFile
& rMetaFile
);
98 void checkPolyPolygon(const GDIMetaFile
& rMetaFile
);
99 void testPolyPolygon();
101 void checkText(const GDIMetaFile
& rMetaFile
);
104 void checkTextArray(const GDIMetaFile
& rMetaFile
);
105 void testTextArray();
107 void checkstretchText(const GDIMetaFile
& rMetaFile
);
108 void teststretchText();
110 void checkTextRect(const GDIMetaFile
& rMetaFile
);
113 void checkTextLine(const GDIMetaFile
& rMetaFile
);
116 void checkBitmaps(const GDIMetaFile
& rMetaFile
);
119 void checkBitmapExs(const GDIMetaFile
& rMetaFile
);
120 void testBitmapExs();
122 void checkMasks(const GDIMetaFile
& rMetaFile
);
125 void checkGradient(const GDIMetaFile
& rMetaFile
);
128 void checkGradientEx(const GDIMetaFile
& rMetaFile
);
129 void testGradientEx();
131 void checkHatch(const GDIMetaFile
& rMetaFile
);
134 void checkWallpaper(const GDIMetaFile
& rMetaFile
);
135 void testWallpaper();
137 void checkClipRegion(const GDIMetaFile
& rMetaFile
);
138 void testClipRegion();
140 void checkIntersectRectClipRegion(const GDIMetaFile
& rMetaFile
);
141 void testIntersectRectClipRegion();
143 void checkIntersectRegionClipRegion(const GDIMetaFile
& rMetaFile
);
144 void testIntersectRegionClipRegion();
146 void checkMoveClipRegion(const GDIMetaFile
& rMetaFile
);
147 void testMoveClipRegion();
149 void checkLineColor(const GDIMetaFile
& rMetaFile
);
150 void testLineColor();
152 void checkFillColor(const GDIMetaFile
& rMetaFile
);
153 void testFillColor();
155 void checkTextColor(const GDIMetaFile
& rMetaFile
);
156 void testTextColor();
158 void checkTextFillColor(const GDIMetaFile
& rMetaFile
);
159 void testTextFillColor();
161 void checkTextLineColor(const GDIMetaFile
& rMetaFile
);
162 void testTextLineColor();
164 void checkOverLineColor(const GDIMetaFile
& rMetaFile
);
165 void testOverLineColor();
167 void checkTextAlign(const GDIMetaFile
& rMetaFile
);
168 void testTextAlign();
170 void checkMapMode(const GDIMetaFile
& rMetaFile
);
173 #if HAVE_MORE_FONTS && !defined(_WIN32)
174 void checkFont(const GDIMetaFile
& rMetaFile
);
178 void checkPushPop(const GDIMetaFile
& rMetaFile
);
181 void checkRasterOp(const GDIMetaFile
& rMetaFile
);
184 void checkTransparent(const GDIMetaFile
& rMetaFile
);
185 void testTransparent();
187 void checkFloatTransparent(const GDIMetaFile
& rMetaFile
);
188 void testFloatTransparent();
190 void checkEPS(const GDIMetaFile
& rMetaFile
);
193 void checkRefPoint(const GDIMetaFile
& rMetaFile
);
196 void checkComment(const GDIMetaFile
& rMetaFile
);
199 void checkLayoutMode(const GDIMetaFile
& rMetaFile
);
200 void testLayoutMode();
202 void checkTextLanguage(const GDIMetaFile
& rMetaFile
);
203 void testTextLanguage();
207 : BootstrapFixture(true, false)
208 , maDataUrl("/vcl/qa/cppunit/svm/data/")
211 CPPUNIT_TEST_SUITE(SvmTest
);
212 CPPUNIT_TEST(testPixel
);
213 CPPUNIT_TEST(testPoint
);
214 CPPUNIT_TEST(testLine
);
215 CPPUNIT_TEST(testRect
);
216 CPPUNIT_TEST(testRoundRect
);
217 CPPUNIT_TEST(testEllipse
);
218 CPPUNIT_TEST(testArc
);
219 CPPUNIT_TEST(testPie
);
220 CPPUNIT_TEST(testChord
);
221 CPPUNIT_TEST(testPolyLine
);
222 CPPUNIT_TEST(testPolygon
);
223 CPPUNIT_TEST(testPolyPolygon
);
224 CPPUNIT_TEST(testText
);
225 CPPUNIT_TEST(testTextArray
);
226 CPPUNIT_TEST(teststretchText
);
227 CPPUNIT_TEST(testTextRect
);
228 CPPUNIT_TEST(testTextLine
);
229 CPPUNIT_TEST(testBitmaps
); // BMP, BMPSCALE, BMPSCALEPART
230 CPPUNIT_TEST(testBitmapExs
); // BMPEX, BMPEXSCALE, BMPEXSCALEPART
231 CPPUNIT_TEST(testMasks
); // MASK, MASKSCALE, MASKSCALEPART
232 CPPUNIT_TEST(testGradient
);
233 CPPUNIT_TEST(testGradientEx
);
234 CPPUNIT_TEST(testHatch
);
235 CPPUNIT_TEST(testWallpaper
);
236 CPPUNIT_TEST(testClipRegion
);
237 CPPUNIT_TEST(testIntersectRectClipRegion
);
238 CPPUNIT_TEST(testIntersectRegionClipRegion
);
239 CPPUNIT_TEST(testMoveClipRegion
);
240 CPPUNIT_TEST(testLineColor
);
241 CPPUNIT_TEST(testFillColor
);
242 CPPUNIT_TEST(testTextColor
);
243 CPPUNIT_TEST(testTextFillColor
);
244 CPPUNIT_TEST(testTextLineColor
);
245 CPPUNIT_TEST(testOverLineColor
);
246 CPPUNIT_TEST(testTextAlign
);
247 CPPUNIT_TEST(testMapMode
);
248 CPPUNIT_TEST(testFont
);
249 CPPUNIT_TEST(testPushPop
);
250 CPPUNIT_TEST(testRasterOp
);
251 CPPUNIT_TEST(testTransparent
);
252 CPPUNIT_TEST(testFloatTransparent
);
253 CPPUNIT_TEST(testEPS
);
254 CPPUNIT_TEST(testRefPoint
);
255 CPPUNIT_TEST(testComment
);
256 CPPUNIT_TEST(testLayoutMode
);
257 CPPUNIT_TEST(testTextLanguage
);
259 CPPUNIT_TEST_SUITE_END();
262 static void setupBaseVirtualDevice(VirtualDevice
& rDevice
, GDIMetaFile
& rMeta
)
264 rDevice
.SetConnectMetaFile(&rMeta
);
265 Size
aVDSize(10, 10);
266 rDevice
.SetOutputSizePixel(aVDSize
);
267 rDevice
.SetBackground(Wallpaper(COL_LIGHTRED
));
271 void SvmTest::checkRendering(ScopedVclPtrInstance
<VirtualDevice
> const & pVirtualDev
, const GDIMetaFile
& rMetaFile
)
273 BitmapEx aSourceBitmapEx
= pVirtualDev
->GetBitmapEx(Point(), Size(10, 10));
274 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDevResult
;
275 pVirtualDevResult
->SetOutputSizePixel(Size(10, 10));
276 const_cast<GDIMetaFile
&>(rMetaFile
).Play(*pVirtualDevResult
);
277 BitmapEx aResultBitmapEx
= pVirtualDevResult
->GetBitmapEx(Point(), Size(10, 10));
279 const bool bWriteCompareBitmap
= false;
281 if (bWriteCompareBitmap
)
283 utl::TempFileNamed aTempFile
;
284 aTempFile
.EnableKillingFile();
287 SvFileStream
aStream(aTempFile
.GetURL() + ".source.png", StreamMode::WRITE
| StreamMode::TRUNC
);
288 vcl::PngImageWriter
aPNGWriter(aStream
);
289 aPNGWriter
.write(aSourceBitmapEx
);
292 SvFileStream
aStream(aTempFile
.GetURL() + ".result.png", StreamMode::WRITE
| StreamMode::TRUNC
);
293 vcl::PngImageWriter
aPNGWriter(aStream
);
294 aPNGWriter
.write(aResultBitmapEx
);
297 CPPUNIT_ASSERT_EQUAL(aSourceBitmapEx
.GetChecksum(), aResultBitmapEx
.GetChecksum());
300 static GDIMetaFile
readMetafile(const OUString
& rUrl
)
302 GDIMetaFile aResultMetafile
;
303 SvFileStream
aFileStream(rUrl
, StreamMode::READ
);
304 aFileStream
.Seek(STREAM_SEEK_TO_BEGIN
);
305 SvmReader
aReader(aFileStream
);
306 aReader
.Read(aResultMetafile
);
307 return aResultMetafile
;
310 static void writeMetaFile(GDIMetaFile
& rInputMetafile
, const OUString
& rUrl
)
312 SvFileStream
aFileStream(rUrl
, StreamMode::WRITE
);
313 aFileStream
.Seek(STREAM_SEEK_TO_BEGIN
);
314 SvmWriter
aWriter(aFileStream
);
315 aWriter
.Write(rInputMetafile
);
319 void SvmTest::writeToFile(GDIMetaFile
& rMetaFile
, std::u16string_view rName
)
323 OUString sFilePath
= getFullUrl(rName
);
324 writeMetaFile(rMetaFile
, sFilePath
);
327 GDIMetaFile
SvmTest::writeAndReadStream(GDIMetaFile
& rMetaFile
, std::u16string_view rName
)
330 writeToFile(rMetaFile
, rName
);
332 SvMemoryStream aStream
;
333 SvmWriter
aWriter(aStream
);
334 aWriter
.Write(rMetaFile
);
335 aStream
.Seek(STREAM_SEEK_TO_BEGIN
);
337 GDIMetaFile aResultMetafile
;
338 SvmReader
aReader(aStream
);
339 aResultMetafile
.Clear();
340 aReader
.Read(aResultMetafile
);
341 return aResultMetafile
;
344 GDIMetaFile
SvmTest::readFile(std::u16string_view sName
)
346 OUString sFilePath
= getFullUrl(sName
);
347 return readMetafile(sFilePath
);
350 xmlDocUniquePtr
SvmTest::dumpMeta(const GDIMetaFile
& rMetaFile
)
352 MetafileXmlDump dumper
;
353 xmlDocUniquePtr pDoc
= dumpAndParse(dumper
, rMetaFile
);
354 CPPUNIT_ASSERT (pDoc
);
356 checkVirtualDevice(pDoc
);
362 void SvmTest::checkVirtualDevice(const xmlDocUniquePtr
& pDoc
)
364 assertXPath(pDoc
, "/metafile/linecolor[1]", "color", "#000000");
365 assertXPath(pDoc
, "/metafile/fillcolor[1]", "color", "#ffffff");
367 assertXPathAttrs(pDoc
, "/metafile/rect[1]", {
368 {"left", "0"}, {"top", "0"},
369 {"right", "9"}, {"bottom", "9"}
372 assertXPath(pDoc
, "/metafile/linecolor[2]", "color", "#000000");
373 assertXPath(pDoc
, "/metafile/fillcolor[2]", "color", "#ffffff");
376 void SvmTest::checkErase(const xmlDocUniquePtr
& pDoc
)
378 assertXPath(pDoc
, "/metafile/linecolor[3]", "color", "#000000");
379 assertXPath(pDoc
, "/metafile/fillcolor[3]", "color", "#ff0000");
381 assertXPathAttrs(pDoc
, "/metafile/rect[2]", {
382 {"left", "0"}, {"top", "0"},
383 {"right", "9"}, {"bottom", "9"}
387 void SvmTest::checkPixel(const GDIMetaFile
& rMetaFile
)
389 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
391 assertXPathAttrs(pDoc
, "/metafile/pixel[1]", {
392 {"x", "8"}, {"y", "1"}, {"color", "#008000"},
395 assertXPathAttrs(pDoc
, "/metafile/pixel[2]", {
396 {"x", "1"}, {"y", "8"}, {"color", "#000080"},
400 void SvmTest::testPixel()
402 GDIMetaFile aGDIMetaFile
;
403 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
404 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
406 pVirtualDev
->DrawPixel(Point(8, 1), COL_GREEN
);
407 pVirtualDev
->DrawPixel(Point(1, 8), COL_BLUE
);
409 checkPixel(writeAndReadStream(aGDIMetaFile
));
410 checkPixel(readFile(u
"pixel.svm"));
413 void SvmTest::checkPoint(const GDIMetaFile
& rMetaFile
)
415 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
417 assertXPathAttrs(pDoc
, "/metafile/point[1]", {
418 {"x", "4"}, {"y", "4"}
422 void SvmTest::testPoint()
424 GDIMetaFile aGDIMetaFile
;
425 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
426 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
428 pVirtualDev
->DrawPixel(Point(4, 4));
430 checkPoint(writeAndReadStream(aGDIMetaFile
));
431 checkPoint(readFile(u
"point.svm"));
434 void SvmTest::checkLine(const GDIMetaFile
& rMetaFile
)
436 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
438 assertXPathAttrs(pDoc
, "/metafile/line[1]", {
439 {"startx", "1"}, {"starty", "1"},
440 {"endx", "8"}, {"endy", "8"},
443 assertXPathAttrs(pDoc
, "/metafile/line[1]", {
444 {"style", "solid"}, {"width", "0"},
445 {"dashlen", "0"}, {"dashcount", "0"},
446 {"dotlen", "0"}, {"dotcount", "0"},
448 {"join", "round"}, {"cap", "butt"}
451 assertXPathAttrs(pDoc
, "/metafile/line[2]", {
452 {"startx", "1"}, {"starty", "8"},
453 {"endx", "8"}, {"endy", "1"},
456 assertXPathAttrs(pDoc
, "/metafile/line[2]", {
457 {"style", "dash"}, {"width", "7"},
458 {"dashlen", "5"}, {"dashcount", "4"},
459 {"dotlen", "3"}, {"dotcount", "2"},
461 {"join", "miter"}, {"cap", "round"}
465 void SvmTest::testLine()
467 GDIMetaFile aGDIMetaFile
;
468 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
469 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
471 pVirtualDev
->DrawLine(Point(1, 1), Point(8, 8));
472 LineInfo
aLineInfo(LineStyle::Dash
, 7);
473 aLineInfo
.SetDashLen(5);
474 aLineInfo
.SetDashCount(4);
475 aLineInfo
.SetDotLen(3);
476 aLineInfo
.SetDotCount(2);
477 aLineInfo
.SetDistance(1);
478 aLineInfo
.SetLineJoin(basegfx::B2DLineJoin::Miter
);
479 aLineInfo
.SetLineCap(css::drawing::LineCap_ROUND
);
480 pVirtualDev
->DrawLine(Point(1, 8), Point(8, 1), aLineInfo
);
482 checkLine(writeAndReadStream(aGDIMetaFile
));
483 checkLine(readFile(u
"line.svm"));
486 void SvmTest::checkRect(const GDIMetaFile
& rMetaFile
)
489 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
491 assertXPath(pDoc
, "/metafile/linecolor[5]", "color", "#123456");
492 assertXPath(pDoc
, "/metafile/fillcolor[5]", "color", "#654321");
494 assertXPathAttrs(pDoc
, "/metafile/rect[3]", {
495 {"left", "1"}, {"top", "2"},
496 {"right", "4"}, {"bottom", "5"},
500 void SvmTest::testRect()
502 GDIMetaFile aGDIMetaFile
;
503 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
504 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
506 pVirtualDev
->SetLineColor(Color(0x123456));
507 pVirtualDev
->SetFillColor(Color(0x654321));
509 pVirtualDev
->DrawRect(tools::Rectangle(Point(1, 2), Size(4, 4)));
511 checkRect(writeAndReadStream(aGDIMetaFile
));
512 checkRect(readFile(u
"rect.svm"));
515 void SvmTest::checkRoundRect(const GDIMetaFile
& rMetaFile
)
517 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
519 assertXPath(pDoc
, "/metafile/linecolor[5]", "color", "#123456");
520 assertXPath(pDoc
, "/metafile/fillcolor[5]", "color", "#654321");
522 assertXPathAttrs(pDoc
, "/metafile/roundrect[1]", {
523 {"left", "1"}, {"top", "2"},
524 {"right", "4"}, {"bottom", "5"},
525 {"horizontalround", "1"}, {"verticalround", "2"}
529 void SvmTest::testRoundRect()
531 GDIMetaFile aGDIMetaFile
;
532 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
533 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
535 pVirtualDev
->SetLineColor(Color(0x123456));
536 pVirtualDev
->SetFillColor(Color(0x654321));
538 pVirtualDev
->DrawRect(tools::Rectangle(Point(1, 2), Size(4, 4)), 1, 2);
540 checkRoundRect(writeAndReadStream(aGDIMetaFile
));
541 checkRoundRect(readFile(u
"roundrect.svm"));
544 void SvmTest::checkEllipse(const GDIMetaFile
& rMetaFile
)
546 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
548 assertXPath(pDoc
, "/metafile/linecolor[5]", "color", "#123456");
549 assertXPath(pDoc
, "/metafile/fillcolor[5]", "color", "#654321");
551 assertXPathAttrs(pDoc
, "/metafile/ellipse[1]", {
552 {"left", "1"}, {"top", "2"},
553 {"right", "4"}, {"bottom", "5"},
557 void SvmTest::testEllipse()
559 GDIMetaFile aGDIMetaFile
;
560 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
561 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
563 pVirtualDev
->SetLineColor(Color(0x123456));
564 pVirtualDev
->SetFillColor(Color(0x654321));
566 pVirtualDev
->DrawEllipse(tools::Rectangle(Point(1, 2), Size(4, 4)));
568 checkEllipse(writeAndReadStream(aGDIMetaFile
));
569 checkEllipse(readFile(u
"ellipse.svm"));
572 void SvmTest::checkArc(const GDIMetaFile
& rMetaFile
)
574 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
576 assertXPath(pDoc
, "/metafile/linecolor[5]", "color", "#123456");
577 assertXPath(pDoc
, "/metafile/fillcolor[5]", "color", "#654321");
579 assertXPathAttrs(pDoc
, "/metafile/arc[1]", {
580 {"left", "1"}, {"top", "2"},
581 {"right", "4"}, {"bottom", "5"},
583 {"startx", "10"}, {"starty", "11"},
584 {"endx", "12"}, {"endy", "13"},
588 void SvmTest::testArc()
590 GDIMetaFile aGDIMetaFile
;
591 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
592 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
594 pVirtualDev
->SetLineColor(Color(0x123456));
595 pVirtualDev
->SetFillColor(Color(0x654321));
597 pVirtualDev
->DrawArc(tools::Rectangle(Point(1, 2), Size(4, 4)), Point(10, 11), Point(12, 13));
599 checkArc(writeAndReadStream(aGDIMetaFile
));
600 checkArc(readFile(u
"arc.svm"));
603 void SvmTest::checkPie(const GDIMetaFile
& rMetaFile
)
605 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
607 assertXPath(pDoc
, "/metafile/linecolor[5]", "color", "#123456");
608 assertXPath(pDoc
, "/metafile/fillcolor[5]", "color", "#654321");
610 assertXPathAttrs(pDoc
, "/metafile/pie[1]", {
611 {"left", "11"}, {"top", "12"},
612 {"right", "14"}, {"bottom", "15"},
614 {"startx", "20"}, {"starty", "21"},
615 {"endx", "22"}, {"endy", "23"},
619 void SvmTest::testPie()
621 GDIMetaFile aGDIMetaFile
;
622 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
623 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
625 pVirtualDev
->SetLineColor(Color(0x123456));
626 pVirtualDev
->SetFillColor(Color(0x654321));
628 pVirtualDev
->DrawPie(tools::Rectangle(Point(11, 12), Size(4, 4)), Point(20, 21), Point(22, 23));
630 checkPie(writeAndReadStream(aGDIMetaFile
));
631 checkPie(readFile(u
"pie.svm"));
634 void SvmTest::checkChord(const GDIMetaFile
& rMetaFile
)
636 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
638 assertXPath(pDoc
, "/metafile/linecolor[5]", "color", "#123456");
639 assertXPath(pDoc
, "/metafile/fillcolor[5]", "color", "#654321");
641 assertXPathAttrs(pDoc
, "/metafile/chord[1]", {
642 {"left", "21"}, {"top", "22"},
643 {"right", "24"}, {"bottom", "25"},
645 {"startx", "30"}, {"starty", "31"},
646 {"endx", "32"}, {"endy", "33"},
650 void SvmTest::testChord()
652 GDIMetaFile aGDIMetaFile
;
653 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
654 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
656 pVirtualDev
->SetLineColor(Color(0x123456));
657 pVirtualDev
->SetFillColor(Color(0x654321));
659 pVirtualDev
->DrawChord(tools::Rectangle(Point(21, 22), Size(4, 4)), Point(30, 31), Point(32, 33));
661 checkChord(writeAndReadStream(aGDIMetaFile
));
662 checkChord(readFile(u
"chord.svm"));
665 void SvmTest::checkPolyLine(const GDIMetaFile
& rMetaFile
)
667 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
669 assertXPathAttrs(pDoc
, "/metafile/polyline[1]", {
670 {"style", "solid"}, {"width", "0"},
671 {"dashlen", "0"}, {"dashcount", "0"},
672 {"dotlen", "0"}, {"dotcount", "0"},
674 {"join", "round"}, {"cap", "butt"}
677 assertXPathAttrs(pDoc
, "/metafile/polyline[1]/point[1]", {{"x", "1"}, {"y", "8"}});
678 assertXPathAttrs(pDoc
, "/metafile/polyline[1]/point[2]", {{"x", "2"}, {"y", "7"}});
679 assertXPathAttrs(pDoc
, "/metafile/polyline[1]/point[3]", {{"x", "3"}, {"y", "6"}});
681 assertXPathAttrs(pDoc
, "/metafile/polyline[2]", {
682 {"style", "dash"}, {"width", "7"},
683 {"dashlen", "5"}, {"dashcount", "4"},
684 {"dotlen", "3"}, {"dotcount", "2"},
686 {"join", "miter"}, {"cap", "round"}
688 assertXPathAttrs(pDoc
, "/metafile/polyline[2]/point[1]", {{"x", "8"}, {"y", "1"}, {"flags", "normal"}});
689 assertXPathAttrs(pDoc
, "/metafile/polyline[2]/point[2]", {{"x", "7"}, {"y", "2"}, {"flags", "control"}});
690 assertXPathAttrs(pDoc
, "/metafile/polyline[2]/point[3]", {{"x", "6"}, {"y", "3"}, {"flags", "smooth"}});
691 assertXPathAttrs(pDoc
, "/metafile/polyline[2]/point[4]", {{"x", "5"}, {"y", "4"}, {"flags", "symmetric"}});
694 void SvmTest::testPolyLine()
696 GDIMetaFile aGDIMetaFile
;
697 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
698 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
700 tools::Polygon
aPolygon(3);
701 aPolygon
.SetPoint(Point(1, 8), 0);
702 aPolygon
.SetPoint(Point(2, 7), 1);
703 aPolygon
.SetPoint(Point(3, 6), 2);
705 pVirtualDev
->DrawPolyLine(aPolygon
);
707 tools::Polygon
aPolygonWithControl(4);
708 aPolygonWithControl
.SetPoint(Point(8, 1), 0);
709 aPolygonWithControl
.SetPoint(Point(7, 2), 1);
710 aPolygonWithControl
.SetPoint(Point(6, 3), 2);
711 aPolygonWithControl
.SetPoint(Point(5, 4), 3);
713 aPolygonWithControl
.SetFlags(0, PolyFlags::Normal
);
714 aPolygonWithControl
.SetFlags(1, PolyFlags::Control
);
715 aPolygonWithControl
.SetFlags(2, PolyFlags::Smooth
);
716 aPolygonWithControl
.SetFlags(3, PolyFlags::Symmetric
);
718 LineInfo
aLineInfo(LineStyle::Dash
, 7);
719 aLineInfo
.SetDashLen(5);
720 aLineInfo
.SetDashCount(4);
721 aLineInfo
.SetDotLen(3);
722 aLineInfo
.SetDotCount(2);
723 aLineInfo
.SetDistance(1);
724 aLineInfo
.SetLineJoin(basegfx::B2DLineJoin::Miter
);
725 aLineInfo
.SetLineCap(css::drawing::LineCap_ROUND
);
727 pVirtualDev
->DrawPolyLine(aPolygonWithControl
, aLineInfo
);
729 checkPolyLine(writeAndReadStream(aGDIMetaFile
));
730 checkPolyLine(readFile(u
"polyline.svm"));
733 void SvmTest::checkPolygon(const GDIMetaFile
& rMetaFile
)
735 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
737 assertXPathAttrs(pDoc
, "/metafile/polygon[1]/point[1]", {{"x", "1"}, {"y", "8"}});
738 assertXPathAttrs(pDoc
, "/metafile/polygon[1]/point[2]", {{"x", "2"}, {"y", "7"}});
739 assertXPathAttrs(pDoc
, "/metafile/polygon[1]/point[3]", {{"x", "3"}, {"y", "6"}});
741 assertXPathAttrs(pDoc
, "/metafile/polygon[2]/point[1]", {{"x", "8"}, {"y", "1"}, {"flags", "normal"}});
742 assertXPathAttrs(pDoc
, "/metafile/polygon[2]/point[2]", {{"x", "7"}, {"y", "2"}, {"flags", "control"}});
743 assertXPathAttrs(pDoc
, "/metafile/polygon[2]/point[3]", {{"x", "6"}, {"y", "3"}, {"flags", "smooth"}});
744 assertXPathAttrs(pDoc
, "/metafile/polygon[2]/point[4]", {{"x", "5"}, {"y", "4"}, {"flags", "symmetric"}});
747 void SvmTest::testPolygon()
749 GDIMetaFile aGDIMetaFile
;
750 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
751 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
753 tools::Polygon
aPolygon(3);
754 aPolygon
.SetPoint(Point(1, 8), 0);
755 aPolygon
.SetPoint(Point(2, 7), 1);
756 aPolygon
.SetPoint(Point(3, 6), 2);
758 pVirtualDev
->DrawPolygon(aPolygon
);
760 tools::Polygon
aPolygonWithControl(4);
761 aPolygonWithControl
.SetPoint(Point(8, 1), 0);
762 aPolygonWithControl
.SetPoint(Point(7, 2), 1);
763 aPolygonWithControl
.SetPoint(Point(6, 3), 2);
764 aPolygonWithControl
.SetPoint(Point(5, 4), 3);
766 aPolygonWithControl
.SetFlags(0, PolyFlags::Normal
);
767 aPolygonWithControl
.SetFlags(1, PolyFlags::Control
);
768 aPolygonWithControl
.SetFlags(2, PolyFlags::Smooth
);
769 aPolygonWithControl
.SetFlags(3, PolyFlags::Symmetric
);
771 pVirtualDev
->DrawPolygon(aPolygonWithControl
);
773 checkPolygon(writeAndReadStream(aGDIMetaFile
));
774 checkPolygon(readFile(u
"polygon.svm"));
777 void SvmTest::checkPolyPolygon(const GDIMetaFile
& rMetaFile
)
779 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
781 assertXPathAttrs(pDoc
, "/metafile/polypolygon[1]/polygon[1]/point[1]", {{"x", "1"}, {"y", "8"}});
782 assertXPathAttrs(pDoc
, "/metafile/polypolygon[1]/polygon[1]/point[2]", {{"x", "2"}, {"y", "7"}});
783 assertXPathAttrs(pDoc
, "/metafile/polypolygon[1]/polygon[1]/point[3]", {{"x", "3"}, {"y", "6"}});
785 assertXPathAttrs(pDoc
, "/metafile/polypolygon[1]/polygon[2]/point[1]", {{"x", "8"}, {"y", "1"}, {"flags", "normal"}});
786 assertXPathAttrs(pDoc
, "/metafile/polypolygon[1]/polygon[2]/point[2]", {{"x", "7"}, {"y", "2"}, {"flags", "control"}});
787 assertXPathAttrs(pDoc
, "/metafile/polypolygon[1]/polygon[2]/point[3]", {{"x", "6"}, {"y", "3"}, {"flags", "smooth"}});
788 assertXPathAttrs(pDoc
, "/metafile/polypolygon[1]/polygon[2]/point[4]", {{"x", "5"}, {"y", "4"}, {"flags", "symmetric"}});
791 void SvmTest::testPolyPolygon()
793 GDIMetaFile aGDIMetaFile
;
794 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
795 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
797 tools::Polygon
aPolygon(3);
798 aPolygon
.SetPoint(Point(1, 8), 0);
799 aPolygon
.SetPoint(Point(2, 7), 1);
800 aPolygon
.SetPoint(Point(3, 6), 2);
802 tools::Polygon
aPolygonWithControl(4);
803 aPolygonWithControl
.SetPoint(Point(8, 1), 0);
804 aPolygonWithControl
.SetPoint(Point(7, 2), 1);
805 aPolygonWithControl
.SetPoint(Point(6, 3), 2);
806 aPolygonWithControl
.SetPoint(Point(5, 4), 3);
808 aPolygonWithControl
.SetFlags(0, PolyFlags::Normal
);
809 aPolygonWithControl
.SetFlags(1, PolyFlags::Control
);
810 aPolygonWithControl
.SetFlags(2, PolyFlags::Smooth
);
811 aPolygonWithControl
.SetFlags(3, PolyFlags::Symmetric
);
813 tools::PolyPolygon
aPolyPolygon(2);
814 aPolyPolygon
.Insert(aPolygon
);
815 aPolyPolygon
.Insert(aPolygonWithControl
);
817 pVirtualDev
->DrawPolyPolygon(aPolyPolygon
);
819 checkPolyPolygon(writeAndReadStream(aGDIMetaFile
));
820 checkPolyPolygon(readFile(u
"polypolygon.svm"));
823 void SvmTest::checkText(const GDIMetaFile
& rMetaFile
)
825 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
827 assertXPathAttrs(pDoc
, "/metafile/text[1]", {
828 {"x", "4"}, {"y", "6"}, {"index", "1"}, {"length", "2"},
831 assertXPathContent(pDoc
, "/metafile/text[1]/textcontent", "xABC");
834 void SvmTest::testText()
836 GDIMetaFile aGDIMetaFile
;
837 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
838 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
840 pVirtualDev
->DrawText(Point(4,6), "xABC", 1, 2);
842 checkText(writeAndReadStream(aGDIMetaFile
));
843 checkText(readFile(u
"text.svm"));
846 void SvmTest::checkTextArray(const GDIMetaFile
& rMetaFile
)
848 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
850 assertXPathAttrs(pDoc
, "/metafile/textarray[1]", {
851 {"x", "4"}, {"y", "6"}, {"index", "1"}, {"length", "4"},
853 assertXPathContent(pDoc
, "/metafile/textarray[1]/dxarray", "15 20 25 ");
854 assertXPathContent(pDoc
, "/metafile/textarray[1]/text", "123456");
857 void SvmTest::testTextArray()
859 GDIMetaFile aGDIMetaFile
;
860 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
861 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
862 sal_Int32
const aDX
[] = { 10, 15, 20, 25, 30, 35 };
863 pVirtualDev
->DrawTextArray(Point(4,6), "123456", KernArraySpan(aDX
), {}, 1, 4);
865 checkTextArray(writeAndReadStream(aGDIMetaFile
));
866 checkTextArray(readFile(u
"textarray.svm"));
869 void SvmTest::checkstretchText(const GDIMetaFile
& rMetaFile
)
871 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
873 assertXPathAttrs(pDoc
, "/metafile/stretchtext[1]", {
874 {"x", "4"}, {"y", "6"}, {"index", "1"}, {"length", "4"}, {"width", "10"}
877 assertXPathContent(pDoc
, "/metafile/stretchtext[1]/textcontent", "123456");
880 void SvmTest::teststretchText()
882 GDIMetaFile aGDIMetaFile
;
883 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
884 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
885 pVirtualDev
->DrawStretchText(Point(4,6), 10, "123456", 1, 4);
887 checkstretchText(writeAndReadStream(aGDIMetaFile
));
888 checkstretchText(readFile(u
"strecthtext.svm"));
891 void SvmTest::checkTextRect(const GDIMetaFile
& rMetaFile
)
893 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
895 assertXPathAttrs(pDoc
, "/metafile/textrect[1]", {
896 {"left", "0"}, {"top", "0"}, {"right", "4"}, {"bottom", "4"}
898 assertXPathContent(pDoc
, "/metafile/textrect[1]/textcontent", "123456");
899 assertXPathContent(pDoc
, "/metafile/textrect[1]/style", "Center");
902 void SvmTest::testTextRect()
904 GDIMetaFile aGDIMetaFile
;
905 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
906 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
907 pVirtualDev
->DrawText(tools::Rectangle(Point(0,0), Size(5,5)), "123456", DrawTextFlags::Center
);
909 checkTextRect(writeAndReadStream(aGDIMetaFile
));
910 checkTextRect(readFile(u
"textrectangle.svm"));
913 void SvmTest::checkTextLine(const GDIMetaFile
& rMetaFile
)
915 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
917 assertXPathAttrs(pDoc
, "/metafile/textline[1]", {
918 {"x", "4"}, {"y", "6"}, {"width", "10"},
919 {"strikeout", "single"}, {"underline", "single"}, {"overline", "single"}
923 void SvmTest::testTextLine()
925 GDIMetaFile aGDIMetaFile
;
926 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
927 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
928 pVirtualDev
->DrawTextLine(Point(4,6), 10, STRIKEOUT_SINGLE
, LINESTYLE_SINGLE
, LINESTYLE_SINGLE
);
930 checkTextLine(writeAndReadStream(aGDIMetaFile
));
931 checkTextLine(readFile(u
"textline.svm"));
934 void SvmTest::checkBitmaps(const GDIMetaFile
& rMetaFile
)
936 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
938 if (SkiaHelper::isVCLSkiaEnabled())
939 return; // TODO SKIA using CRCs is broken (the idea of it)
941 assertXPathAttrs(pDoc
, "/metafile/bmp[1]", {{"x", "1"}, {"y", "2"}, {"crc",
942 #if defined OSL_BIGENDIAN
948 assertXPathAttrs(pDoc
, "/metafile/bmpscale[1]", {
949 {"x", "1"}, {"y", "2"}, {"width", "3"}, {"height", "4"}, {"crc", "4937e32d"}
951 assertXPathAttrs(pDoc
, "/metafile/bmpscalepart[1]", {
952 {"destx", "1"}, {"desty", "2"}, {"destwidth", "3"}, {"destheight", "4"},
953 {"srcx", "2"}, {"srcy", "1"}, {"srcwidth", "4"}, {"srcheight", "3"},
955 #if defined OSL_BIGENDIAN
964 void SvmTest::testBitmaps()
966 GDIMetaFile aGDIMetaFile
;
967 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
968 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
970 Bitmap
aBitmap1(Size(4,4), vcl::PixelFormat::N24_BPP
);
972 BitmapScopedWriteAccess
pAccess(aBitmap1
);
973 pAccess
->Erase(COL_RED
);
975 Bitmap
aBitmap2(Size(4,4), vcl::PixelFormat::N24_BPP
);
977 BitmapScopedWriteAccess
pAccess(aBitmap2
);
978 pAccess
->Erase(COL_GREEN
);
980 Bitmap
aBitmap3(Size(4,4), vcl::PixelFormat::N24_BPP
);
982 BitmapScopedWriteAccess
pAccess(aBitmap3
);
983 pAccess
->Erase(COL_BLUE
);
985 pVirtualDev
->DrawBitmap(Point(1, 2), aBitmap1
);
986 pVirtualDev
->DrawBitmap(Point(1, 2), Size(3, 4), aBitmap2
);
987 pVirtualDev
->DrawBitmap(Point(1, 2), Size(3, 4), Point(2, 1), Size(4, 3), aBitmap3
);
990 GDIMetaFile aReloadedGDIMetaFile
= writeAndReadStream(aGDIMetaFile
);
991 checkBitmaps(aReloadedGDIMetaFile
);
992 checkRendering(pVirtualDev
, aReloadedGDIMetaFile
);
995 GDIMetaFile aFileGDIMetaFile
= readFile(u
"bitmaps.svm");
996 checkBitmaps(aFileGDIMetaFile
);
997 checkRendering(pVirtualDev
, aFileGDIMetaFile
);
1001 void SvmTest::checkBitmapExs(const GDIMetaFile
& rMetaFile
)
1003 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1005 if (SkiaHelper::isVCLSkiaEnabled())
1006 return; // TODO SKIA using CRCs is broken (the idea of it)
1008 std::vector
<OUString
> aExpectedCRC
;
1009 aExpectedCRC
.insert(aExpectedCRC
.end(),
1011 #if defined OSL_BIGENDIAN
1017 "33b4a07c", // 4-bit color bitmap - same as 8-bit color bitmap
1026 "2949ccc7", // 4-bit color bitmap - same as 8-bit color bitmap
1032 assertXPathAttrs(pDoc
, "/metafile/bmpex[1]", {
1033 {"x", "1"}, {"y", "1"}, {"crc", aExpectedCRC
[0]}, {"transparenttype", "bitmap"}
1035 assertXPathAttrs(pDoc
, "/metafile/bmpexscale[1]", {
1036 {"x", "5"}, {"y", "0"}, {"width", "2"}, {"height", "3"},
1037 {"crc", aExpectedCRC
[1]}, {"transparenttype", "bitmap"}
1039 assertXPathAttrs(pDoc
, "/metafile/bmpexscalepart[1]", {
1040 {"destx", "7"}, {"desty", "1"}, {"destwidth", "2"}, {"destheight", "2"},
1041 {"srcx", "0"}, {"srcy", "0"}, {"srcwidth", "3"}, {"srcheight", "4"},
1042 {"crc", aExpectedCRC
[2]}, {"transparenttype", "bitmap"}
1046 assertXPathAttrs(pDoc
, "/metafile/bmpex[2]", {
1047 {"x", "6"}, {"y", "6"}, {"crc", aExpectedCRC
[3]}, {"transparenttype", "bitmap"}
1049 assertXPathAttrs(pDoc
, "/metafile/bmpex[3]", {
1050 {"x", "0"}, {"y", "6"}, {"crc", aExpectedCRC
[4]}, {"transparenttype", "bitmap"}
1052 assertXPathAttrs(pDoc
, "/metafile/bmpex[4]", {
1053 {"x", "2"}, {"y", "6"}, {"crc", aExpectedCRC
[5]}, {"transparenttype", "bitmap"}
1055 assertXPathAttrs(pDoc
, "/metafile/bmpex[5]", {
1056 {"x", "0"}, {"y", "8"}, {"crc", aExpectedCRC
[6]}, {"transparenttype", "bitmap"}
1058 assertXPathAttrs(pDoc
, "/metafile/bmpex[6]", {
1059 {"x", "2"}, {"y", "8"}, {"crc", aExpectedCRC
[7]}, {"transparenttype", "bitmap"}
1064 void SvmTest::testBitmapExs()
1066 GDIMetaFile aGDIMetaFile
;
1067 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1068 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1072 Bitmap
aBitmap(Size(4,4), vcl::PixelFormat::N24_BPP
);
1074 BitmapScopedWriteAccess
pAccess(aBitmap
);
1075 pAccess
->Erase(COL_YELLOW
);
1078 pVirtualDev
->DrawBitmapEx(Point(1, 1), BitmapEx(aBitmap
, COL_WHITE
));
1081 // DrawBitmapEx - Scale
1083 Bitmap
aBitmap(Size(4,4), vcl::PixelFormat::N24_BPP
);
1085 BitmapScopedWriteAccess
pAccess(aBitmap
);
1086 pAccess
->Erase(COL_GREEN
);
1088 pVirtualDev
->DrawBitmapEx(Point(5, 0), Size(2, 3), BitmapEx(aBitmap
, COL_WHITE
));
1091 // DrawBitmapEx - Scale - Part
1093 Bitmap
aBitmap(Size(4,4), vcl::PixelFormat::N24_BPP
);
1095 BitmapScopedWriteAccess
pAccess(aBitmap
);
1096 pAccess
->Erase(COL_BLUE
);
1098 pVirtualDev
->DrawBitmapEx(Point(7, 1), Size(2, 2), Point(0, 0), Size(3, 4), BitmapEx(aBitmap
, COL_WHITE
));
1101 // DrawBitmapEx - 50% transparent
1103 Bitmap
aBitmap(Size(4, 4), vcl::PixelFormat::N24_BPP
);
1104 AlphaMask
aAlpha(Size(4, 4));
1106 BitmapScopedWriteAccess
pAccess(aBitmap
);
1107 pAccess
->Erase(COL_MAGENTA
);
1109 AlphaScopedWriteAccess
pAlphaAccess(aAlpha
);
1110 pAlphaAccess
->Erase(Color(128, 128, 128));
1112 pVirtualDev
->DrawBitmapEx(Point(6, 6), BitmapEx(aBitmap
, aAlpha
));
1115 // DrawBitmapEx - 1-bit
1117 Bitmap
aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP
);
1119 BitmapScopedWriteAccess
pAccess(aBitmap
);
1120 pAccess
->Erase(COL_MAGENTA
);
1122 aBitmap
.Convert(BmpConversion::N1BitThreshold
);
1123 pVirtualDev
->DrawBitmapEx(Point(0, 6), BitmapEx(aBitmap
, COL_WHITE
));
1126 // DrawBitmapEx - used to be 4-bit
1128 Bitmap
aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP
);
1130 BitmapScopedWriteAccess
pAccess(aBitmap
);
1131 pAccess
->Erase(COL_MAGENTA
);
1133 aBitmap
.Convert(BmpConversion::N8BitColors
);
1134 pVirtualDev
->DrawBitmapEx(Point(2, 6), BitmapEx(aBitmap
, COL_WHITE
));
1137 // DrawBitmapEx - 8-bit Color
1139 Bitmap
aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP
);
1141 BitmapScopedWriteAccess
pAccess(aBitmap
);
1142 pAccess
->Erase(COL_MAGENTA
);
1144 aBitmap
.Convert(BmpConversion::N8BitColors
);
1145 pVirtualDev
->DrawBitmapEx(Point(0, 8), BitmapEx(aBitmap
, COL_WHITE
));
1148 // DrawBitmapEx - 8-bit Grey
1150 Bitmap
aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP
);
1152 BitmapScopedWriteAccess
pAccess(aBitmap
);
1153 pAccess
->Erase(COL_MAGENTA
);
1155 aBitmap
.Convert(BmpConversion::N8BitGreys
);
1156 pVirtualDev
->DrawBitmapEx(Point(2, 8), BitmapEx(aBitmap
, COL_WHITE
));
1160 GDIMetaFile aReloadedGDIMetaFile
= writeAndReadStream(aGDIMetaFile
);
1161 checkBitmapExs(aReloadedGDIMetaFile
);
1162 checkRendering(pVirtualDev
, aReloadedGDIMetaFile
);
1165 GDIMetaFile aFileGDIMetaFile
= readFile(u
"bitmapexs.svm");
1166 checkBitmapExs(aFileGDIMetaFile
);
1167 checkRendering(pVirtualDev
, aFileGDIMetaFile
);
1171 void SvmTest::checkMasks(const GDIMetaFile
& rMetaFile
)
1173 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1175 assertXPathAttrs(pDoc
, "/metafile/mask[1]", {
1176 {"x", "1"}, {"y", "2"},
1177 {"color", "#000000"}
1179 assertXPathAttrs(pDoc
, "/metafile/maskscale[1]", {
1180 {"x", "1"}, {"y", "2"}, {"width", "3"}, {"height", "4"},
1181 {"color", "#000000"}
1183 assertXPathAttrs(pDoc
, "/metafile/maskscalepart[1]", {
1184 {"destx", "1"}, {"desty", "2"}, {"destwidth", "3"}, {"destheight", "4"},
1185 {"srcx", "2"}, {"srcy", "1"}, {"srcwidth", "4"}, {"srcheight", "3"},
1186 {"color", "#ff0000"}
1190 // TODO: Masks are kind-of special - we don't persist the color attribute (it is
1191 // always #000000) of the meta-action (which is wrong), but rely on alpha to do
1193 void SvmTest::testMasks()
1195 GDIMetaFile aGDIMetaFile
;
1196 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1197 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1199 Bitmap
aBitmap1(Size(4,4), vcl::PixelFormat::N24_BPP
);
1201 BitmapScopedWriteAccess
pAccess(aBitmap1
);
1202 pAccess
->Erase(COL_RED
);
1204 Bitmap
aBitmap2(Size(4,4), vcl::PixelFormat::N24_BPP
);
1206 BitmapScopedWriteAccess
pAccess(aBitmap2
);
1207 pAccess
->Erase(COL_GREEN
);
1209 Bitmap
aBitmap3(Size(4,4), vcl::PixelFormat::N24_BPP
);
1211 BitmapScopedWriteAccess
pAccess(aBitmap3
);
1212 pAccess
->Erase(COL_BLUE
);
1215 pVirtualDev
->DrawMask(Point(1, 2), aBitmap1
, COL_LIGHTRED
);
1216 pVirtualDev
->DrawMask(Point(1, 2), Size(3, 4), aBitmap2
, COL_LIGHTRED
);
1217 pVirtualDev
->DrawMask(Point(1, 2), Size(3, 4), Point(2, 1), Size(4, 3), aBitmap3
, COL_LIGHTRED
, MetaActionType::MASKSCALEPART
);
1219 checkMasks(writeAndReadStream(aGDIMetaFile
));
1220 checkMasks(readFile(u
"masks.svm"));
1223 void SvmTest::checkGradient(const GDIMetaFile
& rMetaFile
)
1225 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1227 assertXPathAttrs(pDoc
, "/metafile/gradient[1]", {
1228 {"style", "Linear"},
1229 {"startcolor", "#ffffff"},
1230 {"endcolor", "#000000"},
1235 {"startintensity", "100"},
1236 {"endintensity", "100"},
1239 assertXPathAttrs(pDoc
, "/metafile/gradient[1]/rectangle", {
1246 assertXPathAttrs(pDoc
, "/metafile/gradient[2]", {
1247 {"style", "Radial"},
1248 {"startcolor", "#ff0000"},
1249 {"endcolor", "#00ff00"},
1254 {"startintensity", "4"},
1255 {"endintensity", "14"},
1258 assertXPathAttrs(pDoc
, "/metafile/gradient[2]/rectangle", {
1266 void SvmTest::testGradient()
1268 GDIMetaFile aGDIMetaFile
;
1269 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1270 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1272 tools::Rectangle
aRectangle(Point(1, 2), Size(4,5));
1274 Gradient
aGradient(css::awt::GradientStyle_LINEAR
, COL_WHITE
, COL_BLACK
);
1275 pVirtualDev
->DrawGradient(aRectangle
, aGradient
);
1277 tools::Rectangle
aRectangle2(Point(3, 4), Size(1,2));
1279 Gradient aGradient2
;
1280 aGradient2
.SetStyle(css::awt::GradientStyle_RADIAL
);
1281 aGradient2
.SetStartColor(COL_LIGHTRED
);
1282 aGradient2
.SetEndColor(COL_LIGHTGREEN
);
1283 aGradient2
.SetAngle(Degree10(55));
1284 aGradient2
.SetBorder(10);
1285 aGradient2
.SetOfsX(22);
1286 aGradient2
.SetOfsY(24);
1287 aGradient2
.SetStartIntensity(4);
1288 aGradient2
.SetEndIntensity(14);
1289 aGradient2
.SetSteps(64);
1290 pVirtualDev
->DrawGradient(aRectangle2
, aGradient2
);
1292 checkGradient(writeAndReadStream(aGDIMetaFile
));
1293 checkGradient(readFile(u
"gradient.svm"));
1296 void SvmTest::checkGradientEx(const GDIMetaFile
& rMetaFile
)
1298 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1300 assertXPathAttrs(pDoc
, "/metafile/gradientex[1]", {
1301 {"style", "Linear"},
1302 {"startcolor", "#ffffff"},
1303 {"endcolor", "#000000"},
1308 {"startintensity", "100"},
1309 {"endintensity", "100"},
1312 assertXPathAttrs(pDoc
, "/metafile/gradientex[1]/polygon/point[1]", {
1316 assertXPathAttrs(pDoc
, "/metafile/gradientex[1]/polygon/point[2]", {
1320 assertXPathAttrs(pDoc
, "/metafile/gradientex[1]/polygon/point[3]", {
1324 assertXPathAttrs(pDoc
, "/metafile/gradientex[2]", {
1326 {"startcolor", "#ff00ff"},
1327 {"endcolor", "#008080"},
1332 {"startintensity", "4"},
1333 {"endintensity", "14"},
1336 assertXPathAttrs(pDoc
, "/metafile/gradientex[2]/polygon[1]/point[1]", {
1340 assertXPathAttrs(pDoc
, "/metafile/gradientex[2]/polygon[1]/point[2]", {
1344 assertXPathAttrs(pDoc
, "/metafile/gradientex[2]/polygon[2]/point[1]", {
1348 assertXPathAttrs(pDoc
, "/metafile/gradientex[2]/polygon[2]/point[2]", {
1354 void SvmTest::testGradientEx()
1356 GDIMetaFile aGDIMetaFile
;
1357 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1358 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1360 tools::Polygon
aPolygon(3);
1361 aPolygon
.SetPoint(Point(1, 8), 0);
1362 aPolygon
.SetPoint(Point(2, 7), 1);
1363 aPolygon
.SetPoint(Point(3, 6), 2);
1365 tools::PolyPolygon
aPolyPolygon(1);
1366 aPolyPolygon
.Insert(aPolygon
);
1368 Gradient
aGradient(css::awt::GradientStyle_LINEAR
, COL_WHITE
, COL_BLACK
);
1369 pVirtualDev
->DrawGradient(aPolyPolygon
, aGradient
);
1371 tools::Polygon
aPolygon2(2);
1372 aPolygon2
.SetPoint(Point(1, 2), 0);
1373 aPolygon2
.SetPoint(Point(3, 4), 1);
1375 tools::Polygon
aPolygon3(2);
1376 aPolygon3
.SetPoint(Point(8, 9), 0);
1377 aPolygon3
.SetPoint(Point(6, 7), 1);
1379 tools::PolyPolygon
aPolyPolygon2(1);
1380 aPolyPolygon2
.Insert(aPolygon2
);
1381 aPolyPolygon2
.Insert(aPolygon3
);
1383 Gradient aGradient2
;
1384 aGradient2
.SetStyle(css::awt::GradientStyle_AXIAL
);
1385 aGradient2
.SetStartColor(COL_LIGHTMAGENTA
);
1386 aGradient2
.SetEndColor(COL_CYAN
);
1387 aGradient2
.SetAngle(Degree10(55));
1388 aGradient2
.SetBorder(10);
1389 aGradient2
.SetOfsX(22);
1390 aGradient2
.SetOfsY(24);
1391 aGradient2
.SetStartIntensity(4);
1392 aGradient2
.SetEndIntensity(14);
1393 aGradient2
.SetSteps(64);
1394 pVirtualDev
->DrawGradient(aPolyPolygon2
, aGradient2
);
1396 checkGradientEx(writeAndReadStream(aGDIMetaFile
));
1397 checkGradientEx(readFile(u
"gradientex.svm"));
1400 void SvmTest::checkHatch(const GDIMetaFile
& rMetaFile
)
1402 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1404 assertXPathAttrs(pDoc
, "/metafile/hatch[1]/polygon/point[1]", {
1405 {"x", "1"}, {"y", "8"},
1407 assertXPathAttrs(pDoc
, "/metafile/hatch[1]/polygon/point[2]", {
1408 {"x", "2"}, {"y", "7"},
1410 assertXPathAttrs(pDoc
, "/metafile/hatch[1]/polygon/point[3]", {
1411 {"x", "3"}, {"y", "6"},
1414 assertXPathAttrs(pDoc
, "/metafile/hatch[1]/hatch", {
1415 {"style", "Single"},
1416 {"color", "#ffff00"},
1422 void SvmTest::testHatch()
1424 GDIMetaFile aGDIMetaFile
;
1425 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1426 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1428 tools::Polygon
aPolygon(3);
1429 aPolygon
.SetPoint(Point(1, 8), 0);
1430 aPolygon
.SetPoint(Point(2, 7), 1);
1431 aPolygon
.SetPoint(Point(3, 6), 2);
1433 tools::PolyPolygon
aPolyPolygon(1);
1434 aPolyPolygon
.Insert(aPolygon
);
1436 Hatch
aHatch(HatchStyle::Single
, COL_YELLOW
, 15, 900_deg10
);
1438 pVirtualDev
->DrawHatch(aPolyPolygon
, aHatch
);
1440 checkHatch(writeAndReadStream(aGDIMetaFile
));
1441 checkHatch(readFile(u
"hatch.svm"));
1444 void SvmTest::checkWallpaper(const GDIMetaFile
& rMetaFile
)
1446 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1448 // Funny enough - we don't serialize the rectangle of the wallpaper so it's always EMPTY
1449 assertXPathAttrs(pDoc
, "/metafile/wallpaper[1]",
1454 {"bottom", "empty"},
1457 assertXPathAttrs(pDoc
, "/metafile/wallpaper[1]/wallpaper",
1459 {"color", "#00ff00"},
1462 {"scrollable", "true"},
1466 void SvmTest::testWallpaper()
1468 GDIMetaFile aGDIMetaFile
;
1469 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1470 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1472 Wallpaper
aWallpaper(COL_LIGHTGREEN
);
1473 pVirtualDev
->DrawWallpaper(tools::Rectangle(Point(1, 1), Size(3, 3)), aWallpaper
);
1475 checkWallpaper(writeAndReadStream(aGDIMetaFile
));
1476 checkWallpaper(readFile(u
"wallpaper.svm"));
1479 void SvmTest::checkClipRegion(const GDIMetaFile
& rMetaFile
)
1481 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1483 assertXPathAttrs(pDoc
, "/metafile/clipregion[1]", {
1490 assertXPathAttrs(pDoc
, "/metafile/clipregion[2]/polygon[1]/point[1]", {
1495 assertXPathAttrs(pDoc
, "/metafile/clipregion[2]/polygon[1]/point[2]", {
1500 assertXPathAttrs(pDoc
, "/metafile/clipregion[2]/polygon[1]/point[3]", {
1505 assertXPathAttrs(pDoc
, "/metafile/clipregion[3]/polygon[1]/point[1]", {
1510 assertXPathAttrs(pDoc
, "/metafile/clipregion[3]/polygon[1]/point[2]", {
1515 assertXPathAttrs(pDoc
, "/metafile/clipregion[3]/polygon[1]/point[3]", {
1520 assertXPathAttrs(pDoc
, "/metafile/clipregion[3]/polygon[2]/point[1]", {
1525 assertXPathAttrs(pDoc
, "/metafile/clipregion[3]/polygon[2]/point[2]", {
1530 assertXPathAttrs(pDoc
, "/metafile/clipregion[3]/polygon[2]/point[3]", {
1535 assertXPathAttrs(pDoc
, "/metafile/clipregion[4]/polygon[1]/point[1]", {
1540 assertXPathAttrs(pDoc
, "/metafile/clipregion[4]/polygon[1]/point[2]", {
1545 assertXPathAttrs(pDoc
, "/metafile/clipregion[4]/polygon[1]/point[3]", {
1551 void SvmTest::testClipRegion()
1553 GDIMetaFile aGDIMetaFile
;
1554 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1555 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1557 vcl::Region
aRegion(tools::Rectangle(Point(2, 2), Size(4, 4)));
1559 pVirtualDev
->SetClipRegion(aRegion
);
1561 tools::Polygon
aPolygon(3);
1562 aPolygon
.SetPoint(Point(1, 8), 0);
1563 aPolygon
.SetPoint(Point(2, 7), 1);
1564 aPolygon
.SetPoint(Point(3, 6), 2);
1566 vcl::Region
aRegion2(aPolygon
);
1567 pVirtualDev
->SetClipRegion(aRegion2
);
1569 tools::Polygon
aPolygon1(3);
1570 aPolygon1
.SetPoint(Point(4, 9), 0);
1571 aPolygon1
.SetPoint(Point(5, 10), 1);
1572 aPolygon1
.SetPoint(Point(6, 11), 2);
1574 tools::PolyPolygon
aPolyPolygon(2);
1575 aPolyPolygon
.Insert(aPolygon
);
1576 aPolyPolygon
.Insert(aPolygon1
);
1578 vcl::Region
aRegion3(aPolyPolygon
);
1579 pVirtualDev
->SetClipRegion(aRegion3
);
1581 basegfx::B2DPolygon aB2DPolygon
;
1582 aB2DPolygon
.append(basegfx::B2DPoint(0.0, 1.1));
1583 aB2DPolygon
.append(basegfx::B2DPoint(2.2, 3.3));
1584 aB2DPolygon
.append(basegfx::B2DPoint(3.7, 3.8));
1586 basegfx::B2DPolyPolygon
aB2DPolyPolygon(aB2DPolygon
);
1588 vcl::Region
aRegion4(aB2DPolyPolygon
);
1589 pVirtualDev
->SetClipRegion(aRegion4
);
1591 checkClipRegion(writeAndReadStream(aGDIMetaFile
));
1592 checkClipRegion(readFile(u
"clipregion.svm"));
1595 void SvmTest::checkIntersectRectClipRegion(const GDIMetaFile
& rMetaFile
)
1597 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1599 assertXPathAttrs(pDoc
, "/metafile/sectregionclipregion[1]", {
1607 void SvmTest::testIntersectRectClipRegion()
1609 GDIMetaFile aGDIMetaFile
;
1610 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1611 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1613 tools::Rectangle
aRectangle(Point(1, 2), Size(4, 8));
1615 vcl::Region
aRegion(aRectangle
);
1617 pVirtualDev
->IntersectClipRegion(aRegion
);
1618 checkIntersectRectClipRegion(writeAndReadStream(aGDIMetaFile
));
1619 checkIntersectRectClipRegion(readFile(u
"intersectrectclipregion.svm"));
1622 void SvmTest::checkIntersectRegionClipRegion(const GDIMetaFile
& rMetaFile
)
1624 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1626 assertXPathAttrs(pDoc
, "/metafile/sectregionclipregion[1]", {
1633 assertXPathAttrs(pDoc
, "/metafile/sectregionclipregion[2]", {
1640 assertXPathAttrs(pDoc
, "/metafile/sectregionclipregion[3]", {
1648 void SvmTest::testIntersectRegionClipRegion()
1650 GDIMetaFile aGDIMetaFile
;
1651 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1652 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1654 tools::Polygon
aPolygon(3);
1655 aPolygon
.SetPoint(Point(1, 2), 0);
1656 aPolygon
.SetPoint(Point(3, 4), 1);
1657 aPolygon
.SetPoint(Point(5, 6), 2);
1659 vcl::Region
aRegion(aPolygon
);
1660 pVirtualDev
->IntersectClipRegion(aRegion
);
1662 tools::Polygon
aPolygon1(2);
1663 aPolygon1
.SetPoint(Point(5, 6), 0);
1664 aPolygon1
.SetPoint(Point(7, 8), 1);
1666 tools::PolyPolygon
aPolyPolygon(2);
1667 aPolyPolygon
.Insert(aPolygon
);
1668 aPolyPolygon
.Insert(aPolygon1
);
1670 vcl::Region
aRegion1(aPolyPolygon
);
1671 pVirtualDev
->IntersectClipRegion(aRegion1
);
1673 basegfx::B2DPolygon aB2DPolygon
;
1674 aB2DPolygon
.append(basegfx::B2DPoint(0.0, 3.3));
1675 aB2DPolygon
.append(basegfx::B2DPoint(1.1, 4.4));
1676 aB2DPolygon
.append(basegfx::B2DPoint(2.2, 5.5));
1678 basegfx::B2DPolyPolygon
aB2DPolyPolygon(aB2DPolygon
);
1680 vcl::Region
aRegion2(aB2DPolyPolygon
);
1681 pVirtualDev
->IntersectClipRegion(aRegion2
);
1683 checkIntersectRegionClipRegion(writeAndReadStream(aGDIMetaFile
));
1684 checkIntersectRegionClipRegion(readFile(u
"intersectregionclipregion.svm"));
1687 void SvmTest::checkMoveClipRegion(const GDIMetaFile
& rMetaFile
)
1689 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1691 assertXPathAttrs(pDoc
, "/metafile/moveclipregion[1]", {
1696 assertXPathAttrs(pDoc
, "/metafile/moveclipregion[2]", {
1702 void SvmTest::testMoveClipRegion()
1704 GDIMetaFile aGDIMetaFile
;
1705 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1706 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1708 tools::Rectangle
aRectangle(Point(1, 2), Size(4, 8));
1710 vcl::Region
aRegion(aRectangle
);
1712 pVirtualDev
->SetClipRegion(aRegion
);
1714 pVirtualDev
->MoveClipRegion(1, 2);
1715 pVirtualDev
->MoveClipRegion(-3, -4);
1717 checkMoveClipRegion(writeAndReadStream(aGDIMetaFile
));
1718 checkMoveClipRegion(readFile(u
"moveclipregion.svm"));
1721 void SvmTest::checkLineColor(const GDIMetaFile
& rMetaFile
)
1723 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1725 assertXPathAttrs(pDoc
, "/metafile/push/linecolor[1]", {
1726 {"color", "#654321"},
1730 void SvmTest::testLineColor()
1732 GDIMetaFile aGDIMetaFile
;
1733 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1734 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1736 pVirtualDev
->Push();
1737 pVirtualDev
->SetLineColor(Color(0x654321));
1740 checkLineColor(writeAndReadStream(aGDIMetaFile
));
1741 checkLineColor(readFile(u
"linecolor.svm"));
1744 void SvmTest::checkFillColor(const GDIMetaFile
& rMetaFile
)
1746 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1748 assertXPathAttrs(pDoc
, "/metafile/push/fillcolor[1]", {
1749 {"color", "#456789"},
1753 void SvmTest::testFillColor()
1755 GDIMetaFile aGDIMetaFile
;
1756 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1757 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1759 pVirtualDev
->Push();
1760 pVirtualDev
->SetFillColor(Color(0x456789));
1763 checkFillColor(writeAndReadStream(aGDIMetaFile
));
1764 checkFillColor(readFile(u
"fillcolor.svm"));
1767 void SvmTest::checkTextColor(const GDIMetaFile
& rMetaFile
)
1769 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1771 assertXPathAttrs(pDoc
, "/metafile/textcolor[1]", {
1772 {"color", "#123456"},
1776 void SvmTest::testTextColor()
1778 GDIMetaFile aGDIMetaFile
;
1779 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1780 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1782 pVirtualDev
->SetTextColor(Color(0x123456));
1784 checkTextColor(writeAndReadStream(aGDIMetaFile
));
1785 checkTextColor(readFile(u
"textcolor.svm"));
1788 void SvmTest::checkTextFillColor(const GDIMetaFile
& rMetaFile
)
1790 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1792 assertXPathAttrs(pDoc
, "/metafile/textfillcolor[1]", {
1793 {"color", "#234567"},
1797 void SvmTest::testTextFillColor()
1799 GDIMetaFile aGDIMetaFile
;
1800 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1801 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1803 pVirtualDev
->SetTextFillColor(Color(0x234567));
1805 checkTextFillColor(writeAndReadStream(aGDIMetaFile
));
1806 checkTextFillColor(readFile(u
"textfillecolor.svm"));
1809 void SvmTest::checkTextLineColor(const GDIMetaFile
& rMetaFile
)
1811 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1813 assertXPathAttrs(pDoc
, "/metafile/textlinecolor[1]", {
1814 {"color", "#345678"},
1818 void SvmTest::testTextLineColor()
1820 GDIMetaFile aGDIMetaFile
;
1821 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1822 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1824 pVirtualDev
->SetTextLineColor(Color(0x345678));
1826 checkTextLineColor(writeAndReadStream(aGDIMetaFile
));
1827 checkTextLineColor(readFile(u
"textlinecolor.svm"));
1830 void SvmTest::checkOverLineColor(const GDIMetaFile
& rMetaFile
)
1832 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1834 assertXPathAttrs(pDoc
, "/metafile/push/overlinecolor[1]", {
1835 {"color", "#345678"},
1839 void SvmTest::testOverLineColor()
1841 GDIMetaFile aGDIMetaFile
;
1842 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1843 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1845 pVirtualDev
->Push();
1846 pVirtualDev
->SetOverlineColor(Color(0x345678));
1849 checkOverLineColor(writeAndReadStream(aGDIMetaFile
));
1850 checkOverLineColor(readFile(u
"overlinecolor.svm"));
1853 void SvmTest::checkTextAlign(const GDIMetaFile
& rMetaFile
)
1855 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1857 assertXPathAttrs(pDoc
, "/metafile/textalign[1]", {
1858 {"align", "bottom"},
1862 void SvmTest::testTextAlign()
1864 GDIMetaFile aGDIMetaFile
;
1865 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1866 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1868 pVirtualDev
->SetTextAlign(TextAlign::ALIGN_BOTTOM
);
1870 checkTextAlign(writeAndReadStream(aGDIMetaFile
));
1871 checkTextAlign(readFile(u
"textalign.svm"));
1874 void SvmTest::checkMapMode(const GDIMetaFile
& rMetafile
)
1876 xmlDocUniquePtr pDoc
= dumpMeta(rMetafile
);
1878 assertXPathAttrs(pDoc
, "/metafile/mapmode[1]", {
1879 {"mapunit", "MapPixel"},
1882 {"scalex", "(1/1)"},
1886 assertXPathAttrs(pDoc
, "/metafile/mapmode[2]", {
1887 {"mapunit", "Map100thInch"},
1890 {"scalex", "(1/2)"},
1894 assertXPathAttrs(pDoc
, "/metafile/mapmode[3]", {
1895 {"mapunit", "MapRelative"},
1898 {"scalex", "(25/12)"},
1899 {"scaley", "(25/16)"}
1903 void SvmTest::testMapMode()
1905 if (!IsDefaultDPI())
1907 GDIMetaFile aGDIMetafile
;
1908 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1909 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetafile
);
1913 pVirtualDev
->SetMapMode(aMapMode
);
1915 MapMode
aMapMode1(MapUnit::Map100thInch
);
1916 aMapMode1
.SetOrigin(Point(0, 1));
1917 aMapMode1
.SetScaleX(Fraction(1, 2));
1918 aMapMode1
.SetScaleY(Fraction(2, 3));
1920 pVirtualDev
->SetMetafileMapMode(aMapMode1
, false);
1923 pVirtualDev
->SetMetafileMapMode(aMapMode2
, true);
1925 checkMapMode(writeAndReadStream(aGDIMetafile
));
1926 checkMapMode(readFile(u
"mapmode.svm"));
1929 #if HAVE_MORE_FONTS && !defined(_WIN32)
1930 void SvmTest::checkFont(const GDIMetaFile
& rMetafile
)
1932 xmlDocUniquePtr pDoc
= dumpMeta(rMetafile
);
1933 assertXPathAttrs(pDoc
, "/metafile/font[1]", {
1934 {"color", "#ffffff"},
1935 {"fillcolor", "#ffffff"},
1936 {"name", "Liberation Sans"},
1937 {"stylename", "Regular"},
1940 {"orientation", "50"},
1942 {"vertical", "true"},
1947 void SvmTest::testFont()
1950 // Windows interprets Width differently causing build errors
1951 #if !defined(_WIN32)
1952 GDIMetaFile aGDIMetaFile
;
1953 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1954 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1955 vcl::Font
aFont(FontFamily::FAMILY_SCRIPT
, Size(15, 15));
1956 aFont
.SetWeight(FontWeight::WEIGHT_THIN
);
1957 aFont
.SetFamilyName("Liberation Sans");
1958 aFont
.SetStyleName("Regular");
1959 aFont
.SetFontHeight(12);
1960 aFont
.SetAverageFontWidth(12);
1961 aFont
.SetVertical(true);
1962 aFont
.SetOrientation(Degree10(50));
1963 pVirtualDev
->SetFont(aFont
);
1964 checkFont(writeAndReadStream(aGDIMetaFile
));
1965 checkFont(readFile(u
"font.svm"));
1970 void SvmTest::checkPushPop(const GDIMetaFile
& rMetaFile
)
1972 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
1974 assertXPathAttrs(pDoc
, "/metafile/push[1]", {{"flags", "PushAll"}});
1975 assertXPathAttrs(pDoc
, "/metafile/push[1]/linecolor[1]", {{"color", "#800000"}});
1976 assertXPathAttrs(pDoc
, "/metafile/push[1]/line[1]", {
1977 {"startx", "4"}, {"starty", "4"},
1978 {"endx", "6"}, {"endy", "6"},
1980 assertXPathAttrs(pDoc
, "/metafile/push[1]/push[1]", {{"flags", "PushLineColor, PushFillColor"}});
1981 assertXPathAttrs(pDoc
, "/metafile/push[1]/push[1]/line[1]", {
1982 {"startx", "5"}, {"starty", "5"},
1983 {"endx", "7"}, {"endy", "7"},
1987 void SvmTest::testPushPop()
1989 GDIMetaFile aGDIMetaFile
;
1990 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
1991 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
1993 pVirtualDev
->SetLineColor(COL_YELLOW
);
1994 pVirtualDev
->Push();
1995 pVirtualDev
->SetLineColor(COL_RED
);
1996 pVirtualDev
->DrawLine(Point(4,4), Point(6,6));
1997 pVirtualDev
->Push(vcl::PushFlags::FILLCOLOR
| vcl::PushFlags::LINECOLOR
);
1998 pVirtualDev
->SetLineColor(COL_LIGHTRED
);
1999 pVirtualDev
->DrawLine(Point(5,5), Point(7,7));
2002 pVirtualDev
->DrawLine(Point(1,1), Point(8,8));
2004 checkPushPop(writeAndReadStream(aGDIMetaFile
));
2005 checkPushPop(readFile(u
"pushpop.svm"));
2008 void SvmTest::checkRasterOp(const GDIMetaFile
& rMetaFile
)
2010 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
2012 assertXPathAttrs(pDoc
, "/metafile/rasterop[1]", {
2013 {"operation", "xor"},
2017 void SvmTest::testRasterOp()
2019 GDIMetaFile aGDIMetaFile
;
2020 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
2021 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
2023 pVirtualDev
->SetRasterOp(RasterOp::Xor
);
2025 checkRasterOp(writeAndReadStream(aGDIMetaFile
));
2026 checkRasterOp(readFile(u
"rasterop.svm"));
2029 void SvmTest::checkTransparent(const GDIMetaFile
& rMetaFile
)
2031 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
2033 assertXPathAttrs(pDoc
, "/metafile/transparent[1]", {
2034 {"transparence", "50"},
2037 assertXPathAttrs(pDoc
, "/metafile/transparent[1]/polygon/point[1]", {
2038 {"x", "1"}, {"y", "8"},
2040 assertXPathAttrs(pDoc
, "/metafile/transparent[1]/polygon/point[2]", {
2041 {"x", "2"}, {"y", "7"},
2043 assertXPathAttrs(pDoc
, "/metafile/transparent[1]/polygon/point[3]", {
2044 {"x", "3"}, {"y", "6"},
2048 void SvmTest::testTransparent()
2050 GDIMetaFile aGDIMetaFile
;
2051 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
2052 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
2054 tools::Polygon
aPolygon(3);
2055 aPolygon
.SetPoint(Point(1, 8), 0);
2056 aPolygon
.SetPoint(Point(2, 7), 1);
2057 aPolygon
.SetPoint(Point(3, 6), 2);
2059 tools::PolyPolygon
aPolyPolygon(1);
2060 aPolyPolygon
.Insert(aPolygon
);
2062 pVirtualDev
->DrawTransparent(aPolygon
, 50);
2064 CPPUNIT_ASSERT(aGDIMetaFile
.HasTransparentActions());
2065 checkTransparent(writeAndReadStream(aGDIMetaFile
));
2066 checkTransparent(readFile(u
"transparent.svm"));
2069 void SvmTest::checkFloatTransparent(const GDIMetaFile
& rMetaFile
)
2071 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
2073 assertXPathAttrs(pDoc
, "/metafile/floattransparent[1]", {
2078 {"transparent", "true"}
2081 assertXPathAttrs(pDoc
, "/metafile/floattransparent[1]/gradient[1]", {
2082 {"style", "Linear"},
2083 {"startcolor", "#ffffff"},
2084 {"endcolor", "#000000"},
2089 {"startintensity", "100"},
2090 {"endintensity", "100"},
2094 assertXPathAttrs(pDoc
, "/metafile/floattransparent[1]/metafile[1]/point[1]", {
2099 assertXPathAttrs(pDoc
, "/metafile/floattransparent[1]/metafile[1]/point[2]", {
2105 void SvmTest::testFloatTransparent()
2107 GDIMetaFile aGDIMetaFile
;
2108 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
2109 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
2111 GDIMetaFile aGDIMetaFile1
;
2112 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev1
;
2113 setupBaseVirtualDevice(*pVirtualDev1
, aGDIMetaFile1
);
2115 pVirtualDev1
->DrawPixel(Point(1, 8));
2116 pVirtualDev1
->DrawPixel(Point(2, 7));
2118 Gradient
aGradient(css::awt::GradientStyle_LINEAR
, COL_WHITE
, COL_BLACK
);
2120 pVirtualDev
->DrawTransparent(aGDIMetaFile1
, Point(1, 2), Size(3, 4), aGradient
);
2122 checkFloatTransparent(writeAndReadStream(aGDIMetaFile
));
2123 checkFloatTransparent(readFile(u
"floattransparent.svm"));
2126 void SvmTest::checkEPS(const GDIMetaFile
& rMetaFile
)
2128 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
2130 assertXPathAttrs(pDoc
, "/metafile/eps[1]", {
2137 assertXPathAttrs(pDoc
, "/metafile/eps[1]/gfxlink[1]", {
2140 {"type", "EpsBuffer"},
2141 {"userid", "12345"},
2144 {"native", "false"},
2146 {"validmapmode", "true"}
2149 assertXPathAttrs(pDoc
, "/metafile/eps[1]/gfxlink[1]/prefmapmode[1]", {
2150 {"mapunit", "Map100thInch"},
2153 {"scalex", "(1/2)"},
2157 assertXPathAttrs(pDoc
, "/metafile/eps[1]/metafile[1]/point[1]", {
2162 assertXPathAttrs(pDoc
, "/metafile/eps[1]/metafile[1]/point[2]", {
2168 void SvmTest::testEPS()
2170 GDIMetaFile aGDIMetaFile
;
2171 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
2172 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
2174 sal_uInt8 aBuffer
[] = { 'a','b','c' };
2175 SvMemoryStream
stream(aBuffer
, std::size(aBuffer
), StreamMode::READ
);
2176 BinaryDataContainer
aContainer(stream
, std::size(aBuffer
));
2178 MapMode
aMapMode1(MapUnit::Map100thInch
);
2179 aMapMode1
.SetOrigin(Point(0, 1));
2180 aMapMode1
.SetScaleX(Fraction(1, 2));
2181 aMapMode1
.SetScaleY(Fraction(2, 3));
2183 GDIMetaFile aGDIMetaFile1
;
2184 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev1
;
2185 setupBaseVirtualDevice(*pVirtualDev1
, aGDIMetaFile1
);
2187 pVirtualDev1
->DrawPixel(Point(1, 8));
2188 pVirtualDev1
->DrawPixel(Point(2, 7));
2190 GfxLink
aGfxLink(aContainer
, GfxLinkType::EpsBuffer
);
2191 aGfxLink
.SetPrefMapMode(aMapMode1
);
2192 aGfxLink
.SetUserId(12345);
2193 aGfxLink
.SetPrefSize(Size(3, 6));
2194 pVirtualDev
->DrawEPS(Point(1, 8), Size(2, 7), aGfxLink
, &aGDIMetaFile1
);
2196 checkEPS(writeAndReadStream(aGDIMetaFile
));
2197 checkEPS(readFile(u
"eps.svm"));
2200 void SvmTest::checkRefPoint(const GDIMetaFile
& rMetaFile
)
2202 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
2204 assertXPathAttrs(pDoc
, "/metafile/refpoint[1]", {
2210 assertXPathAttrs(pDoc
, "/metafile/refpoint[2]", {
2217 void SvmTest::testRefPoint()
2219 GDIMetaFile aGDIMetaFile
;
2220 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
2221 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
2223 pVirtualDev
->SetRefPoint();
2225 pVirtualDev
->SetRefPoint(Point(1,2));
2227 checkRefPoint(writeAndReadStream(aGDIMetaFile
));
2228 checkRefPoint(readFile(u
"refpoint.svm"));
2231 void SvmTest::checkComment(const GDIMetaFile
& rMetafile
)
2233 xmlDocUniquePtr pDoc
= dumpMeta(rMetafile
);
2235 assertXPathAttrs(pDoc
, "/metafile/comment[1]", {
2239 assertXPathContent(pDoc
, "/metafile/comment[1]/comment[1]", "Test comment");
2241 assertXPathAttrs(pDoc
, "/metafile/comment[2]", {
2245 assertXPathAttrs(pDoc
, "/metafile/comment[2]", {
2246 {"data", "540068006500730065002000610072006500200073006f006d0065002000740065007300740020006400610074006100"}
2249 assertXPathAttrs(pDoc
, "/metafile/comment[2]", {
2253 assertXPathContent(pDoc
, "/metafile/comment[2]/comment[1]", "This is a test comment");
2256 void SvmTest::testComment()
2258 GDIMetaFile aGDIMetaFile
;
2259 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
2260 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
2262 aGDIMetaFile
.AddAction(new MetaCommentAction("Test comment"));
2264 using namespace std::literals::string_view_literals
;
2265 static constexpr auto aString
2266 = "T\0h\0e\0s\0e\0 \0a\0r\0e\0 \0s\0o\0m\0e\0 \0t\0e\0s\0t\0 \0d\0a\0t\0a\0"sv
;
2267 aGDIMetaFile
.AddAction(new MetaCommentAction("This is a test comment", \
2269 reinterpret_cast<const sal_uInt8
*>(aString
.data()), \
2270 aString
.length() ));
2272 checkComment(writeAndReadStream(aGDIMetaFile
));
2273 checkComment(readFile(u
"comment.svm"));
2276 void SvmTest::checkLayoutMode(const GDIMetaFile
& rMetaFile
)
2278 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
2280 assertXPathAttrs(pDoc
, "/metafile/layoutmode[1]", {
2281 {"textlayout", "#0004"}
2284 assertXPathAttrs(pDoc
, "/metafile/layoutmode[2]", {
2285 {"textlayout", "#0001"}
2289 void SvmTest::testLayoutMode()
2291 GDIMetaFile aGDIMetaFile
;
2292 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
2293 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
2295 pVirtualDev
->SetLayoutMode(vcl::text::ComplexTextLayoutFlags::TextOriginLeft
);
2296 pVirtualDev
->SetLayoutMode(vcl::text::ComplexTextLayoutFlags::BiDiRtl
);
2298 checkLayoutMode(writeAndReadStream(aGDIMetaFile
));
2299 checkLayoutMode(readFile(u
"layoutmode.svm"));
2302 void SvmTest::checkTextLanguage(const GDIMetaFile
& rMetaFile
)
2304 xmlDocUniquePtr pDoc
= dumpMeta(rMetaFile
);
2306 assertXPathAttrs(pDoc
, "/metafile/textlanguage[1]", {
2307 {"language", "#0408"}
2310 assertXPathAttrs(pDoc
, "/metafile/textlanguage[2]", {
2311 {"language", "#00ff"}
2315 void SvmTest::testTextLanguage()
2317 GDIMetaFile aGDIMetaFile
;
2318 ScopedVclPtrInstance
<VirtualDevice
> pVirtualDev
;
2319 setupBaseVirtualDevice(*pVirtualDev
, aGDIMetaFile
);
2321 pVirtualDev
->SetDigitLanguage(LANGUAGE_GREEK
);
2322 pVirtualDev
->SetDigitLanguage(LANGUAGE_NONE
);
2324 checkTextLanguage(writeAndReadStream(aGDIMetaFile
));
2325 checkTextLanguage(readFile(u
"textlanguage.svm"));
2328 CPPUNIT_TEST_SUITE_REGISTRATION(SvmTest
);
2330 CPPUNIT_PLUGIN_IMPLEMENT();
2332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */