summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-04-08 00:03:31 +0300
committerAndras Timar <andras.timar@collabora.com>2023-05-13 20:01:54 +0200
commitca2b6a7c4af21ee358773be849ad5b1fedf47408 (patch)
treeb541c15177787c857b69e36c827a34d4be718ee4 /writerfilter
parent9fa9a748a0b4f3b176105c35f36528d7d8f92096 (diff)
tdf#154695: use Chapter Numbering Rules to confirm that ToC needs tabs
Indeed, this still can't handle it per-element, like Word does: the latter would omit both the number and the tab for headings without numbering. But at least the most common case should be handled better now. Change-Id: I0be5d61a5d2cbbf778ee88a11129a6e7655593ec Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150133 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit b6a5f16a9bf3227867bf46b88d012440138b6f24) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150142 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx37
1 files changed, 31 insertions, 6 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 7f23452f92df..26893126ff72 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -51,6 +51,7 @@
#include <com/sun/star/text/XFootnotesSupplier.hpp>
#include <com/sun/star/text/XLineNumberingProperties.hpp>
#include <com/sun/star/style/XStyle.hpp>
+#include <com/sun/star/text/LabelFollow.hpp>
#include <com/sun/star/text/PageNumberType.hpp>
#include <com/sun/star/text/HoriOrientation.hpp>
#include <com/sun/star/text/VertOrientation.hpp>
@@ -60,6 +61,7 @@
#include <com/sun/star/text/SizeType.hpp>
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/text/WrapTextMode.hpp>
+#include <com/sun/star/text/XChapterNumberingSupplier.hpp>
#include <com/sun/star/text/XDependentTextField.hpp>
#include <com/sun/star/text/XParagraphCursor.hpp>
#include <com/sun/star/text/XRedline.hpp>
@@ -6448,6 +6450,10 @@ void DomainMapper_Impl::handleToc
}
+ uno::Reference<container::XIndexAccess> xChapterNumberingRules;
+ if (uno::Reference<text::XChapterNumberingSupplier> xSupplier{ GetTextDocument(),
+ uno::UNO_QUERY })
+ xChapterNumberingRules = xSupplier->getChapterNumberingRules();
uno::Reference<container::XNameContainer> xStyles;
if (uno::Reference<style::XStyleFamiliesSupplier> xStylesSupplier{ GetTextDocument(),
uno::UNO_QUERY })
@@ -6467,13 +6473,32 @@ void DomainMapper_Impl::handleToc
// Get the tab stops coming from the styles; store to the level definitions
uno::Sequence<style::TabStop> tabStops;
- if (xStyles)
+ if (xChapterNumberingRules && xStyles)
{
- OUString style;
- xTOC->getPropertyValue("ParaStyleLevel" + OUString::number(nLevel)) >>= style;
- uno::Reference<beans::XPropertySet> xStyle;
- if (xStyles->getByName(style) >>= xStyle)
- xStyle->getPropertyValue("ParaTabStops") >>= tabStops;
+ // This relies on the chapter numbering rules already defined
+ // (see ListDef::CreateNumberingRules)
+ uno::Sequence<beans::PropertyValue> props;
+ xChapterNumberingRules->getByIndex(nLevel - 1) >>= props;
+ bool bHasNumbering = false;
+ bool bUseTabStop = false;
+ for (const auto& propval : props)
+ {
+ // We rely on PositionAndSpaceMode being always equal to LABEL_ALIGNMENT,
+ // because ListDef::CreateNumberingRules doesn't create legacy lists
+ if (propval.Name == "NumberingType")
+ bHasNumbering = propval.Value != style::NumberingType::NUMBER_NONE;
+ else if (propval.Name == "LabelFollowedBy")
+ bUseTabStop = propval.Value == text::LabelFollow::LISTTAB;
+ // Do not use FirstLineIndent property from the rules, because it is unreliable
+ }
+ if (bHasNumbering && bUseTabStop)
+ {
+ 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(