[Libreoffice-commits] core.git: Branch 'distro/nisz/libreoffice-7-1' - sw/inc sw/qa sw/source

Attila Bakos (NISZ) (via logerrit) logerrit at kemper.freedesktop.org
Mon Jul 5 12:36:58 UTC 2021


 sw/inc/textboxhelper.hxx                 |    2 +
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx |    3 -
 sw/qa/uitest/data/tdf137803.odt          |binary
 sw/qa/uitest/writer_tests7/tdf137803.py  |   61 +++++++++++++++++++++++++++++++
 sw/source/core/doc/textboxhelper.cxx     |   30 +++++++++++++--
 sw/source/core/layout/flycnt.cxx         |   27 +++++++++++++
 6 files changed, 118 insertions(+), 5 deletions(-)

New commits:
commit 653f2ceb8251dbbf38ea8dd4f1b41f3418e779bd
Author:     Attila Bakos (NISZ) <bakos.attilakaroly at nisz.hu>
AuthorDate: Thu Dec 10 10:36:12 2020 +0100
Commit:     Gabor Kelemen <kelemen.gabor2 at nisz.hu>
CommitDate: Mon Jul 5 14:36:24 2021 +0200

    tdf#137803 sw: fix AutoSize and Wrap of textboxes
    
    When autosize (AutoGrowHeight) turned on
    the textbox fell apart. After changing the text
    of the textbox the positions still were different
    for the shape and the textframe.
    
    Now this fix solves, if the text changes,
    the positions (with the size what worked only
    before) synchronized so the textboxes are kept together.
    
    Also Wrap text inside the shape now works like
    the editeng text did, except in the case of empty
    text boxes.
    
    Note: this fixes only editing (without positioning
    the textboxes by the mouse before or after the setting),
    but not import/export, yet.
    
    The ooxmlimport test has been restored to its original
    state, because the fix for the tdf#135198 is fixed
    by this commit.
    
    To start the unit test just give the following command:
    
    $ (cd sw && make UITest_writer_tests7 UITEST_TEST_NAME="tdf137803.tdf137803.test_tdf137803" SAL_USE_VCLPLUGIN=gen)
    
    Change-Id: Ie13a7a1e81e4099cd8540edd7e008118e58134bf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107515
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118436
    Tested-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>

diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index 2043b1ffcfb3..a22086e0d97a 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -72,6 +72,8 @@ public:
     /// Get a property of the underlying TextFrame.
     static void getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
                             css::uno::Any& rValue);
+    /// Get a property of the underlying TextFrame.
+    static css::uno::Any getProperty(SwFrameFormat const* pShape, OUString sPropName);
 
     /// There are two types of enum of anchor type, so this function maps this.
     static css::text::TextContentAnchorType mapAnchorType(const RndStdIds& rAnchorID);
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index d240abbfe628..6732a63a5679 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1066,8 +1066,7 @@ DECLARE_OOXMLIMPORT_TEST(textboxWpsOnly, "textbox-wps-only.docx")
     if ( nsScreen.frame.size.width * scaleFactor > 4000 )
         return;
 #endif
-    // Vertically oriented to page due to tdf#135198
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(5304), getProperty<sal_Int32>(xFrame, "VertOrientPosition"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(2805), getProperty<sal_Int32>(xFrame, "VertOrientPosition"));
 }
 
 DECLARE_OOXMLIMPORT_TEST(testGroupshapeRelsize, "groupshape-relsize.docx")
diff --git a/sw/qa/uitest/data/tdf137803.odt b/sw/qa/uitest/data/tdf137803.odt
new file mode 100644
index 000000000000..8f2f7d5dc49b
Binary files /dev/null and b/sw/qa/uitest/data/tdf137803.odt differ
diff --git a/sw/qa/uitest/writer_tests7/tdf137803.py b/sw/qa/uitest/writer_tests7/tdf137803.py
new file mode 100644
index 000000000000..249dbbb7cacc
--- /dev/null
+++ b/sw/qa/uitest/writer_tests7/tdf137803.py
@@ -0,0 +1,61 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import get_state_as_dict
+import importlib
+import time
+import org.libreoffice.unotest
+import pathlib
+
+def get_url_for_data_file(file_name):
+    return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
+class tdf137803(UITestCase):
+    def test_tdf137803(self):
+        # load the sample file
+        self.ui_test.load_file(get_url_for_data_file("tdf137803.odt"))
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+        xWriterEdit = xWriterDoc.getChild("writer_edit")
+        document = self.ui_test.get_component()
+
+        # select the shape
+        self.xUITest.executeCommand(".uno:JumpToNextFrame")
+        self.ui_test.wait_until_child_is_available(xWriterEdit, 'metricfield')
+
+        # open textattrs dialog
+        self.ui_test.execute_dialog_through_command(".uno:TextAttributes")
+        TextDialog = self.xUITest.getTopFocusWindow();
+
+        # check autosize on
+        TSB_AUTOGROW_SIZE = TextDialog.getChild('TSB_AUTOGROW_SIZE')
+        TSB_AUTOGROW_SIZE.executeAction("CLICK",tuple())
+        ok = TextDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(ok)
+
+        # get the shape
+        drawPage = document.getDrawPages().getByIndex(0)
+        shape = drawPage.getByIndex(0)
+
+        # and the textbox
+        frame = shape.getText()
+
+        # get the positions
+        shapeYPos = shape.getPropertyValue("VertOrientPosition")
+        frameYPos = frame.getPropertyValue("VertOrientPosition")
+        shpsize = shape.getSize().Height
+
+        xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
+        xToolkit.processEventsToIdle()
+
+        # without the fix, at this point the textbox falls apart so this won't be passed
+        self.assertLess(frameYPos, shapeYPos + shpsize)
+
+        # close the doc
+        self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index ae12ec6bea7e..9684c7d6e26c 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -565,6 +565,21 @@ void SwTextBoxHelper::getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID,
     }
 }
 
+css::uno::Any SwTextBoxHelper::getProperty(SwFrameFormat const* pShape, OUString sPropName)
+{
+    if (!pShape)
+        return uno::Any();
+
+    SwFrameFormat* pFormat = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT);
+    if (!pFormat)
+        return uno::Any();
+
+    uno::Reference<beans::XPropertySet> const xPropertySet(
+        SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat), uno::UNO_QUERY);
+
+    return xPropertySet->getPropertyValue(sPropName);
+}
+
 void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
                                    const css::uno::Any& rValue)
 {
@@ -631,6 +646,9 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u
         case RES_FRM_SIZE:
             switch (nMemberID)
             {
+                case MID_FRMSIZE_WIDTH_TYPE:
+                    aPropertyName = UNO_NAME_WIDTH_TYPE;
+                    break;
                 case MID_FRMSIZE_IS_AUTO_HEIGHT:
                     aPropertyName = UNO_NAME_FRAME_ISAUTOMATIC_HEIGHT;
                     break;
@@ -1068,9 +1086,15 @@ void SwTextBoxHelper::updateTextBoxMargin(SdrObject* pObj)
     syncProperty(pParentFormat, UNO_NAME_TEXT_HORZADJUST,
                  xPropertySet->getPropertyValue(UNO_NAME_TEXT_HORZADJUST));
 
-    //FIXME: Sync autogrow: needs repositioning after sync
-    //syncProperty(pParentFormat, RES_FRM_SIZE, MID_FRMSIZE_IS_AUTO_HEIGHT,
-    //             xPropertySet->getPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT));
+    // tdf137803: Sync autogrow:
+    const bool bIsAutoGrow
+        = xPropertySet->getPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT).get<bool>();
+    const bool bIsAutoWrap = xPropertySet->getPropertyValue(UNO_NAME_TEXT_WORDWRAP).get<bool>();
+
+    syncProperty(pParentFormat, RES_FRM_SIZE, MID_FRMSIZE_IS_AUTO_HEIGHT, uno::Any(bIsAutoGrow));
+
+    syncProperty(pParentFormat, RES_FRM_SIZE, MID_FRMSIZE_WIDTH_TYPE,
+                 uno::Any(bIsAutoWrap ? text::SizeType::FIX : text::SizeType::MIN));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx
index 0da839f099c6..acb6354c01bf 100644
--- a/sw/source/core/layout/flycnt.cxx
+++ b/sw/source/core/layout/flycnt.cxx
@@ -47,6 +47,10 @@
 #include "objectformattertxtfrm.hxx"
 #include <HandleAnchorNodeChg.hxx>
 #include <ndtxt.hxx>
+#include <textboxhelper.hxx>
+#include <fmtfollowtextflow.hxx>
+#include <fmtfsize.hxx>
+#include <unoprnms.hxx>
 
 using namespace ::com::sun::star;
 
@@ -395,6 +399,7 @@ void SwFlyAtContentFrame::MakeAll(vcl::RenderContext* pRenderContext)
         SwRectFnSet aRectFnSet(this);
         Point aOldPos( aRectFnSet.GetPos(getFrameArea()) );
         SwFlyFreeFrame::MakeAll(pRenderContext);
+
         const bool bPosChgDueToOwnFormat =
                                 aOldPos != aRectFnSet.GetPos(getFrameArea());
         // #i3317#
@@ -533,6 +538,28 @@ void SwFlyAtContentFrame::MakeAll(vcl::RenderContext* pRenderContext)
             }
         }
     }
+    // tdf#137803: Fix the position of the shape during autoSize
+    SwFrameFormat* pShapeFormat
+        = SwTextBoxHelper::getOtherTextBoxFormat(GetFormat(), RES_FLYFRMFMT);
+    // FIXME: According to tdf37153, ignore FollowTextFlow objs, because
+    // wrong position will applied in that case. FollowTextFlow needs fix.
+    if (pShapeFormat && !pShapeFormat->GetFollowTextFlow().GetValue() &&
+        SwTextBoxHelper::getProperty(pShapeFormat,
+            UNO_NAME_FRAME_ISAUTOMATIC_HEIGHT).get<bool>() )
+    {
+        // get the text area of the shape
+        const tools::Rectangle aTextRectangle
+            = SwTextBoxHelper::getTextRectangle(pShapeFormat, false);
+        // get the original textframe position
+        SwFormatHoriOrient aHOri = pShapeFormat->GetHoriOrient();
+        SwFormatVertOrient aVOri = pShapeFormat->GetVertOrient();
+        // calc the right position of the shape depending on text area
+        aHOri.SetPos(aHOri.GetPos() + aTextRectangle.getX());
+        aVOri.SetPos(aVOri.GetPos() + aTextRectangle.getY());
+        // save the new position for the shape
+        GetFormat()->SetFormatAttr(aHOri);
+        GetFormat()->SetFormatAttr(aVOri);
+    }
     if ( bOsz || bConsiderWrapInfluenceDueToOverlapPrevCol ||
          // #i40444#
          bConsiderWrapInfluenceDueToMovedFwdAnchor )


More information about the Libreoffice-commits mailing list