sw/qa/extras/tiledrendering/tiledrendering.cxx |   43 +++++++++++++++++++++++++
 sw/source/core/fields/docufld.cxx              |   11 +++++-
 2 files changed, 53 insertions(+), 1 deletion(-)

New commits:
commit 092434c48555bedfd9d72620e6e676e6e17709a4
Author:     Dennis Francis <[email protected]>
AuthorDate: Thu May 19 15:27:48 2022 +0530
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon May 30 11:10:22 2022 +0200

    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 <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 8ac5fcc83e02..f0b8e3923158 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -18,6 +18,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>
@@ -165,6 +167,7 @@ public:
     void testCondCollCopy();
     void testMoveShapeHandle();
     void testRedlinePortions();
+    void testAuthorField();
 
     CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -251,6 +254,7 @@ public:
     CPPUNIT_TEST(testCondCollCopy);
     CPPUNIT_TEST(testMoveShapeHandle);
     CPPUNIT_TEST(testRedlinePortions);
+    CPPUNIT_TEST(testAuthorField);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3570,6 +3574,45 @@ void SwTiledRenderingTest::testRedlinePortions()
     assertXPath(pXmlDoc, "//Text[4]", "Portion", " after");
 }
 
+void SwTiledRenderingTest::testAuthorField()
+{
+    SwXTextDocument* pXTextDocument = createDoc();
+    const OUString sAuthor("Abcd Xyz");
+
+    uno::Sequence<beans::PropertyValue> 
aPropertyValues1(comphelper::InitPropertySequence(
+    {
+        {".uno:Author", uno::makeAny(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]/Special[1]", "rText", 
sAuthor);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/fields/docufld.cxx 
b/sw/source/core/fields/docufld.cxx
index 574cac74fe37..4a99b8353e82 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -312,7 +312,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();
 }

Reply via email to