diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-07-10 21:16:32 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-07-11 05:03:30 +0200 |
commit | b915dd9e1559870045481403806dd073f4fb5818 (patch) | |
tree | e9d66d2d2e0bcb6a6bccfab76f7a00fd10f831dd /writerfilter/source/dmapper/DomainMapper_Impl.cxx | |
parent | fcbae818b793a9ee97a1b5ddc53902be7a2376f5 (diff) |
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.kaganski@collabora.com>
Diffstat (limited to 'writerfilter/source/dmapper/DomainMapper_Impl.cxx')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 1389b9cadc02..491c755206b7 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -6322,7 +6322,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 @@ -6361,12 +6361,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) }); } } @@ -6741,7 +6741,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 @@ -6766,13 +6766,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 ) ); } } |