1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
11 #include <sal/config.h>
12
13 #include <string_view>
14
15 #include <test/bootstrapfixture.hxx>
16 #include <test/xmltesttools.hxx>
17 #include <vcl/gdimtf.hxx>
18 #include <vcl/gradient.hxx>
19 #include <vcl/hatch.hxx>
20 #include <vcl/lineinfo.hxx>
21 #include <vcl/virdev.hxx>
22 #include <vcl/pngwrite.hxx>
23
24 #include <bitmap/BitmapWriteAccess.hxx>
25
26 #include <config_features.h>
27 #include <vcl/skia/SkiaHelper.hxx>
28
29 using namespace css;
30
31 class SvmTest : public test::BootstrapFixture, public XmlTestTools
32 {
33 OUString maDataUrl;
34
getFullUrl(std::u16string_view sFileName)35 OUString getFullUrl(std::u16string_view sFileName)
36 {
37 return m_directories.getURLFromSrc(maDataUrl) + sFileName;
38 }
39
40 void checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev, const GDIMetaFile& rMetaFile);
41
42 // write GDI Metafile to a file in data directory
43 // only use this for new tests to create the svm file
44 void writeToFile(GDIMetaFile& rMetaFile, std::u16string_view rName);
45
46 GDIMetaFile writeAndReadStream(
47 GDIMetaFile& rMetaFile, std::u16string_view rName = std::u16string_view());
48
49 GDIMetaFile readFile(std::u16string_view sName);
50
51 xmlDocUniquePtr dumpMeta(const GDIMetaFile& rMetaFile);
52
53 void checkVirtualDevice(const xmlDocUniquePtr& pDoc);
54 void checkErase(const xmlDocUniquePtr& pDoc);
55
56 void checkPixel(const GDIMetaFile& rMetaFile);
57 void testPixel();
58
59 void checkPoint(const GDIMetaFile& rMetaFile);
60 void testPoint();
61
62 void checkLine(const GDIMetaFile& rMetaFile);
63 void testLine();
64
65 void checkRect(const GDIMetaFile& rMetaFile);
66 void testRect();
67
68 void checkRoundRect(const GDIMetaFile& rMetaFile);
69 void testRoundRect();
70
71 void checkEllipse(const GDIMetaFile& rMetaFile);
72 void testEllipse();
73
74 void checkArc(const GDIMetaFile& rMetaFile);
75 void testArc();
76
77 void checkPie(const GDIMetaFile& rMetaFile);
78 void testPie();
79
80 void checkChord(const GDIMetaFile& rMetaFile);
81 void testChord();
82
83 void checkPolyLine(const GDIMetaFile& rMetaFile);
84 void testPolyLine();
85
86 void checkPolygon(const GDIMetaFile& rMetaFile);
87 void testPolygon();
88
89 void checkPolyPolygon(const GDIMetaFile& rMetaFile);
90 void testPolyPolygon();
91
92 void checkText(const GDIMetaFile& rMetaFile);
93 void testText();
94
95 void checkTextArray(const GDIMetaFile& rMetaFile);
96 void testTextArray();
97
98 void checkstretchText(const GDIMetaFile& rMetaFile);
99 void teststretchText();
100
101 void checkTextRect(const GDIMetaFile& rMetaFile);
102 void testTextRect();
103
104 void checkTextLine(const GDIMetaFile& rMetaFile);
105 void testTextLine();
106
107 void checkBitmaps(const GDIMetaFile& rMetaFile);
108 void testBitmaps();
109
110 void checkBitmapExs(const GDIMetaFile& rMetaFile);
111 void testBitmapExs();
112
113 void checkMasks(const GDIMetaFile& rMetaFile);
114 void testMasks();
115
116 void checkGradient(const GDIMetaFile& rMetaFile);
117 void testGradient();
118
119 void checkGradientEx(const GDIMetaFile& rMetaFile);
120 void testGradientEx();
121
122 void checkHatch(const GDIMetaFile& rMetaFile);
123 void testHatch();
124
125 void checkWallpaper(const GDIMetaFile& rMetaFile);
126 void testWallpaper();
127
128 void checkClipRegion(const GDIMetaFile& rMetaFile);
129 void testClipRegion();
130
131 void checkIntersectRectClipRegion(const GDIMetaFile& rMetaFile);
132 void testIntersectRectClipRegion();
133
134 void checkIntersectRegionClipRegion(const GDIMetaFile& rMetaFile);
135 void testIntersectRegionClipRegion();
136
137 //void checkMoveClipRegion(const GDIMetaFile& rMetaFile);
138 void testMoveClipRegion();
139
140 void checkLineColor(const GDIMetaFile& rMetaFile);
141 void testLineColor();
142
143 void checkFillColor(const GDIMetaFile& rMetaFile);
144 void testFillColor();
145
146 void checkTextColor(const GDIMetaFile& rMetaFile);
147 void testTextColor();
148
149 void checkTextFillColor(const GDIMetaFile& rMetaFile);
150 void testTextFillColor();
151
152 void checkTextLineColor(const GDIMetaFile& rMetaFile);
153 void testTextLineColor();
154
155 void checkOverLineColor(const GDIMetaFile& rMetaFile);
156 void testOverLineColor();
157
158 void checkTextAlign(const GDIMetaFile& rMetaFile);
159 void testTextAlign();
160
161 //void checkMapMode(const GDIMetaFile& rMetaFile);
162 void testMapMode();
163
164 //void checkFont(const GDIMetaFile& rMetaFile);
165 void testFont();
166
167 void checkPushPop(const GDIMetaFile& rMetaFile);
168 void testPushPop();
169
170 void checkRasterOp(const GDIMetaFile& rMetaFile);
171 void testRasterOp();
172
173 void checkTransparent(const GDIMetaFile& rMetaFile);
174 void testTransparent();
175
176 //void checkFloatTransparent(const GDIMetaFile& rMetaFile);
177 void testFloatTransparent();
178
179 //void checkEPS(const GDIMetaFile& rMetaFile);
180 void testEPS();
181
182 void checkRefPoint(const GDIMetaFile& rMetaFile);
183 void testRefPoint();
184
185 //void checkComment(const GDIMetaFile& rMetaFile);
186 void testComment();
187
188 //void checkLayoutMode(const GDIMetaFile& rMetaFile);
189 void testLayoutMode();
190
191 //void checkTextLanguage(const GDIMetaFile& rMetaFile);
192 void testTextLanguage();
193
194 public:
SvmTest()195 SvmTest()
196 : BootstrapFixture(true, false)
197 , maDataUrl("/vcl/qa/cppunit/svm/data/")
198 {}
199
200 CPPUNIT_TEST_SUITE(SvmTest);
201 CPPUNIT_TEST(testPixel);
202 CPPUNIT_TEST(testPoint);
203 CPPUNIT_TEST(testLine);
204 CPPUNIT_TEST(testRect);
205 CPPUNIT_TEST(testRoundRect);
206 CPPUNIT_TEST(testEllipse);
207 CPPUNIT_TEST(testArc);
208 CPPUNIT_TEST(testPie);
209 CPPUNIT_TEST(testChord);
210 CPPUNIT_TEST(testPolyLine);
211 CPPUNIT_TEST(testPolygon);
212 CPPUNIT_TEST(testPolyPolygon);
213 CPPUNIT_TEST(testText);
214 CPPUNIT_TEST(testTextArray);
215 CPPUNIT_TEST(teststretchText);
216 CPPUNIT_TEST(testTextRect);
217 CPPUNIT_TEST(testTextLine);
218 CPPUNIT_TEST(testBitmaps); // BMP, BMPSCALE, BMPSCALEPART
219 CPPUNIT_TEST(testBitmapExs); // BMPEX, BMPEXSCALE, BMPEXSCALEPART
220 CPPUNIT_TEST(testMasks); // MASK, MASKSCALE, MASKSCALEPART
221 CPPUNIT_TEST(testGradient);
222 CPPUNIT_TEST(testGradientEx);
223 CPPUNIT_TEST(testHatch);
224 CPPUNIT_TEST(testWallpaper);
225 CPPUNIT_TEST(testClipRegion);
226 CPPUNIT_TEST(testIntersectRectClipRegion);
227 CPPUNIT_TEST(testIntersectRegionClipRegion);
228 CPPUNIT_TEST(testMoveClipRegion);
229 CPPUNIT_TEST(testLineColor);
230 CPPUNIT_TEST(testFillColor);
231 CPPUNIT_TEST(testTextColor);
232 CPPUNIT_TEST(testTextFillColor);
233 CPPUNIT_TEST(testTextLineColor);
234 CPPUNIT_TEST(testOverLineColor);
235 CPPUNIT_TEST(testTextAlign);
236 CPPUNIT_TEST(testMapMode);
237 CPPUNIT_TEST(testFont);
238 CPPUNIT_TEST(testPushPop);
239 CPPUNIT_TEST(testRasterOp);
240 CPPUNIT_TEST(testTransparent);
241 CPPUNIT_TEST(testFloatTransparent);
242 CPPUNIT_TEST(testEPS);
243 CPPUNIT_TEST(testRefPoint);
244 CPPUNIT_TEST(testComment);
245 CPPUNIT_TEST(testLayoutMode);
246 CPPUNIT_TEST(testTextLanguage);
247
248 CPPUNIT_TEST_SUITE_END();
249 };
250
setupBaseVirtualDevice(VirtualDevice & rDevice,GDIMetaFile & rMeta)251 static void setupBaseVirtualDevice(VirtualDevice& rDevice, GDIMetaFile& rMeta)
252 {
253 rDevice.SetConnectMetaFile(&rMeta);
254 Size aVDSize(10, 10);
255 rDevice.SetOutputSizePixel(aVDSize);
256 rDevice.SetBackground(Wallpaper(COL_LIGHTRED));
257 rDevice.Erase();
258 }
259
checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev,const GDIMetaFile & rMetaFile)260 void SvmTest::checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev, const GDIMetaFile& rMetaFile)
261 {
262 BitmapEx aSourceBitmapEx = pVirtualDev->GetBitmapEx(Point(), Size(10, 10));
263 ScopedVclPtrInstance<VirtualDevice> pVirtualDevResult;
264 pVirtualDevResult->SetOutputSizePixel(Size(10, 10));
265 const_cast<GDIMetaFile&>(rMetaFile).Play(*pVirtualDevResult);
266 BitmapEx aResultBitmapEx = pVirtualDevResult->GetBitmapEx(Point(), Size(10, 10));
267
268 const bool bWriteCompareBitmap = false;
269
270 if (bWriteCompareBitmap)
271 {
272 utl::TempFile aTempFile;
273 aTempFile.EnableKillingFile();
274
275 {
276 SvFileStream aStream(aTempFile.GetURL() + ".source.png", StreamMode::WRITE | StreamMode::TRUNC);
277 vcl::PNGWriter aPNGWriter(aSourceBitmapEx);
278 aPNGWriter.Write(aStream);
279 }
280 {
281 SvFileStream aStream(aTempFile.GetURL() + ".result.png", StreamMode::WRITE | StreamMode::TRUNC);
282 vcl::PNGWriter aPNGWriter(aResultBitmapEx);
283 aPNGWriter.Write(aStream);
284 }
285 }
286 CPPUNIT_ASSERT_EQUAL(aSourceBitmapEx.GetChecksum(), aResultBitmapEx.GetChecksum());
287 }
288
readMetafile(const OUString & rUrl)289 static GDIMetaFile readMetafile(const OUString& rUrl)
290 {
291 GDIMetaFile aResultMetafile;
292 SvFileStream aFileStream(rUrl, StreamMode::READ);
293 aFileStream.Seek(STREAM_SEEK_TO_BEGIN);
294 aResultMetafile.Read(aFileStream);
295 return aResultMetafile;
296 }
297
writeMetaFile(GDIMetaFile & rInputMetafile,const OUString & rUrl)298 static void writeMetaFile(GDIMetaFile& rInputMetafile, const OUString& rUrl)
299 {
300 SvFileStream aFileStream(rUrl, StreamMode::WRITE);
301 aFileStream.Seek(STREAM_SEEK_TO_BEGIN);
302 rInputMetafile.Write(aFileStream);
303 aFileStream.Close();
304 }
305
writeToFile(GDIMetaFile & rMetaFile,std::u16string_view rName)306 void SvmTest::writeToFile(GDIMetaFile& rMetaFile, std::u16string_view rName)
307 {
308 if (rName.empty())
309 return;
310 OUString sFilePath = getFullUrl(rName);
311 writeMetaFile(rMetaFile, sFilePath);
312 }
313
writeAndReadStream(GDIMetaFile & rMetaFile,std::u16string_view rName)314 GDIMetaFile SvmTest::writeAndReadStream(GDIMetaFile& rMetaFile, std::u16string_view rName)
315 {
316 if (!rName.empty())
317 writeToFile(rMetaFile, rName);
318
319 SvMemoryStream aStream;
320 rMetaFile.Write(aStream);
321 aStream.Seek(STREAM_SEEK_TO_BEGIN);
322
323 GDIMetaFile aResultMetafile;
324 aResultMetafile.Read(aStream);
325 return aResultMetafile;
326 }
327
readFile(std::u16string_view sName)328 GDIMetaFile SvmTest::readFile(std::u16string_view sName)
329 {
330 OUString sFilePath = getFullUrl(sName);
331 return readMetafile(sFilePath);
332 }
333
dumpMeta(const GDIMetaFile & rMetaFile)334 xmlDocUniquePtr SvmTest::dumpMeta(const GDIMetaFile& rMetaFile)
335 {
336 MetafileXmlDump dumper;
337 xmlDocUniquePtr pDoc = dumpAndParse(dumper, rMetaFile);
338 CPPUNIT_ASSERT (pDoc);
339
340 checkVirtualDevice(pDoc);
341 checkErase(pDoc);
342
343 return pDoc;
344 }
345
checkVirtualDevice(const xmlDocUniquePtr & pDoc)346 void SvmTest::checkVirtualDevice(const xmlDocUniquePtr& pDoc)
347 {
348 assertXPath(pDoc, "/metafile/linecolor[1]", "color", "#000000");
349 assertXPath(pDoc, "/metafile/fillcolor[1]", "color", "#ffffff");
350
351 assertXPathAttrs(pDoc, "/metafile/rect[1]", {
352 {"left", "0"}, {"top", "0"},
353 {"right", "9"}, {"bottom", "9"}
354 });
355
356 assertXPath(pDoc, "/metafile/linecolor[2]", "color", "#000000");
357 assertXPath(pDoc, "/metafile/fillcolor[2]", "color", "#ffffff");
358 }
359
checkErase(const xmlDocUniquePtr & pDoc)360 void SvmTest::checkErase(const xmlDocUniquePtr& pDoc)
361 {
362 assertXPath(pDoc, "/metafile/linecolor[3]", "color", "#000000");
363 assertXPath(pDoc, "/metafile/fillcolor[3]", "color", "#ff0000");
364
365 assertXPathAttrs(pDoc, "/metafile/rect[2]", {
366 {"left", "0"}, {"top", "0"},
367 {"right", "9"}, {"bottom", "9"}
368 });
369 }
370
checkPixel(const GDIMetaFile & rMetaFile)371 void SvmTest::checkPixel(const GDIMetaFile& rMetaFile)
372 {
373 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
374
375 assertXPathAttrs(pDoc, "/metafile/pixel[1]", {
376 {"x", "8"}, {"y", "1"}, {"color", "#008000"},
377 });
378
379 assertXPathAttrs(pDoc, "/metafile/pixel[2]", {
380 {"x", "1"}, {"y", "8"}, {"color", "#000080"},
381 });
382 }
383
testPixel()384 void SvmTest::testPixel()
385 {
386 GDIMetaFile aGDIMetaFile;
387 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
388 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
389
390 pVirtualDev->DrawPixel(Point(8, 1), COL_GREEN);
391 pVirtualDev->DrawPixel(Point(1, 8), COL_BLUE);
392
393 checkPixel(writeAndReadStream(aGDIMetaFile));
394 checkPixel(readFile(u"pixel.svm"));
395 }
396
checkPoint(const GDIMetaFile & rMetaFile)397 void SvmTest::checkPoint(const GDIMetaFile& rMetaFile)
398 {
399 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
400
401 assertXPathAttrs(pDoc, "/metafile/point[1]", {
402 {"x", "4"}, {"y", "4"}
403 });
404 }
405
testPoint()406 void SvmTest::testPoint()
407 {
408 GDIMetaFile aGDIMetaFile;
409 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
410 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
411
412 pVirtualDev->DrawPixel(Point(4, 4));
413
414 checkPoint(writeAndReadStream(aGDIMetaFile));
415 checkPoint(readFile(u"point.svm"));
416 }
417
checkLine(const GDIMetaFile & rMetaFile)418 void SvmTest::checkLine(const GDIMetaFile& rMetaFile)
419 {
420 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
421
422 assertXPathAttrs(pDoc, "/metafile/line[1]", {
423 {"startx", "1"}, {"starty", "1"},
424 {"endx", "8"}, {"endy", "8"},
425 });
426
427 assertXPathAttrs(pDoc, "/metafile/line[1]", {
428 {"style", "solid"}, {"width", "0"},
429 {"dashlen", "0"}, {"dashcount", "0"},
430 {"dotlen", "0"}, {"dotcount", "0"},
431 {"distance", "0"},
432 {"join", "round"}, {"cap", "butt"}
433 });
434
435 assertXPathAttrs(pDoc, "/metafile/line[2]", {
436 {"startx", "1"}, {"starty", "8"},
437 {"endx", "8"}, {"endy", "1"},
438 });
439
440 assertXPathAttrs(pDoc, "/metafile/line[2]", {
441 {"style", "dash"}, {"width", "7"},
442 {"dashlen", "5"}, {"dashcount", "4"},
443 {"dotlen", "3"}, {"dotcount", "2"},
444 {"distance", "1"},
445 {"join", "miter"}, {"cap", "round"}
446 });
447 }
448
testLine()449 void SvmTest::testLine()
450 {
451 GDIMetaFile aGDIMetaFile;
452 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
453 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
454
455 pVirtualDev->DrawLine(Point(1, 1), Point(8, 8));
456 LineInfo aLineInfo(LineStyle::Dash, 7);
457 aLineInfo.SetDashLen(5);
458 aLineInfo.SetDashCount(4);
459 aLineInfo.SetDotLen(3);
460 aLineInfo.SetDotCount(2);
461 aLineInfo.SetDistance(1);
462 aLineInfo.SetLineJoin(basegfx::B2DLineJoin::Miter);
463 aLineInfo.SetLineCap(css::drawing::LineCap_ROUND);
464 pVirtualDev->DrawLine(Point(1, 8), Point(8, 1), aLineInfo);
465
466 checkLine(writeAndReadStream(aGDIMetaFile));
467 checkLine(readFile(u"line.svm"));
468 }
469
checkRect(const GDIMetaFile & rMetaFile)470 void SvmTest::checkRect(const GDIMetaFile& rMetaFile)
471 {
472
473 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
474
475 assertXPath(pDoc, "/metafile/linecolor[5]", "color", "#123456");
476 assertXPath(pDoc, "/metafile/fillcolor[5]", "color", "#654321");
477
478 assertXPathAttrs(pDoc, "/metafile/rect[3]", {
479 {"left", "1"}, {"top", "2"},
480 {"right", "4"}, {"bottom", "5"},
481 });
482 }
483
testRect()484 void SvmTest::testRect()
485 {
486 GDIMetaFile aGDIMetaFile;
487 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
488 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
489
490 pVirtualDev->SetLineColor(Color(0x123456));
491 pVirtualDev->SetFillColor(Color(0x654321));
492
493 pVirtualDev->DrawRect(tools::Rectangle(Point(1, 2), Size(4, 4)));
494
495 checkRect(writeAndReadStream(aGDIMetaFile));
496 checkRect(readFile(u"rect.svm"));
497 }
498
checkRoundRect(const GDIMetaFile & rMetaFile)499 void SvmTest::checkRoundRect(const GDIMetaFile& rMetaFile)
500 {
501 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
502
503 assertXPath(pDoc, "/metafile/linecolor[5]", "color", "#123456");
504 assertXPath(pDoc, "/metafile/fillcolor[5]", "color", "#654321");
505
506 assertXPathAttrs(pDoc, "/metafile/roundrect[1]", {
507 {"left", "1"}, {"top", "2"},
508 {"right", "4"}, {"bottom", "5"},
509 {"horizontalround", "1"}, {"verticalround", "2"}
510 });
511 }
512
testRoundRect()513 void SvmTest::testRoundRect()
514 {
515 GDIMetaFile aGDIMetaFile;
516 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
517 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
518
519 pVirtualDev->SetLineColor(Color(0x123456));
520 pVirtualDev->SetFillColor(Color(0x654321));
521
522 pVirtualDev->DrawRect(tools::Rectangle(Point(1, 2), Size(4, 4)), 1, 2);
523
524 checkRoundRect(writeAndReadStream(aGDIMetaFile));
525 checkRoundRect(readFile(u"roundrect.svm"));
526 }
527
checkEllipse(const GDIMetaFile & rMetaFile)528 void SvmTest::checkEllipse(const GDIMetaFile& rMetaFile)
529 {
530 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
531
532 assertXPath(pDoc, "/metafile/linecolor[5]", "color", "#123456");
533 assertXPath(pDoc, "/metafile/fillcolor[5]", "color", "#654321");
534
535 assertXPathAttrs(pDoc, "/metafile/ellipse[1]", {
536 {"left", "1"}, {"top", "2"},
537 {"right", "4"}, {"bottom", "5"},
538 });
539 }
540
testEllipse()541 void SvmTest::testEllipse()
542 {
543 GDIMetaFile aGDIMetaFile;
544 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
545 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
546
547 pVirtualDev->SetLineColor(Color(0x123456));
548 pVirtualDev->SetFillColor(Color(0x654321));
549
550 pVirtualDev->DrawEllipse(tools::Rectangle(Point(1, 2), Size(4, 4)));
551
552 checkEllipse(writeAndReadStream(aGDIMetaFile));
553 checkEllipse(readFile(u"ellipse.svm"));
554 }
555
checkArc(const GDIMetaFile & rMetaFile)556 void SvmTest::checkArc(const GDIMetaFile& rMetaFile)
557 {
558 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
559
560 assertXPath(pDoc, "/metafile/linecolor[5]", "color", "#123456");
561 assertXPath(pDoc, "/metafile/fillcolor[5]", "color", "#654321");
562
563 assertXPathAttrs(pDoc, "/metafile/arc[1]", {
564 {"left", "1"}, {"top", "2"},
565 {"right", "4"}, {"bottom", "5"},
566
567 {"startx", "10"}, {"starty", "11"},
568 {"endx", "12"}, {"endy", "13"},
569 });
570 }
571
testArc()572 void SvmTest::testArc()
573 {
574 GDIMetaFile aGDIMetaFile;
575 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
576 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
577
578 pVirtualDev->SetLineColor(Color(0x123456));
579 pVirtualDev->SetFillColor(Color(0x654321));
580
581 pVirtualDev->DrawArc(tools::Rectangle(Point(1, 2), Size(4, 4)), Point(10, 11), Point(12, 13));
582
583 checkArc(writeAndReadStream(aGDIMetaFile));
584 checkArc(readFile(u"arc.svm"));
585 }
586
checkPie(const GDIMetaFile & rMetaFile)587 void SvmTest::checkPie(const GDIMetaFile& rMetaFile)
588 {
589 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
590
591 assertXPath(pDoc, "/metafile/linecolor[5]", "color", "#123456");
592 assertXPath(pDoc, "/metafile/fillcolor[5]", "color", "#654321");
593
594 assertXPathAttrs(pDoc, "/metafile/pie[1]", {
595 {"left", "11"}, {"top", "12"},
596 {"right", "14"}, {"bottom", "15"},
597
598 {"startx", "20"}, {"starty", "21"},
599 {"endx", "22"}, {"endy", "23"},
600 });
601 }
602
testPie()603 void SvmTest::testPie()
604 {
605 GDIMetaFile aGDIMetaFile;
606 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
607 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
608
609 pVirtualDev->SetLineColor(Color(0x123456));
610 pVirtualDev->SetFillColor(Color(0x654321));
611
612 pVirtualDev->DrawPie(tools::Rectangle(Point(11, 12), Size(4, 4)), Point(20, 21), Point(22, 23));
613
614 checkPie(writeAndReadStream(aGDIMetaFile));
615 checkPie(readFile(u"pie.svm"));
616 }
617
checkChord(const GDIMetaFile & rMetaFile)618 void SvmTest::checkChord(const GDIMetaFile& rMetaFile)
619 {
620 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
621
622 assertXPath(pDoc, "/metafile/linecolor[5]", "color", "#123456");
623 assertXPath(pDoc, "/metafile/fillcolor[5]", "color", "#654321");
624
625 assertXPathAttrs(pDoc, "/metafile/chord[1]", {
626 {"left", "21"}, {"top", "22"},
627 {"right", "24"}, {"bottom", "25"},
628
629 {"startx", "30"}, {"starty", "31"},
630 {"endx", "32"}, {"endy", "33"},
631 });
632 }
633
testChord()634 void SvmTest::testChord()
635 {
636 GDIMetaFile aGDIMetaFile;
637 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
638 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
639
640 pVirtualDev->SetLineColor(Color(0x123456));
641 pVirtualDev->SetFillColor(Color(0x654321));
642
643 pVirtualDev->DrawChord(tools::Rectangle(Point(21, 22), Size(4, 4)), Point(30, 31), Point(32, 33));
644
645 checkChord(writeAndReadStream(aGDIMetaFile));
646 checkChord(readFile(u"chord.svm"));
647 }
648
checkPolyLine(const GDIMetaFile & rMetaFile)649 void SvmTest::checkPolyLine(const GDIMetaFile& rMetaFile)
650 {
651 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
652
653 assertXPathAttrs(pDoc, "/metafile/polyline[1]", {
654 {"style", "solid"}, {"width", "0"},
655 {"dashlen", "0"}, {"dashcount", "0"},
656 {"dotlen", "0"}, {"dotcount", "0"},
657 {"distance", "0"},
658 {"join", "round"}, {"cap", "butt"}
659 });
660
661 assertXPathAttrs(pDoc, "/metafile/polyline[1]/point[1]", {{"x", "1"}, {"y", "8"}});
662 assertXPathAttrs(pDoc, "/metafile/polyline[1]/point[2]", {{"x", "2"}, {"y", "7"}});
663 assertXPathAttrs(pDoc, "/metafile/polyline[1]/point[3]", {{"x", "3"}, {"y", "6"}});
664
665 assertXPathAttrs(pDoc, "/metafile/polyline[2]", {
666 {"style", "dash"}, {"width", "7"},
667 {"dashlen", "5"}, {"dashcount", "4"},
668 {"dotlen", "3"}, {"dotcount", "2"},
669 {"distance", "1"},
670 {"join", "miter"}, {"cap", "round"}
671 });
672 assertXPathAttrs(pDoc, "/metafile/polyline[2]/point[1]", {{"x", "8"}, {"y", "1"}, {"flags", "normal"}});
673 assertXPathAttrs(pDoc, "/metafile/polyline[2]/point[2]", {{"x", "7"}, {"y", "2"}, {"flags", "control"}});
674 assertXPathAttrs(pDoc, "/metafile/polyline[2]/point[3]", {{"x", "6"}, {"y", "3"}, {"flags", "smooth"}});
675 assertXPathAttrs(pDoc, "/metafile/polyline[2]/point[4]", {{"x", "5"}, {"y", "4"}, {"flags", "symmetric"}});
676 }
677
testPolyLine()678 void SvmTest::testPolyLine()
679 {
680 GDIMetaFile aGDIMetaFile;
681 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
682 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
683
684 tools::Polygon aPolygon(3);
685 aPolygon.SetPoint(Point(1, 8), 0);
686 aPolygon.SetPoint(Point(2, 7), 1);
687 aPolygon.SetPoint(Point(3, 6), 2);
688
689 pVirtualDev->DrawPolyLine(aPolygon);
690
691 tools::Polygon aPolygonWithControl(4);
692 aPolygonWithControl.SetPoint(Point(8, 1), 0);
693 aPolygonWithControl.SetPoint(Point(7, 2), 1);
694 aPolygonWithControl.SetPoint(Point(6, 3), 2);
695 aPolygonWithControl.SetPoint(Point(5, 4), 3);
696
697 aPolygonWithControl.SetFlags(0, PolyFlags::Normal);
698 aPolygonWithControl.SetFlags(1, PolyFlags::Control);
699 aPolygonWithControl.SetFlags(2, PolyFlags::Smooth);
700 aPolygonWithControl.SetFlags(3, PolyFlags::Symmetric);
701
702 LineInfo aLineInfo(LineStyle::Dash, 7);
703 aLineInfo.SetDashLen(5);
704 aLineInfo.SetDashCount(4);
705 aLineInfo.SetDotLen(3);
706 aLineInfo.SetDotCount(2);
707 aLineInfo.SetDistance(1);
708 aLineInfo.SetLineJoin(basegfx::B2DLineJoin::Miter);
709 aLineInfo.SetLineCap(css::drawing::LineCap_ROUND);
710
711 pVirtualDev->DrawPolyLine(aPolygonWithControl, aLineInfo);
712
713 checkPolyLine(writeAndReadStream(aGDIMetaFile));
714 checkPolyLine(readFile(u"polyline.svm"));
715 }
716
checkPolygon(const GDIMetaFile & rMetaFile)717 void SvmTest::checkPolygon(const GDIMetaFile& rMetaFile)
718 {
719 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
720
721 assertXPathAttrs(pDoc, "/metafile/polygon[1]/point[1]", {{"x", "1"}, {"y", "8"}});
722 assertXPathAttrs(pDoc, "/metafile/polygon[1]/point[2]", {{"x", "2"}, {"y", "7"}});
723 assertXPathAttrs(pDoc, "/metafile/polygon[1]/point[3]", {{"x", "3"}, {"y", "6"}});
724
725 assertXPathAttrs(pDoc, "/metafile/polygon[2]/point[1]", {{"x", "8"}, {"y", "1"}, {"flags", "normal"}});
726 assertXPathAttrs(pDoc, "/metafile/polygon[2]/point[2]", {{"x", "7"}, {"y", "2"}, {"flags", "control"}});
727 assertXPathAttrs(pDoc, "/metafile/polygon[2]/point[3]", {{"x", "6"}, {"y", "3"}, {"flags", "smooth"}});
728 assertXPathAttrs(pDoc, "/metafile/polygon[2]/point[4]", {{"x", "5"}, {"y", "4"}, {"flags", "symmetric"}});
729 }
730
testPolygon()731 void SvmTest::testPolygon()
732 {
733 GDIMetaFile aGDIMetaFile;
734 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
735 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
736
737 tools::Polygon aPolygon(3);
738 aPolygon.SetPoint(Point(1, 8), 0);
739 aPolygon.SetPoint(Point(2, 7), 1);
740 aPolygon.SetPoint(Point(3, 6), 2);
741
742 pVirtualDev->DrawPolygon(aPolygon);
743
744 tools::Polygon aPolygonWithControl(4);
745 aPolygonWithControl.SetPoint(Point(8, 1), 0);
746 aPolygonWithControl.SetPoint(Point(7, 2), 1);
747 aPolygonWithControl.SetPoint(Point(6, 3), 2);
748 aPolygonWithControl.SetPoint(Point(5, 4), 3);
749
750 aPolygonWithControl.SetFlags(0, PolyFlags::Normal);
751 aPolygonWithControl.SetFlags(1, PolyFlags::Control);
752 aPolygonWithControl.SetFlags(2, PolyFlags::Smooth);
753 aPolygonWithControl.SetFlags(3, PolyFlags::Symmetric);
754
755 pVirtualDev->DrawPolygon(aPolygonWithControl);
756
757 checkPolygon(writeAndReadStream(aGDIMetaFile));
758 checkPolygon(readFile(u"polygon.svm"));
759 }
760
checkPolyPolygon(const GDIMetaFile & rMetaFile)761 void SvmTest::checkPolyPolygon(const GDIMetaFile& rMetaFile)
762 {
763 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
764
765 assertXPathAttrs(pDoc, "/metafile/polypolygon[1]/polygon[1]/point[1]", {{"x", "1"}, {"y", "8"}});
766 assertXPathAttrs(pDoc, "/metafile/polypolygon[1]/polygon[1]/point[2]", {{"x", "2"}, {"y", "7"}});
767 assertXPathAttrs(pDoc, "/metafile/polypolygon[1]/polygon[1]/point[3]", {{"x", "3"}, {"y", "6"}});
768
769 assertXPathAttrs(pDoc, "/metafile/polypolygon[1]/polygon[2]/point[1]", {{"x", "8"}, {"y", "1"}, {"flags", "normal"}});
770 assertXPathAttrs(pDoc, "/metafile/polypolygon[1]/polygon[2]/point[2]", {{"x", "7"}, {"y", "2"}, {"flags", "control"}});
771 assertXPathAttrs(pDoc, "/metafile/polypolygon[1]/polygon[2]/point[3]", {{"x", "6"}, {"y", "3"}, {"flags", "smooth"}});
772 assertXPathAttrs(pDoc, "/metafile/polypolygon[1]/polygon[2]/point[4]", {{"x", "5"}, {"y", "4"}, {"flags", "symmetric"}});
773 }
774
testPolyPolygon()775 void SvmTest::testPolyPolygon()
776 {
777 GDIMetaFile aGDIMetaFile;
778 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
779 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
780
781 tools::Polygon aPolygon(3);
782 aPolygon.SetPoint(Point(1, 8), 0);
783 aPolygon.SetPoint(Point(2, 7), 1);
784 aPolygon.SetPoint(Point(3, 6), 2);
785
786 tools::Polygon aPolygonWithControl(4);
787 aPolygonWithControl.SetPoint(Point(8, 1), 0);
788 aPolygonWithControl.SetPoint(Point(7, 2), 1);
789 aPolygonWithControl.SetPoint(Point(6, 3), 2);
790 aPolygonWithControl.SetPoint(Point(5, 4), 3);
791
792 aPolygonWithControl.SetFlags(0, PolyFlags::Normal);
793 aPolygonWithControl.SetFlags(1, PolyFlags::Control);
794 aPolygonWithControl.SetFlags(2, PolyFlags::Smooth);
795 aPolygonWithControl.SetFlags(3, PolyFlags::Symmetric);
796
797 tools::PolyPolygon aPolyPolygon(2);
798 aPolyPolygon.Insert(aPolygon);
799 aPolyPolygon.Insert(aPolygonWithControl);
800
801 pVirtualDev->DrawPolyPolygon(aPolyPolygon);
802
803 checkPolyPolygon(writeAndReadStream(aGDIMetaFile));
804 checkPolyPolygon(readFile(u"polypolygon.svm"));
805 }
806
checkText(const GDIMetaFile & rMetaFile)807 void SvmTest::checkText(const GDIMetaFile& rMetaFile)
808 {
809 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
810
811 assertXPathAttrs(pDoc, "/metafile/text[1]", {
812 {"x", "4"}, {"y", "6"}, {"index", "1"}, {"length", "2"},
813 });
814
815 assertXPathContent(pDoc, "/metafile/text[1]/textcontent", "xABC");
816 }
817
testText()818 void SvmTest::testText()
819 {
820 GDIMetaFile aGDIMetaFile;
821 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
822 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
823
824 pVirtualDev->DrawText(Point(4,6), "xABC", 1, 2);
825
826 checkText(writeAndReadStream(aGDIMetaFile));
827 checkText(readFile(u"text.svm"));
828 }
829
checkTextArray(const GDIMetaFile & rMetaFile)830 void SvmTest::checkTextArray(const GDIMetaFile& rMetaFile)
831 {
832 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
833
834 assertXPathAttrs(pDoc, "/metafile/textarray[1]", {
835 {"x", "4"}, {"y", "6"}, {"index", "1"}, {"length", "4"},
836 });
837 assertXPathContent(pDoc, "/metafile/textarray[1]/dxarray", "15 20 25 ");
838 assertXPathContent(pDoc, "/metafile/textarray[1]/text", "123456");
839 }
840
testTextArray()841 void SvmTest::testTextArray()
842 {
843 GDIMetaFile aGDIMetaFile;
844 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
845 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
846 tools::Long const aDX[] = { 10, 15, 20, 25, 30, 35 };
847 pVirtualDev->DrawTextArray(Point(4,6), "123456", aDX, 1, 4);
848
849 checkTextArray(writeAndReadStream(aGDIMetaFile));
850 checkTextArray(readFile(u"textarray.svm"));
851 }
852
checkstretchText(const GDIMetaFile & rMetaFile)853 void SvmTest::checkstretchText(const GDIMetaFile& rMetaFile)
854 {
855 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
856
857 assertXPathAttrs(pDoc, "/metafile/stretchtext[1]", {
858 {"x", "4"}, {"y", "6"}, {"index", "1"}, {"length", "4"}, {"width", "10"}
859 });
860
861 assertXPathContent(pDoc, "/metafile/stretchtext[1]/textcontent", "123456");
862 }
863
teststretchText()864 void SvmTest::teststretchText()
865 {
866 GDIMetaFile aGDIMetaFile;
867 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
868 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
869 pVirtualDev->DrawStretchText(Point(4,6), 10, "123456", 1, 4);
870
871 checkstretchText(writeAndReadStream(aGDIMetaFile));
872 checkstretchText(readFile(u"strecthtext.svm"));
873 }
874
checkTextRect(const GDIMetaFile & rMetaFile)875 void SvmTest::checkTextRect(const GDIMetaFile& rMetaFile)
876 {
877 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
878
879 assertXPathAttrs(pDoc, "/metafile/textrect[1]", {
880 {"left", "0"}, {"top", "0"}, {"right", "4"}, {"bottom", "4"}
881 });
882 assertXPathContent(pDoc, "/metafile/textrect[1]/textcontent", "123456");
883 assertXPathContent(pDoc, "/metafile/textrect[1]/style", "Center");
884 }
885
testTextRect()886 void SvmTest::testTextRect()
887 {
888 GDIMetaFile aGDIMetaFile;
889 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
890 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
891 pVirtualDev->DrawText(tools::Rectangle(Point(0,0), Size(5,5)), "123456", DrawTextFlags::Center);
892
893 checkTextRect(writeAndReadStream(aGDIMetaFile));
894 checkTextRect(readFile(u"textrectangle.svm"));
895 }
896
checkTextLine(const GDIMetaFile & rMetaFile)897 void SvmTest::checkTextLine(const GDIMetaFile& rMetaFile)
898 {
899 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
900
901 assertXPathAttrs(pDoc, "/metafile/textline[1]", {
902 {"x", "4"}, {"y", "6"}, {"width", "10"},
903 {"strikeout", "single"}, {"underline", "single"}, {"overline", "single"}
904 });
905 }
906
testTextLine()907 void SvmTest::testTextLine()
908 {
909 GDIMetaFile aGDIMetaFile;
910 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
911 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
912 pVirtualDev->DrawTextLine(Point(4,6), 10, STRIKEOUT_SINGLE, LINESTYLE_SINGLE, LINESTYLE_SINGLE);
913
914 checkTextLine(writeAndReadStream(aGDIMetaFile));
915 checkTextLine(readFile(u"textline.svm"));
916 }
917
checkBitmaps(const GDIMetaFile & rMetaFile)918 void SvmTest::checkBitmaps(const GDIMetaFile& rMetaFile)
919 {
920 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
921
922 if (SkiaHelper::isVCLSkiaEnabled())
923 return; // TODO SKIA using CRCs is broken (the idea of it)
924
925 assertXPathAttrs(pDoc, "/metafile/bmp[1]", {{"x", "1"}, {"y", "2"}, {"crc", "b8dee5da"}});
926 assertXPathAttrs(pDoc, "/metafile/bmpscale[1]", {
927 {"x", "1"}, {"y", "2"}, {"width", "3"}, {"height", "4"}, {"crc", "281fc589"}
928 });
929 assertXPathAttrs(pDoc, "/metafile/bmpscalepart[1]", {
930 {"destx", "1"}, {"desty", "2"}, {"destwidth", "3"}, {"destheight", "4"},
931 {"srcx", "2"}, {"srcy", "1"}, {"srcwidth", "4"}, {"srcheight", "3"},
932 {"crc", "5e01ddcc"}
933 });
934 }
935
testBitmaps()936 void SvmTest::testBitmaps()
937 {
938 GDIMetaFile aGDIMetaFile;
939 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
940 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
941
942 Bitmap aBitmap1(Size(4,4), vcl::PixelFormat::N24_BPP);
943 {
944 BitmapScopedWriteAccess pAccess(aBitmap1);
945 pAccess->Erase(COL_RED);
946 }
947 Bitmap aBitmap2(Size(4,4), vcl::PixelFormat::N24_BPP);
948 {
949 BitmapScopedWriteAccess pAccess(aBitmap2);
950 pAccess->Erase(COL_GREEN);
951 }
952 Bitmap aBitmap3(Size(4,4), vcl::PixelFormat::N24_BPP);
953 {
954 BitmapScopedWriteAccess pAccess(aBitmap3);
955 pAccess->Erase(COL_BLUE);
956 }
957 pVirtualDev->DrawBitmap(Point(1, 2), aBitmap1);
958 pVirtualDev->DrawBitmap(Point(1, 2), Size(3, 4), aBitmap2);
959 pVirtualDev->DrawBitmap(Point(1, 2), Size(3, 4), Point(2, 1), Size(4, 3), aBitmap3);
960
961 {
962 GDIMetaFile aReloadedGDIMetaFile = writeAndReadStream(aGDIMetaFile);
963 checkBitmaps(aReloadedGDIMetaFile);
964 checkRendering(pVirtualDev, aReloadedGDIMetaFile);
965 }
966 {
967 GDIMetaFile aFileGDIMetaFile = readFile(u"bitmaps.svm");
968 checkBitmaps(aFileGDIMetaFile);
969 checkRendering(pVirtualDev, aFileGDIMetaFile);
970 }
971 }
972
checkBitmapExs(const GDIMetaFile & rMetaFile)973 void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile)
974 {
975 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
976
977 if (SkiaHelper::isVCLSkiaEnabled())
978 return; // TODO SKIA using CRCs is broken (the idea of it)
979
980 std::vector<OUString> aExpectedCRC;
981 aExpectedCRC.insert(aExpectedCRC.end(),
982 {
983 "d8377d4f",
984 "281fc589",
985 "5e01ddcc",
986 "4df0e464",
987 "4322ee3a",
988 "3c80d829", // 4-bit color bitmap - same as 8-bit color bitmap
989 "3c80d829",
990 "71efc447",
991 });
992
993 assertXPathAttrs(pDoc, "/metafile/bmpex[1]", {
994 {"x", "1"}, {"y", "1"}, {"crc", aExpectedCRC[0]}, {"transparenttype", "bitmap"}
995 });
996 assertXPathAttrs(pDoc, "/metafile/bmpexscale[1]", {
997 {"x", "5"}, {"y", "0"}, {"width", "2"}, {"height", "3"},
998 {"crc", aExpectedCRC[1]}, {"transparenttype", "bitmap"}
999 });
1000 assertXPathAttrs(pDoc, "/metafile/bmpexscalepart[1]", {
1001 {"destx", "7"}, {"desty", "1"}, {"destwidth", "2"}, {"destheight", "2"},
1002 {"srcx", "0"}, {"srcy", "0"}, {"srcwidth", "3"}, {"srcheight", "4"},
1003 {"crc", aExpectedCRC[2]}, {"transparenttype", "bitmap"}
1004 });
1005
1006 #ifndef MACOSX
1007 assertXPathAttrs(pDoc, "/metafile/bmpex[2]", {
1008 {"x", "6"}, {"y", "6"}, {"crc", aExpectedCRC[3]}, {"transparenttype", "bitmap"}
1009 });
1010 assertXPathAttrs(pDoc, "/metafile/bmpex[3]", {
1011 {"x", "0"}, {"y", "6"}, {"crc", aExpectedCRC[4]}, {"transparenttype", "bitmap"}
1012 });
1013 assertXPathAttrs(pDoc, "/metafile/bmpex[4]", {
1014 {"x", "2"}, {"y", "6"}, {"crc", aExpectedCRC[5]}, {"transparenttype", "bitmap"}
1015 });
1016 assertXPathAttrs(pDoc, "/metafile/bmpex[5]", {
1017 {"x", "0"}, {"y", "8"}, {"crc", aExpectedCRC[6]}, {"transparenttype", "bitmap"}
1018 });
1019 assertXPathAttrs(pDoc, "/metafile/bmpex[6]", {
1020 {"x", "2"}, {"y", "8"}, {"crc", aExpectedCRC[7]}, {"transparenttype", "bitmap"}
1021 });
1022 #endif
1023 }
1024
testBitmapExs()1025 void SvmTest::testBitmapExs()
1026 {
1027 GDIMetaFile aGDIMetaFile;
1028 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1029 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1030
1031 // DrawBitmapEx
1032 {
1033 Bitmap aBitmap(Size(4,4), vcl::PixelFormat::N24_BPP);
1034 {
1035 BitmapScopedWriteAccess pAccess(aBitmap);
1036 pAccess->Erase(COL_YELLOW);
1037 }
1038
1039 pVirtualDev->DrawBitmapEx(Point(1, 1), BitmapEx(aBitmap, COL_WHITE));
1040 }
1041
1042 // DrawBitmapEx - Scale
1043 {
1044 Bitmap aBitmap(Size(4,4), vcl::PixelFormat::N24_BPP);
1045 {
1046 BitmapScopedWriteAccess pAccess(aBitmap);
1047 pAccess->Erase(COL_GREEN);
1048 }
1049 pVirtualDev->DrawBitmapEx(Point(5, 0), Size(2, 3), BitmapEx(aBitmap, COL_WHITE));
1050 }
1051
1052 // DrawBitmapEx - Scale - Part
1053 {
1054 Bitmap aBitmap(Size(4,4), vcl::PixelFormat::N24_BPP);
1055 {
1056 BitmapScopedWriteAccess pAccess(aBitmap);
1057 pAccess->Erase(COL_BLUE);
1058 }
1059 pVirtualDev->DrawBitmapEx(Point(7, 1), Size(2, 2), Point(0, 0), Size(3, 4), BitmapEx(aBitmap, COL_WHITE));
1060 }
1061
1062 // DrawBitmapEx - 50% transparent
1063 {
1064 Bitmap aBitmap(Size(4, 4), vcl::PixelFormat::N24_BPP);
1065 AlphaMask aAlpha(Size(4, 4));
1066 {
1067 BitmapScopedWriteAccess pAccess(aBitmap);
1068 pAccess->Erase(COL_MAGENTA);
1069
1070 AlphaScopedWriteAccess pAlphaAccess(aAlpha);
1071 pAlphaAccess->Erase(Color(128, 128, 128));
1072 }
1073 pVirtualDev->DrawBitmapEx(Point(6, 6), BitmapEx(aBitmap, aAlpha));
1074 }
1075
1076 // DrawBitmapEx - 1-bit
1077 {
1078 Bitmap aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP);
1079 {
1080 BitmapScopedWriteAccess pAccess(aBitmap);
1081 pAccess->Erase(COL_MAGENTA);
1082 }
1083 aBitmap.Convert(BmpConversion::N1BitThreshold);
1084 pVirtualDev->DrawBitmapEx(Point(0, 6), BitmapEx(aBitmap, COL_WHITE));
1085 }
1086
1087 // DrawBitmapEx - used to be 4-bit
1088 {
1089 Bitmap aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP);
1090 {
1091 BitmapScopedWriteAccess pAccess(aBitmap);
1092 pAccess->Erase(COL_MAGENTA);
1093 }
1094 aBitmap.Convert(BmpConversion::N8BitColors);
1095 pVirtualDev->DrawBitmapEx(Point(2, 6), BitmapEx(aBitmap, COL_WHITE));
1096 }
1097
1098 // DrawBitmapEx - 8-bit Color
1099 {
1100 Bitmap aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP);
1101 {
1102 BitmapScopedWriteAccess pAccess(aBitmap);
1103 pAccess->Erase(COL_MAGENTA);
1104 }
1105 aBitmap.Convert(BmpConversion::N8BitColors);
1106 pVirtualDev->DrawBitmapEx(Point(0, 8), BitmapEx(aBitmap, COL_WHITE));
1107 }
1108
1109 // DrawBitmapEx - 8-bit Grey
1110 {
1111 Bitmap aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP);
1112 {
1113 BitmapScopedWriteAccess pAccess(aBitmap);
1114 pAccess->Erase(COL_MAGENTA);
1115 }
1116 aBitmap.Convert(BmpConversion::N8BitGreys);
1117 pVirtualDev->DrawBitmapEx(Point(2, 8), BitmapEx(aBitmap, COL_WHITE));
1118 }
1119
1120 {
1121 GDIMetaFile aReloadedGDIMetaFile = writeAndReadStream(aGDIMetaFile);
1122 checkBitmapExs(aReloadedGDIMetaFile);
1123 checkRendering(pVirtualDev, aReloadedGDIMetaFile);
1124 }
1125 {
1126 GDIMetaFile aFileGDIMetaFile = readFile(u"bitmapexs.svm");
1127 checkBitmapExs(aFileGDIMetaFile);
1128 checkRendering(pVirtualDev, aFileGDIMetaFile);
1129 }
1130 }
1131
checkMasks(const GDIMetaFile & rMetaFile)1132 void SvmTest::checkMasks(const GDIMetaFile& rMetaFile)
1133 {
1134 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1135
1136 assertXPathAttrs(pDoc, "/metafile/mask[1]", {
1137 {"x", "1"}, {"y", "2"},
1138 {"color", "#000000"}
1139 });
1140 assertXPathAttrs(pDoc, "/metafile/maskscale[1]", {
1141 {"x", "1"}, {"y", "2"}, {"width", "3"}, {"height", "4"},
1142 {"color", "#000000"}
1143 });
1144 assertXPathAttrs(pDoc, "/metafile/maskscalepart[1]", {
1145 {"destx", "1"}, {"desty", "2"}, {"destwidth", "3"}, {"destheight", "4"},
1146 {"srcx", "2"}, {"srcy", "1"}, {"srcwidth", "4"}, {"srcheight", "3"},
1147 {"color", "#ff0000"}
1148 });
1149 }
1150
1151 // TODO: Masks are kind-of special - we don't persist the color attribute (it is
1152 // always #000000) of the meta-action (which is wrong), but rely on alpha to do
1153 // the right thing.
testMasks()1154 void SvmTest::testMasks()
1155 {
1156 GDIMetaFile aGDIMetaFile;
1157 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1158 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1159
1160 Bitmap aBitmap1(Size(4,4), vcl::PixelFormat::N24_BPP);
1161 {
1162 BitmapScopedWriteAccess pAccess(aBitmap1);
1163 pAccess->Erase(COL_RED);
1164 }
1165 Bitmap aBitmap2(Size(4,4), vcl::PixelFormat::N24_BPP);
1166 {
1167 BitmapScopedWriteAccess pAccess(aBitmap2);
1168 pAccess->Erase(COL_GREEN);
1169 }
1170 Bitmap aBitmap3(Size(4,4), vcl::PixelFormat::N24_BPP);
1171 {
1172 BitmapScopedWriteAccess pAccess(aBitmap3);
1173 pAccess->Erase(COL_BLUE);
1174 }
1175
1176 pVirtualDev->DrawMask(Point(1, 2), aBitmap1, COL_LIGHTRED);
1177 pVirtualDev->DrawMask(Point(1, 2), Size(3, 4), aBitmap2, COL_LIGHTRED);
1178 pVirtualDev->DrawMask(Point(1, 2), Size(3, 4), Point(2, 1), Size(4, 3), aBitmap3, COL_LIGHTRED, MetaActionType::MASKSCALEPART);
1179
1180 checkMasks(writeAndReadStream(aGDIMetaFile));
1181 checkMasks(readFile(u"masks.svm"));
1182 }
1183
checkGradient(const GDIMetaFile & rMetaFile)1184 void SvmTest::checkGradient(const GDIMetaFile& rMetaFile)
1185 {
1186 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1187
1188 assertXPathAttrs(pDoc, "/metafile/gradient[1]", {
1189 {"style", "Linear"},
1190 {"startcolor", "#ffffff"},
1191 {"endcolor", "#000000"},
1192 {"angle", "0"},
1193 {"border", "0"},
1194 {"offsetx", "50"},
1195 {"offsety", "50"},
1196 {"startintensity", "100"},
1197 {"endintensity", "100"},
1198 {"steps", "0"},
1199 });
1200 assertXPathAttrs(pDoc, "/metafile/gradient[1]/rectangle", {
1201 {"left", "1"},
1202 {"top", "2"},
1203 {"right", "4"},
1204 {"bottom", "6"},
1205 });
1206
1207 assertXPathAttrs(pDoc, "/metafile/gradient[2]", {
1208 {"style", "Radial"},
1209 {"startcolor", "#ff0000"},
1210 {"endcolor", "#00ff00"},
1211 {"angle", "55"},
1212 {"border", "10"},
1213 {"offsetx", "22"},
1214 {"offsety", "24"},
1215 {"startintensity", "4"},
1216 {"endintensity", "14"},
1217 {"steps", "64"},
1218 });
1219 assertXPathAttrs(pDoc, "/metafile/gradient[2]/rectangle", {
1220 {"left", "3"},
1221 {"top", "4"},
1222 {"right", "3"},
1223 {"bottom", "5"},
1224 });
1225 }
1226
testGradient()1227 void SvmTest::testGradient()
1228 {
1229 GDIMetaFile aGDIMetaFile;
1230 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1231 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1232
1233 tools::Rectangle aRectangle(Point(1, 2), Size(4,5));
1234
1235 Gradient aGradient(GradientStyle::Linear, COL_WHITE, COL_BLACK);
1236 pVirtualDev->DrawGradient(aRectangle, aGradient);
1237
1238 tools::Rectangle aRectangle2(Point(3, 4), Size(1,2));
1239
1240 Gradient aGradient2;
1241 aGradient2.SetStyle(GradientStyle::Radial);
1242 aGradient2.SetStartColor(COL_LIGHTRED);
1243 aGradient2.SetEndColor(COL_LIGHTGREEN);
1244 aGradient2.SetAngle(Degree10(55));
1245 aGradient2.SetBorder(10);
1246 aGradient2.SetOfsX(22);
1247 aGradient2.SetOfsY(24);
1248 aGradient2.SetStartIntensity(4);
1249 aGradient2.SetEndIntensity(14);
1250 aGradient2.SetSteps(64);
1251 pVirtualDev->DrawGradient(aRectangle2, aGradient2);
1252
1253 checkGradient(writeAndReadStream(aGDIMetaFile));
1254 checkGradient(readFile(u"gradient.svm"));
1255 }
1256
checkGradientEx(const GDIMetaFile & rMetaFile)1257 void SvmTest::checkGradientEx(const GDIMetaFile& rMetaFile)
1258 {
1259 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1260
1261 assertXPathAttrs(pDoc, "/metafile/gradientex[1]", {
1262 {"style", "Linear"},
1263 {"startcolor", "#ffffff"},
1264 {"endcolor", "#000000"},
1265 {"angle", "0"},
1266 {"border", "0"},
1267 {"offsetx", "50"},
1268 {"offsety", "50"},
1269 {"startintensity", "100"},
1270 {"endintensity", "100"},
1271 {"steps", "0"}
1272 });
1273 assertXPathAttrs(pDoc, "/metafile/gradientex[1]/polygon/point[1]", {
1274 {"x", "1"},
1275 {"y", "8"}
1276 });
1277 assertXPathAttrs(pDoc, "/metafile/gradientex[1]/polygon/point[2]", {
1278 {"x", "2"},
1279 {"y", "7"}
1280 });
1281 assertXPathAttrs(pDoc, "/metafile/gradientex[1]/polygon/point[3]", {
1282 {"x", "3"},
1283 {"y", "6"}
1284 });
1285 assertXPathAttrs(pDoc, "/metafile/gradientex[2]", {
1286 {"style", "Axial"},
1287 {"startcolor", "#ff00ff"},
1288 {"endcolor", "#008080"},
1289 {"angle", "55"},
1290 {"border", "10"},
1291 {"offsetx", "22"},
1292 {"offsety", "24"},
1293 {"startintensity", "4"},
1294 {"endintensity", "14"},
1295 {"steps", "64"}
1296 });
1297 assertXPathAttrs(pDoc, "/metafile/gradientex[2]/polygon[1]/point[1]", {
1298 {"x", "1"},
1299 {"y", "2"}
1300 });
1301 assertXPathAttrs(pDoc, "/metafile/gradientex[2]/polygon[1]/point[2]", {
1302 {"x", "3"},
1303 {"y", "4"}
1304 });
1305 assertXPathAttrs(pDoc, "/metafile/gradientex[2]/polygon[2]/point[1]", {
1306 {"x", "8"},
1307 {"y", "9"}
1308 });
1309 assertXPathAttrs(pDoc, "/metafile/gradientex[2]/polygon[2]/point[2]", {
1310 {"x", "6"},
1311 {"y", "7"}
1312 });
1313 }
1314
testGradientEx()1315 void SvmTest::testGradientEx()
1316 {
1317 GDIMetaFile aGDIMetaFile;
1318 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1319 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1320
1321 tools::Polygon aPolygon(3);
1322 aPolygon.SetPoint(Point(1, 8), 0);
1323 aPolygon.SetPoint(Point(2, 7), 1);
1324 aPolygon.SetPoint(Point(3, 6), 2);
1325
1326 tools::PolyPolygon aPolyPolygon(1);
1327 aPolyPolygon.Insert(aPolygon);
1328
1329 Gradient aGradient(GradientStyle::Linear, COL_WHITE, COL_BLACK);
1330 pVirtualDev->DrawGradient(aPolyPolygon, aGradient);
1331
1332 tools::Polygon aPolygon2(2);
1333 aPolygon2.SetPoint(Point(1, 2), 0);
1334 aPolygon2.SetPoint(Point(3, 4), 1);
1335
1336 tools::Polygon aPolygon3(2);
1337 aPolygon3.SetPoint(Point(8, 9), 0);
1338 aPolygon3.SetPoint(Point(6, 7), 1);
1339
1340 tools::PolyPolygon aPolyPolygon2(1);
1341 aPolyPolygon2.Insert(aPolygon2);
1342 aPolyPolygon2.Insert(aPolygon3);
1343
1344 Gradient aGradient2;
1345 aGradient2.SetStyle(GradientStyle::Axial);
1346 aGradient2.SetStartColor(COL_LIGHTMAGENTA);
1347 aGradient2.SetEndColor(COL_CYAN);
1348 aGradient2.SetAngle(Degree10(55));
1349 aGradient2.SetBorder(10);
1350 aGradient2.SetOfsX(22);
1351 aGradient2.SetOfsY(24);
1352 aGradient2.SetStartIntensity(4);
1353 aGradient2.SetEndIntensity(14);
1354 aGradient2.SetSteps(64);
1355 pVirtualDev->DrawGradient(aPolyPolygon2, aGradient2);
1356
1357 checkGradientEx(writeAndReadStream(aGDIMetaFile));
1358 checkGradientEx(readFile(u"gradientex.svm"));
1359 }
1360
checkHatch(const GDIMetaFile & rMetaFile)1361 void SvmTest::checkHatch(const GDIMetaFile& rMetaFile)
1362 {
1363 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1364
1365 assertXPathAttrs(pDoc, "/metafile/hatch[1]/polygon/point[1]", {
1366 {"x", "1"}, {"y", "8"},
1367 });
1368 assertXPathAttrs(pDoc, "/metafile/hatch[1]/polygon/point[2]", {
1369 {"x", "2"}, {"y", "7"},
1370 });
1371 assertXPathAttrs(pDoc, "/metafile/hatch[1]/polygon/point[3]", {
1372 {"x", "3"}, {"y", "6"},
1373 });
1374
1375 assertXPathAttrs(pDoc, "/metafile/hatch[1]/hatch", {
1376 {"style", "Single"},
1377 {"color", "#ffff00"},
1378 {"distance", "15"},
1379 {"angle", "900"},
1380 });
1381 }
1382
testHatch()1383 void SvmTest::testHatch()
1384 {
1385 GDIMetaFile aGDIMetaFile;
1386 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1387 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1388
1389 tools::Polygon aPolygon(3);
1390 aPolygon.SetPoint(Point(1, 8), 0);
1391 aPolygon.SetPoint(Point(2, 7), 1);
1392 aPolygon.SetPoint(Point(3, 6), 2);
1393
1394 tools::PolyPolygon aPolyPolygon(1);
1395 aPolyPolygon.Insert(aPolygon);
1396
1397 Hatch aHatch(HatchStyle::Single, COL_YELLOW, 15, 900_deg10);
1398
1399 pVirtualDev->DrawHatch(aPolyPolygon, aHatch);
1400
1401 checkHatch(writeAndReadStream(aGDIMetaFile));
1402 checkHatch(readFile(u"hatch.svm"));
1403 }
1404
checkWallpaper(const GDIMetaFile & rMetaFile)1405 void SvmTest::checkWallpaper(const GDIMetaFile& rMetaFile)
1406 {
1407 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1408
1409 // Funny enough - we don't serialize the rectangle of the wallpaper so it's always EMPTY
1410 assertXPathAttrs(pDoc, "/metafile/wallpaper[1]",
1411 {
1412 {"left", "0"},
1413 {"top", "0"},
1414 {"right", "empty"},
1415 {"bottom", "empty"},
1416 });
1417
1418 assertXPathAttrs(pDoc, "/metafile/wallpaper[1]/wallpaper",
1419 {
1420 {"color", "#00ff00"},
1421 {"style", "Tile"},
1422 {"fixed", "true"},
1423 {"scrollable", "true"},
1424 });
1425 }
1426
testWallpaper()1427 void SvmTest::testWallpaper()
1428 {
1429 GDIMetaFile aGDIMetaFile;
1430 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1431 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1432
1433 Wallpaper aWallpaper(COL_LIGHTGREEN);
1434 pVirtualDev->DrawWallpaper(tools::Rectangle(Point(1, 1), Size(3, 3)), aWallpaper);
1435
1436 checkWallpaper(writeAndReadStream(aGDIMetaFile));
1437 checkWallpaper(readFile(u"wallpaper.svm"));
1438 }
1439
checkClipRegion(const GDIMetaFile & rMetaFile)1440 void SvmTest::checkClipRegion(const GDIMetaFile& rMetaFile)
1441 {
1442 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1443
1444 assertXPathAttrs(pDoc, "/metafile/clipregion[1]", {
1445 {"left", "2"},
1446 {"top", "2"},
1447 {"right", "5"},
1448 {"bottom", "5"},
1449 });
1450 }
1451
testClipRegion()1452 void SvmTest::testClipRegion()
1453 {
1454 GDIMetaFile aGDIMetaFile;
1455 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1456 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1457
1458 vcl::Region aRegion(tools::Rectangle(Point(2, 2), Size(4, 4)));
1459
1460 // TODO
1461 // explicit Region(const tools::Polygon& rPolygon);
1462 // explicit Region(const tools::PolyPolygon& rPolyPoly);
1463 // explicit Region(const basegfx::B2DPolyPolygon&);
1464 pVirtualDev->SetClipRegion(aRegion);
1465
1466 checkClipRegion(writeAndReadStream(aGDIMetaFile));
1467 checkClipRegion(readFile(u"clipregion.svm"));
1468 }
1469
checkIntersectRectClipRegion(const GDIMetaFile & rMetaFile)1470 void SvmTest::checkIntersectRectClipRegion(const GDIMetaFile& rMetaFile)
1471 {
1472 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1473
1474 assertXPathAttrs(pDoc, "/metafile/sectregionclipregion[1]", {
1475 {"left", "1"},
1476 {"top", "2"},
1477 {"right", "4"},
1478 {"bottom", "9"}
1479 });
1480 }
1481
testIntersectRectClipRegion()1482 void SvmTest::testIntersectRectClipRegion()
1483 {
1484 GDIMetaFile aGDIMetaFile;
1485 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1486 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1487
1488 tools::Rectangle aRectangle(Point(1, 2), Size(4, 8));
1489
1490 vcl::Region aRegion(aRectangle);
1491
1492 pVirtualDev->IntersectClipRegion(aRegion);
1493 checkIntersectRectClipRegion(writeAndReadStream(aGDIMetaFile));
1494 checkIntersectRectClipRegion(readFile(u"intersectrectclipregion.svm"));
1495 }
1496
checkIntersectRegionClipRegion(const GDIMetaFile & rMetaFile)1497 void SvmTest::checkIntersectRegionClipRegion(const GDIMetaFile& rMetaFile)
1498 {
1499 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1500
1501 assertXPathAttrs(pDoc, "/metafile/sectregionclipregion[1]", {
1502 {"left", "1"},
1503 {"top", "2"},
1504 {"right", "5"},
1505 {"bottom", "6"}
1506 });
1507
1508 assertXPathAttrs(pDoc, "/metafile/sectregionclipregion[2]", {
1509 {"left", "1"},
1510 {"top", "2"},
1511 {"right", "7"},
1512 {"bottom", "8"}
1513 });
1514
1515 assertXPathAttrs(pDoc, "/metafile/sectregionclipregion[3]", {
1516 {"left", "0"},
1517 {"top", "3"},
1518 {"right", "2"},
1519 {"bottom", "6"}
1520 });
1521 }
1522
testIntersectRegionClipRegion()1523 void SvmTest::testIntersectRegionClipRegion()
1524 {
1525 GDIMetaFile aGDIMetaFile;
1526 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1527 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1528
1529 tools::Polygon aPolygon(3);
1530 aPolygon.SetPoint(Point(1, 2), 0);
1531 aPolygon.SetPoint(Point(3, 4), 1);
1532 aPolygon.SetPoint(Point(5, 6), 2);
1533
1534 vcl::Region aRegion(aPolygon);
1535 pVirtualDev->IntersectClipRegion(aRegion);
1536
1537 tools::Polygon aPolygon1(2);
1538 aPolygon1.SetPoint(Point(5, 6), 0);
1539 aPolygon1.SetPoint(Point(7, 8), 1);
1540
1541 tools::PolyPolygon aPolyPolygon(2);
1542 aPolyPolygon.Insert(aPolygon);
1543 aPolyPolygon.Insert(aPolygon1);
1544
1545 vcl::Region aRegion1(aPolyPolygon);
1546 pVirtualDev->IntersectClipRegion(aRegion1);
1547
1548 basegfx::B2DPolygon aB2DPolygon;
1549 aB2DPolygon.append(basegfx::B2DPoint(0.0, 3.3));
1550 aB2DPolygon.append(basegfx::B2DPoint(1.1, 4.4));
1551 aB2DPolygon.append(basegfx::B2DPoint(2.2, 5.5));
1552
1553 basegfx::B2DPolyPolygon aB2DPolyPolygon(aB2DPolygon);
1554
1555 vcl::Region aRegion2(aB2DPolyPolygon);
1556 pVirtualDev->IntersectClipRegion(aRegion2);
1557
1558 checkIntersectRegionClipRegion(writeAndReadStream(aGDIMetaFile));
1559 checkIntersectRegionClipRegion(readFile(u"intersectregionclipregion.svm"));
1560 }
1561
testMoveClipRegion()1562 void SvmTest::testMoveClipRegion()
1563 {}
1564
checkLineColor(const GDIMetaFile & rMetaFile)1565 void SvmTest::checkLineColor(const GDIMetaFile& rMetaFile)
1566 {
1567 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1568
1569 assertXPathAttrs(pDoc, "/metafile/push/linecolor[1]", {
1570 {"color", "#654321"},
1571 });
1572 }
1573
testLineColor()1574 void SvmTest::testLineColor()
1575 {
1576 GDIMetaFile aGDIMetaFile;
1577 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1578 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1579
1580 pVirtualDev->Push();
1581 pVirtualDev->SetLineColor(Color(0x654321));
1582 pVirtualDev->Pop();
1583
1584 checkLineColor(writeAndReadStream(aGDIMetaFile));
1585 checkLineColor(readFile(u"linecolor.svm"));
1586 }
1587
checkFillColor(const GDIMetaFile & rMetaFile)1588 void SvmTest::checkFillColor(const GDIMetaFile& rMetaFile)
1589 {
1590 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1591
1592 assertXPathAttrs(pDoc, "/metafile/push/fillcolor[1]", {
1593 {"color", "#456789"},
1594 });
1595 }
1596
testFillColor()1597 void SvmTest::testFillColor()
1598 {
1599 GDIMetaFile aGDIMetaFile;
1600 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1601 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1602
1603 pVirtualDev->Push();
1604 pVirtualDev->SetFillColor(Color(0x456789));
1605 pVirtualDev->Pop();
1606
1607 checkFillColor(writeAndReadStream(aGDIMetaFile));
1608 checkFillColor(readFile(u"fillcolor.svm"));
1609 }
1610
checkTextColor(const GDIMetaFile & rMetaFile)1611 void SvmTest::checkTextColor(const GDIMetaFile& rMetaFile)
1612 {
1613 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1614
1615 assertXPathAttrs(pDoc, "/metafile/textcolor[1]", {
1616 {"color", "#123456"},
1617 });
1618 }
1619
testTextColor()1620 void SvmTest::testTextColor()
1621 {
1622 GDIMetaFile aGDIMetaFile;
1623 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1624 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1625
1626 pVirtualDev->SetTextColor(Color(0x123456));
1627
1628 checkTextColor(writeAndReadStream(aGDIMetaFile));
1629 checkTextColor(readFile(u"textcolor.svm"));
1630 }
1631
checkTextFillColor(const GDIMetaFile & rMetaFile)1632 void SvmTest::checkTextFillColor(const GDIMetaFile& rMetaFile)
1633 {
1634 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1635
1636 assertXPathAttrs(pDoc, "/metafile/textfillcolor[1]", {
1637 {"color", "#234567"},
1638 });
1639 }
1640
testTextFillColor()1641 void SvmTest::testTextFillColor()
1642 {
1643 GDIMetaFile aGDIMetaFile;
1644 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1645 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1646
1647 pVirtualDev->SetTextFillColor(Color(0x234567));
1648
1649 checkTextFillColor(writeAndReadStream(aGDIMetaFile));
1650 checkTextFillColor(readFile(u"textfillecolor.svm"));
1651 }
1652
checkTextLineColor(const GDIMetaFile & rMetaFile)1653 void SvmTest::checkTextLineColor(const GDIMetaFile& rMetaFile)
1654 {
1655 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1656
1657 assertXPathAttrs(pDoc, "/metafile/textlinecolor[1]", {
1658 {"color", "#345678"},
1659 });
1660 }
1661
testTextLineColor()1662 void SvmTest::testTextLineColor()
1663 {
1664 GDIMetaFile aGDIMetaFile;
1665 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1666 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1667
1668 pVirtualDev->SetTextLineColor(Color(0x345678));
1669
1670 checkTextLineColor(writeAndReadStream(aGDIMetaFile));
1671 checkTextLineColor(readFile(u"textlinecolor.svm"));
1672 }
1673
checkOverLineColor(const GDIMetaFile & rMetaFile)1674 void SvmTest::checkOverLineColor(const GDIMetaFile& rMetaFile)
1675 {
1676 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1677
1678 assertXPathAttrs(pDoc, "/metafile/push/overlinecolor[1]", {
1679 {"color", "#345678"},
1680 });
1681 }
1682
testOverLineColor()1683 void SvmTest::testOverLineColor()
1684 {
1685 GDIMetaFile aGDIMetaFile;
1686 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1687 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1688
1689 pVirtualDev->Push();
1690 pVirtualDev->SetOverlineColor(Color(0x345678));
1691 pVirtualDev->Pop();
1692
1693 checkOverLineColor(writeAndReadStream(aGDIMetaFile));
1694 checkOverLineColor(readFile(u"overlinecolor.svm"));
1695 }
1696
checkTextAlign(const GDIMetaFile & rMetaFile)1697 void SvmTest::checkTextAlign(const GDIMetaFile& rMetaFile)
1698 {
1699 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1700
1701 assertXPathAttrs(pDoc, "/metafile/textalign[1]", {
1702 {"align", "bottom"},
1703 });
1704 }
1705
testTextAlign()1706 void SvmTest::testTextAlign()
1707 {
1708 GDIMetaFile aGDIMetaFile;
1709 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1710 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1711
1712 pVirtualDev->SetTextAlign(TextAlign::ALIGN_BOTTOM);
1713
1714 checkTextAlign(writeAndReadStream(aGDIMetaFile));
1715 checkTextAlign(readFile(u"textalign.svm"));
1716 }
1717
testMapMode()1718 void SvmTest::testMapMode()
1719 {}
testFont()1720 void SvmTest::testFont()
1721 {}
1722
checkPushPop(const GDIMetaFile & rMetaFile)1723 void SvmTest::checkPushPop(const GDIMetaFile& rMetaFile)
1724 {
1725 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1726
1727 assertXPathAttrs(pDoc, "/metafile/push[1]", {{"flags", "PushAll"}});
1728 assertXPathAttrs(pDoc, "/metafile/push[1]/linecolor[1]", {{"color", "#800000"}});
1729 assertXPathAttrs(pDoc, "/metafile/push[1]/line[1]", {
1730 {"startx", "4"}, {"starty", "4"},
1731 {"endx", "6"}, {"endy", "6"},
1732 });
1733 assertXPathAttrs(pDoc, "/metafile/push[1]/push[1]", {{"flags", "PushLineColor, PushFillColor"}});
1734 assertXPathAttrs(pDoc, "/metafile/push[1]/push[1]/line[1]", {
1735 {"startx", "5"}, {"starty", "5"},
1736 {"endx", "7"}, {"endy", "7"},
1737 });
1738 }
1739
testPushPop()1740 void SvmTest::testPushPop()
1741 {
1742 GDIMetaFile aGDIMetaFile;
1743 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1744 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1745
1746 pVirtualDev->SetLineColor(COL_YELLOW);
1747 pVirtualDev->Push();
1748 pVirtualDev->SetLineColor(COL_RED);
1749 pVirtualDev->DrawLine(Point(4,4), Point(6,6));
1750 pVirtualDev->Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
1751 pVirtualDev->SetLineColor(COL_LIGHTRED);
1752 pVirtualDev->DrawLine(Point(5,5), Point(7,7));
1753 pVirtualDev->Pop();
1754 pVirtualDev->Pop();
1755 pVirtualDev->DrawLine(Point(1,1), Point(8,8));
1756
1757 checkPushPop(writeAndReadStream(aGDIMetaFile));
1758 checkPushPop(readFile(u"pushpop.svm"));
1759 }
1760
checkRasterOp(const GDIMetaFile & rMetaFile)1761 void SvmTest::checkRasterOp(const GDIMetaFile& rMetaFile)
1762 {
1763 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1764
1765 assertXPathAttrs(pDoc, "/metafile/rasterop[1]", {
1766 {"operation", "xor"},
1767 });
1768 }
1769
testRasterOp()1770 void SvmTest::testRasterOp()
1771 {
1772 GDIMetaFile aGDIMetaFile;
1773 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1774 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1775
1776 pVirtualDev->SetRasterOp(RasterOp::Xor);
1777
1778 checkRasterOp(writeAndReadStream(aGDIMetaFile));
1779 checkRasterOp(readFile(u"rasterop.svm"));
1780 }
1781
checkTransparent(const GDIMetaFile & rMetaFile)1782 void SvmTest::checkTransparent(const GDIMetaFile& rMetaFile)
1783 {
1784 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1785
1786 assertXPathAttrs(pDoc, "/metafile/transparent[1]", {
1787 {"transparence", "50"},
1788 });
1789
1790 assertXPathAttrs(pDoc, "/metafile/transparent[1]/polygon/point[1]", {
1791 {"x", "1"}, {"y", "8"},
1792 });
1793 assertXPathAttrs(pDoc, "/metafile/transparent[1]/polygon/point[2]", {
1794 {"x", "2"}, {"y", "7"},
1795 });
1796 assertXPathAttrs(pDoc, "/metafile/transparent[1]/polygon/point[3]", {
1797 {"x", "3"}, {"y", "6"},
1798 });
1799 }
1800
testTransparent()1801 void SvmTest::testTransparent()
1802 {
1803 GDIMetaFile aGDIMetaFile;
1804 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1805 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1806
1807 tools::Polygon aPolygon(3);
1808 aPolygon.SetPoint(Point(1, 8), 0);
1809 aPolygon.SetPoint(Point(2, 7), 1);
1810 aPolygon.SetPoint(Point(3, 6), 2);
1811
1812 tools::PolyPolygon aPolyPolygon(1);
1813 aPolyPolygon.Insert(aPolygon);
1814
1815 pVirtualDev->DrawTransparent(aPolygon, 50);
1816
1817 CPPUNIT_ASSERT(aGDIMetaFile.HasTransparentActions());
1818 checkTransparent(writeAndReadStream(aGDIMetaFile));
1819 checkTransparent(readFile(u"transparent.svm"));
1820 }
1821
testFloatTransparent()1822 void SvmTest::testFloatTransparent()
1823 {}
1824
testEPS()1825 void SvmTest::testEPS()
1826 {}
1827
checkRefPoint(const GDIMetaFile & rMetaFile)1828 void SvmTest::checkRefPoint(const GDIMetaFile& rMetaFile)
1829 {
1830 xmlDocUniquePtr pDoc = dumpMeta(rMetaFile);
1831
1832 assertXPathAttrs(pDoc, "/metafile/refpoint[1]", {
1833 {"x", "0"},
1834 {"y", "0"},
1835 {"set", "false"}
1836 });
1837
1838 assertXPathAttrs(pDoc, "/metafile/refpoint[2]", {
1839 {"x", "1"},
1840 {"y", "2"},
1841 {"set", "true"}
1842 });
1843 }
1844
testRefPoint()1845 void SvmTest::testRefPoint()
1846 {
1847 GDIMetaFile aGDIMetaFile;
1848 ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
1849 setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
1850
1851 pVirtualDev->SetRefPoint();
1852
1853 pVirtualDev->SetRefPoint(Point(1,2));
1854
1855 checkRefPoint(writeAndReadStream(aGDIMetaFile));
1856 checkRefPoint(readFile(u"refpoint.svm"));
1857 }
1858
testComment()1859 void SvmTest::testComment()
1860 {}
1861
testLayoutMode()1862 void SvmTest::testLayoutMode()
1863 {}
1864
testTextLanguage()1865 void SvmTest::testTextLanguage()
1866 {}
1867
1868 CPPUNIT_TEST_SUITE_REGISTRATION(SvmTest);
1869
1870 CPPUNIT_PLUGIN_IMPLEMENT();
1871
1872 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1873