sw/qa/extras/ooxmlimport/data/tdf154319-ToC_with_s_and_d.docx |binary
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx                     |    2 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx             |   37 ++++++++--
 3 files changed, 32 insertions(+), 7 deletions(-)

New commits:
commit 2093a4b0b42f33ac9b00de5bf8357e2b3ec470ca
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Jul 10 21:16:32 2023 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Jul 14 11:24:14 2023 +0200

    tdf#156130: Use default tab stop when TOC*N style doesn't define one
    
    When TOC*N style only defines one tab stop, it's used by Word as the
    page number position, and the tab between chapter number and chapter
    name is set to a default position. When the style has no tab stops,
    they are both defaulted.
    
    testTdf154319 is updated to test this.
    
    Change-Id: I561995a8e96882e1f17ee9982e3fc640e621cda2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154281
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit b915dd9e1559870045481403806dd073f4fb5818)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154260
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/ooxmlimport/data/tdf154319-ToC_with_s_and_d.docx 
b/sw/qa/extras/ooxmlimport/data/tdf154319-ToC_with_s_and_d.docx
index dc5a67824c9d..91a9d0b8adea 100644
Binary files a/sw/qa/extras/ooxmlimport/data/tdf154319-ToC_with_s_and_d.docx 
and b/sw/qa/extras/ooxmlimport/data/tdf154319-ToC_with_s_and_d.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index ca1aeafccc5e..304346b09250 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -1047,7 +1047,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf154319)
     // tdf#154360: check tab stops between the number and the entry text
     // The last (10th) level does not correspont to any MS level (only 9 
levels there)
     constexpr sal_Int32 levelTabStops[]
-        = { 776, 1270, 1270, 1270, 1270, 1270, 1270, 1270, 1270, -1 };
+        = { 776, 1552, 2328, 3104, 3881, 4657, 5433, 6209, 6985, -1 };
 
     //start with level 1, 0 is the header level
     for (sal_Int32 nLevel = 1; nLevel < xLevelFormats->getCount(); ++nLevel)
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 4b8c36521f7e..4d3dd4e1568b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -6068,7 +6068,7 @@ void DomainMapper_Impl::handleAuthor
 }
 
 static uno::Sequence< beans::PropertyValues > lcl_createTOXLevelHyperlinks( 
bool bHyperlinks, const OUString& sChapterNoSeparator,
-                                   const uno::Sequence< beans::PropertyValues 
>& aLevel, const uno::Sequence<style::TabStop>& tabs)
+                                   const uno::Sequence< beans::PropertyValues 
>& aLevel, const std::optional<style::TabStop> numtab)
 {
     //create a copy of the level and add new entries
 
@@ -6107,12 +6107,12 @@ static uno::Sequence< beans::PropertyValues > 
lcl_createTOXLevelHyperlinks( bool
 
         aNewLevel.push_back(item);
 
-        if (tabs.hasElements() && tokenType == tokENum)
+        if (numtab && tokenType == tokENum)
         {
             // There is a fixed tab stop position needed in the level after 
the numbering
             aNewLevel.push_back(
                 { comphelper::makePropertyValue(tokType, 
OUString("TokenTabStop")),
-                  comphelper::makePropertyValue("TabStopPosition", 
tabs[0].Position) });
+                  comphelper::makePropertyValue("TabStopPosition", 
numtab->Position) });
         }
     }
 
@@ -6494,7 +6494,7 @@ void DomainMapper_Impl::handleToc
             xLevelFormats->getByIndex( nLevel ) >>= aLevel;
 
             // Get the tab stops coming from the styles; store to the level 
definitions
-            uno::Sequence<style::TabStop> tabStops;
+            std::optional<style::TabStop> numTab;
             if (xChapterNumberingRules && xStyles)
             {
                 // This relies on the chapter numbering rules already defined
@@ -6519,13 +6519,38 @@ void DomainMapper_Impl::handleToc
                     xTOC->getPropertyValue("ParaStyleLevel" + 
OUString::number(nLevel)) >>= style;
                     uno::Reference<beans::XPropertySet> xStyle;
                     if (xStyles->getByName(style) >>= xStyle)
-                        xStyle->getPropertyValue("ParaTabStops") >>= tabStops;
+                    {
+                        if (uno::Reference<beans::XPropertyState> xPropState{ 
xStyle,
+                                                                              
uno::UNO_QUERY })
+                        {
+                            if (xPropState->getPropertyState("ParaTabStops")
+                                == beans::PropertyState_DIRECT_VALUE)
+                            {
+                                if (uno::Sequence<style::TabStop> tabStops;
+                                    xStyle->getPropertyValue("ParaTabStops") 
>>= tabStops)
+                                {
+                                    // If the style only has one tab stop, 
Word uses it for
+                                    // page number, and generates the other 
from defaults
+                                    if (tabStops.getLength() > 1)
+                                        numTab = tabStops[0];
+                                }
+                            }
+                        }
+                    }
+                    if (!numTab)
+                    {
+                        // Generate the default position.
+                        // Word uses multiples of 440 twips for default 
chapter number tab stops
+                        numTab.emplace();
+                        numTab->Position
+                            = o3tl::convert(440 * nLevel, o3tl::Length::twip, 
o3tl::Length::mm100);
+                    }
                 }
             }
 
             uno::Sequence< beans::PropertyValues > aNewLevel = 
lcl_createTOXLevelHyperlinks(
                                                 bHyperlinks, 
sChapterNoSeparator,
-                                                aLevel, tabStops);
+                                                aLevel, numTab);
             xLevelFormats->replaceByIndex( nLevel, uno::Any( aNewLevel ) );
         }
     }

Reply via email to