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/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
12 #include <test/xmltesttools.hxx>
14 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
15 #include <com/sun/star/drawing/XDrawPage.hpp>
16 #include <com/sun/star/frame/Desktop.hpp>
18 #include <drawinglayer/tools/primitive2dxmldump.hxx>
19 #include <rtl/ustring.hxx>
20 #include <svx/sdr/contact/displayinfo.hxx>
21 #include <svx/sdr/contact/viewcontact.hxx>
22 #include <svx/sdr/contact/viewobjectcontact.hxx>
23 #include <svx/svdpage.hxx>
24 #include <svx/unopage.hxx>
25 #include <vcl/virdev.hxx>
26 #include <sdr/contact/objectcontactofobjlistpainter.hxx>
28 using namespace ::com::sun::star
;
32 /// Tests for svx/source/sdr/ code.
33 class SdrTest
: public test::BootstrapFixture
, public unotest::MacrosTest
, public XmlTestTools
36 uno::Reference
<lang::XComponent
> mxComponent
;
39 virtual void setUp() override
41 test::BootstrapFixture::setUp();
42 mxDesktop
.set(frame::Desktop::create(m_xContext
));
45 virtual void tearDown() override
49 mxComponent
->dispose();
51 test::BootstrapFixture::tearDown();
53 uno::Reference
<lang::XComponent
>& getComponent() { return mxComponent
; }
55 drawinglayer::primitive2d::Primitive2DContainer
56 renderPageToPrimitives(const uno::Reference
<drawing::XDrawPage
>& xDrawPage
);
59 drawinglayer::primitive2d::Primitive2DContainer
60 SdrTest::renderPageToPrimitives(const uno::Reference
<drawing::XDrawPage
>& xDrawPage
)
62 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
63 CPPUNIT_ASSERT(pDrawPage
);
64 SdrPage
* pSdrPage
= pDrawPage
->GetSdrPage();
65 ScopedVclPtrInstance
<VirtualDevice
> aVirtualDevice
;
66 sdr::contact::ObjectContactOfObjListPainter
aObjectContact(*aVirtualDevice
,
67 { pSdrPage
->GetObj(0) }, nullptr);
68 const sdr::contact::ViewObjectContact
& rDrawPageVOContact
69 = pSdrPage
->GetViewContact().GetViewObjectContact(aObjectContact
);
70 sdr::contact::DisplayInfo aDisplayInfo
;
71 return rDrawPageVOContact
.getPrimitive2DSequenceHierarchy(aDisplayInfo
);
74 CPPUNIT_TEST_FIXTURE(SdrTest
, testShadowScaleOrigin
)
76 // Load a document containing a custom shape.
77 test::Directories aDirectories
;
78 OUString aURL
= aDirectories
.getURLFromSrc("svx/qa/unit/data/shadow-scale-origin.pptx");
79 getComponent() = loadFromDesktop(aURL
);
80 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY
);
81 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
83 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
84 = renderPageToPrimitives(xDrawPage
);
86 // Examine the created primitives.
87 drawinglayer::Primitive2dXmlDump aDumper
;
88 xmlDocUniquePtr pDocument
= aDumper
.dumpAndParse(xPrimitiveSequence
);
89 double fShadowX
= getXPath(pDocument
, "//shadow/transform", "xy13").toDouble();
90 double fShadowY
= getXPath(pDocument
, "//shadow/transform", "xy23").toDouble();
91 // Without the accompanying fix in place, this test would have failed with:
94 // i.e. the shadow origin was not the top right corner for scaling (larger x position, so it was
95 // visible on the right of the shape as well).
96 CPPUNIT_ASSERT_EQUAL(-705., std::round(fShadowX
));
97 CPPUNIT_ASSERT_EQUAL(-685., std::round(fShadowY
));
100 CPPUNIT_TEST_FIXTURE(SdrTest
, testZeroWidthTextWrap
)
102 // Load a document containing a 0-width shape with text.
103 test::Directories aDirectories
;
104 OUString aURL
= aDirectories
.getURLFromSrc("svx/qa/unit/data/0-width-text-wrap.pptx");
105 getComponent() = loadFromDesktop(aURL
);
106 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY
);
107 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
109 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
110 = renderPageToPrimitives(xDrawPage
);
112 // Examine the created primitives.
113 drawinglayer::Primitive2dXmlDump aDumper
;
114 xmlDocUniquePtr pDocument
= aDumper
.dumpAndParse(xPrimitiveSequence
);
115 // Without the accompanying fix in place, this test would have failed with:
118 // i.e. the text on the only shape on the slide had 12 lines, not a single one.
119 assertXPath(pDocument
, "//textsimpleportion", 1);
122 CPPUNIT_TEST_FIXTURE(SdrTest
, testSlideBackground
)
124 // Given a document with a slide what has a linked background image:
125 test::Directories aDirectories
;
126 OUString aURL
= aDirectories
.getURLFromSrc(u
"svx/qa/unit/data/slide-background.odp");
127 getComponent() = loadFromDesktop(aURL
);
128 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY
);
129 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
132 // When rendering that document:
133 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
134 = renderPageToPrimitives(xDrawPage
);
136 // Then make sure that the background has a bitmap:
137 drawinglayer::Primitive2dXmlDump aDumper
;
138 xmlDocUniquePtr pDocument
= aDumper
.dumpAndParse(xPrimitiveSequence
);
139 // Without the accompanying fix in place, this test would have failed with:
142 // i.e. the rendering did not find the bitmap.
143 assertXPath(pDocument
, "//bitmap", 1);
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */