oox/source/drawingml/diagram/diagram.cxx |  198 ++++++++++++++++---------------
 1 file changed, 104 insertions(+), 94 deletions(-)

New commits:
commit 781897437a0dac7fc951398ad5d8f90c11cd5e9a
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sat Jan 6 20:16:14 2024 +0000
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jan 9 10:46:59 2024 +0100

    ofz#65567 unset DiagramFontHeights on exception
    
    git diff -w is your friend
    
    Change-Id: I360ebb70e710a5d435ce8153090593784e2ac603
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161685
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/oox/source/drawingml/diagram/diagram.cxx 
b/oox/source/drawingml/diagram/diagram.cxx
index 7927b7aa6945..2efa152ae912 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -311,121 +311,131 @@ void loadDiagram( ShapePtr const & pShape,
     DiagramLayoutPtr pLayout = std::make_shared<DiagramLayout>(*pDiagram);
     pDiagram->setLayout( pLayout );
 
-    // set DiagramFontHeights at filter
-    rFilter.setDiagramFontHeights(&pDiagram->getDiagramFontHeights());
-
-    // data
-    if( !rDataModelPath.isEmpty() )
+    try
     {
-        rtl::Reference< core::FragmentHandler > xRefDataModel(
-                new DiagramDataFragmentHandler( rFilter, rDataModelPath, pData 
));
+        // set DiagramFontHeights at filter
+        rFilter.setDiagramFontHeights(&pDiagram->getDiagramFontHeights());
 
-        importFragment(rFilter,
-                       loadFragment(rFilter,xRefDataModel),
-                       "OOXData",
-                       pDiagram,
-                       xRefDataModel);
+        // data
+        if( !rDataModelPath.isEmpty() )
+        {
+            rtl::Reference< core::FragmentHandler > xRefDataModel(
+                    new DiagramDataFragmentHandler( rFilter, rDataModelPath, 
pData ));
 
-        pDiagram->getDataRelsMap() = 
pShape->resolveRelationshipsOfTypeFromOfficeDoc( rFilter,
-                xRefDataModel->getFragmentPath(), u"image" );
+            importFragment(rFilter,
+                           loadFragment(rFilter,xRefDataModel),
+                           "OOXData",
+                           pDiagram,
+                           xRefDataModel);
 
-        // Pass the info to pShape
-        for (auto const& extDrawing : pData->getExtDrawings())
-        {
-            OUString aFragmentPath = 
rRelations.getFragmentPathFromRelId(extDrawing);
-            // Ignore RelIds which don't resolve to a fragment path.
-            if (aFragmentPath.isEmpty())
-                continue;
-
-            sal_Int32 nCounter = 0;
-            rtl::Reference<core::FragmentHandler> xCounter(
-                new DiagramShapeCounter(rFilter, aFragmentPath, nCounter));
-            rFilter.importFragment(xCounter);
-            // Ignore ext drawings which don't actually have any shapes.
-            if (nCounter == 0)
-                continue;
-
-            pShape->addExtDrawingRelId(extDrawing);
+            pDiagram->getDataRelsMap() = 
pShape->resolveRelationshipsOfTypeFromOfficeDoc( rFilter,
+                    xRefDataModel->getFragmentPath(), u"image" );
+
+            // Pass the info to pShape
+            for (auto const& extDrawing : pData->getExtDrawings())
+            {
+                OUString aFragmentPath = 
rRelations.getFragmentPathFromRelId(extDrawing);
+                // Ignore RelIds which don't resolve to a fragment path.
+                if (aFragmentPath.isEmpty())
+                    continue;
+
+                sal_Int32 nCounter = 0;
+                rtl::Reference<core::FragmentHandler> xCounter(
+                    new DiagramShapeCounter(rFilter, aFragmentPath, nCounter));
+                rFilter.importFragment(xCounter);
+                // Ignore ext drawings which don't actually have any shapes.
+                if (nCounter == 0)
+                    continue;
+
+                pShape->addExtDrawingRelId(extDrawing);
+            }
         }
-    }
 
-    // extLst is present, lets bet on that and ignore the rest of the data 
from here
-    if( pShape->getExtDrawings().empty() )
-    {
-        // layout
-        if( !rLayoutPath.isEmpty() )
+        // extLst is present, lets bet on that and ignore the rest of the data 
from here
+        if( pShape->getExtDrawings().empty() )
         {
-            rtl::Reference< core::FragmentHandler > xRefLayout(
-                    new DiagramLayoutFragmentHandler( rFilter, rLayoutPath, 
pLayout ));
+            // layout
+            if( !rLayoutPath.isEmpty() )
+            {
+                rtl::Reference< core::FragmentHandler > xRefLayout(
+                        new DiagramLayoutFragmentHandler( rFilter, 
rLayoutPath, pLayout ));
+
+                importFragment(rFilter,
+                        loadFragment(rFilter,xRefLayout),
+                        "OOXLayout",
+                        pDiagram,
+                        xRefLayout);
+            }
 
-            importFragment(rFilter,
-                    loadFragment(rFilter,xRefLayout),
-                    "OOXLayout",
-                    pDiagram,
-                    xRefLayout);
+            // style
+            if( !rQStylePath.isEmpty() )
+            {
+                rtl::Reference< core::FragmentHandler > xRefQStyle(
+                        new DiagramQStylesFragmentHandler( rFilter, 
rQStylePath, pDiagram->getStyles() ));
+
+                importFragment(rFilter,
+                        loadFragment(rFilter,xRefQStyle),
+                        "OOXStyle",
+                        pDiagram,
+                        xRefQStyle);
+            }
+        }
+        else
+        {
+            // We still want to add the XDocuments to the DiagramDomMap
+            DiagramDomMap& rMainDomMap = pDiagram->getDomMap();
+            rMainDomMap[OUString("OOXLayout")] = 
loadFragment(rFilter,rLayoutPath);
+            rMainDomMap[OUString("OOXStyle")] = 
loadFragment(rFilter,rQStylePath);
         }
 
-        // style
-        if( !rQStylePath.isEmpty() )
+        // colors
+        if( !rColorStylePath.isEmpty() )
         {
-            rtl::Reference< core::FragmentHandler > xRefQStyle(
-                    new DiagramQStylesFragmentHandler( rFilter, rQStylePath, 
pDiagram->getStyles() ));
+            rtl::Reference< core::FragmentHandler > xRefColorStyle(
+                new ColorFragmentHandler( rFilter, rColorStylePath, 
pDiagram->getColors() ));
 
             importFragment(rFilter,
-                    loadFragment(rFilter,xRefQStyle),
-                    "OOXStyle",
-                    pDiagram,
-                    xRefQStyle);
+                loadFragment(rFilter,xRefColorStyle),
+                "OOXColor",
+                pDiagram,
+                xRefColorStyle);
         }
-    }
-    else
-    {
-        // We still want to add the XDocuments to the DiagramDomMap
-        DiagramDomMap& rMainDomMap = pDiagram->getDomMap();
-        rMainDomMap[OUString("OOXLayout")] = loadFragment(rFilter,rLayoutPath);
-        rMainDomMap[OUString("OOXStyle")] = loadFragment(rFilter,rQStylePath);
-    }
-
-    // colors
-    if( !rColorStylePath.isEmpty() )
-    {
-        rtl::Reference< core::FragmentHandler > xRefColorStyle(
-            new ColorFragmentHandler( rFilter, rColorStylePath, 
pDiagram->getColors() ));
-
-        importFragment(rFilter,
-            loadFragment(rFilter,xRefColorStyle),
-            "OOXColor",
-            pDiagram,
-            xRefColorStyle);
-    }
 
-    if( !pData->getExtDrawings().empty() )
-    {
-        const DiagramColorMap::const_iterator aColor = 
pDiagram->getColors().find("node0");
-        if( aColor != pDiagram->getColors().end() && 
!aColor->second.maTextFillColors.empty())
+        if( !pData->getExtDrawings().empty() )
         {
-            // TODO(F1): well, actually, there might be *several* color
-            // definitions in it, after all it's called list.
-            
pShape->setFontRefColorForNodes(DiagramColor::getColorByIndex(aColor->second.maTextFillColors,
 -1));
+            const DiagramColorMap::const_iterator aColor = 
pDiagram->getColors().find("node0");
+            if( aColor != pDiagram->getColors().end() && 
!aColor->second.maTextFillColors.empty())
+            {
+                // TODO(F1): well, actually, there might be *several* color
+                // definitions in it, after all it's called list.
+                
pShape->setFontRefColorForNodes(DiagramColor::getColorByIndex(aColor->second.maTextFillColors,
 -1));
+            }
         }
-    }
 
-    // collect data, init maps
-    // for Diagram import, do - for now - NOT clear all oox::drawingml::Shape
-    pData->buildDiagramDataModel(false);
+        // collect data, init maps
+        // for Diagram import, do - for now - NOT clear all 
oox::drawingml::Shape
+        pData->buildDiagramDataModel(false);
 
-    // diagram loaded. now lump together & attach to shape
-    pDiagram->addTo(pShape);
-    pShape->setDiagramDoms(pDiagram->getDomsAsPropertyValues());
+        // diagram loaded. now lump together & attach to shape
+        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());
+        // 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());
+        // Prepare support for the advanced DiagramHelper using Diagram & 
Theme data
+        pShape->prepareDiagramHelper(pDiagram, rFilter.getCurrentThemePtr());
+    }
+    catch (...)
+    {
+        // unset DiagramFontHeights at filter if there was a failure
+        // to avoid dangling pointer
+        rFilter.setDiagramFontHeights(nullptr);
+        throw;
+    }
 }
 
 const oox::drawingml::Color&

Reply via email to