From 2128d59ab91da853652305390d56b3287bcb67b1 Mon Sep 17 00:00:00 2001 From: László Németh Date: Fri, 12 Jun 2020 11:11:16 +0200 Subject: tdf#76817: DOCX import: fix chapter numbering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Imported headings got also redundant custom direct numbering, resulting broken automatic chapter numbering: applying standard Heading styles on paragraphs using the associated toolbar menu, Manage Styles dialog window or Ctrl-1–Ctrl-4 shortcut keys, it didn't result continuous numbering. Co-authored-by: Justin Luth Change-Id: Ic1ba5070fa4c387ad527aec05234a4da90fab751 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96198 Tested-by: László Németh Reviewed-by: László Németh --- sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 15 ++++- sw/qa/extras/uiwriter/data2/num-parent-style.docx | Bin 0 -> 14002 bytes sw/qa/extras/uiwriter/uiwriter2.cxx | 78 ++++++++++++++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 14 ++-- 4 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 sw/qa/extras/uiwriter/data2/num-parent-style.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index ac4bf4cd2053..5ff581743ccd 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -771,9 +771,18 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testOOxmlOutlineNumberTypes, "outline-number DECLARE_OOXMLEXPORT_TEST(testNumParentStyle, "num-parent-style.docx") { -//reverting tdf#76817 hard-codes the numbering style on the paragraph, preventing RT of "Outline" style -//I think this unit test is wrong, but I will revert to its original claim. - CPPUNIT_ASSERT(getProperty(getParagraph(4), "NumberingStyleName").startsWith("WWNum")); + CPPUNIT_ASSERT_EQUAL(static_cast(1), + getProperty(getParagraph(1), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty(getParagraph(1), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(static_cast(2), + getProperty(getParagraph(2), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("1.1"), getProperty(getParagraph(2), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(static_cast(1), + getProperty(getParagraph(3), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("2"), getProperty(getParagraph(3), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(static_cast(2), + getProperty(getParagraph(4), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("2.1"), getProperty(getParagraph(4), "ListLabelString")); } DECLARE_OOXMLEXPORT_TEST(testNumOverrideLvltext, "num-override-lvltext.docx") diff --git a/sw/qa/extras/uiwriter/data2/num-parent-style.docx b/sw/qa/extras/uiwriter/data2/num-parent-style.docx new file mode 100644 index 000000000000..4b8c657afa3f Binary files /dev/null and b/sw/qa/extras/uiwriter/data2/num-parent-style.docx differ diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 99f573b139e6..27ed40c0d265 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -1147,6 +1147,84 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf105413) getProperty(getParagraph(1), "ParaStyleName")); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf76817) +{ + load(DATA_DIRECTORY, "num-parent-style.docx"); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"), + getProperty(getParagraph(2), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast(2), + getProperty(getParagraph(2), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("1.1"), + getProperty(getParagraph(2), "ListLabelString")); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"), + getProperty(getParagraph(4), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast(2), + getProperty(getParagraph(4), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("2.1"), + getProperty(getParagraph(4), "ListLabelString")); + + // set Heading 2 style of paragraph 2 to Heading 1 + + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Down(/*bSelect=*/false); + + uno::Sequence 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(getParagraph(2), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast(1), + getProperty(getParagraph(2), "OutlineLevel")); + // This was "1 Heading" instead of "2 Heading" + CPPUNIT_ASSERT_EQUAL(OUString("2"), getProperty(getParagraph(2), "ListLabelString")); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"), + getProperty(getParagraph(4), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast(2), + getProperty(getParagraph(4), "OutlineLevel")); + // This was "2.1 Heading" + CPPUNIT_ASSERT_EQUAL(OUString("3.1"), + getProperty(getParagraph(4), "ListLabelString")); + + // set Heading 1 style of paragraph 3 to Heading 2 + + pWrtShell->Down(/*bSelect=*/false); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"), + getProperty(getParagraph(3), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast(1), + getProperty(getParagraph(3), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("3"), getProperty(getParagraph(3), "ListLabelString")); + + uno::Sequence aPropertyValues2 = comphelper::InitPropertySequence({ + { "Style", uno::makeAny(OUString("Heading 2")) }, + { "FamilyName", uno::makeAny(OUString("ParagraphStyles")) }, + }); + dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues2); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"), + getProperty(getParagraph(3), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast(2), + getProperty(getParagraph(3), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("2.1"), + getProperty(getParagraph(3), "ListLabelString")); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 2"), + getProperty(getParagraph(4), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast(2), + getProperty(getParagraph(4), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("2.2"), + getProperty(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 557b09fa5917..ba94dc430577 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1403,7 +1403,9 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con isNumberingViaStyle = true; // 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. - pParaContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny(pList->GetStyleName()), true ); + // So we skip it only for default outline styles, which are recognized by NumberingManager. + if (!GetCurrentParaStyleName().startsWith("Heading ")) + pParaContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny(pList->GetStyleName()), true ); } else if ( !pList->isOutlineNumbering(nListLevel) ) { @@ -1758,11 +1760,13 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con { OUString paraId; m_xPreviousParagraph->getPropertyValue("ListId") >>= paraId; - assert(!paraId.isEmpty()); // must be on some list? - OUString const listId = pAbsList->MapListId(paraId); - if (listId != paraId) + if (!paraId.isEmpty()) // must be on some list? { - m_xPreviousParagraph->setPropertyValue("ListId", uno::makeAny(listId)); + OUString const listId = pAbsList->MapListId(paraId); + if (listId != paraId) + { + m_xPreviousParagraph->setPropertyValue("ListId", uno::makeAny(listId)); + } } } if (pList->GetCurrentLevel()) -- cgit