diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-04-27 20:48:30 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-04-28 09:03:18 +0200 |
commit | 4ba1909f12b49f020195b5e767045340717ce6df (patch) | |
tree | 12ba92e913c321cc0ca0421c9dcf87879819177c /sw | |
parent | 7cfc983f8f3f4d094cd01128043d5e2021cb80c6 (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.
Change-Id: I1271a6e498553838c3851864b7965a1ba28de663
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92989
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/CppunitTest_sw_core_objectpositioning.mk | 73 | ||||
-rw-r--r-- | sw/Module_sw.mk | 1 | ||||
-rw-r--r-- | sw/qa/core/objectpositioning/data/overlap-crash.odt | bin | 0 -> 22502 bytes | |||
-rw-r--r-- | sw/qa/core/objectpositioning/objectpositioning.cxx | 53 | ||||
-rw-r--r-- | sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx | 9 |
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 0a8ed36b4b7e..d1d4745d2f1f 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -113,6 +113,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_core_layout \ 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 Binary files differnew file mode 100644 index 000000000000..a756c85dd67b --- /dev/null +++ b/sw/qa/core/objectpositioning/data/overlap-crash.odt 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 fd4193918171..3c40f3b91aef 100644 --- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx +++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx @@ -1112,8 +1112,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()) { |