diff options
author | László Németh <nemeth@numbertext.org> | 2020-06-12 11:11:16 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-06-12 17:42:00 +0200 |
commit | 2128d59ab91da853652305390d56b3287bcb67b1 (patch) | |
tree | a770ca02c32e0eec92abe7b44aec2e73e498e275 | |
parent | a7b12e23bf9ac8e394405a1de5835e18e40c27c2 (diff) |
tdf#76817: DOCX import: fix chapter numbering
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 <justin_luth@sil.org>
Change-Id: Ic1ba5070fa4c387ad527aec05234a4da90fab751
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96198
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 15 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/data2/num-parent-style.docx | bin | 0 -> 14002 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 78 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 14 |
4 files changed, 99 insertions, 8 deletions
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<OUString>(getParagraph(4), "NumberingStyleName").startsWith("WWNum")); + 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(static_cast<sal_Int32>(2), + getProperty<sal_Int32>(getParagraph(2), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("1.1"), getProperty<OUString>(getParagraph(2), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), + getProperty<sal_Int32>(getParagraph(3), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("2"), getProperty<OUString>(getParagraph(3), "ListLabelString")); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), + getProperty<sal_Int32>(getParagraph(4), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("2.1"), getProperty<OUString>(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 Binary files differnew file mode 100644 index 000000000000..4b8c657afa3f --- /dev/null +++ b/sw/qa/extras/uiwriter/data2/num-parent-style.docx 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<OUString>(getParagraph(1), "ParaStyleName")); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf76817) +{ + load(DATA_DIRECTORY, "num-parent-style.docx"); + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + 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")); + 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")); + 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")); + // This was "1 Heading" instead of "2 Heading" + 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 was "2.1 Heading" + CPPUNIT_ASSERT_EQUAL(OUString("3.1"), + getProperty<OUString>(getParagraph(4), "ListLabelString")); + + // set Heading 1 style of paragraph 3 to Heading 2 + + pWrtShell->Down(/*bSelect=*/false); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"), + getProperty<OUString>(getParagraph(3), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), + getProperty<sal_Int32>(getParagraph(3), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("3"), getProperty<OUString>(getParagraph(3), "ListLabelString")); + + uno::Sequence<beans::PropertyValue> 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<OUString>(getParagraph(3), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), + getProperty<sal_Int32>(getParagraph(3), "OutlineLevel")); + CPPUNIT_ASSERT_EQUAL(OUString("2.1"), + getProperty<OUString>(getParagraph(3), "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")); + CPPUNIT_ASSERT_EQUAL(OUString("2.2"), + 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 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()) |