summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-05-18 12:26:37 +0200
committerAndras Timar <andras.timar@collabora.com>2018-06-01 10:35:18 +0200
commit1717b2b15a2d90906c20874d6da25a7e5722fb06 (patch)
tree4883454e3a95d310235fed9613df1d0bef794bb4 /svx
parentd3895c7d031557fa51ce718bc5748e17784e825c (diff)
tdf#117614 svx: make drawing.GraphicExportFilter work with sw images
A Writer image has an underlying SdrObject, but GetSdrObjectFromXShape() won't work for it, also we can't an sw SdrObject into an XShape because SvxDrawPage::CreateShape() has no idea how to handle sw's SdrInventor::Swg inventor. Fix the problem by just getting the Graphic of the Writer image and improve GraphicExportFilter to be able to work with just a Graphic as well. (cherry picked from commit aca5e1ba7f33c8913304b5f90ef478f316e64263) Conflicts: svx/CppunitTest_svx_unit.mk svx/source/unodraw/UnoGraphicExporter.cxx Change-Id: I3c9b3005366fcc87815597a27df3cb8a99a8876c Reviewed-on: https://gerrit.libreoffice.org/54688 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/CppunitTest_svx_unit.mk5
-rw-r--r--svx/qa/unit/data/unodraw-writer-image.odtbin0 -> 9564 bytes
-rw-r--r--svx/qa/unit/unodraw.cxx89
-rw-r--r--svx/source/unodraw/UnoGraphicExporter.cxx28
4 files changed, 117 insertions, 5 deletions
diff --git a/svx/CppunitTest_svx_unit.mk b/svx/CppunitTest_svx_unit.mk
index 0bac905a9dc9..0a3df5789a11 100644
--- a/svx/CppunitTest_svx_unit.mk
+++ b/svx/CppunitTest_svx_unit.mk
@@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_use_sdk_api,svx_unit))
$(eval $(call gb_CppunitTest_add_exception_objects,svx_unit, \
svx/qa/unit/svdraw/test_SdrTextObject \
+ svx/qa/unit/unodraw \
svx/qa/unit/xoutdev \
))
@@ -26,6 +27,10 @@ $(eval $(call gb_CppunitTest_use_libraries,svx_unit, \
unotest \
vcl \
utl \
+ comphelper \
+ cppu \
+ test \
+ unotest \
))
$(eval $(call gb_CppunitTest_use_sdk_api,svx_unit))
diff --git a/svx/qa/unit/data/unodraw-writer-image.odt b/svx/qa/unit/data/unodraw-writer-image.odt
new file mode 100644
index 000000000000..5264118a373e
--- /dev/null
+++ b/svx/qa/unit/data/unodraw-writer-image.odt
Binary files differ
diff --git a/svx/qa/unit/unodraw.cxx b/svx/qa/unit/unodraw.cxx
new file mode 100644
index 000000000000..263d3f8c3825
--- /dev/null
+++ b/svx/qa/unit/unodraw.cxx
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <com/sun/star/drawing/GraphicExportFilter.hpp>
+#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <comphelper/propertysequence.hxx>
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+#include <unotools/tempfile.hxx>
+
+using namespace ::com::sun::star;
+
+namespace
+{
+char const DATA_DIRECTORY[] = "/svx/qa/unit/data/";
+
+/// Tests for svx/source/unodraw/ code.
+class UnodrawTest : public test::BootstrapFixture, public unotest::MacrosTest
+{
+ uno::Reference<uno::XComponentContext> mxComponentContext;
+ uno::Reference<lang::XComponent> mxComponent;
+
+public:
+ void testWriterGraphicExport();
+
+ void setUp() override;
+ void tearDown() override;
+
+ CPPUNIT_TEST_SUITE(UnodrawTest);
+ CPPUNIT_TEST(testWriterGraphicExport);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void UnodrawTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
+ mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void UnodrawTest::tearDown()
+{
+ if (mxComponent.is())
+ mxComponent->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+void UnodrawTest::testWriterGraphicExport()
+{
+ // Load a document with a Writer picture in it.
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "unodraw-writer-image.odt";
+ mxComponent = loadFromDesktop(aURL);
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+ uno::Reference<lang::XComponent> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+
+ // Export it as JPEG.
+ uno::Reference<drawing::XGraphicExportFilter> xExportFilter
+ = drawing::GraphicExportFilter::create(mxComponentContext);
+ // This resulted in a css::lang::IllegalArgumentException for a Writer
+ // picture.
+ xExportFilter->setSourceDocument(xShape);
+
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ uno::Sequence<beans::PropertyValue> aProperties(
+ comphelper::InitPropertySequence({ { "URL", uno::Any(aTempFile.GetURL()) },
+ { "MediaType", uno::Any(OUString("image/jpeg")) } }));
+ CPPUNIT_ASSERT(xExportFilter->filter(aProperties));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(UnodrawTest);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/unodraw/UnoGraphicExporter.cxx b/svx/source/unodraw/UnoGraphicExporter.cxx
index df98ffaf8dab..15cfad13e647 100644
--- a/svx/source/unodraw/UnoGraphicExporter.cxx
+++ b/svx/source/unodraw/UnoGraphicExporter.cxx
@@ -164,6 +164,7 @@ namespace {
Reference< XShape > mxShape;
Reference< XDrawPage > mxPage;
Reference< XShapes > mxShapes;
+ Graphic maGraphic;
SvxDrawPage* mpUnoPage;
@@ -988,10 +989,10 @@ sal_Bool SAL_CALL GraphicExporter::filter( const Sequence< PropertyValue >& aDes
{
::SolarMutexGuard aGuard;
- if( nullptr == mpUnoPage )
+ if( !maGraphic && nullptr == mpUnoPage )
return false;
- if( nullptr == mpUnoPage->GetSdrPage() || nullptr == mpDoc )
+ if( !maGraphic && ( nullptr == mpUnoPage->GetSdrPage() || nullptr == mpDoc ) )
return false;
GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();
@@ -1006,9 +1007,11 @@ sal_Bool SAL_CALL GraphicExporter::filter( const Sequence< PropertyValue >& aDes
bool bVectorType = !rFilter.IsExportPixelFormat( nFilter );
// create the output stuff
- Graphic aGraphic;
+ Graphic aGraphic = maGraphic;
- ErrCode nStatus = GetGraphic( aSettings, aGraphic, bVectorType ) ? ERRCODE_NONE : ERRCODE_GRFILTER_FILTERERROR;
+ ErrCode nStatus = ERRCODE_NONE;
+ if (!maGraphic)
+ nStatus = GetGraphic( aSettings, aGraphic, bVectorType ) ? ERRCODE_NONE : ERRCODE_GRFILTER_FILTERERROR;
if( nStatus == ERRCODE_NONE )
{
@@ -1106,7 +1109,22 @@ void SAL_CALL GraphicExporter::setSourceDocument( const Reference< lang::XCompon
if( mxShape.is() )
{
if( nullptr == GetSdrObjectFromXShape( mxShape ) )
- break;
+ {
+ // This is not a Draw shape, let's see if it's a Writer one.
+ uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
+ if (!xPropertySet.is())
+ break;
+ uno::Reference<graphic::XGraphic> xGraphic(
+ xPropertySet->getPropertyValue("Graphic"), uno::UNO_QUERY);
+ if (!xGraphic.is())
+ break;
+
+ maGraphic = Graphic(xGraphic);
+ if (maGraphic.GetType() != GraphicType::NONE)
+ return;
+ else
+ break;
+ }
// get page for this shape
Reference< XChild > xChild( mxShape, UNO_QUERY );