Kaydet (Commit) aca5e1ba authored tarafından Miklos Vajna's avatar Miklos Vajna

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.

Change-Id: I3c9b3005366fcc87815597a27df3cb8a99a8876c
Reviewed-on: https://gerrit.libreoffice.org/54527Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 1462bdc3
......@@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_set_include,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 \
svx/qa/unit/XTableImportExportTest \
))
......@@ -37,6 +38,8 @@ $(eval $(call gb_CppunitTest_use_libraries,svx_unit, \
comphelper \
cppuhelper \
cppu \
test \
unotest \
))
$(eval $(call gb_CppunitTest_use_sdk_api,svx_unit))
......
/* -*- 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: */
......@@ -108,10 +108,10 @@ namespace {
Fraction maScaleX;
Fraction maScaleY;
explicit ExportSettings(const SdrModel& rSdrModel);
explicit ExportSettings(const SdrModel* pSdrModel);
};
ExportSettings::ExportSettings(const SdrModel& rSdrModel)
ExportSettings::ExportSettings(const SdrModel* pSdrModel)
: mnWidth( 0 )
,mnHeight( 0 )
,mbExportOnlyBackground( false )
......@@ -121,8 +121,11 @@ namespace {
,maScaleX( 1, 1 )
,maScaleY( 1, 1 )
{
maScaleX = rSdrModel.GetScaleFraction();
maScaleY = rSdrModel.GetScaleFraction();
if (pSdrModel)
{
maScaleX = pSdrModel->GetScaleFraction();
maScaleY = pSdrModel->GetScaleFraction();
}
}
/** implements a component to export shapes or pages to external graphic formats.
......@@ -161,6 +164,7 @@ namespace {
Reference< XShape > mxShape;
Reference< XDrawPage > mxPage;
Reference< XShapes > mxShapes;
Graphic maGraphic;
SvxDrawPage* mpUnoPage;
......@@ -991,16 +995,16 @@ 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();
// get the arguments from the descriptor
ExportSettings aSettings(*mpDoc);
ExportSettings aSettings(mpDoc);
ParseSettings(aDescriptor, aSettings);
const sal_uInt16 nFilter = !aSettings.maMediaType.isEmpty()
......@@ -1009,9 +1013,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 )
{
......@@ -1109,7 +1115,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)
return;
else
break;
}
// get page for this shape
Reference< XChild > xChild( mxShape, UNO_QUERY );
......@@ -1249,7 +1270,7 @@ Graphic SvxGetGraphicForShape( SdrObject& rShape )
rtl::Reference< GraphicExporter > xExporter( new GraphicExporter() );
Reference< XComponent > xComp( rShape.getUnoShape(), UNO_QUERY_THROW );
xExporter->setSourceDocument( xComp );
ExportSettings aSettings(rShape.getSdrModelFromSdrObject());
ExportSettings aSettings(&rShape.getSdrModelFromSdrObject());
xExporter->GetGraphic( aSettings, aGraphic, true/*bVector*/ );
}
catch( Exception& )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment