sw/qa/extras/ooxmlexport/data/tdf135973.odt |binary sw/qa/extras/ooxmlexport/ooxmlexport15.cxx | 21 +++ sw/source/filter/ww8/wrtw8num.cxx | 30 +---- sw/source/filter/ww8/wrtww8.hxx | 3 sw/source/filter/ww8/ww8atr.cxx | 158 +++++++++++++--------------- 5 files changed, 107 insertions(+), 105 deletions(-)
New commits: commit 2bc32e96df52e7f49b51881aa8f0dc97961c4f60 Author: Vasily Melenchuk <vasily.melenc...@cib.de> AuthorDate: Sun Aug 23 14:02:40 2020 +0300 Commit: Michael Stahl <michael.st...@cib.de> CommitDate: Thu Aug 27 12:58:53 2020 +0200 tdf#135973: DOCX export: improved list override support Removed remains of old override support which are not working now. Partial refactoring and fixing for listid and overrides detection. Change-Id: I1f94a09b7d51fcc3300b056d6d9e8ea6367a4446 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101238 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101438 Reviewed-by: Michael Stahl <michael.st...@cib.de> diff --git a/sw/qa/extras/ooxmlexport/data/tdf135973.odt b/sw/qa/extras/ooxmlexport/data/tdf135973.odt new file mode 100644 index 000000000000..0eb42080f9d6 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf135973.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx index dedad4d00eab..2942b74dd194 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -33,6 +33,27 @@ DECLARE_OOXMLEXPORT_TEST(testTdf133334_followPgStyle, "tdf133334_followPgStyle.o CPPUNIT_ASSERT_EQUAL(2, getPages()); } +DECLARE_OOXMLEXPORT_TEST(testTdf135973, "tdf135973.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + { + uno::Reference<beans::XPropertySet> xPara(getParagraph(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1."), getProperty<OUString>(xPara, "ListLabelString")); + } + { + uno::Reference<beans::XPropertySet> xPara(getParagraph(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2."), getProperty<OUString>(xPara, "ListLabelString")); + } + { + uno::Reference<beans::XPropertySet> xPara(getParagraph(5), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1."), getProperty<OUString>(xPara, "ListLabelString")); + } + { + uno::Reference<beans::XPropertySet> xPara(getParagraph(6), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2."), getProperty<OUString>(xPara, "ListLabelString")); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/wrtw8num.cxx b/sw/source/filter/ww8/wrtw8num.cxx index aef96bcd23cb..088f5d445996 100644 --- a/sw/source/filter/ww8/wrtw8num.cxx +++ b/sw/source/filter/ww8/wrtw8num.cxx @@ -91,22 +91,19 @@ sal_uInt16 MSWordExportBase::OverrideNumRule( OUString const& rListId, SwNumRule const& rAbstractRule) { - auto const numdef = GetNumberingId(rExistingRule); - auto const absnumdef = rListId == rAbstractRule.GetDefaultListId() + const sal_uInt16 numdef = GetNumberingId(rExistingRule); + + const sal_uInt16 absnumdef = rListId == rAbstractRule.GetDefaultListId() ? GetNumberingId(rAbstractRule) : DuplicateAbsNum(rListId, rAbstractRule); auto const mapping = std::make_pair(numdef, absnumdef); - auto it = m_OverridingNumsR.find(mapping); - if (it == m_OverridingNumsR.end()) - { - it = m_OverridingNumsR.insert(std::make_pair(mapping, m_pUsedNumTable->size())).first; - m_OverridingNums.insert(std::make_pair(m_pUsedNumTable->size(), mapping)); + auto it = m_OverridingNums.insert(std::make_pair(m_pUsedNumTable->size(), mapping)); - m_pUsedNumTable->push_back(nullptr); // dummy, it's unique_ptr... - ++m_nUniqueList; // counter for DuplicateNumRule... - } - return it->second; + m_pUsedNumTable->push_back(nullptr); // dummy, it's unique_ptr... + ++m_nUniqueList; // counter for DuplicateNumRule... + + return it.first->first; } void MSWordExportBase::AddListLevelOverride(sal_uInt16 nListId, @@ -148,17 +145,6 @@ sal_uInt16 MSWordExportBase::GetNumberingId( const SwNumRule& rNumRule ) SwNumRule* p = const_cast<SwNumRule*>(&rNumRule); sal_uInt16 nRet = static_cast<sal_uInt16>(m_pUsedNumTable->GetPos(p)); - // Is this list now duplicated into a new list which we should use - // #i77812# - perform 'deep' search in duplication map - std::map<sal_uInt16,sal_uInt16>::const_iterator aResult = m_aRuleDuplicates.end(); - do { - aResult = m_aRuleDuplicates.find(nRet); - if ( aResult != m_aRuleDuplicates.end() ) - { - nRet = (*aResult).second; - } - } while ( aResult != m_aRuleDuplicates.end() ); - return nRet; } diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index 3f64071e2120..9356b87bd86f 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -463,8 +463,6 @@ public: std::unique_ptr<SwNumRuleTable> m_pUsedNumTable; // all used NumRules /// overriding numdef index -> (existing numdef index, abstractnumdef index) std::map<size_t, std::pair<size_t, size_t>> m_OverridingNums; - /// same in reverse - std::map<std::pair<size_t, size_t>, size_t> m_OverridingNumsR; /// list-id -> abstractnumdef index std::map<OUString, size_t> m_Lists; @@ -473,7 +471,6 @@ public: std::map < size_t, std::map<size_t, size_t> > m_ListLevelOverrides; const SwTextNode *m_pTopNodeOfHdFtPage; ///< Top node of host page when in hd/ft - std::map< sal_uInt16, sal_uInt16 > m_aRuleDuplicates; //map to Duplicated numrules std::stack< sal_Int32 > m_aCurrentCharPropStarts; ///< To remember the position in a run. WW8_WrtBookmarks* m_pBkmks; WW8_WrtRedlineAuthor* m_pRedlAuthors; diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index 80efe524b472..0b2c6527c0ea 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -3576,110 +3576,108 @@ void WW8AttributeOutput::CharTwoLines( const SvxTwoLinesItem& rTwoLines ) void AttributeOutputBase::ParaNumRule( const SwNumRuleItem& rNumRule ) { const SwTextNode* pTextNd = nullptr; - sal_uInt16 nNumId; + if (rNumRule.GetValue().isEmpty()) + { + ParaNumRule_Impl(pTextNd, 0, 0); + return; + } + const SwNumRule* pRule = GetExport().m_pDoc->FindNumRulePtr( + rNumRule.GetValue() ); + if (!pRule) + return; + + sal_uInt16 nNumId = GetExport().GetNumberingId(*pRule) + 1; sal_uInt8 nLvl = 0; - if (!rNumRule.GetValue().isEmpty()) + + if (!GetExport().m_pOutFormatNode) { - const SwNumRule* pRule = GetExport().m_pDoc->FindNumRulePtr( - rNumRule.GetValue() ); - nNumId = pRule ? GetExport().GetNumberingId(*pRule) : USHRT_MAX; - if (USHRT_MAX != nNumId) - { - ++nNumId; - if ( GetExport().m_pOutFormatNode ) - { - if ( dynamic_cast< const SwContentNode *>( GetExport().m_pOutFormatNode ) != nullptr ) - { - pTextNd = static_cast<const SwTextNode*>(GetExport().m_pOutFormatNode); + ParaNumRule_Impl(pTextNd, nLvl, nNumId); + return; + } - if( pTextNd->IsCountedInList()) - { - int nLevel = pTextNd->GetActualListLevel(); + if ( dynamic_cast< const SwContentNode *>( GetExport().m_pOutFormatNode ) != nullptr ) + { + pTextNd = static_cast<const SwTextNode*>(GetExport().m_pOutFormatNode); - if (nLevel < 0) - nLevel = 0; + if( pTextNd->IsCountedInList()) + { + int nLevel = pTextNd->GetActualListLevel(); + + if (nLevel < 0) + nLevel = 0; - if (nLevel >= MAXLEVEL) - nLevel = MAXLEVEL - 1; + if (nLevel >= MAXLEVEL) + nLevel = MAXLEVEL - 1; - nLvl = static_cast< sal_uInt8 >(nLevel); + nLvl = static_cast< sal_uInt8 >(nLevel); - if (GetExport().GetExportFormat() == MSWordExportBase::DOCX) // FIXME + if (GetExport().GetExportFormat() == MSWordExportBase::DOCX) // FIXME + { + // tdf#95848 find the abstract list definition + OUString const listId(pTextNd->GetListId()); + if (!listId.isEmpty() + && (listId != pRule->GetDefaultListId() // default list id uses the 1:1 mapping + || pTextNd->IsListRestart()) // or restarting previous list + ) + { + SwList const*const pList( + GetExport().m_pDoc->getIDocumentListsAccess().getListByName(listId)); + if (pList) + { + SwNumRule const*const pAbstractRule( + GetExport().m_pDoc->FindNumRulePtr( + pList->GetDefaultListStyleName())); + assert(pAbstractRule); + if (pAbstractRule == pRule && !pTextNd->IsListRestart()) { - // tdf#95848 find the abstract list definition - OUString const listId(pTextNd->GetListId()); - if (!listId.isEmpty() - && (listId != pRule->GetDefaultListId() // default list id uses the 1:1 mapping - || pTextNd->IsListRestart()) // or restarting previous list - ) - { - SwList const*const pList( - GetExport().m_pDoc->getIDocumentListsAccess().getListByName(listId)); - if (pList) - { - SwNumRule const*const pAbstractRule( - GetExport().m_pDoc->FindNumRulePtr( - pList->GetDefaultListStyleName())); - assert(pAbstractRule); - if (pAbstractRule == pRule && !pTextNd->IsListRestart()) - { - // different list, but no override - nNumId = GetExport().DuplicateAbsNum(listId, *pAbstractRule); - } - else - { - nNumId = GetExport().OverrideNumRule( - *pRule, listId, *pAbstractRule); + // different list, but no override + nNumId = GetExport().DuplicateAbsNum(listId, *pAbstractRule) + 1; + } + else + { + nNumId = GetExport().OverrideNumRule( + *pRule, listId, *pAbstractRule) + 1; - if (pTextNd->IsListRestart()) - { - // For restarted lists we should also keep value for - // future w:lvlOverride / w:startOverride - GetExport().AddListLevelOverride(nNumId, pTextNd->GetActualListLevel(), - pTextNd->GetActualListStartValue()); - } - } - assert(nNumId != USHRT_MAX); - ++nNumId; - } + if (pTextNd->IsListRestart()) + { + // For restarted lists we should also keep value for + // future w:lvlOverride / w:startOverride + GetExport().AddListLevelOverride(nNumId-1, pTextNd->GetActualListLevel(), + pTextNd->GetActualListStartValue()); } } } - else - { - // #i44815# adjust numbering for numbered paragraphs - // without number (NO_NUMLEVEL). These paragraphs - // will receive a list id 0, which WW interprets as - // 'no number'. - nNumId = 0; - } - } - else if ( dynamic_cast< const SwTextFormatColl *>( GetExport().m_pOutFormatNode ) != nullptr ) - { - const SwTextFormatColl* pC = static_cast<const SwTextFormatColl*>(GetExport().m_pOutFormatNode); - if ( pC && pC->IsAssignedToListLevelOfOutlineStyle() ) - nLvl = static_cast< sal_uInt8 >( pC->GetAssignedOutlineStyleLevel() ); } } } else - nNumId = USHRT_MAX; + { + // #i44815# adjust numbering for numbered paragraphs + // without number (NO_NUMLEVEL). These paragraphs + // will receive a list id 0, which WW interprets as + // 'no number'. + nNumId = 0; + } } - else - nNumId = 0; - - if ( USHRT_MAX != nNumId ) + else if ( dynamic_cast< const SwTextFormatColl *>( GetExport().m_pOutFormatNode ) != nullptr ) { - if ( nLvl >= WW8ListManager::nMaxLevel ) - nLvl = WW8ListManager::nMaxLevel - 1; - - ParaNumRule_Impl( pTextNd, nLvl, nNumId ); + const SwTextFormatColl* pC = static_cast<const SwTextFormatColl*>(GetExport().m_pOutFormatNode); + if ( pC && pC->IsAssignedToListLevelOfOutlineStyle() ) + nLvl = static_cast< sal_uInt8 >( pC->GetAssignedOutlineStyleLevel() ); } + + if ( nLvl >= WW8ListManager::nMaxLevel ) + nLvl = WW8ListManager::nMaxLevel - 1; + + ParaNumRule_Impl( pTextNd, nLvl, nNumId); } void WW8AttributeOutput::ParaNumRule_Impl(const SwTextNode* /*pTextNd*/, sal_Int32 const nLvl, sal_Int32 const nNumId) { + if (USHRT_MAX == nNumId) + return; + // write sprmPIlvl and sprmPIlfo SwWW8Writer::InsUInt16( *m_rWW8Export.pO, NS_sprm::sprmPIlvl ); m_rWW8Export.pO->push_back( ::sal::static_int_cast<sal_uInt8>(nLvl) ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits