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 <com/sun/star/awt/XWindow.hpp>
11 #include <com/sun/star/beans/XPropertySet.hpp>
12 #include <com/sun/star/drawing/XDrawPages.hpp>
13 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
14 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
15 #include <com/sun/star/drawing/XShapes.hpp>
16 #include <com/sun/star/text/XText.hpp>
17 #include <com/sun/star/uno/XComponentContext.hpp>
19 #include <cppuhelper/supportsservice.hxx>
21 #include <rtl/ref.hxx>
23 #include <DocumentHandlerForOdp.hxx>
24 #include <ImportFilter.hxx>
25 #include "WpftFilterFixture.hxx"
26 #include "WpftLoader.hxx"
27 #include "wpftimport.hxx"
31 namespace uno
= css::uno
;
33 class PresentationImportFilter
: public writerperfect::ImportFilter
<OdpGenerator
>
36 explicit PresentationImportFilter(const uno::Reference
<uno::XComponentContext
>& rxContext
)
37 : writerperfect::ImportFilter
<OdpGenerator
>(rxContext
)
42 virtual OUString SAL_CALL
getImplementationName() override
;
43 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
44 virtual uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
47 virtual bool doDetectFormat(librevenge::RVNGInputStream
& rInput
, OUString
& rTypeName
) override
;
48 virtual bool doImportDocument(weld::Window
* pWindow
, librevenge::RVNGInputStream
& rInput
,
49 OdpGenerator
& rGenerator
,
50 utl::MediaDescriptor
& rDescriptor
) override
;
52 static void generate(librevenge::RVNGPresentationInterface
& rDocument
);
55 bool PresentationImportFilter::doImportDocument(weld::Window
*, librevenge::RVNGInputStream
&,
56 OdpGenerator
& rGenerator
, utl::MediaDescriptor
&)
58 PresentationImportFilter::generate(rGenerator
);
62 bool PresentationImportFilter::doDetectFormat(librevenge::RVNGInputStream
&, OUString
& rTypeName
)
64 rTypeName
= "WpftDummyPresentation";
69 OUString SAL_CALL
PresentationImportFilter::getImplementationName()
71 return "org.libreoffice.comp.Wpft.QA.PresentationImportFilter";
74 sal_Bool SAL_CALL
PresentationImportFilter::supportsService(const OUString
& rServiceName
)
76 return cppu::supportsService(this, rServiceName
);
79 uno::Sequence
<OUString
> SAL_CALL
PresentationImportFilter::getSupportedServiceNames()
81 return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
84 void PresentationImportFilter::generate(librevenge::RVNGPresentationInterface
& rDocument
)
86 using namespace librevenge
;
88 rDocument
.startDocument(RVNGPropertyList());
89 RVNGPropertyList aProps
;
90 aProps
.insert("svg:width", 800);
91 aProps
.insert("svg:height", 600);
92 rDocument
.startSlide(aProps
);
94 aProps
.insert("svg:x", 50);
95 aProps
.insert("svg:y", 50);
96 aProps
.insert("svg:width", 200);
97 aProps
.insert("svg:height", 100);
98 rDocument
.startTextObject(aProps
);
99 rDocument
.openParagraph(RVNGPropertyList());
100 rDocument
.openSpan(RVNGPropertyList());
101 rDocument
.insertText("My hovercraft is full of eels.");
102 rDocument
.closeSpan();
103 rDocument
.closeParagraph();
104 rDocument
.endTextObject();
105 rDocument
.endSlide();
106 rDocument
.endDocument();
112 class PresentationImportTest
: public writerperfect::test::WpftFilterFixture
117 CPPUNIT_TEST_SUITE(PresentationImportTest
);
119 CPPUNIT_TEST_SUITE_END();
122 void PresentationImportTest::test()
126 rtl::Reference
<PresentationImportFilter
> xFilter
{ new PresentationImportFilter(m_xContext
) };
127 writerperfect::test::WpftLoader
aLoader(createDummyInput(), xFilter
.get(),
128 "private:factory/simpress", m_xDesktop
, m_xContext
);
130 uno::Reference
<drawing::XDrawPagesSupplier
> xDoc(aLoader
.getDocument(), uno::UNO_QUERY
);
131 CPPUNIT_ASSERT(xDoc
.is());
132 uno::Reference
<drawing::XDrawPages
> xPages
= xDoc
->getDrawPages();
133 CPPUNIT_ASSERT(xPages
.is());
134 auto aPage
= xPages
->getByIndex(0);
135 uno::Reference
<beans::XPropertySet
> xPageProps
;
136 CPPUNIT_ASSERT(aPage
>>= xPageProps
);
137 CPPUNIT_ASSERT(xPageProps
.is());
139 CPPUNIT_ASSERT(xPageProps
->getPropertyValue("Height") >>= nProp
);
140 CPPUNIT_ASSERT_EQUAL(sal_Int32(600), nProp
);
141 CPPUNIT_ASSERT(xPageProps
->getPropertyValue("Width") >>= nProp
);
142 CPPUNIT_ASSERT_EQUAL(sal_Int32(800), nProp
);
143 uno::Reference
<drawing::XShapes
> xShapes(xPageProps
, uno::UNO_QUERY
);
144 CPPUNIT_ASSERT(xShapes
.is());
145 auto aShape
= xShapes
->getByIndex(0);
146 uno::Reference
<drawing::XShapeDescriptor
> xShapeDesc
;
147 CPPUNIT_ASSERT(aShape
>>= xShapeDesc
);
148 CPPUNIT_ASSERT(xShapeDesc
.is());
149 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.TextShape"), xShapeDesc
->getShapeType());
150 uno::Reference
<text::XText
> xText(xShapeDesc
, uno::UNO_QUERY
);
151 CPPUNIT_ASSERT_EQUAL(OUString("My hovercraft is full of eels."), xText
->getString());
154 CPPUNIT_TEST_SUITE_REGISTRATION(PresentationImportTest
);
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */