tdf#145056 Delete autofilter settings when turning off autofilter
[LibreOffice.git] / vcl / qa / cppunit / GraphicTest.cxx
blob51c619ee4765dfa431ec42bd803c3b450e3cc27b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <sal/config.h>
11 #include <config_oox.h>
12 #include <com/sun/star/graphic/XGraphic.hpp>
13 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
14 #include <cppunit/TestAssert.h>
15 #include <cppunit/TestFixture.h>
16 #include <cppunit/extensions/HelperMacros.h>
17 #include <cppunit/plugin/TestPlugIn.h>
18 #include <test/bootstrapfixture.hxx>
20 #include <com/sun/star/beans/PropertyValue.hpp>
22 #include <vcl/BitmapReadAccess.hxx>
23 #include <vcl/graph.hxx>
24 #include <vcl/graphicfilter.hxx>
25 #include <tools/stream.hxx>
26 #include <unotest/directories.hxx>
27 #include <comphelper/DirectoryHelper.hxx>
28 #include <comphelper/hash.hxx>
29 #include <unotools/ucbstreamhelper.hxx>
30 #include <unotools/tempfile.hxx>
31 #include <vcl/cvtgrf.hxx>
32 #include <vcl/metaact.hxx>
33 #include <vcl/wmf.hxx>
35 #include <impgraph.hxx>
36 #include <graphic/GraphicFormatDetector.hxx>
38 #if USE_TLS_NSS
39 #include <nss.h>
40 #endif
42 using namespace css;
44 class GraphicTest : public test::BootstrapFixture
46 public:
47 ~GraphicTest();
50 GraphicTest::~GraphicTest()
52 #if USE_TLS_NSS
53 NSS_Shutdown();
54 #endif
57 namespace
59 BitmapEx createBitmap(bool alpha = false)
61 Bitmap aBitmap(Size(120, 100), vcl::PixelFormat::N24_BPP);
62 aBitmap.Erase(COL_LIGHTRED);
64 aBitmap.SetPrefSize(Size(6000, 5000));
65 aBitmap.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
67 if (alpha)
69 sal_uInt8 uAlphaValue = 0x80;
70 AlphaMask aAlphaMask(Size(120, 100), &uAlphaValue);
72 return BitmapEx(aBitmap, aAlphaMask);
74 else
76 return BitmapEx(aBitmap);
80 void createBitmapAndExportForType(SvStream& rStream, std::u16string_view sType, bool alpha)
82 BitmapEx aBitmapEx = createBitmap(alpha);
84 uno::Sequence<beans::PropertyValue> aFilterData;
85 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
86 sal_uInt16 nFilterFormat = rGraphicFilter.GetExportFormatNumberForShortName(sType);
87 rGraphicFilter.ExportGraphic(aBitmapEx, u"none", rStream, nFilterFormat, &aFilterData);
89 rStream.Seek(STREAM_SEEK_TO_BEGIN);
92 Graphic makeUnloadedGraphic(std::u16string_view sType, bool alpha = false)
94 SvMemoryStream aStream;
95 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
96 createBitmapAndExportForType(aStream, sType, alpha);
97 return rGraphicFilter.ImportUnloadedGraphic(aStream);
100 std::string toHexString(const std::vector<unsigned char>& a)
102 std::stringstream aStrm;
103 for (auto& i : a)
105 aStrm << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(i);
108 return aStrm.str();
111 std::vector<unsigned char> calculateHash(SvStream* pStream)
113 comphelper::Hash aHashEngine(comphelper::HashType::SHA1);
114 const sal_uInt32 nSize(pStream->remainingSize());
115 std::vector<sal_uInt8> aData(nSize);
116 aHashEngine.update(aData.data(), nSize);
117 return aHashEngine.finalize();
120 bool checkBitmap(Graphic& rGraphic)
122 bool bResult = true;
124 Bitmap aBitmap(rGraphic.GetBitmapEx().GetBitmap());
126 BitmapScopedReadAccess pReadAccess(aBitmap);
127 for (tools::Long y = 0; y < rGraphic.GetSizePixel().Height(); y++)
129 for (tools::Long x = 0; x < rGraphic.GetSizePixel().Width(); x++)
131 if (pReadAccess->HasPalette())
133 sal_uInt32 nIndex = pReadAccess->GetPixelIndex(y, x);
134 Color aColor = pReadAccess->GetPaletteColor(nIndex);
135 bResult &= (aColor == COL_LIGHTRED);
137 else
139 Color aColor = pReadAccess->GetPixel(y, x);
140 bResult &= (aColor == COL_LIGHTRED);
146 return bResult;
149 constexpr OUString DATA_DIRECTORY = u"/vcl/qa/cppunit/data/"_ustr;
150 constexpr OUString PDFEXPORT_DATA_DIRECTORY = u"/vcl/qa/cppunit/pdfexport/data/"_ustr;
152 Graphic loadGraphic(std::u16string_view const& rFilename)
154 test::Directories aDirectories;
155 OUString aFilename = aDirectories.getURLFromSrc(DATA_DIRECTORY) + rFilename;
156 SvFileStream aFileStream(aFilename, StreamMode::READ);
157 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
159 Graphic aGraphic;
160 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, rGraphicFilter.ImportGraphic(aGraphic, u"", aFileStream,
161 GRFILTER_FORMAT_DONTKNOW));
162 return aGraphic;
165 Graphic importUnloadedGraphic(std::u16string_view const& rFilename)
167 test::Directories aDirectories;
168 OUString aFilename = aDirectories.getURLFromSrc(DATA_DIRECTORY) + rFilename;
169 SvFileStream aFileStream(aFilename, StreamMode::READ);
170 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
171 return rGraphicFilter.ImportUnloadedGraphic(aFileStream);
174 int getEmfPlusActionsCount(const Graphic& graphic)
176 const GDIMetaFile& metafile = graphic.GetGDIMetaFile();
177 int emfPlusCount = 0;
178 for (size_t i = 0; i < metafile.GetActionSize(); ++i)
180 MetaAction* action = metafile.GetAction(i);
181 if (action->GetType() == MetaActionType::COMMENT)
183 const MetaCommentAction* commentAction = static_cast<const MetaCommentAction*>(action);
184 if (commentAction->GetComment() == "EMF_PLUS")
185 ++emfPlusCount;
188 return emfPlusCount;
191 int getPolygonActionsCount(const Graphic& graphic)
193 const GDIMetaFile& metafile = graphic.GetGDIMetaFile();
194 int polygonCount = 0;
195 for (size_t i = 0; i < metafile.GetActionSize(); ++i)
197 MetaAction* action = metafile.GetAction(i);
198 if (action->GetType() == MetaActionType::POLYGON)
199 ++polygonCount;
201 return polygonCount;
204 } //namespace
206 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphic)
208 // make unloaded test graphic
209 Graphic aGraphic = makeUnloadedGraphic(u"png");
210 Graphic aGraphic2 = aGraphic;
212 // check available
213 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
214 CPPUNIT_ASSERT_EQUAL(false, aGraphic2.isAvailable());
216 CPPUNIT_ASSERT_EQUAL(true, aGraphic2.makeAvailable());
217 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
218 CPPUNIT_ASSERT_EQUAL(true, aGraphic2.isAvailable());
220 // check GetSizePixel doesn't load graphic
221 aGraphic = makeUnloadedGraphic(u"png");
222 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
223 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
224 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
225 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
227 // check GetPrefSize doesn't load graphic
228 CPPUNIT_ASSERT_EQUAL(tools::Long(6000), aGraphic.GetPrefSize().Width());
229 CPPUNIT_ASSERT_EQUAL(tools::Long(5000), aGraphic.GetPrefSize().Height());
230 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
232 // check GetSizeBytes loads graphic
233 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
234 CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
235 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
237 //check Type
238 aGraphic = makeUnloadedGraphic(u"png");
239 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
240 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
241 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
242 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
243 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
246 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphicLoadingPng)
248 Graphic aGraphic = makeUnloadedGraphic(u"png");
250 // check available
251 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
252 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
253 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
254 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
255 CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
256 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
258 CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
261 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphicLoadingGif)
263 Graphic aGraphic = makeUnloadedGraphic(u"gif");
265 // check available
266 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
267 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
268 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
269 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
270 CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
271 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
273 CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
276 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphicLoadingJpg)
278 Graphic aGraphic = makeUnloadedGraphic(u"jpg");
280 // check available
281 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
282 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
283 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
284 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
285 CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
286 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
288 CPPUNIT_ASSERT_EQUAL(false, checkBitmap(aGraphic));
291 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphicLoadingTif)
293 Graphic aGraphic = makeUnloadedGraphic(u"tif");
295 // check available
296 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
297 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
298 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
299 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
300 CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
301 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
303 CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
306 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphicLoadingWebp)
308 Graphic aGraphic = makeUnloadedGraphic(u"webp");
310 // check available
311 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
312 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
313 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
314 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
315 CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
316 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
318 CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
321 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphicWmf)
323 // Create some in-memory WMF data, set its own preferred size to 99x99.
324 BitmapEx aBitmapEx = createBitmap();
325 SvMemoryStream aStream;
326 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
327 sal_uInt16 nFilterFormat = rGraphicFilter.GetExportFormatNumberForShortName(u"wmf");
328 Graphic aGraphic(aBitmapEx);
329 aGraphic.SetPrefSize(Size(99, 99));
330 aGraphic.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
331 rGraphicFilter.ExportGraphic(aGraphic, u"none", aStream, nFilterFormat);
332 aStream.Seek(STREAM_SEEK_TO_BEGIN);
334 // Now lazy-load this WMF data, with a custom preferred size of 42x42.
335 Size aMtfSize100(42, 42);
336 aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, &aMtfSize100);
337 aGraphic.makeAvailable();
339 // Without the accompanying fix in place, this test would have failed with:
340 // - Expected: 42x42
341 // - Actual : 99x99
342 // i.e. the custom preferred size was lost after lazy-load.
343 CPPUNIT_ASSERT_EQUAL(Size(42, 42), aGraphic.GetPrefSize());
346 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphicAlpha)
348 // make unloaded test graphic with alpha
349 Graphic aGraphic = makeUnloadedGraphic(u"png", true);
351 CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsAlpha());
352 CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsTransparent());
353 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
355 // make unloaded test graphic without alpha
356 aGraphic = makeUnloadedGraphic(u"png", false);
358 CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsAlpha());
359 CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsTransparent());
360 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
363 CPPUNIT_TEST_FIXTURE(GraphicTest, testUnloadedGraphicSizeUnit)
365 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
366 test::Directories aDirectories;
367 OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "inch-size.pct";
368 Size aMtfSize100(42, 42);
369 SvFileStream aStream(aURL, StreamMode::READ);
370 Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream, 0, &aMtfSize100);
372 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
373 CPPUNIT_ASSERT_EQUAL(Size(42, 42), aGraphic.GetPrefSize());
375 // Force it to swap in
376 aGraphic.makeAvailable();
378 // Without the accompanying fix in place, this test would have failed with:
379 // - Expected: 400x363
380 // - Actual : 42x42
381 // i.e. a mm100 size was used as a hint and the inch size was set for a non-matching unit.
382 CPPUNIT_ASSERT_EQUAL(Size(400, 363), aGraphic.GetPrefSize());
385 CPPUNIT_TEST_FIXTURE(GraphicTest, testWMFRoundtrip)
387 // Load a WMF file.
388 test::Directories aDirectories;
389 OUString aURL = aDirectories.getURLFromSrc(u"vcl/qa/cppunit/data/roundtrip.wmf");
390 SvFileStream aStream(aURL, StreamMode::READ);
391 sal_uInt64 nExpectedSize = aStream.TellEnd();
392 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
393 Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
395 // Save as WMF.
396 utl::TempFileNamed aTempFile;
397 aTempFile.EnableKillingFile();
398 sal_uInt16 nFormat = rGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
399 SvStream& rOutStream = *aTempFile.GetStream(StreamMode::READWRITE);
400 rGraphicFilter.ExportGraphic(aGraphic, u"", rOutStream, nFormat);
402 // Check if we preserved the WMF data perfectly.
403 sal_uInt64 nActualSize = rOutStream.TellEnd();
405 // Without the accompanying fix in place, this test would have failed with:
406 // - Expected: 6475
407 // - Actual : 2826
408 // i.e. we lost some of the WMF data on roundtrip.
409 CPPUNIT_ASSERT_EQUAL(nExpectedSize, nActualSize);
412 CPPUNIT_TEST_FIXTURE(GraphicTest, testWMFWithEmfPlusRoundtrip)
414 // Load a WMF file.
415 test::Directories aDirectories;
416 OUString aURL = aDirectories.getURLFromSrc(u"vcl/qa/cppunit/data/wmf-embedded-emfplus.wmf");
417 SvFileStream aStream(aURL, StreamMode::READ);
418 sal_uInt64 nExpectedSize = aStream.TellEnd();
419 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
420 Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
422 CPPUNIT_ASSERT_GREATER(0, getEmfPlusActionsCount(aGraphic));
423 CPPUNIT_ASSERT_EQUAL(0, getPolygonActionsCount(aGraphic));
425 for (bool useConvertMetafile : { false, true })
427 // Save as WMF.
428 utl::TempFileNamed aTempFile;
429 SvStream& rOutStream = *aTempFile.GetStream(StreamMode::READWRITE);
430 if (useConvertMetafile)
431 ConvertGraphicToWMF(aGraphic, rOutStream, nullptr);
432 else
434 sal_uInt16 nFormat = rGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
435 rGraphicFilter.ExportGraphic(aGraphic, u"", rOutStream, nFormat);
437 CPPUNIT_ASSERT_EQUAL(nExpectedSize, rOutStream.TellEnd());
439 rOutStream.Seek(0);
440 Graphic aNewGraphic = rGraphicFilter.ImportUnloadedGraphic(rOutStream);
441 // Check that reading the WMF back preserves the EMF+ actions in it.
442 CPPUNIT_ASSERT_GREATER(0, getEmfPlusActionsCount(aNewGraphic));
443 // EmfReader::ReadEnhWMF() drops non-EMF+ drawing actions if EMF+ is found.
444 CPPUNIT_ASSERT_EQUAL(0, getPolygonActionsCount(aNewGraphic));
446 // With EMF+ disabled there should be no EMF+ actions.
447 auto aVectorGraphicData = std::make_shared<VectorGraphicData>(
448 aNewGraphic.GetGfxLink().getDataContainer(), VectorGraphicDataType::Wmf);
449 aVectorGraphicData->setEnableEMFPlus(false);
450 Graphic aNoEmfPlusGraphic(aVectorGraphicData);
451 CPPUNIT_ASSERT_EQUAL(0, getEmfPlusActionsCount(aNoEmfPlusGraphic));
452 CPPUNIT_ASSERT_GREATER(0, getPolygonActionsCount(aNoEmfPlusGraphic));
456 CPPUNIT_TEST_FIXTURE(GraphicTest, testEmfToWmfConversion)
458 // Load EMF data.
459 GraphicFilter aGraphicFilter;
460 test::Directories aDirectories;
461 OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "to-wmf.emf";
462 SvFileStream aStream(aURL, StreamMode::READ);
463 Graphic aGraphic;
464 // This similar to an application/x-openoffice-wmf mime type in manifest.xml in the ODF case.
465 sal_uInt16 nFormatEMF = aGraphicFilter.GetImportFormatNumberForShortName(u"EMF");
466 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE,
467 aGraphicFilter.ImportGraphic(aGraphic, u"", aStream, nFormatEMF));
468 CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Emf, aGraphic.getVectorGraphicData()->getType());
470 // Save as WMF.
471 sal_uInt16 nFilterType = aGraphicFilter.GetExportFormatNumberForShortName(u"WMF");
472 SvMemoryStream aGraphicStream;
473 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE,
474 aGraphicFilter.ExportGraphic(aGraphic, u"", aGraphicStream, nFilterType));
475 aGraphicStream.Seek(0);
476 vcl::GraphicFormatDetector aDetector(aGraphicStream, OUString());
477 CPPUNIT_ASSERT(aDetector.detect());
478 CPPUNIT_ASSERT(aDetector.checkWMF());
480 // Without the accompanying fix in place, this test would have failed with:
481 // - Expected: WMF
482 // - Actual : EMF
483 // i.e. EMF data was requested to be converted to WMF, but the output was still EMF.
484 CPPUNIT_ASSERT_EQUAL(u"WMF"_ustr,
485 vcl::getImportFormatShortName(aDetector.getMetadata().mnFormat));
487 // Import the WMF result and check for traces of EMF+ in it.
488 Graphic aWmfGraphic;
489 aGraphicStream.Seek(0);
490 sal_uInt16 nFormatWMF = aGraphicFilter.GetImportFormatNumberForShortName(u"WMF");
491 CPPUNIT_ASSERT_EQUAL(
492 ERRCODE_NONE, aGraphicFilter.ImportGraphic(aWmfGraphic, u"", aGraphicStream, nFormatWMF));
493 int nCommentCount = 0;
494 for (size_t i = 0; i < aWmfGraphic.GetGDIMetaFile().GetActionSize(); ++i)
496 MetaAction* pAction = aWmfGraphic.GetGDIMetaFile().GetAction(i);
497 if (pAction->GetType() == MetaActionType::COMMENT)
499 auto pComment = static_cast<MetaCommentAction*>(pAction);
500 if (pComment->GetComment().startsWith("EMF_PLUS"))
502 ++nCommentCount;
506 // Without the accompanying fix in place, this test would have failed with:
507 // - Expected less or equal than: 4
508 // - Actual : 8
509 // i.e. even more EMF+ comments were left in the WMF output. The ideal would be to get this down
510 // to 0, though.
511 CPPUNIT_ASSERT_LESSEQUAL(4, nCommentCount);
514 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingGraphic_PNG_WithGfxLink)
516 // Prepare Graphic from a PNG image first
517 Graphic aGraphic = makeUnloadedGraphic(u"png");
519 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
520 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
521 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
523 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
524 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
526 BitmapChecksum aChecksumBeforeSwapping = aGraphic.GetChecksum();
528 CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsGfxLink());
529 // Expect the compressed png is be at least W * H / 2
530 CPPUNIT_ASSERT_LESS(sal_uInt32(120 * 100 / 2), aGraphic.GetGfxLink().GetDataSize());
532 // We loaded the Graphic and made it available
533 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
534 // Get the declared byte size of the graphic
535 sal_uLong rByteSize = aGraphic.GetSizeBytes();
537 // Check the swap file (shouldn't exist)
538 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
540 // Swapping out
541 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
542 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
543 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
545 // Byte size doesn't change when we swapped out
546 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
548 // Check the swap file (still shouldn't exist)
549 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
551 // Let's swap in
552 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
553 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
554 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
555 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
557 CPPUNIT_ASSERT_EQUAL(aChecksumBeforeSwapping, aGraphic.GetChecksum());
559 // Check the bitmap
560 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
561 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
562 CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
565 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingGraphic_PNG_WithoutGfxLink)
567 // Prepare Graphic from a PNG image first
569 // Make sure to construct the Graphic from BitmapEx, so that we
570 // don't have the GfxLink present.
571 Graphic aGraphic(makeUnloadedGraphic(u"png").GetBitmapEx());
573 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
574 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
575 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
577 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
578 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
580 BitmapChecksum aChecksumBeforeSwapping = aGraphic.GetChecksum();
582 CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
584 // We loaded the Graphic and made it available
585 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
587 // Get the declared byte size of the graphic
588 sal_uLong rByteSize = aGraphic.GetSizeBytes();
589 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
591 // Swapping out
592 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
593 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
594 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
596 // Byte size doesn't change when we swapped out
597 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
599 // Let's check the swap file
601 { // Check the swap file content
602 SvStream* pStream = aGraphic.ImplGetImpGraphic()->getSwapFileStream();
603 pStream->Seek(0);
605 // Check size of the stream
606 CPPUNIT_ASSERT_EQUAL(sal_uInt64(36079), pStream->remainingSize());
608 std::vector<unsigned char> aHash = calculateHash(pStream);
609 CPPUNIT_ASSERT_EQUAL(std::string("9347511e3b80dfdfaadf91a3bdef55a8ae85552b"),
610 toHexString(aHash));
613 // SWAP IN
614 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
615 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
616 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
617 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
619 // reset the checksum to make sure we don't get the cached value
620 aGraphic.ImplGetImpGraphic()->resetChecksum();
621 CPPUNIT_ASSERT_EQUAL(aChecksumBeforeSwapping, aGraphic.GetChecksum());
623 // File shouldn't be available anymore
624 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
626 // Check the bitmap
627 CPPUNIT_ASSERT_EQUAL(tools::Long(120), aGraphic.GetSizePixel().Width());
628 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetSizePixel().Height());
630 CPPUNIT_ASSERT_EQUAL(true, checkBitmap(aGraphic));
633 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingGraphicProperties_PNG_WithGfxLink)
635 // Prepare Graphic from a PNG image
636 Graphic aGraphic = makeUnloadedGraphic(u"png");
638 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
639 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
640 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
642 // Origin URL
643 aGraphic.setOriginURL(u"Origin URL"_ustr);
644 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
646 //Set PrefMapMode
647 CPPUNIT_ASSERT_EQUAL(MapUnit::Map100thMM, aGraphic.GetPrefMapMode().GetMapUnit());
648 aGraphic.SetPrefMapMode(MapMode(MapUnit::MapTwip));
649 CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
651 // Set the PrefSize
652 CPPUNIT_ASSERT_EQUAL(tools::Long(6000), aGraphic.GetPrefSize().Width());
653 CPPUNIT_ASSERT_EQUAL(tools::Long(5000), aGraphic.GetPrefSize().Height());
654 aGraphic.SetPrefSize(Size(200, 100));
655 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
656 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
658 // SWAP OUT
659 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
660 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
661 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
662 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
664 // Check properties
665 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
666 CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
667 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
668 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
670 // SWAP IN
671 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
672 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
673 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
674 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
676 // Check properties
677 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
678 CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
679 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
680 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
683 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingGraphicProperties_PNG_WithoutGfxLink)
685 // Prepare Graphic from a PNG image
686 Graphic aGraphic(makeUnloadedGraphic(u"png").GetBitmapEx());
688 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
689 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
690 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
692 // Origin URL
693 aGraphic.setOriginURL(u"Origin URL"_ustr);
694 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
696 //Set PrefMapMode
697 CPPUNIT_ASSERT_EQUAL(MapUnit::Map100thMM, aGraphic.GetPrefMapMode().GetMapUnit());
698 aGraphic.SetPrefMapMode(MapMode(MapUnit::MapTwip));
699 CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
701 // Set the PrefSize
702 CPPUNIT_ASSERT_EQUAL(tools::Long(6000), aGraphic.GetPrefSize().Width());
703 CPPUNIT_ASSERT_EQUAL(tools::Long(5000), aGraphic.GetPrefSize().Height());
704 aGraphic.SetPrefSize(Size(200, 100));
705 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
706 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
708 // SWAP OUT
709 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
710 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
711 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
712 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
714 // Check properties
715 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
716 CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
717 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
718 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
720 // SWAP IN
721 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
722 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
723 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
724 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
726 // Check properties
727 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
728 CPPUNIT_ASSERT_EQUAL(MapUnit::MapTwip, aGraphic.GetPrefMapMode().GetMapUnit());
729 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
730 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
733 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingVectorGraphic_SVG_WithGfxLink)
735 test::Directories aDirectories;
736 OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
737 SvFileStream aStream(aURL, StreamMode::READ);
738 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
739 Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
740 // Loaded into "prepared" state
742 // Check that the state is as expected
743 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
744 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
746 // Load the vector graphic
747 auto pVectorData = aGraphic.getVectorGraphicData();
748 CPPUNIT_ASSERT_EQUAL(true, bool(pVectorData));
749 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
751 CPPUNIT_ASSERT_EQUAL(size_t(223), pVectorData->getBinaryDataContainer().getSize());
753 CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsGfxLink());
754 CPPUNIT_ASSERT_EQUAL(sal_uInt32(223), aGraphic.GetGfxLink().GetDataSize());
756 // Remember checksum so we can compare after swapping back in again
757 BitmapChecksum aBitmapChecksumBeforeSwapping = aGraphic.GetBitmapEx().GetChecksum();
759 // Check we are not swapped out yet
760 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
762 // Get the declared byte size of the graphic
763 sal_uLong rByteSize = aGraphic.GetSizeBytes();
764 CPPUNIT_ASSERT_EQUAL(sal_uLong(223), rByteSize);
766 // Make sure we don't have a file
767 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
769 // SWAP OUT the Graphic and make sure it's not available currently
770 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
771 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
772 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
774 // We use GfxLink so no swap file in this case
775 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
777 // Byte size doesn't change when we swapped out
778 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
780 // SWAP IN
781 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
782 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
783 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
784 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
786 // Compare that the checksum of the bitmap is still the same
787 CPPUNIT_ASSERT_EQUAL(aBitmapChecksumBeforeSwapping, aGraphic.GetBitmapEx().GetChecksum());
789 // Byte size shouldn't change
790 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
793 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingVectorGraphic_SVG_WithoutGfxLink)
795 test::Directories aDirectories;
796 OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
797 SvFileStream aStream(aURL, StreamMode::READ);
798 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
800 Graphic aInputGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
801 CPPUNIT_ASSERT_EQUAL(size_t(223),
802 aInputGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
804 // Create graphic
805 Graphic aGraphic(aInputGraphic.getVectorGraphicData());
807 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
808 CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
809 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
811 CPPUNIT_ASSERT_EQUAL(size_t(223),
812 aGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
814 CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
816 BitmapChecksum aBitmapChecksumBeforeSwapping = aGraphic.GetBitmapEx().GetChecksum();
818 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
820 // Get the declared byte size of the graphic
821 sal_uLong rByteSize = aGraphic.GetSizeBytes();
822 CPPUNIT_ASSERT_EQUAL(sal_uLong(223), rByteSize);
824 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
826 // Swapping out
827 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
828 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
829 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
831 // Byte size doesn't change when we swapped out
832 // TODO: In case we don't trigger GetBitmapEx (above) the size is 0
833 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
835 // Let's check the swap file
837 // Check the swap file content
838 SvStream* pStream = aGraphic.ImplGetImpGraphic()->getSwapFileStream();
839 pStream->Seek(0);
841 // Check size of the stream
842 CPPUNIT_ASSERT_EQUAL(sal_uInt64(247), pStream->remainingSize());
844 std::vector<unsigned char> aHash = calculateHash(pStream);
845 CPPUNIT_ASSERT_EQUAL(std::string("666820973fd95e6cd9e7bc5f1c53732acbc99326"),
846 toHexString(aHash));
849 // Let's swap in
850 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
851 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
852 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
854 // Check the Graphic
855 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
857 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
858 CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
860 size_t nVectorByteSize = aGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize();
861 CPPUNIT_ASSERT_EQUAL(size_t(223), nVectorByteSize);
863 CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
865 CPPUNIT_ASSERT_EQUAL(aBitmapChecksumBeforeSwapping, aGraphic.GetBitmapEx().GetChecksum());
867 // File shouldn't be available anymore
868 CPPUNIT_ASSERT_EQUAL(static_cast<SvStream*>(nullptr),
869 aGraphic.ImplGetImpGraphic()->getSwapFileStream());
872 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingGraphicProperties_SVG_WithGfxLink)
874 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
875 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
876 if (!IsDefaultDPI())
877 return;
879 // We check that Graphic properties like MapMode, PrefSize are properly
880 // restored through a swap cycle
882 test::Directories aDirectories;
883 OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
884 SvFileStream aStream(aURL, StreamMode::READ);
885 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
886 Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
887 // Loaded into "prepared" state
889 // Load the vector graphic
890 auto pVectorData = aGraphic.getVectorGraphicData();
891 CPPUNIT_ASSERT_EQUAL(true, bool(pVectorData));
892 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
894 // Origin URL
895 aGraphic.setOriginURL(u"Origin URL"_ustr);
896 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
898 // Check size in pixels
899 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
900 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
902 // Set and check the PrefSize
903 CPPUNIT_ASSERT_EQUAL(tools::Long(1349), aGraphic.GetPrefSize().Width());
904 CPPUNIT_ASSERT_EQUAL(tools::Long(1349), aGraphic.GetPrefSize().Height());
905 aGraphic.SetPrefSize(Size(200, 100));
906 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
907 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
909 // SWAP OUT the Graphic and make sure it's not available currently
910 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
911 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
912 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
913 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
915 // Check properties
916 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
917 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
918 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
919 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
920 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
922 // SWAP IN
923 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
924 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
925 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
926 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
928 // Check properties
929 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
930 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
931 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
932 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
933 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
936 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingGraphicProperties_SVG_WithoutGfxLink)
938 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
939 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
940 if (!IsDefaultDPI())
941 return;
943 test::Directories aDirectories;
944 OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
945 SvFileStream aStream(aURL, StreamMode::READ);
946 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
948 Graphic aInputGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
949 CPPUNIT_ASSERT_EQUAL(size_t(223),
950 aInputGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
952 // Create graphic
953 Graphic aGraphic(aInputGraphic.getVectorGraphicData());
955 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
956 CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
957 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
958 CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
959 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
961 // Origin URL
962 aGraphic.setOriginURL(u"Origin URL"_ustr);
963 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
965 // Check size in pixels
966 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
967 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
969 // Set and check the PrefSize
970 CPPUNIT_ASSERT_EQUAL(tools::Long(1349), aGraphic.GetPrefSize().Width());
971 CPPUNIT_ASSERT_EQUAL(tools::Long(1349), aGraphic.GetPrefSize().Height());
972 aGraphic.SetPrefSize(Size(200, 100));
973 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
974 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
976 // SWAP OUT the Graphic and make sure it's not available currently
977 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
978 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
979 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
980 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
982 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
984 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
985 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
986 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
987 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
989 // SWAP IN
990 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
991 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
992 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
993 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
995 CPPUNIT_ASSERT_EQUAL(u"Origin URL"_ustr, aGraphic.getOriginURL());
997 CPPUNIT_ASSERT_EQUAL(tools::Long(200), aGraphic.GetPrefSize().Width());
998 CPPUNIT_ASSERT_EQUAL(tools::Long(100), aGraphic.GetPrefSize().Height());
999 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Width());
1000 CPPUNIT_ASSERT_EQUAL(tools::Long(51), aGraphic.GetSizePixel().Height());
1003 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingVectorGraphic_PDF_WithGfxLink)
1005 test::Directories aDirectories;
1006 OUString aURL = aDirectories.getURLFromSrc(PDFEXPORT_DATA_DIRECTORY) + "SimpleMultiPagePDF.pdf";
1007 SvFileStream aStream(aURL, StreamMode::READ);
1008 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
1009 Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
1011 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1012 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1014 // Load the vector graphic
1015 CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
1017 // Set the page index
1018 aGraphic.getVectorGraphicData()->setPageIndex(1);
1020 CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, aGraphic.getVectorGraphicData()->getType());
1021 CPPUNIT_ASSERT_EQUAL(size_t(17693),
1022 aGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
1023 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1024 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aGraphic.getVectorGraphicData()->getPageIndex());
1026 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1028 // SWAP OUT
1029 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
1030 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1031 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1033 // SWAP IN
1034 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1035 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
1036 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1037 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1039 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aGraphic.getVectorGraphicData()->getPageIndex());
1042 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingVectorGraphic_PDF_WithoutGfxLink)
1044 test::Directories aDirectories;
1045 OUString aURL = aDirectories.getURLFromSrc(PDFEXPORT_DATA_DIRECTORY) + "SimpleMultiPagePDF.pdf";
1046 SvFileStream aStream(aURL, StreamMode::READ);
1047 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
1048 Graphic aInputGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
1050 // Create graphic
1051 Graphic aGraphic(aInputGraphic.getVectorGraphicData());
1053 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1054 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1055 CPPUNIT_ASSERT_EQUAL(true, bool(aGraphic.getVectorGraphicData()));
1057 // Set the page index
1058 aGraphic.getVectorGraphicData()->setPageIndex(1);
1060 CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, aGraphic.getVectorGraphicData()->getType());
1061 CPPUNIT_ASSERT_EQUAL(size_t(17693),
1062 aGraphic.getVectorGraphicData()->getBinaryDataContainer().getSize());
1063 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1064 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aGraphic.getVectorGraphicData()->getPageIndex());
1066 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1068 // SWAP OUT
1069 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
1070 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1071 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1073 // SWAP IN
1074 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1075 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
1076 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1077 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1079 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aGraphic.getVectorGraphicData()->getPageIndex());
1082 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingAnimationGraphic_GIF_WithGfxLink)
1084 test::Directories aDirectories;
1085 OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "123_Numbers.gif";
1086 SvFileStream aStream(aURL, StreamMode::READ);
1087 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
1088 Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
1089 // Loaded into "prepared" state
1091 // Check that the state is as expected
1092 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1093 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1095 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
1096 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1098 CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsGfxLink());
1100 CPPUNIT_ASSERT_EQUAL(tools::Long(124), aGraphic.GetSizePixel().Width());
1101 CPPUNIT_ASSERT_EQUAL(tools::Long(146), aGraphic.GetSizePixel().Height());
1103 CPPUNIT_ASSERT_EQUAL(sal_uInt32(1515), aGraphic.GetGfxLink().GetDataSize());
1105 // Remember checksum so we can compare after swapping back in again
1106 BitmapChecksum aBitmapChecksumBeforeSwapping = aGraphic.GetBitmapEx().GetChecksum();
1108 // Check we are not swapped out yet
1109 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1111 // Get the declared byte size of the graphic
1112 sal_uLong rByteSize = aGraphic.GetSizeBytes();
1113 CPPUNIT_ASSERT_EQUAL(sal_uLong(89552), rByteSize);
1115 // Make sure we don't have a file
1116 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
1118 // SWAP OUT the Graphic and make sure it's not available currently
1119 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
1120 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1121 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1123 // We use GfxLink so no swap file in this case
1124 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
1126 // Byte size doesn't change when we swapped out
1127 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
1129 // SWAP IN
1130 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1131 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
1132 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1133 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1135 // Compare that the checksum of the bitmap is still the same
1136 CPPUNIT_ASSERT_EQUAL(aBitmapChecksumBeforeSwapping, aGraphic.GetBitmapEx().GetChecksum());
1138 // Byte size shouldn't change
1139 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
1142 CPPUNIT_TEST_FIXTURE(GraphicTest, testSwappingAnimationGraphic_GIF_WithoutGfxLink)
1144 test::Directories aDirectories;
1145 OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "123_Numbers.gif";
1146 SvFileStream aStream(aURL, StreamMode::READ);
1147 GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
1148 Graphic aInputGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
1149 Graphic aGraphic(aInputGraphic.GetAnimation());
1151 // Check animation graphic
1152 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1153 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
1154 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1155 CPPUNIT_ASSERT_EQUAL(true, aGraphic.IsAnimated());
1157 CPPUNIT_ASSERT_EQUAL(tools::Long(124), aGraphic.GetSizePixel().Width());
1158 CPPUNIT_ASSERT_EQUAL(tools::Long(146), aGraphic.GetSizePixel().Height());
1160 CPPUNIT_ASSERT_EQUAL(false, aGraphic.IsGfxLink());
1162 // We loaded the Graphic and made it available
1163 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1165 // Get the declared byte size of the graphic
1166 sal_uLong rByteSize = aGraphic.GetSizeBytes();
1167 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->getSwapFileStream() == nullptr);
1169 // SWAP OUT
1170 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1171 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->swapOut());
1172 CPPUNIT_ASSERT_EQUAL(true, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1173 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1175 // Byte size doesn't change when we swapped out
1176 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
1178 // Let's check the swap file
1180 // Check the swap file content
1181 SvStream* pStream = aGraphic.ImplGetImpGraphic()->getSwapFileStream();
1182 pStream->Seek(0);
1184 // Check size of the stream
1185 CPPUNIT_ASSERT_EQUAL(sal_uInt64(15139), pStream->remainingSize());
1187 std::vector<unsigned char> aHash = calculateHash(pStream);
1188 CPPUNIT_ASSERT_EQUAL(std::string("ecae5354edd9cf98553eb3153e44181f56d35338"),
1189 toHexString(aHash));
1192 // SWAP IN
1193 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
1194 CPPUNIT_ASSERT_EQUAL(true, aGraphic.makeAvailable());
1195 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
1196 CPPUNIT_ASSERT_EQUAL(false, aGraphic.ImplGetImpGraphic()->isSwappedOut());
1198 // File shouldn't be available anymore
1199 CPPUNIT_ASSERT_EQUAL(static_cast<SvStream*>(nullptr),
1200 aGraphic.ImplGetImpGraphic()->getSwapFileStream());
1202 // Check the bitmap
1203 CPPUNIT_ASSERT_EQUAL(tools::Long(124), aGraphic.GetSizePixel().Width());
1204 CPPUNIT_ASSERT_EQUAL(tools::Long(146), aGraphic.GetSizePixel().Height());
1206 // Byte size is still the same
1207 CPPUNIT_ASSERT_EQUAL(rByteSize, aGraphic.GetSizeBytes());
1210 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadMET)
1212 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.met");
1213 CPPUNIT_ASSERT_EQUAL(GraphicType::GdiMetafile, aGraphic.GetType());
1216 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadBMP)
1218 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.bmp");
1219 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1220 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
1221 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
1224 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadPSD)
1226 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.psd");
1227 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1228 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
1229 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
1232 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadTGA)
1234 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.tga");
1235 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1236 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
1237 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
1240 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadXBM)
1242 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.xbm");
1243 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1244 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
1245 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
1248 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadXPM)
1250 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.xpm");
1251 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1252 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
1253 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
1256 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadPCX)
1258 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.pcx");
1259 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1260 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
1261 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
1264 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadEPS)
1266 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.eps");
1267 CPPUNIT_ASSERT_EQUAL(GraphicType::GdiMetafile, aGraphic.GetType());
1270 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadWEBP)
1272 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.webp");
1273 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1274 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Width());
1275 CPPUNIT_ASSERT_EQUAL(tools::Long(10), aGraphic.GetSizePixel().Height());
1278 CPPUNIT_TEST_FIXTURE(GraphicTest, testLoadSVGZ)
1280 Graphic aGraphic = loadGraphic(u"TypeDetectionExample.svgz");
1281 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1282 const auto[scalingX, scalingY] = getDPIScaling();
1283 CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingX), aGraphic.GetSizePixel().Width());
1284 CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingY), aGraphic.GetSizePixel().Height());
1287 CPPUNIT_TEST_FIXTURE(GraphicTest, testTdf156016)
1289 // Without the fix in place, this test would have failed with
1290 // - Expected: 0x0(Error Area:Io Class:NONE Code:0)
1291 // - Actual : 0x8203(Error Area:Vcl Class:General Code:3)
1292 Graphic aGraphic = loadGraphic(u"tdf156016.svg");
1293 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1294 const auto[scalingX, scalingY] = getDPIScaling();
1295 CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingX), aGraphic.GetSizePixel().Width());
1296 CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingY), aGraphic.GetSizePixel().Height());
1299 CPPUNIT_TEST_FIXTURE(GraphicTest, testTdf149545)
1301 // Without the fix in place, this test would have failed with
1302 // - Expected: 0x0(Error Area:Io Class:NONE Code:0)
1303 // - Actual : 0x8203(Error Area:Vcl Class:General Code:3)
1304 Graphic aGraphic = loadGraphic(u"tdf149545.svg");
1305 CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
1306 const auto[scalingX, scalingY] = getDPIScaling();
1307 CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingX), aGraphic.GetSizePixel().Width());
1308 CPPUNIT_ASSERT_EQUAL(tools::Long(100 * scalingY), aGraphic.GetSizePixel().Height());
1311 CPPUNIT_TEST_FIXTURE(GraphicTest, testAvailableThreaded)
1313 Graphic jpgGraphic1 = importUnloadedGraphic(u"TypeDetectionExample.jpg");
1314 Graphic jpgGraphic2 = importUnloadedGraphic(u"Exif1.jpg");
1315 Graphic pngGraphic1 = importUnloadedGraphic(u"TypeDetectionExample.png");
1316 Graphic pngGraphic2 = importUnloadedGraphic(u"testBasicMorphology.png");
1317 std::vector<Graphic*> graphics = { &jpgGraphic1, &jpgGraphic2, &pngGraphic1, &pngGraphic2 };
1318 std::vector<Size> sizes;
1319 for (auto& graphic : graphics)
1321 CPPUNIT_ASSERT(!graphic->isAvailable());
1322 sizes.push_back(graphic->GetSizePixel());
1324 GraphicFilter& graphicFilter = GraphicFilter::GetGraphicFilter();
1325 graphicFilter.MakeGraphicsAvailableThreaded(graphics);
1326 int i = 0;
1327 for (auto& graphic : graphics)
1329 CPPUNIT_ASSERT(graphic->isAvailable());
1330 CPPUNIT_ASSERT_EQUAL(sizes[i], graphic->GetSizePixel());
1331 ++i;
1335 CPPUNIT_TEST_FIXTURE(GraphicTest, testColorChangeToTransparent)
1337 Graphic aGraphic = importUnloadedGraphic(u"testColorChange-red-linear-gradient.png");
1339 auto xGraphic = aGraphic.GetXGraphic();
1340 uno::Reference<graphic::XGraphicTransformer> xGraphicTransformer{ xGraphic, uno::UNO_QUERY };
1341 ::Color nColorFrom{ ColorTransparency, 0x00, 0xFF, 0x00, 0x00 };
1342 ::Color nColorTo{ ColorTransparency, 0xFF, 0xFF, 0x00, 0x00 };
1343 sal_uInt8 nTolerance{ 15 };
1345 auto xGraphicAfter = xGraphicTransformer->colorChange(
1346 xGraphic, static_cast<sal_Int32>(nColorFrom), nTolerance, static_cast<sal_Int32>(nColorTo),
1347 static_cast<sal_Int8>(nColorTo.GetAlpha()));
1349 Graphic aGraphicAfter{ xGraphicAfter };
1350 const BitmapEx& rBitmapAfter = aGraphicAfter.GetBitmapExRef();
1351 const BitmapEx& rBitmapBefore = aGraphic.GetBitmapExRef();
1352 // Without the accompanying fix in place, this test would have failed with:
1353 // - Expected: rgba[ff000000]
1354 // - Actual : rgba[f00000ff]
1355 // i.e. the color change to transparent didn't apply correctly
1356 CPPUNIT_ASSERT_EQUAL(nColorTo, rBitmapAfter.GetPixelColor(386, 140));
1358 // Test if color stayed same on 410,140
1359 // colorChange with nTolerance 15 shouldn't change this pixel.
1360 CPPUNIT_ASSERT_EQUAL(rBitmapBefore.GetPixelColor(410, 140),
1361 rBitmapAfter.GetPixelColor(410, 140));
1364 CPPUNIT_PLUGIN_IMPLEMENT();
1366 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */