diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-03-19 17:54:26 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-05-19 11:30:10 +0200 |
commit | c62f573b3ecb89cc842ea88b61e99863a33d4212 (patch) | |
tree | 054345af8a95443acee799e8ee58fe993068e3b9 | |
parent | 0acdc84c5053dc32c0f65ec416f3f21502537496 (diff) |
sw pad-to-3 numbering: add DOCX filter
There is no NS_ooxml::LN_Value_ST_NumberFormat_foo code for this on the
import side, rather the number format code is set to
NS_ooxml::LN_Value_ST_NumberFormat_custom, then a separate
NS_ooxml::LN_CT_NumFmt_format contains the number format string.
Declare w14 as an XML namespace on the export side, even if we write no
<w14:something> elements. This is needed by <mc:Choice Requires="w14">,
which refers to an XML namespace in the OOXML markup. (Interestingly
officeotron doesn't check for this, though.)
(cherry picked from commit 52ed1091be05d5a07a021403095c52f0f3986ed6)
Change-Id: If5fbcea4f163bd4d1a1ed820e15ceb61dc9c0519
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/arabic-zero3-numbering.docx | bin | 0 -> 5934 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 13 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 30 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/dmapper/ConversionHelper.cxx | 12 | ||||
-rw-r--r-- | writerfilter/source/dmapper/ConversionHelper.hxx | 1 | ||||
-rw-r--r-- | writerfilter/source/dmapper/NumberingManager.cxx | 25 | ||||
-rw-r--r-- | writerfilter/source/dmapper/NumberingManager.hxx | 3 |
8 files changed, 82 insertions, 7 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/arabic-zero3-numbering.docx b/sw/qa/extras/ooxmlexport/data/arabic-zero3-numbering.docx Binary files differnew file mode 100644 index 000000000000..bd95186a6091 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/arabic-zero3-numbering.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 71e17ec25964..379ae540bb46 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -121,6 +121,19 @@ DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.docx") aMap["NumberingType"].get<sal_uInt16>()); } +DECLARE_ODFEXPORT_TEST(testArabicZero3Numbering, "arabic-zero3-numbering.docx") +{ + auto xNumberingRules + = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); + comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 65 + // - Actual : 4 + // i.e. numbering type was ARABIC, not ARABIC_ZERO3. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO3), + aMap["NumberingType"].get<sal_uInt16>()); +} + CPPUNIT_TEST_FIXTURE(Test, testArabicZeroNumberingFootnote) { // Create a document, set footnote numbering type to ARABIC_ZERO. diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index c4f01bbcb804..fafd5c5d189b 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -6321,7 +6321,7 @@ static OString impl_NumberingType( sal_uInt16 nNumberingType ) } // Converting Level Numbering Format Code to string -static OString impl_LevelNFC( sal_uInt16 nNumberingType , const SfxItemSet *pOutSet) +static OString impl_LevelNFC(sal_uInt16 nNumberingType, const SfxItemSet* pOutSet, OString& rFormat) { OString aType; @@ -6374,6 +6374,10 @@ static OString impl_LevelNFC( sal_uInt16 nNumberingType , const SfxItemSet *pOut case style::NumberingType::TEXT_ORDINAL: aType="ordinalText"; break; case style::NumberingType::SYMBOL_CHICAGO: aType="chicago"; break; case style::NumberingType::ARABIC_ZERO: aType = "decimalZero"; break; + case style::NumberingType::ARABIC_ZERO3: + aType = "custom"; + rFormat = "001, 002, 003, ..."; + break; /* Fallback the rest to decimal. case style::NumberingType::NATIVE_NUMBERING: @@ -6787,10 +6791,30 @@ void DocxAttributeOutput::NumberingLevel( sal_uInt8 nLevel, FSNS( XML_w, XML_val ), m_rExport.m_pStyles->GetStyleId(nId) ); } // format - OString aFormat( impl_LevelNFC( nNumberingType ,pOutSet) ); + OString aCustomFormat; + OString aFormat(impl_LevelNFC(nNumberingType, pOutSet, aCustomFormat)); if ( !aFormat.isEmpty() ) - m_pSerializer->singleElementNS(XML_w, XML_numFmt, FSNS(XML_w, XML_val), aFormat); + { + if (aCustomFormat.isEmpty()) + { + m_pSerializer->singleElementNS(XML_w, XML_numFmt, FSNS(XML_w, XML_val), aFormat); + } + else + { + m_pSerializer->startElementNS(XML_mc, XML_AlternateContent); + m_pSerializer->startElementNS(XML_mc, XML_Choice, XML_Requires, "w14"); + + m_pSerializer->singleElementNS(XML_w, XML_numFmt, FSNS(XML_w, XML_val), aFormat, + FSNS(XML_w, XML_format), aCustomFormat); + + m_pSerializer->endElementNS(XML_mc, XML_Choice); + m_pSerializer->startElementNS(XML_mc, XML_Fallback); + m_pSerializer->singleElementNS(XML_w, XML_numFmt, FSNS(XML_w, XML_val), "decimal"); + m_pSerializer->endElementNS(XML_mc, XML_Fallback); + m_pSerializer->endElementNS(XML_mc, XML_AlternateContent); + } + } // suffix const char *pSuffix = nullptr; diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index b0f1ccf51627..a46b3eb779a2 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -762,7 +762,10 @@ void DocxExport::WriteNumbering() FSNS( XML_xmlns, XML_w ), m_pFilter->getNamespaceURL(OOX_NS(doc)).toUtf8(), FSNS( XML_xmlns, XML_o ), m_pFilter->getNamespaceURL(OOX_NS(vmlOffice)).toUtf8(), FSNS( XML_xmlns, XML_r ), m_pFilter->getNamespaceURL(OOX_NS(officeRel)).toUtf8(), - FSNS( XML_xmlns, XML_v ), m_pFilter->getNamespaceURL(OOX_NS(vml)).toUtf8() ); + FSNS( XML_xmlns, XML_v ), m_pFilter->getNamespaceURL(OOX_NS(vml)).toUtf8(), + FSNS( XML_xmlns, XML_mc ), m_pFilter->getNamespaceURL(OOX_NS(mce)).toUtf8(), + FSNS( XML_xmlns, XML_w14 ), m_pFilter->getNamespaceURL(OOX_NS(w14)).toUtf8(), + FSNS( XML_mc, XML_Ignorable ), "w14" ); BulletDefinitions(); diff --git a/writerfilter/source/dmapper/ConversionHelper.cxx b/writerfilter/source/dmapper/ConversionHelper.cxx index 81d0dce54fa9..d8ca06e5ed34 100644 --- a/writerfilter/source/dmapper/ConversionHelper.cxx +++ b/writerfilter/source/dmapper/ConversionHelper.cxx @@ -614,6 +614,18 @@ sal_Int16 ConvertNumberingType(sal_Int32 nFmt) return nRet; } +sal_Int16 ConvertCustomNumberFormat(const OUString& rFormat) +{ + sal_Int16 nRet = -1; + + if (rFormat == "001, 002, 003, ...") + { + nRet = style::NumberingType::ARABIC_ZERO3; + } + + return nRet; +} + util::DateTime ConvertDateStringToDateTime( const OUString& rDateTime ) { util::DateTime aDateTime; diff --git a/writerfilter/source/dmapper/ConversionHelper.hxx b/writerfilter/source/dmapper/ConversionHelper.hxx index 25ca7f8b8ce9..fd7a85870d2b 100644 --- a/writerfilter/source/dmapper/ConversionHelper.hxx +++ b/writerfilter/source/dmapper/ConversionHelper.hxx @@ -51,6 +51,7 @@ namespace ConversionHelper{ sal_Int16 convertTableJustification( sal_Int32 nIntValue ); css::text::RubyAdjust convertRubyAlign( sal_Int32 nIntValue ); sal_Int16 ConvertNumberingType(sal_Int32 nFmt); + sal_Int16 ConvertCustomNumberFormat(const OUString& rFormat); css::util::DateTime ConvertDateStringToDateTime(const OUString& rDateTime); } // namespace ConversionHelper diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx index e3feb55ee2ef..5a74e421a31b 100644 --- a/writerfilter/source/dmapper/NumberingManager.cxx +++ b/writerfilter/source/dmapper/NumberingManager.cxx @@ -130,6 +130,8 @@ void ListLevel::SetValue( Id nId, sal_Int32 nValue ) m_bHasValues = true; } +void ListLevel::SetCustomNumberFormat(const OUString& rValue) { m_aCustomNumberFormat = rValue; } + bool ListLevel::HasValues() const { return m_bHasValues; @@ -190,7 +192,15 @@ uno::Sequence<beans::PropertyValue> ListLevel::GetLevelProperties(bool bDefaults if( m_nIStartAt >= 0) aNumberingProperties.push_back(lcl_makePropVal<sal_Int16>(PROP_START_WITH, m_nIStartAt) ); - sal_Int16 nNumberFormat = ConversionHelper::ConvertNumberingType(m_nNFC); + sal_Int16 nNumberFormat = -1; + if (m_nNFC == NS_ooxml::LN_Value_ST_NumberFormat_custom) + { + nNumberFormat = ConversionHelper::ConvertCustomNumberFormat(m_aCustomNumberFormat); + } + else + { + nNumberFormat = ConversionHelper::ConvertNumberingType(m_nNFC); + } if( m_nNFC >= 0) { if (m_xGraphicBitmap.is()) @@ -692,8 +702,17 @@ void ListsManager::lcl_attribute( Id nName, Value& rVal ) case NS_ooxml::LN_CT_Lvl_isLgl: case NS_ooxml::LN_CT_Lvl_legacy: if ( pCurrentLvl.get( ) ) - pCurrentLvl->SetValue( nName, sal_Int32( nIntValue ) ); - break; + { + if (nName == NS_ooxml::LN_CT_NumFmt_format) + { + pCurrentLvl->SetCustomNumberFormat(rVal.getString()); + } + else + { + pCurrentLvl->SetValue(nName, sal_Int32(nIntValue)); + } + } + break; case NS_ooxml::LN_CT_Num_numId: m_pCurrentDefinition->SetId( rVal.getString().toInt32( ) ); break; diff --git a/writerfilter/source/dmapper/NumberingManager.hxx b/writerfilter/source/dmapper/NumberingManager.hxx index 3949c3bf7dcd..88ce887869a1 100644 --- a/writerfilter/source/dmapper/NumberingManager.hxx +++ b/writerfilter/source/dmapper/NumberingManager.hxx @@ -45,6 +45,8 @@ class ListLevel : public PropertyMap sal_Int32 m_nIStartAt; //LN_CT_Lvl_start sal_Int32 m_nStartOverride; sal_Int32 m_nNFC; //LN_CT_Lvl_numFmt + /// LN_CT_NumFmt_format, in case m_nNFC is custom. + OUString m_aCustomNumberFormat; sal_Int16 m_nXChFollow; //LN_IXCHFOLLOW OUString m_sBulletChar; css::awt::Size m_aGraphicSize; @@ -69,6 +71,7 @@ public: // Setters for the import void SetValue( Id nId, sal_Int32 nValue ); + void SetCustomNumberFormat(const OUString& rValue); void SetBulletChar( const OUString& sValue ) { m_sBulletChar = sValue; }; void SetGraphicSize( const css::awt::Size& aValue ) { m_aGraphicSize = aValue; }; |