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 5b9471ad3698aa7892985299b169a70b4e058443 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Mon Jul 10 21:16:32 2023 +0300 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Jul 26 14:47:38 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/+/154259 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> 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 a0a4d8051686..6edd873dc7ed 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -1063,7 +1063,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf154319) // tdf#154360: check tab stops between the number and the entry text // The last (10th) level does not correspond 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 77a68dd5a535..308768cc78eb 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -6314,7 +6314,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 @@ -6353,12 +6353,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) }); } } @@ -6733,7 +6733,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 @@ -6758,13 +6758,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 ) ); } }