summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-02-04 14:33:37 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-02-04 16:08:07 +0100
commita2f85c062aafb3fd9dfb1c6c6e87e1e73e7545a3 (patch)
tree282f68919f0fbc79e9fec63e83540ecc2fbaf970
parent7ffd38fc54dda2d2c84eab19c40efcbac7fb0bff (diff)
tdf#130362 sw: fix anchoring of inline math objects
Regression from a7528cd6f17ea5c5b29e7d607e54c62de0d9e7db (sw: insert image: set anchor to at-char by default, 2019-11-18), that defaulted to at-char anchoring for charts and images. What was not considered is that math objects had a previous as-char default (not to-para), and that is supposed to be unchanged. Change-Id: I2a91af6425035b48a0e47ad9b10939945855cd16 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87976 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sw/CppunitTest_sw_core_doc.mk72
-rw-r--r--sw/Module_sw.mk1
-rw-r--r--sw/inc/IDocumentContentOperations.hxx2
-rw-r--r--sw/inc/fesh.hxx2
-rw-r--r--sw/qa/core/doc/doc.cxx65
-rw-r--r--sw/source/core/doc/DocumentContentOperationsManager.cxx10
-rw-r--r--sw/source/core/frmedt/fefly1.cxx2
-rw-r--r--sw/source/core/inc/DocumentContentOperationsManager.hxx2
8 files changed, 151 insertions, 5 deletions
diff --git a/sw/CppunitTest_sw_core_doc.mk b/sw/CppunitTest_sw_core_doc.mk
new file mode 100644
index 000000000000..487e02322ef4
--- /dev/null
+++ b/sw/CppunitTest_sw_core_doc.mk
@@ -0,0 +1,72 @@
+# -*- 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_doc))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_doc))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_doc, \
+ sw/qa/core/doc/doc \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_doc, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ sfx \
+ sw \
+ test \
+ unotest \
+ utl \
+ vcl \
+ svt \
+ tl \
+ svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_doc,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_doc,\
+ -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_doc,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_doc))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_doc))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_doc,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_doc,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_doc))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_doc, \
+ modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_doc))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 08391411ba55..44c33f9d9951 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -105,6 +105,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_apitests \
CppunitTest_sw_unowriter \
CppunitTest_sw_core_text \
+ CppunitTest_sw_core_doc \
CppunitTest_sw_uibase_shells \
CppunitTest_sw_core_accessibilitycheck \
))
diff --git a/sw/inc/IDocumentContentOperations.hxx b/sw/inc/IDocumentContentOperations.hxx
index 6ba51df9f740..b6857c346a33 100644
--- a/sw/inc/IDocumentContentOperations.hxx
+++ b/sw/inc/IDocumentContentOperations.hxx
@@ -180,7 +180,7 @@ public:
*/
virtual SwFlyFrameFormat* InsertEmbObject(
const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj,
- const SfxItemSet* pFlyAttrSet) = 0;
+ SfxItemSet* pFlyAttrSet) = 0;
virtual SwFlyFrameFormat* InsertOLE(
const SwPaM &rRg, const OUString& rObjName, sal_Int64 nAspect,
diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index 46f6be2294b0..87319659505a 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -626,7 +626,7 @@ public:
bool GetPageNumber( long nYPos, bool bAtCursorPos, sal_uInt16& rPhyNum, sal_uInt16& rVirtNum, OUString &rDisplay ) const;
SwFlyFrameFormat* InsertObject( const svt::EmbeddedObjectRef&,
- const SfxItemSet* pFlyAttrSet );
+ SfxItemSet* pFlyAttrSet );
bool FinishOLEObj(); ///< Shutdown server.
void GetTableAttr( SfxItemSet & ) const;
diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
new file mode 100644
index 000000000000..3141c12011cc
--- /dev/null
+++ b/sw/qa/core/doc/doc.cxx
@@ -0,0 +1,65 @@
+/* -*- 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 <vcl/gdimtf.hxx>
+#include <comphelper/classids.hxx>
+#include <tools/globname.hxx>
+#include <svtools/embedhlp.hxx>
+
+#include <wrtsh.hxx>
+#include <fmtanchr.hxx>
+
+static char const DATA_DIRECTORY[] = "/sw/qa/core/doc/data/";
+
+/// Covers sw/source/core/doc/ fixes.
+class SwCoreDocTest : public SwModelTestBase
+{
+public:
+ SwDoc* createDoc(const char* pName = nullptr);
+};
+
+SwDoc* SwCoreDocTest::createDoc(const char* pName)
+{
+ if (!pName)
+ loadURL("private:factory/swriter", nullptr);
+ else
+ load(DATA_DIRECTORY, pName);
+
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ return pTextDoc->GetDocShell()->GetDoc();
+}
+
+CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testMathInsertAnchorType)
+{
+ // Given an empty document.
+ SwDoc* pDoc = createDoc();
+
+ // When inserting an a math object.
+ SwWrtShell* pShell = pDoc->GetDocShell()->GetWrtShell();
+ SvGlobalName aGlobalName(SO3_SM_CLASSID);
+ pShell->InsertObject(svt::EmbeddedObjectRef(), &aGlobalName);
+
+ // Then the anchor type should be as-char.
+ SwFrameFormats& rFormats = *pDoc->GetSpzFrameFormats();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rFormats.size());
+ const SwFrameFormat& rFormat = *rFormats[0];
+ const SwFormatAnchor& rAnchor = rFormat.GetAnchor();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1
+ // - Actual : 4
+ // i.e. the anchor type was at-char, not as-char.
+ CPPUNIT_ASSERT_EQUAL(RndStdIds::FLY_AS_CHAR, rAnchor.GetAnchorId());
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 4a412897da24..265ebd4d655e 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -2856,14 +2856,22 @@ SwFlyFrameFormat* DocumentContentOperationsManager::InsertGraphicObject(
SwFlyFrameFormat* DocumentContentOperationsManager::InsertEmbObject(
const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj,
- const SfxItemSet* pFlyAttrSet)
+ SfxItemSet* pFlyAttrSet)
{
sal_uInt16 nId = RES_POOLFRM_OLE;
if (xObj.is())
{
SvGlobalName aClassName( xObj->getClassID() );
if (SotExchange::IsMath(aClassName))
+ {
nId = RES_POOLFRM_FORMEL;
+ if (pFlyAttrSet && pFlyAttrSet->HasItem(RES_ANCHOR))
+ {
+ // Clear the at-char anchor set in the SwFlyFrameAttrMgr ctor, so the as-char one
+ // set later in pFrameFormat is considered.
+ pFlyAttrSet->ClearItem(RES_ANCHOR);
+ }
+ }
}
SwFrameFormat* pFrameFormat = m_rDoc.getIDocumentStylePoolAccess().GetFrameFormatFromPool( nId );
diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 203aaa1eeaee..51f2f7f04c75 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -881,7 +881,7 @@ void SwFEShell::Insert( const OUString& rGrfName, const OUString& rFltName,
}
SwFlyFrameFormat* SwFEShell::InsertObject( const svt::EmbeddedObjectRef& xObj,
- const SfxItemSet* pFlyAttrSet )
+ SfxItemSet* pFlyAttrSet )
{
SwFlyFrameFormat* pFormat = nullptr;
SET_CURR_SHELL( this );
diff --git a/sw/source/core/inc/DocumentContentOperationsManager.hxx b/sw/source/core/inc/DocumentContentOperationsManager.hxx
index 4f523bec9f3d..2d600b6ff8ba 100644
--- a/sw/source/core/inc/DocumentContentOperationsManager.hxx
+++ b/sw/source/core/inc/DocumentContentOperationsManager.hxx
@@ -73,7 +73,7 @@ public:
SwDrawFrameFormat* InsertDrawObj( const SwPaM &rRg, SdrObject& rDrawObj, const SfxItemSet& rFlyAttrSet ) override;
- SwFlyFrameFormat* InsertEmbObject(const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj, const SfxItemSet* pFlyAttrSet) override;
+ SwFlyFrameFormat* InsertEmbObject(const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj, SfxItemSet* pFlyAttrSet) override;
SwFlyFrameFormat* InsertOLE(const SwPaM &rRg, const OUString& rObjName, sal_Int64 nAspect, const SfxItemSet* pFlyAttrSet,
const SfxItemSet* pGrfAttrSet) override;