[Libreoffice-commits] core.git: sw/qa writerfilter/source

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 7 12:33:30 UTC 2020


 sw/qa/extras/ooxmlexport/data/tdf132271.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx        |    8 ++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    3 
 writerfilter/source/dmapper/PropertyMap.cxx       |   81 ++++++++++++++++++++++
 4 files changed, 91 insertions(+), 1 deletion(-)

New commits:
commit 288db6eb47fbbd2b3ca34ffea0686d8ed8ed9be9
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Mon Sep 7 09:48:45 2020 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Mon Sep 7 14:32:51 2020 +0200

    tdf#132271 DOCX: import change tracking in floating tables
    
    Change-Id: If892a16875ef16015639aacf8359d15c953fb1d2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102149
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf132271.docx b/sw/qa/extras/ooxmlexport/data/tdf132271.docx
new file mode 100644
index 000000000000..202bfdda2ba0
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf132271.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index a80b76a21223..c36b399f4352 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -971,6 +971,14 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf125894, "tdf125894.docx")
     assertXPath(pXmlDoc, "//w:ins");
 }
 
+DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf132271, "tdf132271.docx")
+{
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // import change tracking in floating tables
+    assertXPath(pXmlDoc, "//w:del", 2);
+    assertXPath(pXmlDoc, "//w:ins", 2);
+}
+
 DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf128156, "tdf128156.docx")
 {
     xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index ec83a7c2d5f9..77d7ce21a0dd 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2633,7 +2633,8 @@ void DomainMapper_Impl::CreateRedline(uno::Reference<text::XTextRange> const& xR
             uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW );
             xRedline->makeRedline( sType, aRedlineProperties );
         }
-        else
+        // store frame and (possible floating) table redline data for restoring them after frame conversion
+        if (m_bIsActualParagraphFramed || (hasTableManager() && getTableManager().isInTable()))
         {
             aFramedRedlines.push_back( uno::makeAny(xRange) );
             aFramedRedlines.push_back( uno::makeAny(sType) );
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index 578738175238..4e08279a8427 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -45,8 +45,11 @@
 #include <com/sun/star/text/VertOrientation.hpp>
 #include <com/sun/star/text/WritingMode.hpp>
 #include <com/sun/star/text/WritingMode2.hpp>
+#include <com/sun/star/text/XRedline.hpp>
 #include <com/sun/star/text/XTextColumns.hpp>
 #include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/text/XTextFrame.hpp>
+#include <com/sun/star/text/XTextTablesSupplier.hpp>
 #include <com/sun/star/text/TextGridMode.hpp>
 #include <com/sun/star/text/XTextCopy.hpp>
 #include <com/sun/star/style/VerticalAlignment.hpp>
@@ -1371,15 +1374,93 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
         rInfo.m_nBreakType = m_nBreakType;
         if ( FloatingTableConversion( rDM_Impl, rInfo ) )
         {
+            std::vector<css::uno::Any> aFramedRedlines = rDM_Impl.aFramedRedlines;
             try
             {
+                // convert redline ranges to cursor movement and character length
+                std::vector<sal_Int32> redPos, redLen;
+                std::vector<OUString> redCell;
+                OUString sTableName;
+                for( size_t i = 0; i < aFramedRedlines.size(); i+=3)
+                {
+                    uno::Reference<text::XText> xCell;
+                    uno::Reference< text::XTextRange > xRange;
+                    aFramedRedlines[i] >>= xRange;
+                    uno::Reference< beans::XPropertySet > xRangeProperties;
+                    if ( xRange.is() )
+                    {
+                        xRangeProperties.set( xRange, uno::UNO_QUERY_THROW );
+
+                        const uno::Sequence<beans::Property> aRangeProperties
+                            = xRangeProperties->getPropertySetInfo()->getProperties();
+
+                        for (const beans::Property& rProperty : aRangeProperties)
+                        {
+                            const OUString& rKey = rProperty.Name;
+                            uno::Any aValue = xRangeProperties->getPropertyValue(rKey);
+                            if ( rKey == "TextTable" )
+                            {
+                                uno::Reference<text::XTextTable> xTable;
+                                aValue >>= xTable;
+                                uno::Reference<beans::XPropertySet> xTableProperties(xTable, uno::UNO_QUERY);
+                                xTableProperties->getPropertyValue("TableName") >>= sTableName;
+                            }
+                            else if ( rKey == "Cell" )
+                            {
+                                 OUString sCellName;
+                                 aValue >>= xCell;
+                                 uno::Reference<beans::XPropertySet> xCellProperties(xCell, uno::UNO_QUERY);
+                                 xCellProperties->getPropertyValue("CellName") >>= sCellName;
+                                 redCell.push_back(sCellName);
+                            }
+                        }
+
+                        uno::Reference<text::XTextCursor> xRangeCursor = xCell->createTextCursorByRange( xRange );
+                        if ( xRangeCursor.is() )
+                        {
+                            sal_Int32 nLen = xRange->getString().getLength();
+                            redLen.push_back(nLen);
+                            xRangeCursor->gotoStart(true);
+                            redPos.push_back(xRangeCursor->getString().getLength() - nLen);
+                        }
+                        else
+                        {
+                            // failed createTextCursorByRange()
+                            redLen.push_back(-1);
+                            redPos.push_back(-1);
+                        }
+                    }
+                }
+
                 xBodyText->convertToTextFrame(rInfo.m_xStart, rInfo.m_xEnd,
                                               rInfo.m_aFrameProperties);
+
+                uno::Reference<text::XTextTablesSupplier> xTextDocument(rDM_Impl.GetTextDocument(), uno::UNO_QUERY);
+                uno::Reference<container::XNameAccess> xTables = xTextDocument->getTextTables();
+                uno::Reference<text::XTextTable> xTable(xTables->getByName(sTableName), uno::UNO_QUERY);
+                for( size_t i = 0; i < aFramedRedlines.size(); i+=3)
+                {
+                    OUString sType;
+                    beans::PropertyValues aRedlineProperties( 3 );
+                    // skip failed createTextCursorByRange()
+                    if (redPos[i/3] == -1)
+                        continue;
+                    aFramedRedlines[i+1] >>= sType;
+                    aFramedRedlines[i+2] >>= aRedlineProperties;
+                    uno::Reference<text::XText> xCell(xTable->getCellByName(redCell[i/3]), uno::UNO_QUERY);
+                    uno::Reference<text::XTextCursor> xCrsr = xCell->createTextCursor();
+                    xCrsr->goRight(redPos[i/3], false);
+                    xCrsr->goRight(redLen[i/3], true);
+                    uno::Reference < text::XRedline > xRedline( xCrsr, uno::UNO_QUERY_THROW );
+                    xRedline->makeRedline( sType, aRedlineProperties );
+                }
             }
             catch (const uno::Exception&)
             {
                 DBG_UNHANDLED_EXCEPTION("writerfilter", "convertToTextFrame() failed");
             }
+
+            aFramedRedlines.clear();
         }
     }
     rPendingFloatingTables.clear();


More information about the Libreoffice-commits mailing list