22#include <com/sun/star/awt/Point.hpp>
23#include <com/sun/star/awt/Size.hpp>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/drawing/XShape.hpp>
26#include <com/sun/star/drawing/XShapes.hpp>
27#include <com/sun/star/xml/dom/XDocument.hpp>
28#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
34#include <oox/token/namespaces.hxx>
50 std::vector<ShapePtr>& rChildren = pShape->getChildren();
53 for (
size_t i = 0;
i < rChildren.size(); ++
i)
54 rChildren[
i]->setZOrder(
i);
56 for (
size_t i = 0;
i < rChildren.size(); ++
i)
59 sal_Int32 nZOrderOff = pChild->getZOrderOff();
64 pChild->setZOrder(pChild->getZOrder() + nZOrderOff);
65 pChild->setZOrderOff(0);
67 for (sal_Int32 j = 0; j < nZOrderOff; ++j)
70 if (
nIndex >= rChildren.size())
75 pNext->setZOrder(pNext->getZOrder() - 1);
80 std::sort(rChildren.begin(), rChildren.end(),
81 [](
const ShapePtr&
a,
const ShapePtr& b) { return a->getZOrder() < b->getZOrder(); });
84 for (
const auto& rChild : rChildren)
91 std::vector<ShapePtr>& rChildren = pShape->getChildren();
93 rChildren.erase(std::remove_if(rChildren.begin(), rChildren.end(),
95 return aChild->getServiceName()
96 ==
"com.sun.star.drawing.GroupShape"
97 && aChild->getChildren().empty();
101 for (
const auto& pChild : rChildren)
110 if (pParentShape->getSize().Width == 0 || pParentShape->getSize().Height == 0)
111 SAL_WARN(
"oox.drawingml",
"Diagram cannot be correctly laid out. Size: "
112 << pParentShape->getSize().Width <<
"x" << pParentShape->getSize().Height);
114 pParentShape->setChildSize(pParentShape->getSize());
117 if (
mpLayout->getNode() && pRootPoint)
121 mpLayout->getNode()->setExistingShape(pParentShape);
122 mpLayout->getNode()->accept(aCreationVisitor);
126 mpLayout->getNode()->accept(aLayoutingVisitor);
132 ShapePtr pBackground = std::make_shared<Shape>(
"com.sun.star.drawing.CustomShape");
133 pBackground->setSubType(XML_rect);
134 pBackground->getCustomShapeProperties()->setShapePresetType(XML_rect);
135 pBackground->setSize(pParentShape->getSize());
136 pBackground->getFillProperties() = *
mpData->getBackgroundShapeFillProperties();
137 pBackground->setLocked(
true);
141 pBackground->setDiagramDataModelID(
getData()->getBackgroundShapeModelID());
143 auto& aChildren = pParentShape->getChildren();
144 aChildren.insert(aChildren.begin(), pBackground);
148: maDiagramFontHeights()
159 uno::Sequence<beans::PropertyValue> aValue(
length);
160 beans::PropertyValue* pValue = aValue.getArray();
163 pValue->Name = mainDom.first;
164 pValue->Value <<= mainDom.second;
170 pValue->Name =
"OOXDiagramDataRels";
179 = std::map<std::shared_ptr<drawingml::Shape>, css::uno::Reference<css::drawing::XShape>>;
188 const ShapePairs& rShapePairs = rNameAndPairs.second;
189 double nMinScale = 100.0;
190 for (
const auto& rShapePair : rShapePairs)
192 uno::Reference<beans::XPropertySet> xPropertySet(rShapePair.second, uno::UNO_QUERY);
193 if (xPropertySet.is())
195 double nTextFitToSizeScale = 0.0;
196 xPropertySet->getPropertyValue(
"TextFitToSizeScale") >>= nTextFitToSizeScale;
197 if (nTextFitToSizeScale > 0 && nTextFitToSizeScale < nMinScale)
199 nMinScale = nTextFitToSizeScale;
205 if (nMinScale < 100.0)
207 for (
const auto& rShapePair : rShapePairs)
209 uno::Reference<beans::XPropertySet> xPropertySet(rShapePair.second, uno::UNO_QUERY);
210 if (xPropertySet.is())
212 xPropertySet->setPropertyValue(
"TextFitToSizeScale",
uno::Any(nMinScale));
224 const OUString& rFragmentPath )
235 return loadFragment( rFilter, rxHandler->getFragmentPath() );
239 const uno::Reference<xml::dom::XDocument>& rXDom,
240 const OUString& rDocName,
245 rMainDomMap[rDocName] = rXDom;
247 uno::Reference<xml::sax::XFastSAXSerializable> xSerializer(
248 rXDom, uno::UNO_QUERY_THROW);
264 sal_Int32& nCounter);
273 const OUString& rFragmentPath, sal_Int32& nCounter)
274 : FragmentHandler2(rFilter, rFragmentPath)
280 const AttributeList& )
284 case DSP_TOKEN(drawing):
285 case DSP_TOKEN(spTree):
300 const OUString& rDataModelPath,
301 const OUString& rLayoutPath,
302 const OUString& rQStylePath,
303 const OUString& rColorStylePath,
306 DiagramPtr pDiagram = std::make_shared<Diagram>();
309 pDiagram->setData(
pData );
312 pDiagram->setLayout( pLayout );
318 if( !rDataModelPath.isEmpty() )
329 pDiagram->getDataRelsMap() = pShape->resolveRelationshipsOfTypeFromOfficeDoc( rFilter,
330 xRefDataModel->getFragmentPath(),
u"image" );
333 for (
auto const& extDrawing :
pData->getExtDrawings())
337 if (aFragmentPath.isEmpty())
340 sal_Int32 nCounter = 0;
342 new DiagramShapeCounter(rFilter, aFragmentPath, nCounter));
348 pShape->addExtDrawingRelId(extDrawing);
353 if( pShape->getExtDrawings().empty() )
356 if( !rLayoutPath.isEmpty() )
369 if( !rQStylePath.isEmpty() )
385 rMainDomMap[OUString(
"OOXLayout")] =
loadFragment(rFilter,rLayoutPath);
386 rMainDomMap[OUString(
"OOXStyle")] =
loadFragment(rFilter,rQStylePath);
390 if( !rColorStylePath.isEmpty() )
402 if( !
pData->getExtDrawings().empty() )
404 const DiagramColorMap::const_iterator aColor = pDiagram->getColors().find(
"node0");
405 if( aColor != pDiagram->getColors().end() && !aColor->second.maTextFillColors.empty())
409 pShape->setFontRefColorForNodes(DiagramColor::getColorByIndex(aColor->second.maTextFillColors, -1));
415 pData->buildDiagramDataModel(
false);
418 pDiagram->addTo(pShape);
419 pShape->setDiagramDoms(pDiagram->getDomsAsPropertyValues());
425 pData->setThemeDocument(aTheme->getFragment());
432DiagramColor::getColorByIndex(
const std::vector<oox::drawingml::Color>& rColors, sal_Int32 nIndex)
434 assert(!rColors.empty());
437 return rColors[rColors.size() - 1];
440 return rColors[
nIndex % rColors.size()];
Provides access to attribute values of an element.
OUString getFragmentPathFromRelId(const OUString &rRelId) const
Returns the full fragment path for the passed relation identifier.
void setDiagramFontHeights(NamedShapePairs *pDiagramFontHeights)
virtual std::shared_ptr<::oox::drawingml::Theme > getCurrentThemePtr() const
May be implemented by filters which handle Diagrams, default returns empty ptr.
bool importFragment(const rtl::Reference< FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
DiagramLayoutPtr mpLayout
oox::core::NamedShapePairs maDiagramFontHeights
css::uno::Sequence< css::uno::Sequence< css::uno::Any > > maDataRelsMap
DiagramDomMap maMainDomMap
void syncDiagramFontHeights()
void addTo(const ShapePtr &pShape)
const OoxDiagramDataPtr & getData() const
css::uno::Sequence< css::beans::PropertyValue > getDomsAsPropertyValues() const
#define SAL_WARN(area, stream)
std::unique_ptr< sal_Int32[]> pData
OString generateGUIDString()
static uno::Reference< xml::dom::XDocument > loadFragment(core::XmlFilterBase &rFilter, const rtl::Reference< core::FragmentHandler > &rxHandler)
std::shared_ptr< Diagram > DiagramPtr
std::shared_ptr< DiagramData > OoxDiagramDataPtr
std::shared_ptr< Shape > ShapePtr
static void removeUnneededGroupShapes(const ShapePtr &pShape)
Removes empty group shapes, now that their spacing influenced the layout.
static void sortChildrenByZOrder(const ShapePtr &pShape)
std::map< std::shared_ptr< drawingml::Shape >, css::uno::Reference< css::drawing::XShape > > ShapePairs
std::map< OUString, css::uno::Reference< css::xml::dom::XDocument > > DiagramDomMap
static void importFragment(core::XmlFilterBase &rFilter, const uno::Reference< xml::dom::XDocument > &rXDom, const OUString &rDocName, const DiagramPtr &pDiagram, const rtl::Reference< core::FragmentHandler > &rxHandler)
std::shared_ptr< DiagramLayout > DiagramLayoutPtr
void loadDiagram(ShapePtr const &pShape, core::XmlFilterBase &rFilter, const OUString &rDataModelPath, const OUString &rLayoutPath, const OUString &rQStylePath, const OUString &rColorStylePath, const oox::core::Relations &rRelations)
load diagram data, and put resulting graphic into shape
static uno::Reference< xml::dom::XDocument > loadFragment(core::XmlFilterBase &rFilter, const OUString &rFragmentPath)