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/beans/XPropertySet.hpp>
11 #include <com/sun/star/drawing/XDrawPages.hpp>
12 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
13 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
14 #include <com/sun/star/drawing/XShapes.hpp>
15 #include <com/sun/star/text/XText.hpp>
16 #include <com/sun/star/uno/XComponentContext.hpp>
18 #include <cppuhelper/supportsservice.hxx>
20 #include <rtl/ref.hxx>
22 #include <DocumentHandlerForOdg.hxx>
23 #include <ImportFilter.hxx>
24 #include "WpftFilterFixture.hxx"
25 #include "WpftLoader.hxx"
26 #include "wpftimport.hxx"
30 namespace uno
= css::uno
;
32 class DrawingImportFilter
: public writerperfect::ImportFilter
<OdgGenerator
>
35 explicit DrawingImportFilter(const uno::Reference
<uno::XComponentContext
>& rxContext
)
36 : writerperfect::ImportFilter
<OdgGenerator
>(rxContext
)
41 virtual OUString SAL_CALL
getImplementationName() override
;
42 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
43 virtual uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
46 virtual bool doDetectFormat(librevenge::RVNGInputStream
& rInput
, OUString
& rTypeName
) override
;
47 virtual bool doImportDocument(weld::Window
* pWindow
, librevenge::RVNGInputStream
& rInput
,
48 OdgGenerator
& rGenerator
,
49 utl::MediaDescriptor
& rDescriptor
) override
;
51 static void generate(librevenge::RVNGDrawingInterface
& rDocument
);
54 bool DrawingImportFilter::doImportDocument(weld::Window
*, librevenge::RVNGInputStream
&,
55 OdgGenerator
& rGenerator
, utl::MediaDescriptor
&)
57 DrawingImportFilter::generate(rGenerator
);
61 bool DrawingImportFilter::doDetectFormat(librevenge::RVNGInputStream
&, OUString
& rTypeName
)
63 rTypeName
= "WpftDummyDrawing";
68 OUString SAL_CALL
DrawingImportFilter::getImplementationName()
70 return u
"org.libreoffice.comp.Wpft.QA.DrawingImportFilter"_ustr
;
73 sal_Bool SAL_CALL
DrawingImportFilter::supportsService(const OUString
& rServiceName
)
75 return cppu::supportsService(this, rServiceName
);
78 uno::Sequence
<OUString
> SAL_CALL
DrawingImportFilter::getSupportedServiceNames()
80 return { u
"com.sun.star.document.ImportFilter"_ustr
,
81 u
"com.sun.star.document.ExtendedTypeDetection"_ustr
};
84 void DrawingImportFilter::generate(librevenge::RVNGDrawingInterface
& 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
.startPage(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();
106 rDocument
.endDocument();
112 class DrawingImportTest
: public writerperfect::test::WpftFilterFixture
117 CPPUNIT_TEST_SUITE(DrawingImportTest
);
119 CPPUNIT_TEST_SUITE_END();
122 void DrawingImportTest::test()
126 rtl::Reference
<DrawingImportFilter
> xFilter
{ new DrawingImportFilter(m_xContext
) };
127 writerperfect::test::WpftLoader
aLoader(createDummyInput(), xFilter
,
128 u
"private:factory/sdraw"_ustr
, 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(u
"Height"_ustr
) >>= nProp
);
140 CPPUNIT_ASSERT_EQUAL(sal_Int32(600), nProp
);
141 CPPUNIT_ASSERT(xPageProps
->getPropertyValue(u
"Width"_ustr
) >>= 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(u
"com.sun.star.drawing.TextShape"_ustr
, xShapeDesc
->getShapeType());
150 uno::Reference
<text::XText
> xText(xShapeDesc
, uno::UNO_QUERY
);
151 CPPUNIT_ASSERT_EQUAL(u
"My hovercraft is full of eels."_ustr
, xText
->getString());
154 CPPUNIT_TEST_SUITE_REGISTRATION(DrawingImportTest
);
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */