1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <test/unoapi_test.hxx>
12 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
13 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <sal/types.h>
16 #include <tools/stream.hxx>
17 #include <unotools/tempfile.hxx>
18 #include <vcl/graph.hxx>
19 #include <vcl/graphicfilter.hxx>
20 #include <svx/xoutbmp.hxx>
21 #include <vcl/filter/PDFiumLibrary.hxx>
22 #include <docmodel/uno/UnoComplexColor.hxx>
24 using namespace com::sun::star
;
26 class XOutdevTest
: public UnoApiTest
30 : UnoApiTest(u
"svx/qa/unit/data/"_ustr
)
35 CPPUNIT_TEST_FIXTURE(XOutdevTest
, testPdfGraphicExport
)
37 auto pPdfium
= vcl::pdf::PDFiumLibrary::get();
43 // Import the graphic.
45 OUString aURL
= createFileURL(u
"graphic.pdf");
46 SvFileStream
aStream(aURL
, StreamMode::READ
);
47 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
,
48 GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic
, aURL
, aStream
));
51 XOutFlags
const eFlags
= XOutFlags::DontExpandFilename
| XOutFlags::DontAddExtension
52 | XOutFlags::UseNativeIfPossible
;
53 OUString aTempURL
= maTempFile
.GetURL();
54 XOutBitmap::WriteGraphic(aGraphic
, aTempURL
, u
"pdf"_ustr
, eFlags
);
56 // Assert that the output looks like a PDF.
57 SvStream
* pStream
= maTempFile
.GetStream(StreamMode::READ
);
58 CPPUNIT_ASSERT(pStream
->TellEnd() > 5);
59 sal_uInt8 sFirstBytes
[5];
60 pStream
->ReadBytes(sFirstBytes
, 5);
61 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('%'), sFirstBytes
[0]);
62 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('P'), sFirstBytes
[1]);
63 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('D'), sFirstBytes
[2]);
64 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('F'), sFirstBytes
[3]);
65 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('-'), sFirstBytes
[4]);
68 CPPUNIT_TEST_FIXTURE(XOutdevTest
, testTdf60684
)
71 OUString aURL
= createFileURL(u
"tdf60684.jpg");
72 SvFileStream
aStream(aURL
, StreamMode::READ
);
73 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
,
74 GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic
, aURL
, aStream
));
77 XOutFlags
const eFlags
= XOutFlags::DontExpandFilename
| XOutFlags::DontAddExtension
78 | XOutFlags::UseNativeIfPossible
;
79 OUString aTempURL
= maTempFile
.GetURL();
80 XOutBitmap::WriteGraphic(aGraphic
, aTempURL
, u
"png"_ustr
, eFlags
);
82 SvStream
* pStream
= maTempFile
.GetStream(StreamMode::READ
);
83 CPPUNIT_ASSERT(pStream
->TellEnd() > 4);
84 sal_uInt8 sFirstBytes
[4];
85 pStream
->ReadBytes(sFirstBytes
, 4);
87 //Checks if the file's header matches a PNG's expected header
88 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('P'), sFirstBytes
[1]);
89 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('N'), sFirstBytes
[2]);
90 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8
>('G'), sFirstBytes
[3]);
93 CPPUNIT_TEST_FIXTURE(XOutdevTest
, testFillColorThemeUnoApi
)
95 // Given an empty Impress document with a (title) shape:
96 loadFromURL(u
"private:factory/simpress"_ustr
);
98 // When setting the theme index of the shape's fill color:
99 uno::Reference
<drawing::XDrawPagesSupplier
> xPagesSupplier(mxComponent
, uno::UNO_QUERY
);
100 uno::Reference
<drawing::XDrawPage
> xPage(xPagesSupplier
->getDrawPages()->getByIndex(0),
102 uno::Reference
<beans::XPropertySet
> xShape(xPage
->getByIndex(0), uno::UNO_QUERY
);
105 model::ComplexColor aComplexColor
;
106 aComplexColor
.setThemeColor(model::ThemeColorType::Accent1
);
107 aComplexColor
.addTransformation({ model::TransformationType::LumMod
, 2000 });
108 aComplexColor
.addTransformation({ model::TransformationType::LumOff
, 8000 });
109 xShape
->setPropertyValue(u
"FillComplexColor"_ustr
,
110 uno::Any(model::color::createXComplexColor(aComplexColor
)));
113 // Then make sure the value we read back is the expected one:
115 uno::Reference
<util::XComplexColor
> xComplexColor
;
116 CPPUNIT_ASSERT(xShape
->getPropertyValue(u
"FillComplexColor"_ustr
) >>= xComplexColor
);
117 CPPUNIT_ASSERT(xComplexColor
.is());
118 auto aComplexColor
= model::color::getFromXComplexColor(xComplexColor
);
119 CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1
, aComplexColor
.getThemeColorType());
120 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod
,
121 aComplexColor
.getTransformations()[0].meType
);
122 CPPUNIT_ASSERT_EQUAL(sal_Int16(2000), aComplexColor
.getTransformations()[0].mnValue
);
123 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff
,
124 aComplexColor
.getTransformations()[1].meType
);
125 CPPUNIT_ASSERT_EQUAL(sal_Int16(8000), aComplexColor
.getTransformations()[1].mnValue
);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */