summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2018-12-14 16:56:18 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2019-06-20 18:05:15 +0200
commita33ab4be7747f6c84e66ee9e826b583d376de938 (patch)
treef995fbb9d636752fbb4add01ed897fe627daa700 /filter
parent96922b783f04a1be28083312b7f8a813d67bade4 (diff)
lok: Implement SVG export of selected Writer image
A Writer image does not behave similar to other shapes, so we need to generate a shape to get the export code working. Change-Id: Icfb25ceb40f73f1018d379863b836d8303e539f3 Reviewed-on: https://gerrit.libreoffice.org/65176 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> (cherry picked from commit d856ba77faa8db9300c99f7dcaa9101bdeca849b)
Diffstat (limited to 'filter')
-rw-r--r--filter/source/svg/svgexport.cxx65
-rw-r--r--filter/source/svg/svgfilter.cxx38
-rw-r--r--filter/source/svg/svgfilter.hxx8
3 files changed, 99 insertions, 12 deletions
diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index b2ec3d307769..5cad38635871 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -31,6 +31,8 @@
#include <com/sun/star/text/textfield/Type.hpp>
#include <com/sun/star/util/MeasureUnit.hpp>
#include <com/sun/star/xml/sax/Writer.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/ShapeCollection.hpp>
#include <rtl/bootstrap.hxx>
#include <svtools/miscopt.hxx>
@@ -52,6 +54,8 @@
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/animationexport.hxx>
+#include <svx/svdograf.hxx>
+#include <svx/svdpage.hxx>
#include <memory>
@@ -532,7 +536,7 @@ bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
}
}
- if(mbWriterOrCalcFilter)
+ if(mbWriterFilter || mbCalcFilter)
return implExportWriterOrCalc(xOStm);
return implExportImpressOrDraw(xOStm);
@@ -674,6 +678,45 @@ bool SVGFilter::implExportWriterOrCalc( const Reference< XOutputStream >& rxOStm
return bRet;
}
+bool SVGFilter::implExportWriterTextGraphic( const Reference< view::XSelectionSupplier >& xSelectionSupplier )
+{
+ Any selection = xSelectionSupplier->getSelection();
+ uno::Reference<lang::XServiceInfo> xSelection;
+ selection >>= xSelection;
+ if (xSelection.is() && xSelection->supportsService("com.sun.star.text.TextGraphicObject"))
+ {
+ uno::Reference<beans::XPropertySet> xPropertySet(xSelection, uno::UNO_QUERY);
+ uno::Reference<graphic::XGraphic> xGraphic;
+ xPropertySet->getPropertyValue("Graphic") >>= xGraphic;
+
+ if (!xGraphic.is())
+ return false;
+
+ const Graphic aGraphic(xGraphic);
+
+ // Calculate size from Graphic
+ Point aPos( OutputDevice::LogicToLogic(aGraphic.GetPrefMapMode().GetOrigin(), aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)) );
+ Size aSize( OutputDevice::LogicToLogic(aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)) );
+
+ assert(mSelectedPages.size() == 1);
+ SvxDrawPage* pSvxDrawPage(SvxDrawPage::getImplementation(mSelectedPages[0]));
+ if(pSvxDrawPage == nullptr || pSvxDrawPage->GetSdrPage() == nullptr)
+ return false;
+
+ SdrGrafObj* pGraphicObj = new SdrGrafObj(pSvxDrawPage->GetSdrPage()->getSdrModelFromSdrPage(), aGraphic, tools::Rectangle( aPos, aSize ));
+ uno::Reference< drawing::XShape > xShape = GetXShapeForSdrObject(pGraphicObj);
+ uno::Reference< XPropertySet > xShapePropSet(xShape, uno::UNO_QUERY);
+ css::awt::Rectangle aBoundRect (aPos.X(), aPos.Y(), aSize.Width(), aSize.Height());
+ xShapePropSet->setPropertyValue("BoundRect", uno::Any(aBoundRect));
+ xShapePropSet->setPropertyValue("Graphic", uno::Any(xGraphic));
+
+ maShapeSelection = drawing::ShapeCollection::create(comphelper::getProcessComponentContext());
+ maShapeSelection->add(xShape);
+ }
+
+ return true;
+}
+
Reference< XWriter > SVGFilter::implCreateExportDocumentHandler( const Reference< XOutputStream >& rxOStm )
{
@@ -785,7 +828,7 @@ bool SVGFilter::implExportDocument()
}
}
- if(mbWriterOrCalcFilter)
+ if(mbWriterFilter || mbCalcFilter)
implExportDocumentHeaderWriterOrCalc(nDocX, nDocY, nDocWidth, nDocHeight);
else
implExportDocumentHeaderImpressOrDraw(nDocX, nDocY, nDocWidth, nDocHeight);
@@ -2058,7 +2101,23 @@ bool SVGFilter::implCreateObjectsFromShape( const Reference< css::drawing::XDraw
if( pObj )
{
- const Graphic aGraphic(SdrExchangeView::GetObjGraphic(*pObj));
+ Graphic aGraphic(SdrExchangeView::GetObjGraphic(*pObj));
+
+ // Writer graphic shapes are handled differently
+ if( mbWriterFilter && aGraphic.GetType() == GraphicType::NONE )
+ {
+ if (rxShape->getShapeType() == "com.sun.star.drawing.GraphicObjectShape")
+ {
+ uno::Reference<beans::XPropertySet> xPropertySet(rxShape, uno::UNO_QUERY);
+ uno::Reference<graphic::XGraphic> xGraphic;
+ xPropertySet->getPropertyValue("Graphic") >>= xGraphic;
+
+ if (!xGraphic.is())
+ return false;
+
+ aGraphic = Graphic(xGraphic);
+ }
+ }
if( aGraphic.GetType() != GraphicType::NONE )
{
diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx
index 93a27ba634b6..d2e18d5688c2 100644
--- a/filter/source/svg/svgfilter.cxx
+++ b/filter/source/svg/svgfilter.cxx
@@ -88,7 +88,9 @@ SVGFilter::SVGFilter( const Reference< XComponentContext >& rxCtx ) :
mbExportShapeSelection(false),
maFilterData(),
mxDefaultPage(),
- mbWriterOrCalcFilter(false),
+ mbWriterFilter(false),
+ mbCalcFilter(false),
+ mbImpressFilter(false),
mpDefaultSdrPage( nullptr ),
mpSdrModel( nullptr ),
mbPresentation( false ),
@@ -107,7 +109,9 @@ SVGFilter::~SVGFilter()
sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescriptor )
{
- mbWriterOrCalcFilter = false;
+ mbWriterFilter = false;
+ mbCalcFilter = false;
+ mbImpressFilter = false;
if(mxDstDoc.is()) // Import works for Impress / draw only
return filterImpressOrDraw(rDescriptor);
@@ -120,9 +124,19 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto
{
OUString sFilterName;
rDescriptor[nInd].Value >>= sFilterName;
- if(sFilterName != "impress_svg_Export")
+ if(sFilterName == "impress_svg_Export")
{
- mbWriterOrCalcFilter = true;
+ mbImpressFilter = true;
+ return filterImpressOrDraw(rDescriptor);
+ }
+ else if(sFilterName == "writer_svg_Export")
+ {
+ mbWriterFilter = true;
+ return filterWriterOrCalc(rDescriptor);
+ }
+ else if(sFilterName == "calc_svg_Export")
+ {
+ mbCalcFilter = true;
return filterWriterOrCalc(rDescriptor);
}
break;
@@ -549,7 +563,7 @@ sal_Bool SVGFilter::filterWriterOrCalc( const Sequence< PropertyValue >& rDescri
}
}
- if(!bSelectionOnly) // For Writer onéy the selection-only mode is supported
+ if(!bSelectionOnly) // For Writer only the selection-only mode is supported
return false;
uno::Reference<frame::XDesktop2> xDesktop(frame::Desktop::create(mxContext));
@@ -564,10 +578,18 @@ sal_Bool SVGFilter::filterWriterOrCalc( const Sequence< PropertyValue >& rDescri
if (!xSelection.is())
return false;
- xSelection->getSelection() >>= maShapeSelection;
+ bool bGotSelection = xSelection->getSelection() >>= maShapeSelection;
- if (!maShapeSelection)
- return false;
+ if (!bGotSelection)
+ {
+ if (mbWriterFilter)
+ {
+ // For Writer we might have a non-shape graphic
+ bGotSelection = implExportWriterTextGraphic(xSelection);
+ }
+ if (!bGotSelection)
+ return false;
+ }
// Select only one draw page
uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier( mxSrcDoc, uno::UNO_QUERY );
diff --git a/filter/source/svg/svgfilter.hxx b/filter/source/svg/svgfilter.hxx
index 435bd35073ff..683f3f1591f2 100644
--- a/filter/source/svg/svgfilter.hxx
+++ b/filter/source/svg/svgfilter.hxx
@@ -30,6 +30,7 @@
#include <com/sun/star/lang/XComponent.hpp>
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/xml/sax/XWriter.hpp>
+#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <osl/diagnose.h>
#include <sal/log.hxx>
@@ -57,6 +58,7 @@ using namespace ::com::sun::star::document;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star;
using namespace ::com::sun::star::xml::sax;
#define SVG_EXPORT_ALLPAGES ((sal_Int32)-1)
@@ -211,7 +213,9 @@ private:
Reference< css::drawing::XDrawPage > mxDefaultPage;
std::vector< Reference< css::drawing::XDrawPage > > mSelectedPages;
- bool mbWriterOrCalcFilter;
+ bool mbWriterFilter;
+ bool mbCalcFilter;
+ bool mbImpressFilter;
/// Impress / draw only members
@@ -235,6 +239,8 @@ private:
bool implExport( const Sequence< PropertyValue >& rDescriptor );
bool implExportImpressOrDraw( const Reference< XOutputStream >& rxOStm );
bool implExportWriterOrCalc( const Reference< XOutputStream >& rxOStm );
+ bool implExportWriterTextGraphic( const Reference< view::XSelectionSupplier >& xSelectionSupplier );
+
static Reference< XWriter > implCreateExportDocumentHandler( const Reference< XOutputStream >& rxOStm );
void implGetPagePropSet( const Reference< css::drawing::XDrawPage > & rxPage );