summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-04-27 20:48:30 +0200
committerMichael Stahl <michael.stahl@cib.de>2020-04-28 10:28:41 +0200
commite1dd961e46a016f2641a96d5632757c8db4b1953 (patch)
tree6869a7639688909491e1e0fd480f3022b40bb3d3
parent750a10a4484cb8a05102092532848df500256a79 (diff)
tdf#131729 sw: handle no drawing objects when calculating overlap of objects
Regression from commit d37096f59e7e0286e55008153591a60bab92b9e8 (Related: tdf#124600 sw anchored object allow overlap: add layout, 2019-09-19), we assumed that the anchor frame always has draw objects, but that may not be the case. That happens when dragging a to-character anchored object around, before the object is added to its anchor. (cherry picked from commit 4ba1909f12b49f020195b5e767045340717ce6df) Change-Id: I1271a6e498553838c3851864b7965a1ba28de663 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93002 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--sw/CppunitTest_sw_core_objectpositioning.mk73
-rw-r--r--sw/Module_sw.mk1
-rw-r--r--sw/qa/core/objectpositioning/data/overlap-crash.odtbin0 -> 22502 bytes
-rw-r--r--sw/qa/core/objectpositioning/objectpositioning.cxx53
-rw-r--r--sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx9
5 files changed, 134 insertions, 2 deletions
diff --git a/sw/CppunitTest_sw_core_objectpositioning.mk b/sw/CppunitTest_sw_core_objectpositioning.mk
new file mode 100644
index 000000000000..e083c199d74c
--- /dev/null
+++ b/sw/CppunitTest_sw_core_objectpositioning.mk
@@ -0,0 +1,73 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_core_objectpositioning))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_objectpositioning))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_objectpositioning, \
+ sw/qa/core/objectpositioning/objectpositioning \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_objectpositioning, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ sfx \
+ svxcore \
+ sw \
+ test \
+ unotest \
+ utl \
+ vcl \
+ svt \
+ tl \
+ svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_objectpositioning,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_objectpositioning,\
+ -I$(SRCDIR)/sw/inc \
+ -I$(SRCDIR)/sw/source/core/inc \
+ -I$(SRCDIR)/sw/source/uibase/inc \
+ -I$(SRCDIR)/sw/qa/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_core_objectpositioning,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_objectpositioning))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_objectpositioning))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_objectpositioning,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_objectpositioning,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_objectpositioning))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_objectpositioning, \
+ modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_objectpositioning))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 4784dcc64f8b..dc4f303d7a3b 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -109,6 +109,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_uibase_shells \
CppunitTest_sw_core_frmedt \
CppunitTest_sw_core_txtnode \
+ CppunitTest_sw_core_objectpositioning \
))
ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/objectpositioning/data/overlap-crash.odt b/sw/qa/core/objectpositioning/data/overlap-crash.odt
new file mode 100644
index 000000000000..a756c85dd67b
--- /dev/null
+++ b/sw/qa/core/objectpositioning/data/overlap-crash.odt
Binary files differ
diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx b/sw/qa/core/objectpositioning/objectpositioning.cxx
new file mode 100644
index 000000000000..c73e97567f20
--- /dev/null
+++ b/sw/qa/core/objectpositioning/objectpositioning.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <comphelper/classids.hxx>
+#include <svtools/embedhlp.hxx>
+#include <svx/svdpage.hxx>
+#include <tools/globname.hxx>
+#include <unotest/bootstrapfixturebase.hxx>
+#include <vcl/gdimtf.hxx>
+
+#include <wrtsh.hxx>
+#include <fmtanchr.hxx>
+#include <IDocumentDrawModelAccess.hxx>
+#include <drawdoc.hxx>
+#include <dcontact.hxx>
+
+static char const DATA_DIRECTORY[] = "/sw/qa/core/objectpositioning/data/";
+
+/// Covers sw/source/core/objectpositioning/ fixes.
+class SwCoreObjectpositioningTest : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testOverlapCrash)
+{
+ // Load a document with 2 images.
+ load(DATA_DIRECTORY, "overlap-crash.odt");
+
+ // Change their anchor type to to-char.
+ uno::Reference<beans::XPropertySet> xShape1(getShape(1), uno::UNO_QUERY);
+ xShape1->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+ uno::Reference<beans::XPropertySet> xShape2(getShape(1), uno::UNO_QUERY);
+ xShape2->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+
+ // Insert a new paragraph at the start.
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwDocShell* pDocShell = pTextDoc->GetDocShell();
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ // Without the accompanying fix in place, this test would have crashed.
+ pWrtShell->SplitNode();
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
index 89fe27e30558..18c08f8540d9 100644
--- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
@@ -1117,8 +1117,13 @@ void SwToContentAnchoredObjectPosition::CalcOverlap(const SwTextFrame* pAnchorFr
}
// Get the list of objects.
- const SwSortedObjs& rSortedObjs = *pAnchorFrameForVertPos->GetDrawObjs();
- for (const auto& pAnchoredObj : rSortedObjs)
+ auto pSortedObjs = pAnchorFrameForVertPos->GetDrawObjs();
+ if (!pSortedObjs)
+ {
+ return;
+ }
+
+ for (const auto& pAnchoredObj : *pSortedObjs)
{
if (pAnchoredObj == &GetAnchoredObj())
{