svx/qa/unit/data/auto-height-multi-col-shape.pptx |binary
 svx/qa/unit/svdraw.cxx                            |   27 ++++++++++++++++++++++
 svx/source/svdraw/svdoashp.cxx                    |   11 ++++++++
 3 files changed, 38 insertions(+)

New commits:
commit 77fca57f7ce1c218a6c1f19c5bc4cc440d0bf2cd
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu Oct 21 16:49:53 2021 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Oct 22 19:30:12 2021 +0200

    tdf#140022 sd: fix inteaction between multi-col shape text and automatic 
height
    
    Multi-column shape text works by assuming a fixed height, then flowing
    content to a next column once the current one is full.
    
    Automatic height works by first laying out the text and then resizing
    the shape to have a matching height.
    
    When both are enabled, then we used to first calculate the automatic
    height and then lay out the multi-col text using that height. PowerPoint
    takes the height from the file format and lays out the multi-col text
    using that fixed height, and only editing modifies the automatic height.
    
    Fix the problem by not updating the automatic height when we have
    multiple columns, this is meant to improve the stability of the layout
    anyway.
    
    Manual testing shows that editing the text on the UI still updates the
    automatic height, as probably expected.
    
    Based on Mike Kaganski's research - thanks! :-)
    
    Change-Id: Iaf46c6008018b4bf26310322f25788a49c1d27f0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124048
    Tested-by: Mike Kaganski <[email protected]>
    Reviewed-by: Mike Kaganski <[email protected]>
    (cherry picked from commit 7e74c6cf8d0a56cc061f48e1c6f397d393165220)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124062
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/svx/qa/unit/data/auto-height-multi-col-shape.pptx 
b/svx/qa/unit/data/auto-height-multi-col-shape.pptx
new file mode 100644
index 000000000000..12f232b0f236
Binary files /dev/null and b/svx/qa/unit/data/auto-height-multi-col-shape.pptx 
differ
diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx
index 783420d56fea..6d4b4457b2c1 100644
--- a/svx/qa/unit/svdraw.cxx
+++ b/svx/qa/unit/svdraw.cxx
@@ -160,6 +160,33 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testTextEditEmptyGrabBag)
     // old text.
     CPPUNIT_ASSERT(!aGrabBag.hasElements());
 }
+
+CPPUNIT_TEST_FIXTURE(SvdrawTest, testAutoHeightMultiColShape)
+{
+    // Given a document containing a shape that has:
+    // 1) automatic height (resize shape to fix text)
+    // 2) multiple columns (2)
+    OUString aURL
+        = 
m_directories.getURLFromSrc(u"svx/qa/unit/data/auto-height-multi-col-shape.pptx");
+
+    // When loading that document:
+    getComponent().set(loadFromDesktop(aURL, 
"com.sun.star.presentation.PresentationDocument"));
+
+    // Make sure the in-file shape height is kept, even if nominally the the 
shape height is
+    // automatic:
+    uno::Reference<drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> 
xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+                                                 uno::UNO_QUERY);
+    uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 6882
+    // - Actual  : 3452
+    // i.e. the shape height was smaller than expected, leading to a 2 columns 
layout instead of
+    // laying out all the text in the first column.
+    // 2477601 is from slide1.xml, <a:ext cx="4229467" cy="2477601"/>, 360 is 
emu -> mm100.
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(2477601 / 360), 
xShape->getSize().Height,
+                                 1);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx
index 53d180435e9b..112e44bd531d 100644
--- a/svx/source/svdraw/svdoashp.cxx
+++ b/svx/source/svdraw/svdoashp.cxx
@@ -2318,7 +2318,18 @@ bool 
SdrObjCustomShape::AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool
                             nHgt=aSiz2.Height()+1; // a little more tolerance
                     }
                     else
+                    {
                         nHgt = rOutliner.GetTextHeight()+1; // a little more 
tolerance
+
+                        sal_Int16 nColumns = 
GetMergedItem(SDRATTR_TEXTCOLUMNS_NUMBER).GetValue();
+                        if (bHgtGrow && nColumns > 1)
+                        {
+                            // Both 'resize shape to fix text' and multiple 
columns are enabled. The
+                            // first means a dynamic height, the second 
expects a fixed height.
+                            // Resolve this conflict by going with the 
original height.
+                            nHgt = rR.getHeight();
+                        }
+                    }
                     rOutliner.Clear();
                 }
             }

Reply via email to