Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sd / qa / unit / PNGExportTests.cxx
blob5ca65f545dc28c5d2111414d4a16d0aa072377cf
2 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /*
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <sal/config.h>
13 #include <test/unoapi_test.hxx>
15 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
16 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
17 #include <com/sun/star/frame/Desktop.hpp>
18 #include <comphelper/propertyvalue.hxx>
19 #include <vcl/BitmapReadAccess.hxx>
20 #include <vcl/filter/PngImageReader.hxx>
22 using namespace ::com::sun::star;
24 class SdPNGExportTest : public UnoApiTest
26 public:
27 SdPNGExportTest()
28 : UnoApiTest("/sd/qa/unit/data/")
33 static void assertColorsAreSimilar(const std::string& message, const BitmapColor& expected,
34 const BitmapColor& actual, int nDelta)
36 // Check that the two colors match or are reasonably similar.
37 if (expected.GetColorError(actual) <= nDelta)
38 return;
40 CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual);
43 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf105998)
45 loadFromURL(u"odp/tdf105998.odp");
46 uno::Reference<uno::XComponentContext> xContext = getComponentContext();
47 CPPUNIT_ASSERT(xContext.is());
48 uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
49 = drawing::GraphicExportFilter::create(xContext);
51 uno::Sequence<beans::PropertyValue> aDescriptor{
52 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
53 comphelper::makePropertyValue("FilterName", OUString("PNG"))
56 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
57 uno::Reference<drawing::XDrawPage> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
58 uno::UNO_QUERY);
59 uno::Reference<lang::XComponent> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
60 xGraphicExporter->setSourceDocument(xShape);
61 xGraphicExporter->filter(aDescriptor);
63 SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
64 vcl::PngImageReader aPNGReader(aFileStream);
65 BitmapEx aBMPEx = aPNGReader.read();
67 // make sure only the shape is exported
68 Size aSize = aBMPEx.GetSizePixel();
69 const auto[scalingX, scalingY] = getDPIScaling();
70 CPPUNIT_ASSERT_DOUBLES_EQUAL(193 * scalingX, aSize.getWidth(), 1.5);
71 CPPUNIT_ASSERT_DOUBLES_EQUAL(193 * scalingY, aSize.getHeight(), 1.5);
72 if (!IsDefaultDPI())
73 return;
75 // Check all borders are red
76 // use assertColorsAreSimilar since the color might differ a little bit on mac
77 Bitmap aBMP = aBMPEx.GetBitmap();
79 Bitmap::ScopedReadAccess pReadAccess(aBMP);
80 for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
82 const Color aColorTop = pReadAccess->GetColor(0, nX);
83 const Color aColorBottom = pReadAccess->GetColor(aSize.Height() - 1, nX);
85 assertColorsAreSimilar("Incorrect top border", COL_LIGHTRED, aColorTop, 5);
87 // Without the fix in place, this test would have failed with
88 // - Expected: Color: R:255 G:0 B:0 A:0
89 // - Actual : Color: R:9 G:9 B:9 A:0
90 assertColorsAreSimilar("Incorrect bottom border", COL_LIGHTRED, aColorBottom, 5);
93 for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
95 const Color aColorLeft = pReadAccess->GetColor(nY, 0);
96 const Color aColorRight = pReadAccess->GetColor(nY, aSize.Width() - 1);
98 assertColorsAreSimilar("Incorrect left border", COL_LIGHTRED, aColorLeft, 5);
99 assertColorsAreSimilar("Incorrect right border", COL_LIGHTRED, aColorRight, 5);
104 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf126319)
106 loadFromURL(u"odg/tdf126319.odg");
107 uno::Reference<uno::XComponentContext> xContext = getComponentContext();
108 CPPUNIT_ASSERT(xContext.is());
109 uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
110 = drawing::GraphicExportFilter::create(xContext);
112 uno::Sequence<beans::PropertyValue> aDescriptor{
113 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
114 comphelper::makePropertyValue("FilterName", OUString("PNG"))
117 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
118 uno::Reference<drawing::XDrawPage> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
119 uno::UNO_QUERY);
120 uno::Reference<lang::XComponent> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
121 xGraphicExporter->setSourceDocument(xShape);
122 xGraphicExporter->filter(aDescriptor);
124 SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
125 vcl::PngImageReader aPNGReader(aFileStream);
126 BitmapEx aBMPEx = aPNGReader.read();
128 // make sure only the shape is exported
129 Size aSize = aBMPEx.GetSizePixel();
130 const auto[scalingX, scalingY] = getDPIScaling();
131 CPPUNIT_ASSERT_DOUBLES_EQUAL(295 * scalingX, aSize.getWidth(), 1.5);
132 CPPUNIT_ASSERT_DOUBLES_EQUAL(134 * scalingY, aSize.getHeight(), 1.5);
133 if (!IsDefaultDPI())
134 return;
136 // Check all borders are red or similar. Ignore the corners
137 Bitmap aBMP = aBMPEx.GetBitmap();
139 Bitmap::ScopedReadAccess pReadAccess(aBMP);
140 for (tools::Long nX = 2; nX < aSize.Width() - 2; ++nX)
142 const Color aColorTop = pReadAccess->GetColor(0, nX);
143 // tdf#150102 the exported graphic now has no longer an empty bottom
144 // row, so test with '-1' in height , same as already in test
145 // testTdf105998 above
146 const Color aColorBottom = pReadAccess->GetColor(aSize.Height() - 1, nX);
148 assertColorsAreSimilar("Incorrect top border", COL_LIGHTRED, aColorTop, 5);
150 // Without the fix in place, this test would have failed with
151 // - Expected: Color: R:255 G:0 B:0 A:0
152 // - Actual : Color: R:77 G:0 B:0 A:0
153 assertColorsAreSimilar("Incorrect bottom border", COL_LIGHTRED, aColorBottom, 5);
156 for (tools::Long nY = 2; nY < aSize.Height() - 2; ++nY)
158 const Color aColorLeft = pReadAccess->GetColor(nY, 0);
159 // tdf#150102 the exported graphic now has no longer an empty right
160 // column, so test with '-1' in width , same as already in test
161 // testTdf105998 above
162 const Color aColorRight = pReadAccess->GetColor(nY, aSize.Width() - 1);
164 assertColorsAreSimilar("Incorrect left border", COL_LIGHTRED, aColorLeft, 5);
165 assertColorsAreSimilar("Incorrect right border", COL_LIGHTRED, aColorRight, 5);
170 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf136632)
172 // Reuse existing file
173 loadFromURL(u"odp/tdf105998.odp");
174 uno::Reference<uno::XComponentContext> xContext = getComponentContext();
175 CPPUNIT_ASSERT(xContext.is());
176 uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
177 = drawing::GraphicExportFilter::create(xContext);
179 uno::Sequence<beans::PropertyValue> aFilterData{ comphelper::makePropertyValue("Translucent",
180 sal_Int32(0)) };
182 uno::Sequence<beans::PropertyValue> aDescriptor{
183 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
184 comphelper::makePropertyValue("FilterName", OUString("PNG")),
185 comphelper::makePropertyValue("FilterData", aFilterData)
188 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
189 uno::Reference<drawing::XDrawPage> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
190 uno::UNO_QUERY);
191 uno::Reference<lang::XComponent> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
192 xGraphicExporter->setSourceDocument(xShape);
193 xGraphicExporter->filter(aDescriptor);
195 SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
196 vcl::PngImageReader aPNGReader(aFileStream);
197 BitmapEx aBMPEx = aPNGReader.read();
198 AlphaMask aAlpha = aBMPEx.GetAlphaMask();
199 AlphaMask::ScopedReadAccess pReadAccess(aAlpha);
201 // Without the fix in place, this test would have failed here
202 CPPUNIT_ASSERT(!pReadAccess);
205 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf113163)
207 loadFromURL(u"pptx/tdf113163.pptx");
208 uno::Reference<uno::XComponentContext> xContext = getComponentContext();
209 CPPUNIT_ASSERT(xContext.is());
210 uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
211 = drawing::GraphicExportFilter::create(xContext);
213 uno::Sequence<beans::PropertyValue> aFilterData{
214 comphelper::makePropertyValue("PixelWidth", sal_Int32(100)),
215 comphelper::makePropertyValue("PixelHeight", sal_Int32(100))
218 uno::Sequence<beans::PropertyValue> aDescriptor{
219 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
220 comphelper::makePropertyValue("FilterName", OUString("PNG")),
221 comphelper::makePropertyValue("FilterData", aFilterData)
224 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
225 uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
226 uno::UNO_QUERY);
227 xGraphicExporter->setSourceDocument(xPage);
228 xGraphicExporter->filter(aDescriptor);
230 SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
231 vcl::PngImageReader aPNGReader(aFileStream);
232 BitmapEx aBMPEx = aPNGReader.read();
234 // make sure the bitmap is not empty and correct size (PNG export->import was successful)
235 Size aSize = aBMPEx.GetSizePixel();
236 CPPUNIT_ASSERT_EQUAL(Size(100, 100), aSize);
237 Bitmap aBMP = aBMPEx.GetBitmap();
239 Bitmap::ScopedReadAccess pReadAccess(aBMP);
240 for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
242 for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
244 // Check all pixels in the image are black
245 // Without the fix in place, this test would have failed with
246 // - Expected: 0
247 // - Actual : 16777215
248 const Color aColor = pReadAccess->GetColor(nY, nX);
249 CPPUNIT_ASSERT_EQUAL(COL_BLACK, aColor);
255 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf147119)
257 loadFromURL(u"odg/tdf147119.odg");
258 uno::Reference<uno::XComponentContext> xContext = getComponentContext();
259 CPPUNIT_ASSERT(xContext.is());
260 uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
261 = drawing::GraphicExportFilter::create(xContext);
263 uno::Sequence<beans::PropertyValue> aFilterData{
264 comphelper::makePropertyValue("PixelWidth", sal_Int32(100)),
265 comphelper::makePropertyValue("PixelHeight", sal_Int32(100)),
266 comphelper::makePropertyValue("Translucent", sal_Int32(1)),
269 uno::Sequence<beans::PropertyValue> aDescriptor{
270 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
271 comphelper::makePropertyValue("FilterName", OUString("PNG")),
272 comphelper::makePropertyValue("FilterData", aFilterData)
275 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
276 uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
277 uno::UNO_QUERY);
278 xGraphicExporter->setSourceDocument(xPage);
279 xGraphicExporter->filter(aDescriptor);
281 SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
282 vcl::PngImageReader aPNGReader(aFileStream);
283 BitmapEx aBMPEx = aPNGReader.read();
285 Size aSize = aBMPEx.GetSizePixel();
286 CPPUNIT_ASSERT_EQUAL(Size(100, 100), aSize);
287 AlphaMask aAlpha = aBMPEx.GetAlphaMask();
289 AlphaMask::ScopedReadAccess pReadAccess(aAlpha);
290 for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
292 for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
294 // Without the fix in place, this test would have failed with
295 // - Expected: Color: R:255 G:255 B:255 A:0
296 // - Actual : Color: R:0 G:0 B:0 A:0
297 const Color aColor = pReadAccess->GetColor(nY, nX);
298 CPPUNIT_ASSERT_EQUAL(COL_WHITE, aColor);
304 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf113197)
306 loadFromURL(u"odp/tdf113197.odp");
307 uno::Reference<uno::XComponentContext> xContext = getComponentContext();
308 CPPUNIT_ASSERT(xContext.is());
309 uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
310 = drawing::GraphicExportFilter::create(xContext);
312 uno::Sequence<beans::PropertyValue> aFilterData{
313 comphelper::makePropertyValue("PixelWidth", sal_Int32(100)),
314 comphelper::makePropertyValue("PixelHeight", sal_Int32(100)),
317 uno::Sequence<beans::PropertyValue> aDescriptor{
318 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
319 comphelper::makePropertyValue("FilterName", OUString("PNG")),
320 comphelper::makePropertyValue("FilterData", aFilterData)
323 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
324 uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
325 uno::UNO_QUERY);
326 xGraphicExporter->setSourceDocument(xPage);
327 xGraphicExporter->filter(aDescriptor);
329 SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
330 vcl::PngImageReader aPNGReader(aFileStream);
331 BitmapEx aBMPEx = aPNGReader.read();
333 // make sure the bitmap is not empty and correct size (PNG export->import was successful)
334 Size aSize = aBMPEx.GetSizePixel();
335 CPPUNIT_ASSERT_EQUAL(Size(100, 100), aSize);
336 Bitmap aBMP = aBMPEx.GetBitmap();
338 Bitmap::ScopedReadAccess pReadAccess(aBMP);
339 for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
341 // Check the bottom half of the document is white
342 for (tools::Long nY = 50; nY < aSize.Height() - 1; ++nY)
344 // Check all pixels in the image are black
345 // Without the fix in place, this test would have failed with
346 // - Expected: Color: R:255 G:255 B:255 A:0
347 // - Actual : Color: R:153 G:0 B:51 A:0
348 const Color aColor = pReadAccess->GetColor(nY, nX);
349 CPPUNIT_ASSERT_EQUAL(COL_WHITE, aColor);
355 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf93124)
357 loadFromURL(u"ppt/tdf93124.ppt");
358 uno::Reference<uno::XComponentContext> xContext = getComponentContext();
359 CPPUNIT_ASSERT(xContext.is());
360 uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
361 = drawing::GraphicExportFilter::create(xContext);
363 uno::Sequence<beans::PropertyValue> aFilterData{
364 comphelper::makePropertyValue("PixelWidth", sal_Int32(320)),
365 comphelper::makePropertyValue("PixelHeight", sal_Int32(180))
368 uno::Sequence<beans::PropertyValue> aDescriptor{
369 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
370 comphelper::makePropertyValue("FilterName", OUString("PNG")),
371 comphelper::makePropertyValue("FilterData", aFilterData)
374 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
375 uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
376 uno::UNO_QUERY);
377 xGraphicExporter->setSourceDocument(xPage);
378 xGraphicExporter->filter(aDescriptor);
380 SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
381 vcl::PngImageReader aPNGReader(aFileStream);
382 BitmapEx aBMPEx = aPNGReader.read();
384 // make sure the bitmap is not empty and correct size (PNG export->import was successful)
385 CPPUNIT_ASSERT_EQUAL(Size(320, 180), aBMPEx.GetSizePixel());
386 Bitmap aBMP = aBMPEx.GetBitmap();
388 Bitmap::ScopedReadAccess pReadAccess(aBMP);
389 int nNonWhiteCount = 0;
390 // The word "Top" should be in rectangle 34,4 - 76,30. If text alignment is wrong, the rectangle will be white.
391 for (tools::Long nY = 4; nY < (4 + 26); ++nY)
393 for (tools::Long nX = 34; nX < (34 + 43); ++nX)
395 const Color aColor = pReadAccess->GetColor(nY, nX);
396 if ((aColor.GetRed() != 0xff) || (aColor.GetGreen() != 0xff)
397 || (aColor.GetBlue() != 0xff))
398 ++nNonWhiteCount;
401 CPPUNIT_ASSERT_MESSAGE("Tdf93124: vertical alignment of text is incorrect!",
402 nNonWhiteCount > 50);
406 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf99729)
408 const OUString filenames[] = { "odp/tdf99729-new.odp", "odp/tdf99729-legacy.odp" };
409 int nonwhitecounts[] = { 0, 0 };
410 for (size_t i = 0; i < SAL_N_ELEMENTS(filenames); ++i)
412 // 1st check for new behaviour - having AnchoredTextOverflowLegacy compatibility flag set to false in settings.xml
413 loadFromURL(filenames[i]);
415 uno::Reference<uno::XComponentContext> xContext = getComponentContext();
416 CPPUNIT_ASSERT(xContext.is());
417 uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
418 = drawing::GraphicExportFilter::create(xContext);
419 CPPUNIT_ASSERT(xGraphicExporter.is());
421 uno::Sequence<beans::PropertyValue> aFilterData{
422 comphelper::makePropertyValue("PixelWidth", sal_Int32(320)),
423 comphelper::makePropertyValue("PixelHeight", sal_Int32(240))
426 uno::Sequence<beans::PropertyValue> aDescriptor{
427 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
428 comphelper::makePropertyValue("FilterName", OUString("PNG")),
429 comphelper::makePropertyValue("FilterData", aFilterData)
432 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
433 uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
434 uno::UNO_QUERY);
435 CPPUNIT_ASSERT(xPage.is());
436 xGraphicExporter->setSourceDocument(xPage);
437 xGraphicExporter->filter(aDescriptor);
439 SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
440 vcl::PngImageReader aPNGReader(aFileStream);
441 BitmapEx aBMPEx = aPNGReader.read();
442 Bitmap aBMP = aBMPEx.GetBitmap();
443 Bitmap::ScopedReadAccess pRead(aBMP);
444 for (tools::Long nX = 154; nX < (154 + 12); ++nX)
446 for (tools::Long nY = 16; nY < (16 + 96); ++nY)
448 const Color aColor = pRead->GetColor(nY, nX);
449 if ((aColor.GetRed() != 0xff) || (aColor.GetGreen() != 0xff)
450 || (aColor.GetBlue() != 0xff))
451 ++nonwhitecounts[i];
455 // The numbers 1-9 should be above the Text Box in rectangle 154,16 - 170,112.
456 // If text alignment is wrong, the rectangle will be white.
457 CPPUNIT_ASSERT_MESSAGE("Tdf99729: vertical alignment of text is incorrect!",
458 nonwhitecounts[0] > 100); // it is 134 with cleartype disabled
459 // The numbers 1-9 should be below the Text Box -> rectangle 154,16 - 170,112 should be white.
460 CPPUNIT_ASSERT_EQUAL_MESSAGE("Tdf99729: legacy vertical alignment of text is incorrect!", 0,
461 nonwhitecounts[1]);
464 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf155048)
466 loadFromURL(u"odg/diagonalLine.fodg");
468 auto xGraphicExporter = drawing::GraphicExportFilter::create(getComponentContext());
469 CPPUNIT_ASSERT(xGraphicExporter);
471 auto xSupplier = mxComponent.queryThrow<css::drawing::XDrawPagesSupplier>();
472 auto xPage = xSupplier->getDrawPages()->getByIndex(0).queryThrow<css::lang::XComponent>();
473 xGraphicExporter->setSourceDocument(xPage);
475 // 1. AA disabled
477 #ifdef MACOSX
478 // Disable test that always fails with Apple Retina displays
479 // With a HiDPI display on macOS, each logical pixel is backed
480 // by 4 physical pixels. Turning off antialiasing and drawing a
481 // diagonal line causes many logical pixels on the edge of the
482 // diagonal line to have a mixture of white and blue physical
483 // pixels. Then, when such logical pixels are fetched via
484 // BitmapEx::GetPixelColor(), their underlying 4 white and blue
485 // physical pixels are combined into blended shades of white
486 // and blue.
487 #else
488 css::uno::Sequence<css::beans::PropertyValue> aFilterData{
489 comphelper::makePropertyValue("PixelWidth", sal_Int32(200)),
490 comphelper::makePropertyValue("PixelHeight", sal_Int32(200)),
491 comphelper::makePropertyValue("AntiAliasing", false),
494 css::uno::Sequence<css::beans::PropertyValue> aDescriptor{
495 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
496 comphelper::makePropertyValue("FilterName", OUString("PNG")),
497 comphelper::makePropertyValue("FilterData", aFilterData)
500 xGraphicExporter->filter(aDescriptor);
502 BitmapEx bmp = vcl::PngImageReader(*maTempFile.GetStream(StreamMode::READ)).read();
503 std::set<Color> foundColors;
504 for (tools::Long x = 0; x < bmp.GetSizePixel().Width(); ++x)
505 for (tools::Long y = 0; y < bmp.GetSizePixel().Height(); ++y)
506 foundColors.insert(bmp.GetPixelColor(x, y));
508 // There must be only two colors (white and blue) in the bitmap generated without AA
509 CPPUNIT_ASSERT_EQUAL(size_t(2), foundColors.size());
510 maTempFile.CloseStream();
511 #endif
514 // 2. AA enabled
516 css::uno::Sequence<css::beans::PropertyValue> aFilterData{
517 comphelper::makePropertyValue("PixelWidth", sal_Int32(200)),
518 comphelper::makePropertyValue("PixelHeight", sal_Int32(200)),
519 comphelper::makePropertyValue("AntiAliasing", true),
522 css::uno::Sequence<css::beans::PropertyValue> aDescriptor{
523 comphelper::makePropertyValue("URL", maTempFile.GetURL()),
524 comphelper::makePropertyValue("FilterName", OUString("PNG")),
525 comphelper::makePropertyValue("FilterData", aFilterData)
528 xGraphicExporter->filter(aDescriptor);
530 BitmapEx bmp = vcl::PngImageReader(*maTempFile.GetStream(StreamMode::READ)).read();
531 std::set<Color> foundColors;
532 for (tools::Long x = 0; x < bmp.GetSizePixel().Width(); ++x)
533 for (tools::Long y = 0; y < bmp.GetSizePixel().Height(); ++y)
534 foundColors.insert(bmp.GetPixelColor(x, y));
536 // With AA, the number of colors will be greater - it is 19 on my system
537 CPPUNIT_ASSERT_GREATER(size_t(2), foundColors.size());
538 maTempFile.CloseStream();
542 CPPUNIT_PLUGIN_IMPLEMENT();