summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-01-04 16:28:03 +0100
committerAndras Timar <andras.timar@collabora.com>2022-03-15 13:01:53 +0100
commit2b6853729591c9a687cf5855a26acc2a4e8f5e5d (patch)
tree099c7dc84738d68d8a6d3f5c17c1b1c87cb47704
parentd58091edd8e248de4042d56751115784c206144d (diff)
sc export chart as graphic: handle PDF
The context menu for Calc charts would call into GraphicFilter::ExportGraphic(), which has explicit code for e.g. SVG, but not for PDF. The graphic exporter to PDF is only meant to work with images backed with PDF data, not with all shapes. Fix the problem by explicitly handling PDF in GraphicHelper::SaveShapeAsGraphic() in svx/, and invoking the normal PDF export in that case. Continue to fall back to XGraphicExportFilter for other formats. This requires passing down the current document from sc/. (cherry picked from commit 77d2bbaa18e0be5347d7bd7167b245264789e0a4) Conflicts: sc/source/ui/drawfunc/chartsh.cxx svx/Module_svx.mk svx/source/core/graphichelper.cxx Change-Id: Ia5f78bffa1d26989bb0ad3ed265b922e609f076f
-rw-r--r--include/svx/graphichelper.hxx12
-rw-r--r--sc/source/ui/drawfunc/chartsh.cxx9
-rw-r--r--svx/source/core/graphichelper.cxx83
3 files changed, 80 insertions, 24 deletions
diff --git a/include/svx/graphichelper.hxx b/include/svx/graphichelper.hxx
index b582de4a2669..7a5e483a1b37 100644
--- a/include/svx/graphichelper.hxx
+++ b/include/svx/graphichelper.hxx
@@ -24,6 +24,10 @@
#include <svx/svxdllapi.h>
namespace com::sun::star::drawing { class XShape; }
+namespace com::sun::star::lang
+{
+class XComponent;
+}
namespace weld { class Widget; }
namespace weld { class Window; }
@@ -33,7 +37,13 @@ class SVXCORE_DLLPUBLIC GraphicHelper
public:
static void GetPreferredExtension( OUString& rExtension, const Graphic& rGraphic );
static OUString ExportGraphic(weld::Window* pWin, const Graphic& rGraphic, const OUString& rGraphicName);
- static void SaveShapeAsGraphic(weld::Window* pWin, const css::uno::Reference< css::drawing::XShape >& xShape);
+ static void
+ SaveShapeAsGraphicToPath(const css::uno::Reference<css::lang::XComponent>& xComponent,
+ const css::uno::Reference<css::drawing::XShape>& xShape,
+ const OUString& rMimeType, const OUString& rPath);
+ static void SaveShapeAsGraphic(weld::Window* pWin,
+ const css::uno::Reference<css::lang::XComponent>& xComponent,
+ const css::uno::Reference<css::drawing::XShape>& xShape);
static short HasToSaveTransformedImage(weld::Widget* pWin);
};
diff --git a/sc/source/ui/drawfunc/chartsh.cxx b/sc/source/ui/drawfunc/chartsh.cxx
index 25b66b0fb7e2..87b73f4fc88d 100644
--- a/sc/source/ui/drawfunc/chartsh.cxx
+++ b/sc/source/ui/drawfunc/chartsh.cxx
@@ -92,8 +92,15 @@ void ScChartShell::ExecuteExportAsGraphic( SfxRequest& )
if( dynamic_cast<const SdrOle2Obj*>( pObject) )
{
vcl::Window* pWin = GetViewData().GetActiveWin();
+ css::uno::Reference<css::lang::XComponent> xComponent;
+ const SfxObjectShell* pShell = GetObjectShell();
+ if (pShell)
+ {
+ xComponent = pShell->GetModel();
+ }
Reference< drawing::XShape > xSourceDoc( pObject->getUnoShape(), UNO_QUERY_THROW );
- GraphicHelper::SaveShapeAsGraphic(pWin ? pWin->GetFrameWeld() : nullptr, xSourceDoc);
+ GraphicHelper::SaveShapeAsGraphic(pWin ? pWin->GetFrameWeld() : nullptr, xComponent,
+ xSourceDoc);
}
}
diff --git a/svx/source/core/graphichelper.cxx b/svx/source/core/graphichelper.cxx
index 160f8147f76c..18a86bad37e4 100644
--- a/svx/source/core/graphichelper.cxx
+++ b/svx/source/core/graphichelper.cxx
@@ -46,9 +46,14 @@
#include <com/sun/star/beans/XPropertyAccess.hpp>
#include <com/sun/star/task/ErrorCodeIOException.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
+#include <com/sun/star/drawing/ShapeCollection.hpp>
#include <map>
+#include <sfx2/objsh.hxx>
+#include <unotools/streamwrap.hxx>
+#include <comphelper/propertyvalue.hxx>
+
using namespace css::uno;
using namespace css::lang;
using namespace css::graphic;
@@ -338,7 +343,61 @@ OUString GraphicHelper::ExportGraphic(weld::Window* pParent, const Graphic& rGra
return OUString();
}
-void GraphicHelper::SaveShapeAsGraphic(weld::Window* pParent, const Reference< drawing::XShape >& xShape)
+void GraphicHelper::SaveShapeAsGraphicToPath(
+ const css::uno::Reference<css::lang::XComponent>& xComponent,
+ const css::uno::Reference<css::drawing::XShape>& xShape, const OUString& aExportMimeType,
+ const OUString& sPath)
+{
+ Reference<XComponentContext> xContext(::comphelper::getProcessComponentContext());
+ Reference<XInputStream> xGraphStream;
+
+ if (xGraphStream.is())
+ {
+ Reference<XSimpleFileAccess3> xFileAccess = SimpleFileAccess::create(xContext);
+ xFileAccess->writeFile(sPath, xGraphStream);
+ }
+ else if (xComponent.is() && aExportMimeType == "application/pdf")
+ {
+ css::uno::Reference<css::lang::XMultiServiceFactory> xMSF(xContext->getServiceManager(),
+ css::uno::UNO_QUERY);
+ css::uno::Reference<css::document::XExporter> xExporter(
+ xMSF->createInstance("com.sun.star.comp.PDF.PDFFilter"), css::uno::UNO_QUERY);
+ xExporter->setSourceDocument(xComponent);
+
+ css::uno::Reference<css::drawing::XShapes> xShapes
+ = css::drawing::ShapeCollection::create(comphelper::getProcessComponentContext());
+ xShapes->add(xShape);
+ css::uno::Sequence<PropertyValue> aFilterData{
+ comphelper::makePropertyValue("Selection", xShapes),
+ };
+ SvFileStream aStream(sPath, StreamMode::READWRITE | StreamMode::TRUNC);
+ css::uno::Reference<css::io::XOutputStream> xStream(new utl::OStreamWrapper(aStream));
+ css::uno::Sequence<PropertyValue> aDescriptor{
+ comphelper::makePropertyValue("FilterData", aFilterData),
+ comphelper::makePropertyValue("OutputStream", xStream)
+ };
+ css::uno::Reference<css::document::XFilter> xFilter(xExporter, css::uno::UNO_QUERY);
+ xFilter->filter(aDescriptor);
+ }
+ else
+ {
+ Reference<css::drawing::XGraphicExportFilter> xGraphicExporter = css::drawing::GraphicExportFilter::create( xContext );
+
+ Sequence<PropertyValue> aDescriptor( 2 );
+ aDescriptor[0].Name = "MediaType";
+ aDescriptor[0].Value <<= aExportMimeType;
+ aDescriptor[1].Name = "URL";
+ aDescriptor[1].Value <<= sPath;
+
+ Reference< XComponent > xSourceDocument( xShape, UNO_QUERY_THROW );
+ xGraphicExporter->setSourceDocument( xSourceDocument );
+ xGraphicExporter->filter( aDescriptor );
+ }
+}
+
+void GraphicHelper::SaveShapeAsGraphic(weld::Window* pParent,
+ const css::uno::Reference<css::lang::XComponent>& xComponent,
+ const Reference<drawing::XShape>& xShape)
{
try
{
@@ -386,27 +445,7 @@ void GraphicHelper::SaveShapeAsGraphic(weld::Window* pParent, const Reference<
OUString sPath( xFilePicker->getFiles().getConstArray()[0] );
OUString aExportMimeType( aMimeTypeMap[xFilePicker->getCurrentFilter()] );
- Reference< XInputStream > xGraphStream;
-
- if( xGraphStream.is() )
- {
- Reference<XSimpleFileAccess3> xFileAccess = SimpleFileAccess::create( xContext );
- xFileAccess->writeFile( sPath, xGraphStream );
- }
- else
- {
- Reference<css::drawing::XGraphicExportFilter> xGraphicExporter = css::drawing::GraphicExportFilter::create( xContext );
-
- Sequence<PropertyValue> aDescriptor( 2 );
- aDescriptor[0].Name = "MediaType";
- aDescriptor[0].Value <<= aExportMimeType;
- aDescriptor[1].Name = "URL";
- aDescriptor[1].Value <<= sPath;
-
- Reference< XComponent > xSourceDocument( xShape, UNO_QUERY_THROW );
- xGraphicExporter->setSourceDocument( xSourceDocument );
- xGraphicExporter->filter( aDescriptor );
- }
+ GraphicHelper::SaveShapeAsGraphicToPath(xComponent, xShape, aExportMimeType, sPath);
}
}
catch( Exception& )