sw/qa/extras/ooxmlexport/data/tdf63561_clearTabs.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx            |    8 +++
 sw/source/filter/ww8/docxattributeoutput.cxx          |   42 ++++++++----------
 3 files changed, 28 insertions(+), 22 deletions(-)

New commits:
commit 5fa898acb96fb344b526bd6e3892c4f4fae6e4f8
Author:     Justin Luth <justin_l...@sil.org>
AuthorDate: Wed Jul 11 08:18:22 2018 +0300
Commit:     Miklos Vajna <vmik...@collabora.co.uk>
CommitDate: Wed Jul 25 10:18:53 2018 +0200

    tdf#63561 docx export: "clear" unused inherited tabs
    
    If a style contains tab definitions, then the paragraph inherits
    these. They are added to any tabs defined at the paragraph
    level. Unwanted inherited tabs must be explicitly removed.
    
    (TODO: LO ought to be inheriting from ALL parents, so the same
    logic ought to apply to a style's parent tabs, but currently
    LO does not import that way. So the proof unit test looks
    different in MSO compared to LO.)
    
    Change-Id: Ida8ed2792482655d512c753fdff8d02062d895a8
    Reviewed-on: https://gerrit.libreoffice.org/57255
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_l...@sil.org>
    (cherry picked from commit 859a0389b5639397e9c46cd4828a35793bd194f8)
    Reviewed-on: https://gerrit.libreoffice.org/57267
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf63561_clearTabs.docx 
b/sw/qa/extras/ooxmlexport/data/tdf63561_clearTabs.docx
new file mode 100644
index 000000000000..228b9b5478ba
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf63561_clearTabs.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index af4fa6661907..6249547816df 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -56,6 +56,14 @@ DECLARE_OOXMLEXPORT_TEST(testTdf46938_clearTabStop, 
"tdf46938_clearTabStop.docx"
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty< 
uno::Sequence<style::TabStop> >(getParagraph(1), "ParaTabStops").getLength());
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf63561_clearTabs, "tdf63561_clearTabs.docx")
+{
+    // MSO2013 gives 5,7, and 4 respectively
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty< 
uno::Sequence<style::TabStop> >(getParagraph(1), "ParaTabStops").getLength());
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty< 
uno::Sequence<style::TabStop> >(getParagraph(3), "ParaTabStops").getLength());
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4), getProperty< 
uno::Sequence<style::TabStop> >(getParagraph(4), "ParaTabStops").getLength());
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf82065_Ind_start_strict, 
"tdf82065_Ind_start_strict.docx")
 {
     uno::Reference<beans::XPropertySet> 
xPropertySet(getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY);
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index b7373bfa5235..95de428c320c 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -7711,31 +7711,13 @@ static void impl_WriteTabElement( FSHelperPtr const & 
pSerializer,
 
 void DocxAttributeOutput::ParaTabStop( const SvxTabStopItem& rTabStop )
 {
-    sal_uInt16 nCount = rTabStop.Count();
+    const SvxTabStopItem* pInheritedTabs = GetExport().m_pStyAttr ? 
GetExport().m_pStyAttr->GetItem<SvxTabStopItem>(RES_PARATR_TABSTOP) : nullptr;
+    const sal_uInt16 nInheritedTabCount = pInheritedTabs ? 
pInheritedTabs->Count() : 0;
+    const sal_uInt16 nCount = rTabStop.Count();
 
     // <w:tabs> must contain at least one <w:tab>, so don't write it empty
-    if( nCount == 0 )
-    {
-        // clear style tabs - otherwise style will override...
-        if( GetExport().m_pStyAttr )
-        {
-            const SvxTabStopItem* pStyleTabs = 
GetExport().m_pStyAttr->GetItem<SvxTabStopItem>(RES_PARATR_TABSTOP);
-            if( pStyleTabs && pStyleTabs->Count() )
-            {
-                m_pSerializer->startElementNS( XML_w, XML_tabs, FSEND );
-                for( int i = 0; i < pStyleTabs->Count(); ++i )
-                {
-                    m_pSerializer->singleElementNS( XML_w, XML_tab,
-                        FSNS( XML_w, XML_val ), OString("clear"),
-                        FSNS( XML_w, XML_pos ), 
OString::number(pStyleTabs->At(i).GetTabPos()),
-                        FSEND );
-                }
-                m_pSerializer->endElementNS( XML_w, XML_tabs );
-            }
-        }
-
+    if ( !nCount && !nInheritedTabCount )
         return;
-    }
     if( nCount == 1 && rTabStop[ 0 ].GetAdjustment() == SvxTabAdjust::Default )
     {
         GetExport().setDefaultTabStop( rTabStop[ 0 ].GetTabPos());
@@ -7744,6 +7726,22 @@ void DocxAttributeOutput::ParaTabStop( const 
SvxTabStopItem& rTabStop )
 
     m_pSerializer->startElementNS( XML_w, XML_tabs, FSEND );
 
+    // clear unused inherited tabs - otherwise the style will add them back in
+    sal_Int32 nCurrTab = 0;
+    for ( sal_uInt16 i = 0; i < nInheritedTabCount; ++i )
+    {
+        while ( nCurrTab < nCount && rTabStop[nCurrTab] < 
pInheritedTabs->At(i) )
+            ++nCurrTab;
+
+        if ( nCurrTab == nCount || pInheritedTabs->At(i) < rTabStop[nCurrTab] )
+        {
+            m_pSerializer->singleElementNS( XML_w, XML_tab,
+                FSNS( XML_w, XML_val ), OString("clear"),
+                FSNS( XML_w, XML_pos ), 
OString::number(pInheritedTabs->At(i).GetTabPos()),
+                FSEND );
+        }
+    }
+
     for (sal_uInt16 i = 0; i < nCount; i++ )
     {
         if( rTabStop[i].GetAdjustment() != SvxTabAdjust::Default )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to