summaryrefslogtreecommitdiff
path: root/oox/source/drawingml
diff options
context:
space:
mode:
authorArmin Le Grand (Allotropia) <Armin.Le.Grand@me.com>2022-04-08 17:38:12 +0200
committerArmin Le Grand <Armin.Le.Grand@me.com>2022-04-11 09:54:33 +0200
commit027db2df5371183136f87e84ec4829d59eef209b (patch)
tree490e5cbfd0404e3b3efb2e37ea9c337da3a2060d /oox/source/drawingml
parenta5c27f59c4e28d9ec1c1ce8f8c0c5ef6fc68772c (diff)
Advanced Diagram support: Make Style/Theme info available
The Style/Theme information is central for re-creating the Diagram shape representation. Make that data available in the ModelData classes in svx. With that information, a re- creation with all needed attributes is possible, e.g. when the model gets changed (remove/add data entries). Also some cleanups done. Change-Id: Icd925c9731891092f1ddd96c8feb165e1f846f4f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132738 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'oox/source/drawingml')
-rw-r--r--oox/source/drawingml/diagram/diagram.cxx6
-rw-r--r--oox/source/drawingml/diagram/diagramhelper.cxx35
-rw-r--r--oox/source/drawingml/diagram/diagramhelper.hxx7
3 files changed, 45 insertions, 3 deletions
diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx
index d12deea33d2f..484e7af9fd13 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -416,6 +416,12 @@ void loadDiagram( ShapePtr const & pShape,
pDiagram->addTo(pShape);
pShape->setDiagramDoms(pDiagram->getDomsAsPropertyValues());
+ // Get the oox::Theme definition and - if available - move/secure the
+ // original ImportData directly to the Diagram ModelData
+ std::shared_ptr<::oox::drawingml::Theme> aTheme(rFilter.getCurrentThemePtr());
+ if(aTheme)
+ pData->setThemeDocument(aTheme->getFragment()); //getTempFile());
+
// Prepare support for the advanced DiagramHelper using Diagram & Theme data
pShape->prepareDiagramHelper(pDiagram, rFilter.getCurrentThemePtr());
}
diff --git a/oox/source/drawingml/diagram/diagramhelper.cxx b/oox/source/drawingml/diagram/diagramhelper.cxx
index 4ed76e5bff1c..cc6efd9ba50e 100644
--- a/oox/source/drawingml/diagram/diagramhelper.cxx
+++ b/oox/source/drawingml/diagram/diagramhelper.cxx
@@ -26,6 +26,8 @@
#include <drawingml/fillproperties.hxx>
#include <svx/svdmodel.hxx>
#include <comphelper/processfactory.hxx>
+#include <oox/drawingml/themefragmenthandler.hxx>
+#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
using namespace ::com::sun::star;
@@ -101,7 +103,7 @@ void AdvancedDiagramHelper::reLayout(SdrObjGroup& rTarget)
// set oox::Theme at Filter. All LineStyle/FillStyle/Colors/Attributes
// will be taken from there
- xFilter->setCurrentTheme(mpThemePtr);
+ xFilter->setCurrentTheme(getOrCreateThemePtr(xFilter));
css::uno::Reference< css::lang::XComponent > aComponentModel( rUnoModel, uno::UNO_QUERY );
xFilter->setTargetDocument(aComponentModel);
@@ -183,6 +185,37 @@ void AdvancedDiagramHelper::doAnchor(SdrObjGroup& rTarget)
anchorToSdrObjGroup(rTarget);
}
+std::shared_ptr< ::oox::drawingml::Theme > AdvancedDiagramHelper::getOrCreateThemePtr(
+ rtl::Reference< oox::shape::ShapeFilterBase >& rxFilter) const
+{
+ static bool bForceThemePtrReceation(false);
+
+ // (Re-)Use already existing Theme if existing/imported if possible.
+ // If not, re-import Theme if data is available and thus possible
+ if(hasDiagramData() && (bForceThemePtrReceation || !mpThemePtr))
+ {
+ // get the originally imported dom::XDocument
+ const uno::Reference< css::xml::dom::XDocument >& xThemeDocument(mpDiagramPtr->getData()->getThemeDocument());
+
+ if(xThemeDocument)
+ {
+ // reset local Theme ModelData *always* to get rid of former data that would
+ // else be added additionally
+ const_cast<AdvancedDiagramHelper*>(this)->mpThemePtr = std::make_shared<oox::drawingml::Theme>();
+
+ // import Theme ModelData
+ rxFilter->importFragment(
+ new ThemeFragmentHandler(
+ *rxFilter, OUString(), *mpThemePtr ),
+ uno::Reference< css::xml::sax::XFastSAXSerializable >(
+ xThemeDocument,
+ uno::UNO_QUERY_THROW));
+ }
+ }
+
+ return mpThemePtr;
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/diagram/diagramhelper.hxx b/oox/source/drawingml/diagram/diagramhelper.hxx
index 33fd2da9d7a1..d8fd46ce57a1 100644
--- a/oox/source/drawingml/diagram/diagramhelper.hxx
+++ b/oox/source/drawingml/diagram/diagramhelper.hxx
@@ -22,6 +22,7 @@
#include <rtl/ustring.hxx>
#include <oox/drawingml/theme.hxx>
+#include <oox/shape/ShapeFilterBase.hxx>
#include <svx/svdogrp.hxx>
namespace oox::drawingml {
@@ -43,8 +44,8 @@ class Diagram;
// - im/export Diagram model to other representations
class AdvancedDiagramHelper final : public IDiagramHelper
{
- const std::shared_ptr< Diagram > mpDiagramPtr;
- const std::shared_ptr<::oox::drawingml::Theme> mpThemePtr;
+ const std::shared_ptr< Diagram > mpDiagramPtr;
+ std::shared_ptr<::oox::drawingml::Theme> mpThemePtr;
css::awt::Size maImportSize;
@@ -73,6 +74,8 @@ public:
virtual bool removeNode(const OUString& rNodeId) override;
void doAnchor(SdrObjGroup& rTarget);
+ std::shared_ptr< ::oox::drawingml::Theme > getOrCreateThemePtr(
+ rtl::Reference< oox::shape::ShapeFilterBase>& rxFilter ) const;
};
}