[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - sw/qa sw/source

Michael Stahl (via logerrit) logerrit at kemper.freedesktop.org
Sat Jul 18 12:31:15 UTC 2020


 sw/qa/core/unocore/unocore.cxx      |   22 ++++++++++++++++++++++
 sw/source/core/unocore/unodraw.cxx  |    9 ++++++++-
 sw/source/core/unocore/unoframe.cxx |    9 ++++++++-
 3 files changed, 38 insertions(+), 2 deletions(-)

New commits:
commit f95b21dba6af08c0e1c5c37488024e00cb9bf2f2
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Jul 15 16:44:37 2020 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Sat Jul 18 14:30:42 2020 +0200

    sw: fix crash when using anchor of at-paragraph fly ...
    
    ... to insert fieldmark; the problem is that the anchor doesn't have
    SwIndex so the resulting sw::mark::Fieldmark's positions won't have
    SwIndex either, so they aren't updated when its dummy chars are inserted
    in lcl_SetFieldMarks().
    
    Change-Id: Id6281f45aa1f1337f1ae599877f155b129389d81
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98852
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>
    (cherry picked from commit ca2dfac3e790fb384e904502fe1ededd695001af)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98981
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index d8d72ecf369f..a4a39489da60 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -15,6 +15,7 @@
 #include <com/sun/star/text/AutoTextContainer.hpp>
 #include <com/sun/star/text/VertOrientation.hpp>
 #include <com/sun/star/text/XAutoTextGroup.hpp>
+#include <com/sun/star/text/XTextFrame.hpp>
 #include <com/sun/star/text/XTextPortionAppend.hpp>
 #include <com/sun/star/text/XTextContentAppend.hpp>
 #include <com/sun/star/text/XTextRangeCompare.hpp>
@@ -86,6 +87,27 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testTdf119081)
     CPPUNIT_ASSERT_EQUAL(OUString("x"), pWrtShell->GetCurrentShellCursor().GetText());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, flyAtParaAnchor)
+{
+    mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    uno::Reference<lang::XMultiServiceFactory> const xMSF(mxComponent, uno::UNO_QUERY_THROW);
+    uno::Reference<text::XTextDocument> const xTD(mxComponent, uno::UNO_QUERY_THROW);
+    uno::Reference<text::XTextFrame> const xTextFrame(
+        xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySet> const xFrameProps(xTextFrame, uno::UNO_QUERY_THROW);
+    xFrameProps->setPropertyValue("AnchorType",
+                                  uno::makeAny(text::TextContentAnchorType_AT_PARAGRAPH));
+    auto const xText = xTD->getText();
+    auto const xTextCursor = xText->createTextCursor();
+    CPPUNIT_ASSERT(xTextCursor.is());
+    xText->insertTextContent(xTextCursor, xTextFrame, false);
+    auto const xAnchor = xTextFrame->getAnchor();
+    uno::Reference<text::XTextContent> const xFieldmark(
+        xMSF->createInstance("com.sun.star.text.Fieldmark"), uno::UNO_QUERY_THROW);
+    // this crashed because the anchor didn't have SwIndex
+    xText->insertTextContent(xAnchor, xFieldmark, false);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index 698b05b5ac96..a94255c55408 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -2069,7 +2069,14 @@ uno::Reference< text::XTextRange >  SwXShape::getAnchor()
             (rAnchor.GetContentAnchor() && !rAnchor.GetPageNum()))
         {
             const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor());
-            aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+            if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA)
+            {   // ensure that SwXTextRange has SwIndex
+                aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(rPos.nNode), nullptr);
+            }
+            else
+            {
+                aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+            }
         }
     }
     else
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 69171335a842..e2e5c9411715 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2646,7 +2646,14 @@ uno::Reference< text::XTextRange >  SwXFrame::getAnchor()
         (rAnchor.GetContentAnchor() && !rAnchor.GetPageNum()))
     {
         const SwPosition &rPos = *(rAnchor.GetContentAnchor());
-        aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+        if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA)
+        {   // ensure that SwXTextRange has SwIndex
+            aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(rPos.nNode), nullptr);
+        }
+        else
+        {
+            aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+        }
     }
 
     return aRef;


More information about the Libreoffice-commits mailing list