oox/source/drawingml/diagram/diagramlayoutatoms.cxx |   56 +++++++++++++++++++-
 sd/qa/unit/data/pptx/smartart-autofit-sync.pptx     |binary
 sd/qa/unit/import-tests-smartart.cxx                |   11 +++
 3 files changed, 66 insertions(+), 1 deletion(-)

New commits:
commit 1333c831b511e38ec114f51b4bf5e6fef3d7b30e
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Sep 14 16:58:38 2020 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Sep 15 18:09:58 2020 +0200

    oox smartart: handle <dgm:prSet ... custT="1"/>
    
    Which defines that a data node has text properties as direct formatting,
    so autoscale should not happen.
    
    We decide autofit at a shape level, smartart defines custom text props
    at a data node level. So take the shape, go to its first presentation
    node, get its data node and see if it has custom text props. If not,
    continue to scale text down till it fits.
    
    smartart-autofit-sync.pptx is extended to contain a 3rd shape: the first
    two have their autofit scaling synchronized, while the 3rd has a fixed
    font size of 10pt.
    
    (cherry picked from commit 89b385c2336e5b3868d2a040e11134b349b7d010)
    
    Change-Id: I6caacdaab9a36072b9ad5021bd217c955b09b790
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102727
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx 
b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 6823e45b3043..6175832a426d 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -479,6 +479,54 @@ void ApplyConstraintToLayout(const Constraint& 
rConstraint, LayoutPropertyMap& r
         }
     }
 }
+
+/// Does the first data node of this shape have customized text properties?
+bool HasCustomText(const ShapePtr& rShape, LayoutNode& rLayoutNode)
+{
+    const PresPointShapeMap& rPresPointShapeMap
+        = rLayoutNode.getDiagram().getLayout()->getPresPointShapeMap();
+    const DiagramData::StringMap& rPresOfNameMap
+        = rLayoutNode.getDiagram().getData()->getPresOfNameMap();
+    const DiagramData::PointNameMap& rPointNameMap
+        = rLayoutNode.getDiagram().getData()->getPointNameMap();
+    // Get the first presentation node of the shape.
+    const dgm::Point* pPresNode = nullptr;
+    for (const auto& rPair : rPresPointShapeMap)
+    {
+        if (rPair.second == rShape)
+        {
+            pPresNode = rPair.first;
+            break;
+        }
+    }
+    // Get the first data node of the presentation node.
+    dgm::Point* pDataNode = nullptr;
+    if (pPresNode)
+    {
+        auto itPresToData = rPresOfNameMap.find(pPresNode->msModelId);
+        if (itPresToData != rPresOfNameMap.end())
+        {
+            for (const auto& rPair : itPresToData->second)
+            {
+                const DiagramData::SourceIdAndDepth& rItem = rPair.second;
+                auto it = rPointNameMap.find(rItem.msSourceId);
+                if (it != rPointNameMap.end())
+                {
+                    pDataNode = it->second;
+                    break;
+                }
+            }
+        }
+    }
+
+    // If we have a data node, see if its text is customized or not.
+    if (pDataNode)
+    {
+        return pDataNode->mbCustomText;
+    }
+
+    return false;
+}
 }
 
 void AlgAtom::layoutShape(const ShapePtr& rShape, const 
std::vector<Constraint>& rConstraints,
@@ -1453,7 +1501,13 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const 
std::vector<Constraint>&
                         if (!aRun->getTextCharacterProperties().moHeight.has())
                             aRun->getTextCharacterProperties().moHeight = 
fFontSize * 100;
             }
-            
pTextBody->getTextProperties().maPropertyMap.setProperty(PROP_TextFitToSize, 
drawing::TextFitToSizeType_AUTOFIT);
+
+            if (!HasCustomText(rShape, getLayoutNode()))
+            {
+                // No customized text properties: enable autofit.
+                pTextBody->getTextProperties().maPropertyMap.setProperty(
+                    PROP_TextFitToSize, drawing::TextFitToSizeType_AUTOFIT);
+            }
 
             // ECMA-376-1:2016 21.4.7.5 ST_AutoTextRotation (Auto Text 
Rotation)
             const sal_Int32 nautoTxRot = maMap.count(XML_autoTxRot) ? 
maMap.find(XML_autoTxRot)->second : XML_upr;
diff --git a/sd/qa/unit/data/pptx/smartart-autofit-sync.pptx 
b/sd/qa/unit/data/pptx/smartart-autofit-sync.pptx
index f682c143f584..9a6ce0f494c5 100644
Binary files a/sd/qa/unit/data/pptx/smartart-autofit-sync.pptx and 
b/sd/qa/unit/data/pptx/smartart-autofit-sync.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx 
b/sd/qa/unit/import-tests-smartart.cxx
index 0d41e3094052..4844afe5a84e 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -1557,6 +1557,17 @@ void SdImportTestSmartArt::testAutofitSync()
     // requested that their scaling matches.
     CPPUNIT_ASSERT_EQUAL(nSecondScale, nFirstScale);
 
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 0 (drawing::TextFitToSizeType_NONE)
+    // - Actual  : 3 (TextFitToSizeType_AUTOFIT)
+    // i.e. the 3rd shape had font size as direct formatting, but its 
automatic text scale was not
+    // disabled.
+    uno::Reference<beans::XPropertySet> 
xThirdInner(getChildShape(getChildShape(xMiddle, 4), 0),
+                                                     uno::UNO_QUERY);
+    drawing::TextFitToSizeType eType{};
+    CPPUNIT_ASSERT(xThirdInner->getPropertyValue("TextFitToSize") >>= eType);
+    CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_NONE, eType);
+
     xDocShRef->DoClose();
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to