sw/qa/extras/uiwriter/data/tdf50447.fodt                |   26 ++
 sw/qa/extras/uiwriter/uiwriter2.cxx                     |  153 ++++++++++++++++
 sw/source/core/doc/DocumentContentOperationsManager.cxx |   75 +++++++
 3 files changed, 252 insertions(+), 2 deletions(-)

New commits:
commit 97440778670d6b471d8165eb9f86def08e1b8602
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Tue Aug 24 14:26:57 2021 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Aug 30 10:47:33 2021 +0200

    tdf#144173 sw track changes: keep format of hints
    
    When a text has multiple character formatting settings
    enabled and a new one is applied with tracked changes,
    only one of the former settings is restored upon rejecting
    the changes.
    
    Follow-up to commit ee3171adb24a3d720466fa43bec869910333f892
    "tdf#143918 sw: fix reject of multiple changes".
    
    Change-Id: I6f3fb52dbd536efaf084b1fc5b8032658353af91
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121012
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/data/tdf50447.fodt 
b/sw/qa/extras/uiwriter/data/tdf50447.fodt
new file mode 100644
index 000000000000..db849a632e81
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf50447.fodt
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:config="urn:oas
 is:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:formx="urn:openoffice:names:
 experimental:ooxml-odf-interop:xmlns:form:1.0" 
xmlns:css3t="http://www.w3.org/TR/css3-text/"; office:version="1.2" 
office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:automatic-styles>
+  <style:style style:name="T1" style:family="text">
+   <style:text-properties style:text-underline-style="solid" 
style:text-underline-width="auto" style:text-underline-color="font-color"/>
+  </style:style>
+  <style:style style:name="T2" style:family="text">
+   <style:text-properties fo:font-style="italic" 
style:font-style-asian="italic" style:font-style-complex="italic"/>
+  </style:style>
+  <style:style style:name="T6" style:family="text">
+   <style:text-properties fo:font-style="italic" fo:font-weight="bold" 
style:font-style-asian="italic" style:font-weight-asian="bold" 
style:font-style-complex="italic" style:font-weight-complex="bold"/>
+  </style:style>
+  <style:style style:name="T7" style:family="text">
+   <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" 
style:font-weight-complex="bold"/>
+  </style:style>
+  <style:style style:name="T8" style:family="text">
+   <style:text-properties style:text-underline-style="solid" 
style:text-underline-width="auto" style:text-underline-color="font-color" 
fo:font-weight="bold" style:font-weight-asian="bold" 
style:font-weight-complex="bold"/>
+  </style:style>
+ </office:automatic-styles>
+  <office:body>
+    <office:text>
+   <text:h text:outline-level="1"><text:span 
text:style-name="T8">Lorem</text:span><text:span text:style-name="T7"> 
</text:span><text:span text:style-name="T6">ipsum</text:span></text:h>
+   <text:p text:style-name="Standard"><text:span 
text:style-name="T1">dolor</text:span> sit <text:span 
text:style-name="T2">amet</text:span>.</text:p>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 2b263a7849dd..a1603ab50f30 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -3005,6 +3005,159 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf143939)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf50447_keep_hints)
+{
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf50447.fodt");
+
+    // first paragraph (_Lorem_ /ipsum/)
+
+    auto xText = getParagraph(1)->getText();
+    CPPUNIT_ASSERT(xText.is());
+    {
+        auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 
1)));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("Lorem"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::SINGLE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+
+        xCursor = xText->createTextCursorByRange(getRun(getParagraph(1), 2));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString(" "), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::NONE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+
+        xCursor = xText->createTextCursorByRange(getRun(getParagraph(1), 3));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("ipsum"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::NONE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+    }
+
+    // second paragraph (_dolor_ sit /amet/.)
+
+    xText = getParagraph(2)->getText();
+    CPPUNIT_ASSERT(xText.is());
+    {
+        auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(2), 
1)));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("dolor"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::SINGLE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+
+        xCursor = xText->createTextCursorByRange(getRun(getParagraph(2), 2));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString(" sit "), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::NONE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+
+        xCursor = xText->createTextCursorByRange(getRun(getParagraph(2), 3));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("amet"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::NONE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+    }
+
+    // turn on red-lining and show changes
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | 
RedlineFlags::ShowDelete
+                                                      | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+
+    // modify character formatting of the all the text
+
+    dispatchCommand(mxComponent, ".uno:SelectAll", {});
+    dispatchCommand(mxComponent, ".uno:SuperScript", {});
+
+    // multiple format redlines for the multiple hints
+
+    SwEditShell* const pEditShell(pDoc->GetEditShell());
+    // This was 1.
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(7), 
pEditShell->GetRedlineCount());
+
+    // reject tracked changes
+
+    dispatchCommand(mxComponent, ".uno:RejectAllTrackedChanges", {});
+
+    // all hints and text portions between them got back the original 
formattings
+
+    xText = getParagraph(1)->getText();
+    CPPUNIT_ASSERT(xText.is());
+    {
+        auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 
1)));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("Lorem"), xCursor->getString());
+        // This was NONE
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::SINGLE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+
+        xCursor = xText->createTextCursorByRange(getRun(getParagraph(1), 2));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString(" "), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::NONE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+
+        xCursor = xText->createTextCursorByRange(getRun(getParagraph(1), 3));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("ipsum"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::NONE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        // This was NONE
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+    }
+
+    // second paragraph (_dolor_ sit /amet/.)
+
+    xText = getParagraph(2)->getText();
+    CPPUNIT_ASSERT(xText.is());
+    {
+        auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(2), 
1)));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("dolor"), xCursor->getString());
+        // This was NONE
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::SINGLE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+
+        xCursor = xText->createTextCursorByRange(getRun(getParagraph(2), 2));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString(" sit "), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::NONE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+
+        xCursor = xText->createTextCursorByRange(getRun(getParagraph(2), 3));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("amet"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(awt::FontUnderline::NONE),
+                             getProperty<sal_Int16>(xCursor, "CharUnderline"));
+        // This was NONE
+        CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC,
+                             getProperty<awt::FontSlant>(xCursor, 
"CharPosture"));
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf101873)
 {
     SwDoc* pDoc = createSwDoc();
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 9af97d1c4626..8257bec7d8f2 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -1296,6 +1296,77 @@ namespace //local functions originally from docfmt.cxx
         }
     }
 
+    // create format redline(s) for the given range:
+    // to track the original formatting stored in the
+    // hints, create redlines for all parts of the
+    // range partitioned by boundaries of the hints.
+    void lcl_SetRedlines(
+        SwDoc& rDoc,
+        const SwPaM &rRg)
+    {
+        SwNodeIndex aIdx( rRg.Start()->nNode );
+        const SwNodeIndex aEndNd( rRg.End()->nNode );
+        while( aIdx <= aEndNd )
+        {
+            SwTextNode *pNode = aIdx.GetNode().GetTextNode();
+            if( pNode )
+            {
+                const sal_Int32 nStart = aIdx == rRg.Start()->nNode
+                        ? rRg.Start()->nContent.GetIndex()
+                        : 0;
+                const sal_Int32 nEnd = aIdx < aEndNd
+                        ? pNode->GetText().getLength()
+                        : rRg.End()->nContent.GetIndex();
+
+                if( SwpHints *pHints = pNode->GetpSwpHints() )
+                {
+                    const size_t nCount = pHints->Count();
+                    sal_Int32 nRedEnd = nStart;
+                    for( size_t i = 0; i < nCount; ++i )
+                    {
+                        SwTextAttr *pAttr = pHints->Get( i );
+
+                        if ( pAttr->GetStart() > nEnd )
+                        {
+                            break; // after the range
+                        }
+
+                        if ( !pAttr->GetEnd() || *pAttr->GetEnd() < nStart )
+                        {
+                            continue; // before the range
+                        }
+
+                        // range part before the hint
+                        if ( nRedEnd < pAttr->GetStart() )
+                        {
+                            SwPaM aPam( *pNode, nRedEnd, *pNode, 
pAttr->GetStart() );
+                            lcl_SetRedline(rDoc, aPam);
+                        }
+
+                        // range part at the hint
+                        sal_Int32 nRedStart = std::max(pAttr->GetStart(), 
nStart);
+                        nRedEnd = std::min(*pAttr->GetEnd(), nEnd);
+                        SwPaM aPam2( *pNode, nRedStart, *pNode, nRedEnd );
+                        lcl_SetRedline(rDoc, aPam2);
+                    }
+
+                    // range part after the last hint
+                    if ( nRedEnd < nEnd )
+                    {
+                        SwPaM aPam( *pNode, nRedEnd, *pNode, nEnd );
+                        lcl_SetRedline(rDoc, aPam);
+                    }
+                }
+                else
+                {
+                    SwPaM aPam( *pNode, nStart, *pNode, nEnd );
+                    lcl_SetRedline(rDoc, aPam);
+                }
+            }
+            ++aIdx;
+        }
+    }
+
     /// Insert Hints according to content types;
     // Is used in SwDoc::Insert(..., SwFormatHint &rHt)
 
@@ -1708,7 +1779,7 @@ namespace //local functions originally from docfmt.cxx
                     if( pUndo )
                         pUndo->SaveRedlineData( aPam, false );
 
-                    lcl_SetRedline(rDoc, aPam);
+                    lcl_SetRedlines(rDoc, aPam);
                 }
 
                 // the SwRegHistory inserts the attribute into the TextNode!
@@ -1738,7 +1809,7 @@ namespace //local functions originally from docfmt.cxx
             if( pUndo )
                 pUndo->SaveRedlineData( rRg, false );
 
-            lcl_SetRedline(rDoc, rRg);
+            lcl_SetRedlines(rDoc, rRg);
         }
 
         /* now if range */

Reply via email to