sw/qa/extras/tiledrendering/tiledrendering.cxx | 41 +++++++++++++++++++++++++ sw/source/core/fields/docufld.cxx | 11 ++++++ 2 files changed, 51 insertions(+), 1 deletion(-)
New commits: commit cf9e91f4082a9b01014e99e112e14a12246ce5f2 Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Thu May 19 15:27:48 2022 +0530 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Jan 3 07:27:10 2023 +0000 sw: prefer view's redline author name... to expand SwAuthorFieldType. Redline author name is set in SwXTextDocument::initializeForTiledRendering each time a new view is created. Change-Id: I316e0cae4399796682949de14b6d4b924833eb04 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134608 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143649 (cherry picked from commit 8be4a713e9f44bf05aebc0a3054654a18b4de065) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143585 Tested-by: Jenkins diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index e39dc418f8a2..f9c4e77e1631 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -19,6 +19,8 @@ #include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/AuthorDisplayFormat.hpp> #include <com/sun/star/datatransfer/XTransferable2.hpp> #include <test/helper/transferable.hxx> @@ -3790,6 +3792,45 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testDateContentControl) CPPUNIT_ASSERT_EQUAL(OUString("2022-05-30"), pTextNode->GetExpandText(pWrtShell->GetLayout())); } +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testAuthorField) +{ + SwXTextDocument* pXTextDocument = createDoc(); + const OUString sAuthor("Abcd Xyz"); + + uno::Sequence<beans::PropertyValue> aPropertyValues1(comphelper::InitPropertySequence( + { + {".uno:Author", uno::Any(sAuthor)}, + })); + pXTextDocument->initializeForTiledRendering(aPropertyValues1); + + auto insertAuthorField = [this]() + { + uno::Reference<lang::XMultiServiceFactory> const xMSF(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextDocument> const xTD(mxComponent, uno::UNO_QUERY_THROW); + + auto const xText = xTD->getText(); + auto const xTextCursor = xText->createTextCursor(); + CPPUNIT_ASSERT(xTextCursor.is()); + + xTextCursor->gotoEnd(false); + + uno::Reference<text::XTextField> const xTextField( + xMSF->createInstance("com.sun.star.text.textfield.Author"), uno::UNO_QUERY_THROW); + + uno::Reference<beans::XPropertySet> xTextFieldProps(xTextField, uno::UNO_QUERY_THROW); + xTextFieldProps->setPropertyValue("FullName", uno::Any(true)); + + xText->insertTextContent(xTextCursor, xTextField, false); + }; + + insertAuthorField(); + Scheduler::ProcessEventsToIdle(); + + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + + assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/SwParaPortion[1]/SwLineLayout[1]/SwFieldPortion[1]", "expand", sAuthor); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx index 2015216f2a91..98010119566e 100644 --- a/sw/source/core/fields/docufld.cxx +++ b/sw/source/core/fields/docufld.cxx @@ -315,7 +315,16 @@ OUString SwAuthorFieldType::Expand(sal_uLong nFormat) { SvtUserOptions& rOpt = SW_MOD()->GetUserOptions(); if((nFormat & 0xff) == AF_NAME) - return rOpt.GetFullName(); + { + // Prefer the view's redline author name. + // (set in SwXTextDocument::initializeForTiledRendering) + std::size_t nAuthor = SW_MOD()->GetRedlineAuthor(); + OUString sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor); + if (sAuthor.isEmpty()) + return rOpt.GetFullName(); + + return sAuthor; + } return rOpt.GetID(); }