From ec746c830c4ce86e446b929a88a3376a51871314 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 27 Nov 2013 11:40:46 +0100 Subject: [PATCH] oox: initial import of wpg:wgp We import something that's visible, but the position of the shape is not correct yet. Change-Id: Ie68f0ebad1cc992a6c8d7704d7262f7e983f3b19 --- oox/Library_oox.mk | 1 + oox/source/shape/ShapeContextHandler.cxx | 38 ++++++++++++++- oox/source/shape/ShapeContextHandler.hxx | 2 + oox/source/shape/WpgContext.cxx | 59 ++++++++++++++++++++++++ oox/source/shape/WpgContext.hxx | 38 +++++++++++++++ 5 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 oox/source/shape/WpgContext.cxx create mode 100644 oox/source/shape/WpgContext.hxx diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk index 7bd371017d4c..b7e763c6f575 100644 --- a/oox/Library_oox.mk +++ b/oox/Library_oox.mk @@ -277,6 +277,7 @@ $(eval $(call gb_Library_add_exception_objects,oox,\ oox/source/shape/ShapeContextHandler \ oox/source/shape/ShapeDrawingFragmentHandler \ oox/source/shape/ShapeFilterBase \ + oox/source/shape/WpgContext \ oox/source/shape/WpsContext \ oox/source/token/namespacemap \ oox/source/token/propertynames \ diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx index bcf43c85542d..c12518d56fd6 100644 --- a/oox/source/shape/ShapeContextHandler.cxx +++ b/oox/source/shape/ShapeContextHandler.cxx @@ -23,6 +23,7 @@ #include "ShapeDrawingFragmentHandler.hxx" #include "LockedCanvasContext.hxx" #include "WpsContext.hxx" +#include "WpgContext.hxx" #include "oox/vml/vmldrawingfragment.hxx" #include "oox/vml/vmlshape.hxx" #include "oox/drawingml/themefragmenthandler.hxx" @@ -136,6 +137,26 @@ uno::Reference ShapeContextHandler::getWpsContext return mxWpsContext; } +uno::Reference ShapeContextHandler::getWpgContext(sal_Int32 nElement) +{ + if (!mxWpgContext.is()) + { + FragmentHandler2Ref rFragmentHandler(new ShapeFragmentHandler(*mxFilterBase, msRelationFragmentPath)); + ShapePtr pMasterShape; + + switch (getBaseToken(nElement)) + { + case XML_wgp: + mxWpgContext.set(new WpgContext(*rFragmentHandler)); + break; + default: + break; + } + } + + return mxWpgContext; +} + uno::Reference ShapeContextHandler::getGraphicShapeContext(::sal_Int32 Element ) { @@ -216,6 +237,9 @@ ShapeContextHandler::getContextHandler() case NMSP_wps: xResult.set(getWpsContext(mnStartToken)); break; + case NMSP_wpg: + xResult.set(getWpgContext(mnStartToken)); + break; default: xResult.set(getGraphicShapeContext(mnStartToken)); break; @@ -240,7 +264,7 @@ void SAL_CALL ShapeContextHandler::startFastElement mpThemePtr.reset(new Theme()); - if (Element == DGM_TOKEN(relIds) || Element == LC_TOKEN(lockedCanvas) || Element == C_TOKEN(chart) || Element == WPS_TOKEN(wsp)) + if (Element == DGM_TOKEN(relIds) || Element == LC_TOKEN(lockedCanvas) || Element == C_TOKEN(chart) || Element == WPS_TOKEN(wsp) || Element == WPG_TOKEN(wgp)) { // Parse the theme relation, if available; the diagram won't have colors without it. if (!msRelationFragmentPath.isEmpty()) @@ -432,6 +456,18 @@ ShapeContextHandler::getShape() throw (uno::RuntimeException) mxWpsContext.clear(); } } + else if (mxWpgContext.is()) + { + ShapePtr pShape = dynamic_cast(mxWpgContext.get())->getShape(); + if (pShape) + { + basegfx::B2DHomMatrix aMatrix; + pShape->setPosition(maPosition); + pShape->addShape(*mxFilterBase, mpThemePtr.get(), xShapes, aMatrix, pShape->getFillProperties()); + xResult = pShape->getXShape(); + mxWpgContext.clear(); + } + } else if (mpShape.get() != NULL) { basegfx::B2DHomMatrix aTransformation; diff --git a/oox/source/shape/ShapeContextHandler.hxx b/oox/source/shape/ShapeContextHandler.hxx index 0c213131fee4..7a9b93c0f679 100644 --- a/oox/source/shape/ShapeContextHandler.hxx +++ b/oox/source/shape/ShapeContextHandler.hxx @@ -155,6 +155,7 @@ private: css::uno::Reference mxDiagramShapeContext; css::uno::Reference mxLockedCanvasContext; css::uno::Reference mxWpsContext; + css::uno::Reference mxWpgContext; css::uno::Reference mxChartShapeContext; core::XmlFilterRef mxFilterBase; @@ -169,6 +170,7 @@ private: css::uno::Reference getDiagramShapeContext(); css::uno::Reference getLockedCanvasContext(sal_Int32 nElement); css::uno::Reference getWpsContext(sal_Int32 nElement); + css::uno::Reference getWpgContext(sal_Int32 nElement); css::uno::Reference getContextHandler(); }; diff --git a/oox/source/shape/WpgContext.cxx b/oox/source/shape/WpgContext.cxx new file mode 100644 index 000000000000..f83fe75ced27 --- /dev/null +++ b/oox/source/shape/WpgContext.cxx @@ -0,0 +1,59 @@ +/* -*- 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 "WpgContext.hxx" +#include +#include + +using namespace com::sun::star; + +namespace oox { namespace shape { + +WpgContext::WpgContext(ContextHandler2Helper& rParent) +: ContextHandler2(rParent) +{ + mpShape.reset(new oox::drawingml::Shape("com.sun.star.drawing.GroupShape")); +} + +WpgContext::~WpgContext() +{ +} + +oox::drawingml::ShapePtr WpgContext::getShape() +{ + return mpShape; +} + +oox::core::ContextHandlerRef WpgContext::onCreateContext(sal_Int32 nElementToken, const oox::AttributeList& /*rAttribs*/) +{ + switch (getBaseToken(nElementToken)) + { + case XML_wgp: + break; + case XML_cNvGrpSpPr: + break; + case XML_grpSpPr: + return new oox::drawingml::ShapePropertiesContext(*this, *mpShape); + break; + case XML_wsp: + { + oox::drawingml::ShapePtr pShape(new oox::drawingml::Shape("com.sun.star.drawing.CustomShape")); + return new oox::drawingml::ShapeContext(*this, mpShape, pShape); + } + break; + default: + SAL_WARN("oox", "WpgContext::createFastChildContext: unhandled element: " << getBaseToken(nElementToken)); + break; + } + return 0; +} + +} } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/shape/WpgContext.hxx b/oox/source/shape/WpgContext.hxx new file mode 100644 index 000000000000..3a609860012e --- /dev/null +++ b/oox/source/shape/WpgContext.hxx @@ -0,0 +1,38 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_OOX_SOURCE_SHAPE_WPGCONTEXT_HXX +#define INCLUDED_OOX_SOURCE_SHAPE_WPGCONTEXT_HXX + +#include "oox/core/contexthandler2.hxx" +#include "oox/drawingml/shape.hxx" + +namespace oox { namespace shape { + +/// Wpg is the drawingML equivalent of v:group. +class WpgContext : public oox::core::ContextHandler2 +{ +public: + WpgContext(oox::core::ContextHandler2Helper& rParent); + virtual ~WpgContext(); + + virtual oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElementToken, const oox::AttributeList& rAttribs) SAL_OVERRIDE; + + oox::drawingml::ShapePtr getShape(); + +protected: + oox::drawingml::ShapePtr mpShape; +}; + + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */