diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-03-24 11:01:56 +0300 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-04-27 23:18:16 +0200 |
commit | 06ca51c4820538fe684b7801d2b5f968487eecb6 (patch) | |
tree | 14d5643021033cb9974ceec99a5523b646421f9e /writerfilter | |
parent | 74241bb153b1a002e523a84767fda70ce73f395b (diff) |
tdf#154360: use TOC(N) styles in DOCX as the source of ToC tab stop position
Change-Id: Iab8001f8be8a8af437e8898079d55ff57dd6fa3b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149494
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149548
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 76 |
1 files changed, 50 insertions, 26 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 9e6ce49ec750..bb8ac11129b3 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -6044,35 +6044,34 @@ 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< beans::PropertyValues >& aLevel, const uno::Sequence<style::TabStop>& tabs) { //create a copy of the level and add new entries std::vector<css::beans::PropertyValues> aNewLevel; - aNewLevel.reserve(aLevel.getLength() + 4); // at most 4 added items + aNewLevel.reserve(aLevel.getLength() + 5); // at most 5 added items static constexpr OUStringLiteral tokType(u"TokenType"); static constexpr OUStringLiteral tokHStart(u"TokenHyperlinkStart"); static constexpr OUStringLiteral tokHEnd(u"TokenHyperlinkEnd"); static constexpr OUStringLiteral tokPNum(u"TokenPageNumber"); + static constexpr OUStringLiteral tokENum(u"TokenEntryNumber"); if (bHyperlinks) aNewLevel.push_back({ comphelper::makePropertyValue(tokType, tokHStart) }); for (const auto& item : aLevel) { - if (bHyperlinks - && std::any_of(item.begin(), item.end(), - [](const css::beans::PropertyValue& p) { - return p.Name == tokType - && (p.Value == tokHStart || p.Value == tokHEnd); - })) + OUString tokenType; + if (auto it = std::find_if(item.begin(), item.end(), + [](const auto& p) { return p.Name == tokType; }); + it != item.end()) + it->Value >>= tokenType; + + if (bHyperlinks && (tokenType == tokHStart || tokenType == tokHEnd)) continue; // We add hyperlink ourselves, so just skip existing hyperlink start / end - if (!sChapterNoSeparator.isEmpty() - && std::any_of(item.begin(), item.end(), - [](const css::beans::PropertyValue& p) - { return p.Name == tokType && p.Value == tokPNum; })) + if (!sChapterNoSeparator.isEmpty() && tokenType == tokPNum) { // This is an existing page number token; insert the chapter and separator before it aNewLevel.push_back( @@ -6083,6 +6082,14 @@ static uno::Sequence< beans::PropertyValues > lcl_createTOXLevelHyperlinks( bool } aNewLevel.push_back(item); + + if (tabs.hasElements() && 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) }); + } } if (bHyperlinks) @@ -6440,22 +6447,39 @@ void DomainMapper_Impl::handleToc xTOC->setPropertyValue(getPropertyName(PROP_CREATE_FROM_LEVEL_PARAGRAPH_STYLES), uno::Any( true )); } - if(bHyperlinks || !sChapterNoSeparator.isEmpty()) + + uno::Reference<container::XNameContainer> xStyles; + if (uno::Reference<style::XStyleFamiliesSupplier> xStylesSupplier{ GetTextDocument(), + uno::UNO_QUERY }) { - uno::Reference< container::XIndexReplace> xLevelFormats; - xTOC->getPropertyValue(getPropertyName(PROP_LEVEL_FORMAT)) >>= xLevelFormats; - sal_Int32 nLevelCount = xLevelFormats->getCount(); - //start with level 1, 0 is the header level - for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel) - { - uno::Sequence< beans::PropertyValues > aLevel; - xLevelFormats->getByIndex( nLevel ) >>= aLevel; + auto xStyleFamilies = xStylesSupplier->getStyleFamilies(); + xStyleFamilies->getByName(getPropertyName(PROP_PARAGRAPH_STYLES)) >>= xStyles; + } + + uno::Reference< container::XIndexReplace> xLevelFormats; + xTOC->getPropertyValue(getPropertyName(PROP_LEVEL_FORMAT)) >>= xLevelFormats; + sal_Int32 nLevelCount = xLevelFormats->getCount(); + //start with level 1, 0 is the header level + for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel) + { + uno::Sequence< beans::PropertyValues > aLevel; + xLevelFormats->getByIndex( nLevel ) >>= aLevel; - uno::Sequence< beans::PropertyValues > aNewLevel = lcl_createTOXLevelHyperlinks( - bHyperlinks, sChapterNoSeparator, - aLevel ); - xLevelFormats->replaceByIndex( nLevel, uno::Any( aNewLevel ) ); + // Get the tab stops coming from the styles; store to the level definitions + uno::Sequence<style::TabStop> tabStops; + if (xStyles) + { + OUString style; + xTOC->getPropertyValue("ParaStyleLevel" + OUString::number(nLevel)) >>= style; + uno::Reference<beans::XPropertySet> xStyle; + if (xStyles->getByName(style) >>= xStyle) + xStyle->getPropertyValue("ParaTabStops") >>= tabStops; } + + uno::Sequence< beans::PropertyValues > aNewLevel = lcl_createTOXLevelHyperlinks( + bHyperlinks, sChapterNoSeparator, + aLevel, tabStops); + xLevelFormats->replaceByIndex( nLevel, uno::Any( aNewLevel ) ); } } else if (bTableOfFigures && xTOC.is()) @@ -6479,7 +6503,7 @@ void DomainMapper_Impl::handleToc uno::Sequence< beans::PropertyValues > aNewLevel = lcl_createTOXLevelHyperlinks( bHyperlinks, sChapterNoSeparator, - aLevel ); + aLevel, {}); xLevelFormats->replaceByIndex( 1, uno::Any( aNewLevel ) ); } } |