[Libreoffice-commits] core.git: sw/qa writerfilter/source
László Németh (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 12 15:42:56 UTC 2020
sw/qa/extras/uiwriter/data2/tdf76817.docx |binary
sw/qa/extras/uiwriter/uiwriter2.cxx | 55 ++++++++++++++++++++++
writerfilter/source/dmapper/DomainMapper_Impl.cxx | 2
writerfilter/source/dmapper/NumberingManager.cxx | 5 ++
writerfilter/source/dmapper/NumberingManager.hxx | 5 ++
5 files changed, 66 insertions(+), 1 deletion(-)
New commits:
commit de1b634a151c198584dc152676183f519c50a2da
Author: László Németh <nemeth at numbertext.org>
AuthorDate: Fri Jun 12 13:14:51 2020 +0200
Commit: László Németh <nemeth at numbertext.org>
CommitDate: Fri Jun 12 17:42:18 2020 +0200
tdf#76817: DOCX import: fix custom chapter numbering
When one of the parents of the default Heading style
has got custom paragraph style instead of the
default Heading 1 – Heading 10, apply direct numbering
again to avoid bad or missing numbering.
Change-Id: I7e94600b5ac2cbf593a95eda6c0d6cd9d731dd75
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96199
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth at numbertext.org>
diff --git a/sw/qa/extras/uiwriter/data2/tdf76817.docx b/sw/qa/extras/uiwriter/data2/tdf76817.docx
new file mode 100644
index 000000000000..20478778a0d3
Binary files /dev/null and b/sw/qa/extras/uiwriter/data2/tdf76817.docx differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 27ed40c0d265..68470cecdc72 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1225,6 +1225,61 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf76817)
getProperty<OUString>(getParagraph(4), "ListLabelString"));
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf76817_custom_outline)
+{
+ load(DATA_DIRECTORY, "tdf76817.docx");
+
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+
+ CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
+ getProperty<OUString>(getParagraph(1), "ParaStyleName"));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
+ getProperty<sal_Int32>(getParagraph(1), "OutlineLevel"));
+ CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty<OUString>(getParagraph(1), "ListLabelString"));
+
+ CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
+ getProperty<OUString>(getParagraph(2), "ParaStyleName"));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
+ getProperty<sal_Int32>(getParagraph(2), "OutlineLevel"));
+ // This wasn't numbered
+ CPPUNIT_ASSERT_EQUAL(OUString("1.1"),
+ getProperty<OUString>(getParagraph(2), "ListLabelString"));
+
+ CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
+ getProperty<OUString>(getParagraph(4), "ParaStyleName"));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
+ getProperty<sal_Int32>(getParagraph(4), "OutlineLevel"));
+ // This wasn't numbered
+ CPPUNIT_ASSERT_EQUAL(OUString("2.1"),
+ getProperty<OUString>(getParagraph(4), "ListLabelString"));
+
+ // set Heading 2 style of paragraph 2 to Heading 1
+
+ SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->Down(/*bSelect=*/false);
+
+ uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence({
+ { "Style", uno::makeAny(OUString("Heading 1")) },
+ { "FamilyName", uno::makeAny(OUString("ParagraphStyles")) },
+ });
+ dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues);
+
+ CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
+ getProperty<OUString>(getParagraph(2), "ParaStyleName"));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
+ getProperty<sal_Int32>(getParagraph(2), "OutlineLevel"));
+ CPPUNIT_ASSERT_EQUAL(OUString("2"), getProperty<OUString>(getParagraph(2), "ListLabelString"));
+
+ CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"),
+ getProperty<OUString>(getParagraph(4), "ParaStyleName"));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
+ getProperty<sal_Int32>(getParagraph(4), "OutlineLevel"));
+ // This wasn't numbered
+ CPPUNIT_ASSERT_EQUAL(OUString("3.1"),
+ getProperty<OUString>(getParagraph(4), "ListLabelString"));
+}
+
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf123102)
{
createDoc("tdf123102.odt");
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index ba94dc430577..8cc1f7c02358 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1404,7 +1404,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
// Since LO7.0/tdf#131321 fixed the loss of numbering in styles, this OUGHT to be obsolete,
// but now other new/critical LO7.0 code expects it, and perhaps some corner cases still need it as well.
// So we skip it only for default outline styles, which are recognized by NumberingManager.
- if (!GetCurrentParaStyleName().startsWith("Heading "))
+ if (!GetCurrentParaStyleName().startsWith("Heading ") || nListLevel >= pList->GetDefaultParentLevels())
pParaContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny(pList->GetStyleName()), true );
}
else if ( !pList->isOutlineNumbering(nListLevel) )
diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx
index 8a17e6ead556..713313fbba74 100644
--- a/writerfilter/source/dmapper/NumberingManager.cxx
+++ b/writerfilter/source/dmapper/NumberingManager.cxx
@@ -400,6 +400,7 @@ const OUString& AbstractListDef::MapListId(OUString const& rId)
ListDef::ListDef( ) : AbstractListDef( )
{
+ m_nDefaultParentLevels = WW_OUTLINE_MAX + 1;
}
ListDef::~ListDef( )
@@ -572,6 +573,10 @@ void ListDef::CreateNumberingRules( DomainMapper& rDMapper,
xOutlineRules->replaceByIndex(nLevel, uno::makeAny(comphelper::containerToSequence(aLvlProps)));
}
+ // first level with custom pStyle
+ if ( WW_OUTLINE_MAX + 1 == m_nDefaultParentLevels && pAbsLevel->GetParaStyle( ) )
+ m_nDefaultParentLevels = nLevel;
+
nLevel++;
}
diff --git a/writerfilter/source/dmapper/NumberingManager.hxx b/writerfilter/source/dmapper/NumberingManager.hxx
index 070086daa52b..6173f1431f0e 100644
--- a/writerfilter/source/dmapper/NumberingManager.hxx
+++ b/writerfilter/source/dmapper/NumberingManager.hxx
@@ -180,6 +180,9 @@ private:
/// mapped list style name
OUString m_StyleName;
+ /// not custom outline parent levels
+ sal_Int16 m_nDefaultParentLevels;
+
public:
typedef tools::SvRef< ListDef > Pointer;
@@ -194,6 +197,8 @@ public:
OUString GetStyleName() const { return m_StyleName; };
OUString GetStyleName(sal_Int32 nId, css::uno::Reference<css::container::XNameContainer> const& xStyles);
+ sal_Int16 GetDefaultParentLevels() const { return m_nDefaultParentLevels; };
+
css::uno::Sequence< css::uno::Sequence<css::beans::PropertyValue> > GetMergedPropertyValues();
void CreateNumberingRules(DomainMapper& rDMapper, css::uno::Reference<css::lang::XMultiServiceFactory> const& xFactory);
More information about the Libreoffice-commits
mailing list