diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-03-05 15:57:33 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-03-05 18:41:19 +0100 |
commit | 5c7d0c5bafd244f1bfb3930e0229f1f3f2371c82 (patch) | |
tree | 5369b892fe1ba03136c4a49070ed06e289411000 /sw | |
parent | 7f049babd79ad14242dd346945c31a90607082ed (diff) |
sw padded numbering: add DOC footnote filter
Import side: remove the duplication between SwWW8ImplReader::CoreLoad()
and WW8ListManager::ReadLVL(). The CoreLoad() version did not support
reading 0x16 as it did a "& 0xf" on the value before parsing.
Export side: Writer supports footnote numbering type per-document, Word
supports it per-section. So next to the per-document export add a
per-section one, that's what Word actually reads. Similar code was there
already for DOCX.
Change-Id: Ic94e953cfee4514aabe507a8bcf75445bf05f401
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90023
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ww8export/ww8export3.cxx | 33 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8num.cxx | 5 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8sty.cxx | 8 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.hxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8atr.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.cxx | 18 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.hxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par3.cxx | 160 |
8 files changed, 160 insertions, 76 deletions
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx index 5900892cadf6..5f9b8e2eefc6 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -20,6 +20,7 @@ #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextTablesSupplier.hpp> #include <com/sun/star/text/WritingMode2.hpp> +#include <com/sun/star/text/XTextContentAppend.hpp> class Test : public SwModelTestBase { @@ -52,7 +53,7 @@ DECLARE_WW8EXPORT_TEST(testTdf37778_readonlySection, "tdf37778_readonlySection.d CPPUNIT_ASSERT(drawing::FillStyle_NONE != getProperty<drawing::FillStyle>(xStyle, "FillStyle")); } -DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.doc") +DECLARE_WW8EXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.doc") { auto xNumberingRules = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); @@ -65,6 +66,36 @@ DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.doc") aMap["NumberingType"].get<sal_uInt16>()); } +CPPUNIT_TEST_FIXTURE(SwModelTestBase, testArabicZeroNumberingFootnote) +{ + // Create a document, set footnote numbering type to ARABIC_ZERO. + loadURL("private:factory/swriter", nullptr); + uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xFootnoteSettings + = xFootnotesSupplier->getFootnoteSettings(); + sal_uInt16 nNumberingType = style::NumberingType::ARABIC_ZERO; + xFootnoteSettings->setPropertyValue("NumberingType", uno::makeAny(nNumberingType)); + + // Insert a footnote. + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextContent> xFootnote( + xFactory->createInstance("com.sun.star.text.Footnote"), uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextContentAppend> xTextContentAppend(xTextDocument->getText(), + uno::UNO_QUERY); + xTextContentAppend->appendTextContent(xFootnote, {}); + + reload("MS Word 97", ""); + xFootnotesSupplier.set(mxComponent, uno::UNO_QUERY); + sal_uInt16 nExpected = style::NumberingType::ARABIC_ZERO; + auto nActual = getProperty<sal_uInt16>(xFootnotesSupplier->getFootnoteSettings(), "NumberingType"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 64 + // - Actual : 4 + // i.e. the numbering type was ARABIC, not ARABIC_ZERO. + CPPUNIT_ASSERT_EQUAL(nExpected, nActual); +} + DECLARE_WW8EXPORT_TEST(testTdf122429_header, "tdf122429_header.doc") { uno::Reference<container::XNameAccess> pageStyles = getStyles("PageStyles"); diff --git a/sw/source/filter/ww8/wrtw8num.cxx b/sw/source/filter/ww8/wrtw8num.cxx index 49e2eb8f4bc5..17ba17f35888 100644 --- a/sw/source/filter/ww8/wrtw8num.cxx +++ b/sw/source/filter/ww8/wrtw8num.cxx @@ -248,6 +248,11 @@ void MSWordExportBase::NumberingDefinitions() } } +/** + * Converts the SVX numbering type to MSONFC. + * + * This is used for paragraph numbering purposes. + */ static sal_uInt8 GetLevelNFC( sal_uInt16 eNumType, const SfxItemSet *pOutSet) { sal_uInt8 nRet = 0; diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 9b1bcf33026b..9725eac43ae9 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -1329,6 +1329,7 @@ void WW8AttributeOutput::StartSection() void WW8AttributeOutput::SectFootnoteEndnotePr() { const SwFootnoteInfo& rInfo = m_rWW8Export.m_pDoc->GetFootnoteInfo(); + const SwEndNoteInfo& rEndNoteInfo = m_rWW8Export.m_pDoc->GetEndNoteInfo(); m_rWW8Export.InsUInt16( NS_sprm::sprmSRncFtn ); switch( rInfo.m_eNum ) { @@ -1336,6 +1337,13 @@ void WW8AttributeOutput::SectFootnoteEndnotePr() case FTNNUM_CHAPTER: m_rWW8Export.pO->push_back( sal_uInt8/*rncRstSect*/ (1) ); break; default: m_rWW8Export.pO->push_back( sal_uInt8/*rncCont*/ (0) ); break; } + + m_rWW8Export.InsUInt16(NS_sprm::sprmSNfcFtnRef); + sal_uInt8 nId = WW8Export::GetNumId(rInfo.m_aFormat.GetNumberingType()); + SwWW8Writer::InsUInt16(*m_rWW8Export.pO, nId); + m_rWW8Export.InsUInt16(NS_sprm::sprmSNfcEdnRef); + nId = WW8Export::GetNumId(rEndNoteInfo.m_aFormat.GetNumberingType()); + SwWW8Writer::InsUInt16(*m_rWW8Export.pO, nId); } void WW8AttributeOutput::SectionFormProtection( bool bProtected ) diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index ef34318a3ec3..9e302b6cc9e8 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -1136,7 +1136,11 @@ public: void SetHdFtIndex(unsigned int nHdFtIndex) { m_nHdFtIndex = nHdFtIndex; } void IncrementHdFtIndex() { ++m_nHdFtIndex; } - /// Convert the SVX numbering type to id + /** + * Converts the SVX numbering type to MSONFC. + * + * This is used for section, footnote and endnote numbering purposes. + */ static sal_uInt8 GetNumId( sal_uInt16 eNumType ); /// Guess the script (asian/western). diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index f1d1222fcf64..f0e14722cffe 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -730,6 +730,10 @@ sal_uInt8 WW8Export::GetNumId( sal_uInt16 eNumType ) // nothing, WW does the same (undocumented) case SVX_NUM_NUMBER_NONE: nRet = 0xff; break; + case SVX_NUM_ARABIC_ZERO: + // 0x16, msonfcArabicLZ + nRet = 22; + break; } return nRet; } diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index e7275d0486dc..9f930a949dde 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -5127,16 +5127,6 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const *pGloss) m_xSBase.reset(new WW8ScannerBase(m_pStrm,m_pTableStream,m_pDataStream, m_xWwFib.get())); - static const SvxNumType eNumTA[16] = - { - SVX_NUM_ARABIC, SVX_NUM_ROMAN_UPPER, SVX_NUM_ROMAN_LOWER, - SVX_NUM_CHARS_UPPER_LETTER_N, SVX_NUM_CHARS_LOWER_LETTER_N, - SVX_NUM_ARABIC, SVX_NUM_ARABIC, SVX_NUM_ARABIC, - SVX_NUM_ARABIC, SVX_NUM_ARABIC, SVX_NUM_ARABIC, - SVX_NUM_ARABIC, SVX_NUM_ARABIC, SVX_NUM_ARABIC, - SVX_NUM_ARABIC, SVX_NUM_ARABIC - }; - if (m_xSBase->AreThereFootnotes()) { static const SwFootnoteNum eNumA[4] = @@ -5148,8 +5138,8 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const *pGloss) aInfo.m_ePos = FTNPOS_PAGE; aInfo.m_eNum = eNumA[m_xWDop->rncFootnote]; - sal_uInt16 nfcFootnoteRef = m_xWDop->nfcFootnoteRef & 0xF; - aInfo.m_aFormat.SetNumberingType( eNumTA[nfcFootnoteRef] ); + sal_uInt16 nfcFootnoteRef = m_xWDop->nfcFootnoteRef; + aInfo.m_aFormat.SetNumberingType(WW8ListManager::GetSvxNumTypeFromMSONFC(nfcFootnoteRef)); if( m_xWDop->nFootnote ) aInfo.m_nFootnoteOffset = m_xWDop->nFootnote - 1; m_rDoc.SetFootnoteInfo( aInfo ); @@ -5157,8 +5147,8 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const *pGloss) if (m_xSBase->AreThereEndnotes()) { SwEndNoteInfo aInfo = m_rDoc.GetEndNoteInfo(); // Same as for Footnote - sal_uInt16 nfcEdnRef = m_xWDop->nfcEdnRef & 0xF; - aInfo.m_aFormat.SetNumberingType( eNumTA[nfcEdnRef] ); + sal_uInt16 nfcEdnRef = m_xWDop->nfcEdnRef; + aInfo.m_aFormat.SetNumberingType(WW8ListManager::GetSvxNumTypeFromMSONFC(nfcEdnRef)); if( m_xWDop->nEdn ) aInfo.m_nFootnoteOffset = m_xWDop->nEdn - 1; m_rDoc.SetEndNoteInfo( aInfo ); diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx index e7d8384f8091..bc047d6f7751 100644 --- a/sw/source/filter/ww8/ww8par.hxx +++ b/sw/source/filter/ww8/ww8par.hxx @@ -157,6 +157,8 @@ public: ~WW8ListManager() COVERITY_NOEXCEPT_FALSE; SwNumRule* GetNumRule(size_t i); size_t GetWW8LSTInfoNum() const{return maLSTInfos.size();} + static SvxNumType GetSvxNumTypeFromMSONFC(sal_uInt16 nMSONFC); + private: wwSprmParser const maSprmParser; SwWW8ImplReader& rReader; diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx index 118764b4d73d..1e1a5341b67a 100644 --- a/sw/source/filter/ww8/ww8par3.cxx +++ b/sw/source/filter/ww8/ww8par3.cxx @@ -527,6 +527,102 @@ static OUString sanitizeString(const OUString& rString) return rString; } +SvxNumType WW8ListManager::GetSvxNumTypeFromMSONFC(sal_uInt16 nNFC) +{ + SvxNumType nType(SVX_NUM_ARABIC); + + switch (nNFC) + { + case 0: + nType = SVX_NUM_ARABIC; + break; + case 1: + nType = SVX_NUM_ROMAN_UPPER; + break; + case 2: + nType = SVX_NUM_ROMAN_LOWER; + break; + case 3: + nType = SVX_NUM_CHARS_UPPER_LETTER_N; + break; + case 4: + nType = SVX_NUM_CHARS_LOWER_LETTER_N; + break; + case 5: + // actually: ORDINAL + nType = SVX_NUM_ARABIC; + break; + case 22: + // 0x16, msonfcArabicLZ + nType = SVX_NUM_ARABIC_ZERO; + break; + case 23: + nType = SVX_NUM_CHAR_SPECIAL; + + break; + case 255: + nType = SVX_NUM_NUMBER_NONE; + break; + case 14: + case 19: + nType = SVX_NUM_FULL_WIDTH_ARABIC; + break; + case 30: + nType = SVX_NUM_TIAN_GAN_ZH; + break; + case 31: + nType = SVX_NUM_DI_ZI_ZH; + break; + case 35: + case 36: + case 37: + case 11: + case 39: + nType = SVX_NUM_NUMBER_LOWER_ZH; + break; + case 34: + nType = SVX_NUM_NUMBER_UPPER_ZH_TW; + break; + case 38: + nType = SVX_NUM_NUMBER_UPPER_ZH; + break; + case 10: + nType = SVX_NUM_NUMBER_TRADITIONAL_JA; + break; + case 20: + nType = SVX_NUM_AIU_FULLWIDTH_JA; + break; + case 12: + nType = SVX_NUM_AIU_HALFWIDTH_JA; + break; + case 21: + nType = SVX_NUM_IROHA_FULLWIDTH_JA; + break; + case 13: + nType = SVX_NUM_IROHA_HALFWIDTH_JA; + break; + case 24: + nType = SVX_NUM_HANGUL_SYLLABLE_KO; + break; + case 25: + nType = SVX_NUM_HANGUL_JAMO_KO; + break; + case 41: + nType = SVX_NUM_NUMBER_HANGUL_KO; + break; + //case 42: + //case 43: + case 44: + nType = SVX_NUM_NUMBER_UPPER_KO; + break; + default: + nType = SVX_NUM_ARABIC; + break; + } + + return nType; +} + bool WW8ListManager::ReadLVL(SwNumFormat& rNumFormat, std::unique_ptr<SfxItemSet>& rpItemSet, sal_uInt16 nLevelStyle, bool bSetStartNo, std::deque<bool> &rNotReallyThere, sal_uInt16 nLevel, @@ -742,67 +838,11 @@ bool WW8ListManager::ReadLVL(SwNumFormat& rNumFormat, std::unique_ptr<SfxItemSet if( 0 <= aLVL.nStartAt ) nStartNo = static_cast<sal_uInt16>(aLVL.nStartAt); - switch( aLVL.nNFC ) + nType = GetSvxNumTypeFromMSONFC(aLVL.nNFC); + //For i120928,type info + if (bIsPicBullet) { - case 0: - nType = SVX_NUM_ARABIC; - break; - case 1: - nType = SVX_NUM_ROMAN_UPPER; - break; - case 2: - nType = SVX_NUM_ROMAN_LOWER; - break; - case 3: - nType = SVX_NUM_CHARS_UPPER_LETTER_N; - break; - case 4: - nType = SVX_NUM_CHARS_LOWER_LETTER_N; - break; - case 5: - // actually: ORDINAL - nType = SVX_NUM_ARABIC; - break; - case 22: - // 0x16, msonfcArabicLZ - nType = SVX_NUM_ARABIC_ZERO; - break; - case 23: - nType = SVX_NUM_CHAR_SPECIAL; - //For i120928,type info - if (bIsPicBullet) - { - nType = SVX_NUM_BITMAP; - } - - break; - case 255: - nType = SVX_NUM_NUMBER_NONE; - break; - case 14: - case 19:nType = SVX_NUM_FULL_WIDTH_ARABIC; break; - case 30:nType = SVX_NUM_TIAN_GAN_ZH; break; - case 31:nType = SVX_NUM_DI_ZI_ZH; break; - case 35: - case 36: - case 37: - case 11: - case 39:nType = SVX_NUM_NUMBER_LOWER_ZH; break; - case 34:nType = SVX_NUM_NUMBER_UPPER_ZH_TW; break; - case 38:nType = SVX_NUM_NUMBER_UPPER_ZH; break; - case 10:nType = SVX_NUM_NUMBER_TRADITIONAL_JA; break; - case 20:nType = SVX_NUM_AIU_FULLWIDTH_JA; break; - case 12:nType = SVX_NUM_AIU_HALFWIDTH_JA; break; - case 21:nType = SVX_NUM_IROHA_FULLWIDTH_JA; break; - case 13:nType = SVX_NUM_IROHA_HALFWIDTH_JA; break; - case 24:nType = SVX_NUM_HANGUL_SYLLABLE_KO; break; - case 25:nType = SVX_NUM_HANGUL_JAMO_KO; break; - case 41:nType = SVX_NUM_NUMBER_HANGUL_KO; break; - //case 42: - //case 43: - case 44:nType = SVX_NUM_NUMBER_UPPER_KO; break; - default: - nType= SVX_NUM_ARABIC; break; + nType = SVX_NUM_BITMAP; } //If a number level is not going to be used, then record this fact |