sw/qa/extras/ooxmlexport/ooxmlexport.cxx          |   15 +++-
 sw/qa/extras/uiwriter/data2/num-parent-style.docx |binary
 sw/qa/extras/uiwriter/uiwriter2.cxx               |   78 ++++++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   14 ++-
 4 files changed, 99 insertions(+), 8 deletions(-)

New commits:
commit 7ed62ccc2bc436001bbf033db22ec2f19c70fdf2
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Jun 12 11:11:16 2020 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jun 16 13:41:23 2020 +0200

    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_l...@sil.org>
    Change-Id: Ic1ba5070fa4c387ad527aec05234a4da90fab751
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96198
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 2128d59ab91da853652305390d56b3287bcb67b1)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96211
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

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
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<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 7476f7d1ee56..0fee7eb801aa 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) )
             {
@@ -1740,11 +1742,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())
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to