summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-09-18 16:47:59 +0200
committerEike Rathke <erack@redhat.com>2017-09-18 18:10:41 +0200
commitb149201a076ed2d39fb95dd1c3d1367c9ef6924d (patch)
tree7a6ccc7f71973efc22a570995b8df315eef558d4 /svtools
parent7654183a53cd221e54a10a1bf5497df0c788860d (diff)
Export to PNG: use proper dialog and filter options, tdf#108317
... and not the crude JPG ones. The com.sun.star.svtools.SvFilterOptionsDialog service has all we need, so teach it to cope with non-Graphics source documents and let ExportDialog handle that as well, just the actual rendering needs to go via GraphicExportFilter (and effectively DocumentToGraphicRenderer), so don't let that overwrite the properties set by the filter dialog. Switching to the dialog then is just a matter of changing the UIComponent in filter/source/config/fragments/filters/calc_png_Export The same mechanism probably could be used by Writer as well by adjusting filter/source/config/fragments/filters/writer_png_Export.xcu and maybe filter/source/config/fragments/filters/writer_jpg_Export.xcu in which case the GraphicExportOptionsDialog likely would be moot then. Also, it looks like a filter/source/config/fragments/filters/calc_jpg_Export.xcu (which doesn't exist yet) could be possible using the same mechanism. Change-Id: I1fb9b33a6490dc39d7591b2b5913be182bb820e5 Reviewed-on: https://gerrit.libreoffice.org/42421 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'svtools')
-rw-r--r--svtools/source/filter/SvFilterOptionsDialog.cxx22
-rw-r--r--svtools/source/filter/exportdialog.cxx45
-rw-r--r--svtools/source/filter/exportdialog.hxx3
3 files changed, 57 insertions, 13 deletions
diff --git a/svtools/source/filter/SvFilterOptionsDialog.cxx b/svtools/source/filter/SvFilterOptionsDialog.cxx
index 134a09ee1fdc..e5bd7ab7e392 100644
--- a/svtools/source/filter/SvFilterOptionsDialog.cxx
+++ b/svtools/source/filter/SvFilterOptionsDialog.cxx
@@ -72,7 +72,8 @@ class SvFilterOptionsDialog : public cppu::WeakImplHelper
OUString maDialogTitle;
FieldUnit meFieldUnit;
- bool mbExportSelection;
+ bool mbExportSelection;
+ bool mbGraphicsSource;
public:
@@ -106,7 +107,8 @@ public:
SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference< uno::XComponentContext >& rxContext ) :
mxContext ( rxContext ),
meFieldUnit ( FUNIT_CM ),
- mbExportSelection ( false )
+ mbExportSelection ( false ),
+ mbGraphicsSource ( true )
{
}
@@ -198,8 +200,9 @@ sal_Int16 SvFilterOptionsDialog::execute()
OUString aStr;
maMediaDescriptor[ j ].Value >>= aStr;
aInternalFilterName = aStr;
- aInternalFilterName = aInternalFilterName.replaceAll( "draw_", "" );
- aInternalFilterName = aInternalFilterName.replaceAll( "impress_", "" );
+ aInternalFilterName = aInternalFilterName.replaceFirst( "draw_", "" );
+ aInternalFilterName = aInternalFilterName.replaceFirst( "impress_", "" );
+ aInternalFilterName = aInternalFilterName.replaceFirst( "calc_", "" );
break;
}
else if ( rName == "Graphic" )
@@ -223,7 +226,8 @@ 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, xGraphic )->Execute() == RET_OK )
+ if ( ScopedVclPtrInstance<ExportDialog>( aFltCallDlgPara, mxContext, mxSourceDocument, mbExportSelection,
+ bIsPixelFormat, mbGraphicsSource, xGraphic )->Execute() == RET_OK )
nRet = ui::dialogs::ExecutableDialogResults::OK;
// taking the out parameter from the dialog
@@ -238,6 +242,8 @@ void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComp
{
mxSourceDocument = xDoc;
+ mbGraphicsSource = true; // default Draw and Impress like it was before
+
// try to set the corresponding metric unit
OUString aConfigPath;
uno::Reference< lang::XServiceInfo > xServiceInfo
@@ -248,6 +254,12 @@ void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComp
aConfigPath = "Office.Impress/Layout/Other/MeasureUnit";
else if ( xServiceInfo->supportsService("com.sun.star.drawing.DrawingDocument") )
aConfigPath = "Office.Draw/Layout/Other/MeasureUnit";
+ else
+ {
+ mbGraphicsSource = false;
+ if ( xServiceInfo->supportsService("com.sun.star.sheet.SpreadsheetDocument") )
+ aConfigPath = "Office.Calc/Layout/Other/MeasureUnit";
+ }
if ( !aConfigPath.isEmpty() )
{
FilterConfigItem aConfigItem( aConfigPath );
diff --git a/svtools/source/filter/exportdialog.cxx b/svtools/source/filter/exportdialog.cxx
index cd2e84e2cd95..db1c77e2b38e 100644
--- a/svtools/source/filter/exportdialog.cxx
+++ b/svtools/source/filter/exportdialog.cxx
@@ -24,6 +24,7 @@
#include <vcl/FilterConfigItem.hxx>
#include <svtools/strings.hrc>
#include <svtools/svtresid.hxx>
+#include <svtools/DocumentToGraphicRenderer.hxx>
#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/drawing/XDrawView.hpp>
@@ -316,7 +317,7 @@ awt::Size ExportDialog::GetOriginalSize()
aShapesRange = basegfx::B2DRange( 0, 0, nWidth, nHeight );
}
}
- else
+ else if (mxShapes.is() || mxShape.is())
{
uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory = graphic::PrimitiveFactory2D::create( mxContext );
@@ -347,6 +348,13 @@ awt::Size ExportDialog::GetOriginalSize()
}
}
}
+ else if (!mbGraphicsSource)
+ {
+ DocumentToGraphicRenderer aRenderer( mxSourceDocument, mbExportSelection);
+ const sal_Int32 nCurrentPage = aRenderer.getCurrentPageWriter();
+ const Size aSize = aRenderer.getDocumentSizeIn100mm( nCurrentPage);
+ return awt::Size( aSize.Width(), aSize.Height());
+ }
return awt::Size( static_cast<sal_Int32>(aShapesRange.getWidth()), static_cast<sal_Int32>(aShapesRange.getHeight()) );
}
@@ -369,11 +377,13 @@ void ExportDialog::GetGraphicSource()
if ( xSelectionSupplier.is() )
{
uno::Any aAny( xSelectionSupplier->getSelection() );
- if ( ! ( aAny >>= mxShapes ) )
- aAny >>= mxShape;
+ if ( aAny >>= mxShapes )
+ mbGraphicsSource = true;
+ else if ( aAny >>= mxShape )
+ mbGraphicsSource = true;
}
}
- if ( !mxShape.is() && !mxShapes.is() )
+ if ( !mxShape.is() && !mxShapes.is() && mbGraphicsSource )
{
uno::Reference< drawing::XDrawView > xDrawView( xController, uno::UNO_QUERY );
if ( xDrawView.is() )
@@ -385,6 +395,9 @@ void ExportDialog::GetGraphicSource()
}
}
}
+ // For !mbGraphicsSource the mxSourceDocument is used, from
+ // which XRenderable can query XController and
+ // XSelectionSupplier the same.
}
}
}
@@ -417,9 +430,26 @@ void ExportDialog::GetGraphicStream()
mpTempStream = new SvMemoryStream();
maBitmap = Bitmap();
- if ( mxGraphic.is() )
+ uno::Reference< graphic::XGraphic > xGraphic;
+ if (!mbGraphicsSource && !mxGraphic.is())
+ {
+ // Create a Graphic to be used below.
+ DocumentToGraphicRenderer aRenderer( mxSourceDocument, mbExportSelection);
+ const sal_Int32 nCurrentPage = aRenderer.getCurrentPageWriter();
+ const Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels( nCurrentPage);
+
+ const Size aTargetSizePixel( mbIsPixelFormat ?
+ Size( maSize.Width, maSize.Height) :
+ aDocumentSizePixel );
+
+ Graphic aGraphic( aRenderer.renderToGraphic( nCurrentPage,
+ aDocumentSizePixel, aTargetSizePixel, COL_WHITE));
+ xGraphic = aGraphic.GetXGraphic();
+ }
+
+ if ( mxGraphic.is() || xGraphic.is() )
{
- Graphic aGraphic( mxGraphic );
+ Graphic aGraphic( mxGraphic.is() ? mxGraphic : xGraphic );
if ( aGraphic.GetType() == GraphicType::Bitmap )
{
@@ -554,7 +584,7 @@ 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, bool bGraphicsSource,
const css::uno::Reference< css::graphic::XGraphic >& rxGraphic)
: ModalDialog(rPara.pWindow, "GraphicExportDialog", "svt/ui/graphicexport.ui")
, mrFltCallPara(rPara)
@@ -580,6 +610,7 @@ ExportDialog::ExportDialog(FltCallDialogParameter& rPara,
, maOriginalSize(awt::Size(0, 0))
, mbIsPixelFormat(bIsPixelFormat)
, mbExportSelection(bExportSelection)
+ , mbGraphicsSource(bGraphicsSource)
{
get(mpMfSizeX, "widthmf-nospin");
get(mpMfSizeY, "heightmf-nospin");
diff --git a/svtools/source/filter/exportdialog.hxx b/svtools/source/filter/exportdialog.hxx
index 538a30d3e4bc..5c50660cb2e5 100644
--- a/svtools/source/filter/exportdialog.hxx
+++ b/svtools/source/filter/exportdialog.hxx
@@ -126,6 +126,7 @@ private:
bool mbIsPixelFormat;
bool mbExportSelection;
+ bool mbGraphicsSource; // whether source document is graphics (Draw, Impress) or not (Calc, Writer)
sal_Int32 mnInitialResolutionUnit;
@@ -173,7 +174,7 @@ 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, bool bGraphicsSource,
const css::uno::Reference< css::graphic::XGraphic >& rxGraphic = nullptr);
virtual ~ExportDialog() override;
virtual void dispose() override;