diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2017-07-20 12:18:37 +0200 |
---|---|---|
committer | Marco Cecchetti <mrcekets@gmail.com> | 2017-07-20 15:35:11 +0200 |
commit | f715c6cfa41ad5a552181bad5e36e8e03f96f480 (patch) | |
tree | 44ad9bb0cb896f24b3664a02e8ab68be9c1ed3f1 /svtools | |
parent | 0d5b54116b92c126eb7fcd7b832aceed17011c79 (diff) |
support for filter dialog when an image is exported from context menu
When user save the selected image in a non-vector format the filter
dialog used in Draw pops up for filter setting.
Change-Id: Ic98b48a47322e807627b7a2ccd8044ec0db30efc
Reviewed-on: https://gerrit.libreoffice.org/40223
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Marco Cecchetti <mrcekets@gmail.com>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/filter/SvFilterOptionsDialog.cxx | 11 | ||||
-rw-r--r-- | svtools/source/filter/exportdialog.cxx | 130 | ||||
-rw-r--r-- | svtools/source/filter/exportdialog.hxx | 5 |
3 files changed, 106 insertions, 40 deletions
diff --git a/svtools/source/filter/SvFilterOptionsDialog.cxx b/svtools/source/filter/SvFilterOptionsDialog.cxx index b3303392bb00..134a09ee1fdc 100644 --- a/svtools/source/filter/SvFilterOptionsDialog.cxx +++ b/svtools/source/filter/SvFilterOptionsDialog.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/document/XExporter.hpp> #include <com/sun/star/document/XViewDataSupplier.hpp> #include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/Sequence.h> @@ -187,10 +188,12 @@ sal_Int16 SvFilterOptionsDialog::execute() sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL; OUString aInternalFilterName; + uno::Reference<graphic::XGraphic> xGraphic; sal_Int32 j, nCount = maMediaDescriptor.getLength(); for ( j = 0; j < nCount; j++ ) { - if ( maMediaDescriptor[ j ].Name == "FilterName" ) + const OUString& rName = maMediaDescriptor[ j ].Name; + if ( rName == "FilterName" ) { OUString aStr; maMediaDescriptor[ j ].Value >>= aStr; @@ -199,6 +202,10 @@ sal_Int16 SvFilterOptionsDialog::execute() aInternalFilterName = aInternalFilterName.replaceAll( "impress_", "" ); break; } + else if ( rName == "Graphic" ) + { + maMediaDescriptor[ j ].Value >>= xGraphic; + } } if ( !aInternalFilterName.isEmpty() ) { @@ -216,7 +223,7 @@ sal_Int16 SvFilterOptionsDialog::execute() aFltCallDlgPara.aFilterData = maFilterDataSequence; aFltCallDlgPara.aFilterExt = aGraphicFilter.GetExportFormatShortName( nFormat ); bool bIsPixelFormat( aGraphicFilter.IsExportPixelFormat( nFormat ) ); - if ( ScopedVclPtrInstance<ExportDialog>( aFltCallDlgPara, mxContext, mxSourceDocument, mbExportSelection, bIsPixelFormat )->Execute() == RET_OK ) + if ( ScopedVclPtrInstance<ExportDialog>( aFltCallDlgPara, mxContext, mxSourceDocument, mbExportSelection, bIsPixelFormat, xGraphic )->Execute() == RET_OK ) nRet = ui::dialogs::ExecutableDialogResults::OK; // taking the out parameter from the dialog diff --git a/svtools/source/filter/exportdialog.cxx b/svtools/source/filter/exportdialog.cxx index 49c4fd8621b6..ca47490e3816 100644 --- a/svtools/source/filter/exportdialog.cxx +++ b/svtools/source/filter/exportdialog.cxx @@ -352,6 +352,9 @@ awt::Size ExportDialog::GetOriginalSize() void ExportDialog::GetGraphicSource() { + if (mxGraphic.is()) + return; + if ( mxSourceDocument.is() ) { uno::Reference< frame::XModel > xModel( mxSourceDocument, uno::UNO_QUERY ); @@ -414,38 +417,76 @@ void ExportDialog::GetGraphicStream() mpTempStream = new SvMemoryStream(); maBitmap = Bitmap(); - uno::Reference < io::XStream > xStream( new utl::OStreamWrapper( *mpTempStream ) ); - uno::Reference < io::XOutputStream > xOutputStream( xStream->getOutputStream() ); - - uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter = - drawing::GraphicExportFilter::create( mxContext ); - - OUString sFormat( maExt ); - uno::Sequence< beans::PropertyValue > aDescriptor( 3 ); - aDescriptor[0].Name = "OutputStream"; - aDescriptor[0].Value <<= xOutputStream; - aDescriptor[1].Name = "FilterName"; - aDescriptor[1].Value <<= sFormat; - aDescriptor[2].Name = "FilterData"; - aDescriptor[2].Value <<= aNewFilterData; - - uno::Reference< lang::XComponent > xSourceDoc; - if ( mxPage.is() ) - xSourceDoc.set( mxPage, uno::UNO_QUERY_THROW ); - else if ( mxShapes.is() ) - xSourceDoc.set( mxShapes, uno::UNO_QUERY_THROW ); - else if ( mxShape.is() ) - xSourceDoc.set( mxShape, uno::UNO_QUERY_THROW ); - if ( xSourceDoc.is() ) + if ( mxGraphic.is() ) { - xGraphicExporter->setSourceDocument( xSourceDoc ); - xGraphicExporter->filter( aDescriptor ); + SvMemoryStream* pTempStream = dynamic_cast<SvMemoryStream*>( mpTempStream ); + Graphic aGraphic( mxGraphic ); - if ( mnFormat == FORMAT_JPG ) + if ( aGraphic.GetType() == GraphicType::Bitmap ) { - mpTempStream->Seek( STREAM_SEEK_TO_BEGIN ); - maBitmap = GetGraphicBitmap( *mpTempStream ); - mpTempStream->Seek( STREAM_SEEK_TO_END ); + Size aSizePixel( aGraphic.GetSizePixel() ); + if( maSize.Width && maSize.Height && + ( ( maSize.Width != aSizePixel.Width() ) || + ( maSize.Height != aSizePixel.Height() ) ) ) + { + BitmapEx aBmpEx( aGraphic.GetBitmapEx() ); + // export: use highest quality + aBmpEx.Scale( Size( maSize.Width, maSize.Height ), BmpScaleFlag::Lanczos ); + aGraphic = aBmpEx; + } + } + + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + const sal_uInt16 nFilter = rFilter.GetExportFormatNumberForShortName( maExt ); + if ( rFilter.IsExportPixelFormat( nFilter ) ) + { + pTempStream->SetResizeOffset(1024); + pTempStream->SetStreamSize(1024); + rFilter.ExportGraphic( aGraphic, "", *pTempStream, nFilter, &aNewFilterData ); + + if ( mnFormat == FORMAT_JPG ) + { + mpTempStream->Seek( STREAM_SEEK_TO_BEGIN ); + maBitmap = GetGraphicBitmap( *mpTempStream ); + mpTempStream->Seek( STREAM_SEEK_TO_END ); + } + } + } + else + { + uno::Reference < io::XStream > xStream( new utl::OStreamWrapper( *mpTempStream ) ); + uno::Reference < io::XOutputStream > xOutputStream( xStream->getOutputStream() ); + + uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter = + drawing::GraphicExportFilter::create( mxContext ); + + OUString sFormat( maExt ); + uno::Sequence< beans::PropertyValue > aDescriptor( 3 ); + aDescriptor[0].Name = "OutputStream"; + aDescriptor[0].Value <<= xOutputStream; + aDescriptor[1].Name = "FilterName"; + aDescriptor[1].Value <<= sFormat; + aDescriptor[2].Name = "FilterData"; + aDescriptor[2].Value <<= aNewFilterData; + + uno::Reference< lang::XComponent > xSourceDoc; + if ( mxPage.is() ) + xSourceDoc.set( mxPage, uno::UNO_QUERY_THROW ); + else if ( mxShapes.is() ) + xSourceDoc.set( mxShapes, uno::UNO_QUERY_THROW ); + else if ( mxShape.is() ) + xSourceDoc.set( mxShape, uno::UNO_QUERY_THROW ); + if ( xSourceDoc.is() ) + { + xGraphicExporter->setSourceDocument( xSourceDoc ); + xGraphicExporter->filter( aDescriptor ); + + if ( mnFormat == FORMAT_JPG ) + { + mpTempStream->Seek( STREAM_SEEK_TO_BEGIN ); + maBitmap = GetGraphicBitmap( *mpTempStream ); + mpTempStream->Seek( STREAM_SEEK_TO_END ); + } } } } @@ -514,11 +555,13 @@ bool ExportDialog::IsTempExportAvailable() const ExportDialog::ExportDialog(FltCallDialogParameter& rPara, const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference< css::lang::XComponent >& rxSourceDocument, - bool bExportSelection, bool bIsPixelFormat) + bool bExportSelection, bool bIsPixelFormat, + const css::uno::Reference< css::graphic::XGraphic >& rxGraphic) : ModalDialog(rPara.pWindow, "GraphicExportDialog", "svt/ui/graphicexport.ui") , mrFltCallPara(rPara) , mxContext(rxContext) , mxSourceDocument(rxSourceDocument) + , mxGraphic(rxGraphic) , mpSbCompression(nullptr) , mpNfCompression(nullptr) , msEstimatedSizePix1(SvtResId(STR_SVT_ESTIMATED_SIZE_PIX_1)) @@ -603,18 +646,31 @@ ExportDialog::ExportDialog(FltCallDialogParameter& rPara, Size aResolution( Application::GetDefaultDevice()->LogicToPixel( Size( 100, 100 ), MapUnit::MapCM ) ); maResolution.Width = aResolution.Width(); maResolution.Height= aResolution.Height(); - maOriginalSize = GetOriginalSize(); - if ( bIsPixelFormat ) + + if ( mxGraphic.is() ) { - double fPixelsPer100thmm = static_cast< double >( maResolution.Width ) / 100000.0; - maSize = awt::Size( static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Width ) + 0.5 ), - static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Height ) + 0.5 ) ); + Graphic aGraphic(mxGraphic); + Size aSize = aGraphic.GetSizePixel(); + maSize = awt::Size(aSize.getWidth(), aSize.getHeight()); + double f100thmmPerPixel = 100000.0 / static_cast< double >( maResolution.Width ); + maOriginalSize = awt::Size( + static_cast< sal_Int32 >( f100thmmPerPixel * maSize.Width ), + static_cast< sal_Int32 >( f100thmmPerPixel * maSize.Height ) ); } else { - maSize = maOriginalSize; + maOriginalSize = GetOriginalSize(); + if ( bIsPixelFormat ) + { + double fPixelsPer100thmm = static_cast< double >( maResolution.Width ) / 100000.0; + maSize = awt::Size( static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Width ) + 0.5 ), + static_cast< sal_Int32 >( ( fPixelsPer100thmm * maOriginalSize.Height ) + 0.5 ) ); + } + else + { + maSize = maOriginalSize; + } } - setupControls(); // Size diff --git a/svtools/source/filter/exportdialog.hxx b/svtools/source/filter/exportdialog.hxx index ec9452239cfb..efa386c0ebd6 100644 --- a/svtools/source/filter/exportdialog.hxx +++ b/svtools/source/filter/exportdialog.hxx @@ -52,6 +52,8 @@ private: mxContext; const css::uno::Reference< css::lang::XComponent >& mxSourceDocument; + const css::uno::Reference< css::graphic::XGraphic >& + mxGraphic; VclPtr<NumericField> mpMfSizeX; VclPtr<ListBox> mpLbSizeX; @@ -171,7 +173,8 @@ public: ExportDialog( FltCallDialogParameter& rPara, const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference< css::lang::XComponent >& rxSourceDocument, - bool bExportSelection, bool bIsExportVectorFormat ); + bool bExportSelection, bool bIsExportVectorFormat, + const css::uno::Reference< css::graphic::XGraphic >& rxGraphic = nullptr); virtual ~ExportDialog() override; virtual void dispose() override; }; |