[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Mar 19 20:29:13 UTC 2020


 sw/qa/extras/ooxmlexport/data/arabic-zero3-numbering.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport14.cxx                |   13 ++++++
 sw/source/filter/ww8/docxattributeoutput.cxx              |   30 ++++++++++++--
 sw/source/filter/ww8/docxexport.cxx                       |    5 +-
 writerfilter/source/dmapper/ConversionHelper.cxx          |   12 +++++
 writerfilter/source/dmapper/ConversionHelper.hxx          |    1 
 writerfilter/source/dmapper/NumberingManager.cxx          |   25 ++++++++++-
 writerfilter/source/dmapper/NumberingManager.hxx          |    3 +
 8 files changed, 82 insertions(+), 7 deletions(-)

New commits:
commit 52ed1091be05d5a07a021403095c52f0f3986ed6
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Mar 19 17:54:26 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Mar 19 21:28:38 2020 +0100

    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.)
    
    Change-Id: If5fbcea4f163bd4d1a1ed820e15ceb61dc9c0519
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90761
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/data/arabic-zero3-numbering.docx b/sw/qa/extras/ooxmlexport/data/arabic-zero3-numbering.docx
new file mode 100644
index 000000000000..bd95186a6091
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/arabic-zero3-numbering.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 049218cc8ac8..0292587800c6 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -150,6 +150,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 636f12bf5deb..342c2a4d8557 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -6319,7 +6319,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;
 
@@ -6372,6 +6372,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:
@@ -6740,10 +6744,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 bdb39000533b..a74292d27e54 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -755,7 +755,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 0743bd45b891..39fc03606626 100644
--- a/writerfilter/source/dmapper/ConversionHelper.cxx
+++ b/writerfilter/source/dmapper/ConversionHelper.cxx
@@ -618,6 +618,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 cc474f3884a5..387c5d7786a8 100644
--- a/writerfilter/source/dmapper/ConversionHelper.hxx
+++ b/writerfilter/source/dmapper/ConversionHelper.hxx
@@ -52,6 +52,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 9c337708d255..3c927b828a2a 100644
--- a/writerfilter/source/dmapper/NumberingManager.cxx
+++ b/writerfilter/source/dmapper/NumberingManager.cxx
@@ -125,6 +125,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;
@@ -235,7 +237,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())
@@ -743,8 +753,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 8dec42778d28..40ff314d5145 100644
--- a/writerfilter/source/dmapper/NumberingManager.hxx
+++ b/writerfilter/source/dmapper/NumberingManager.hxx
@@ -44,6 +44,8 @@ class ListLevel : public PropertyMap
 {
     sal_Int32                                     m_nIStartAt;       //LN_CT_Lvl_start
     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;
@@ -67,6 +69,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; };
 


More information about the Libreoffice-commits mailing list