chart2/qa/extras/chart2export3.cxx                  |   21 +++++++++++++++++++
 chart2/qa/extras/data/pptx/tdf137691_dataTable.pptx |binary
 oox/inc/drawingml/chart/objectformatter.hxx         |    3 ++
 oox/source/drawingml/chart/datasourceconverter.cxx  |    5 ++++
 oox/source/drawingml/chart/objectformatter.cxx      |   22 ++++++++++++++++++++
 oox/source/token/properties.txt                     |    1 
 6 files changed, 52 insertions(+)

New commits:
commit 371a2245d61cc6f6a994bc2914fe73a5aaf08e18
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Jan 5 21:20:02 2024 -0500
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Jan 10 14:20:49 2024 +0100

    tdf#137691 chart2 import: provide NumberFormat to DataSeries
    
    make CppunitTest_chart2_export3 CPPUNIT_TEST_NAME=tdf137691
    
    This patch provides some very foundational support
    to importing a chart. It will open up a lot of doors
    to improve LinkToSource - since now the Source key is defined.
    
    Likely the source key should default to -1 instead of 0,
    so that LinkToSource can know whether or not the source is defined.
    
    /chart2/qa/extras/data/docx/testSeriesIdxOrder.docx
    is an example of where this patchset SHOULD have worked,
    but somehow it is losing its key during import...
    
    Unfortunately I have run out of time and can not follow
    these rabbit trails. Well, at least not until this change
    is considered a regression for some particular document...
    
    Change-Id: Ieddf2103002616aca2a408bde1f86d45c08dfc85
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161702
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161845
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/chart2/qa/extras/chart2export3.cxx 
b/chart2/qa/extras/chart2export3.cxx
index 59416198ce0f..70bcc8fdfb18 100644
--- a/chart2/qa/extras/chart2export3.cxx
+++ b/chart2/qa/extras/chart2export3.cxx
@@ -664,6 +664,27 @@ CPPUNIT_TEST_FIXTURE(Chart2ExportTest3, testTableOnPage3)
     CPPUNIT_ASSERT_EQUAL(OUString("If oversubscription relative to allowance 
holds steady at average oversubscription level B15-B17"), aColumnDesc[3]);
 }
 
+CPPUNIT_TEST_FIXTURE(Chart2ExportTest3, tdf137691)
+{
+    // given a doc where the banana negative data formats as ($123) and the 
pineapple data as $(123)
+    loadFromFile(u"pptx/tdf137691_dataTable.pptx");
+    // saveAndReload("Impress MS PowerPoint 2007 XML"); // Always exports as 
key 0 (General)
+
+    Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 
0), uno::UNO_QUERY);
+
+    Reference< chart2::data::XDataSequence > xDataSeq;
+    xDataSeq.set(getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0));
+    const sal_Int32 nKey_bananas = xDataSeq->getNumberFormatKeyByIndex(-1);
+    // This should not be General format (0), but a defined format (129)
+    CPPUNIT_ASSERT(nKey_bananas);
+
+    xDataSeq.set(getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1));
+    const sal_Int32 nKey_pineapples = xDataSeq->getNumberFormatKeyByIndex(-1);
+    // This should not be General format (0), but a defined format (130)
+    CPPUNIT_ASSERT(nKey_pineapples);
+    CPPUNIT_ASSERT(nKey_pineapples != nKey_bananas);
+}
+
 CPPUNIT_TEST_FIXTURE(Chart2ExportTest3, testMultipleAxisXLSX)
 {
     loadFromFile(u"ods/multiple_axis.ods");
diff --git a/chart2/qa/extras/data/pptx/tdf137691_dataTable.pptx 
b/chart2/qa/extras/data/pptx/tdf137691_dataTable.pptx
new file mode 100644
index 000000000000..edb465d729af
Binary files /dev/null and 
b/chart2/qa/extras/data/pptx/tdf137691_dataTable.pptx differ
diff --git a/oox/inc/drawingml/chart/objectformatter.hxx 
b/oox/inc/drawingml/chart/objectformatter.hxx
index 9498f0484d50..4ba0d51f4119 100644
--- a/oox/inc/drawingml/chart/objectformatter.hxx
+++ b/oox/inc/drawingml/chart/objectformatter.hxx
@@ -142,6 +142,9 @@ public:
     /** Returns true, if the passed shape properties have automatic fill mode. 
*/
     static bool         isAutomaticFill( const ModelRef< Shape >& rxShapeProp 
);
 
+    /** Returns the index lookup key given for this number formatting code **/
+    sal_Int32 getNumberFormatKey(const OUString& sNumberFormat);
+
 private:
     std::shared_ptr< ObjectFormatterData > mxData;
 };
diff --git a/oox/source/drawingml/chart/datasourceconverter.cxx 
b/oox/source/drawingml/chart/datasourceconverter.cxx
index 92cacb4286bf..c07ea397d537 100644
--- a/oox/source/drawingml/chart/datasourceconverter.cxx
+++ b/oox/source/drawingml/chart/datasourceconverter.cxx
@@ -78,6 +78,11 @@ Reference< XDataSequence > 
DataSequenceConverter::createDataSequence( const OUSt
     // set sequence role
     PropertySet aSeqProp( xDataSeq );
     aSeqProp.setProperty( PROP_Role, rRole );
+
+    const sal_Int32 nKey = 
getFormatter().getNumberFormatKey(mrModel.maFormatCode);
+    if (nKey >= 0)
+        aSeqProp.setProperty(PROP_NumberFormatKey, nKey);
+
     return xDataSeq;
 }
 
diff --git a/oox/source/drawingml/chart/objectformatter.cxx 
b/oox/source/drawingml/chart/objectformatter.cxx
index ff52053c97c9..2013ea461753 100644
--- a/oox/source/drawingml/chart/objectformatter.cxx
+++ b/oox/source/drawingml/chart/objectformatter.cxx
@@ -23,6 +23,7 @@
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
 #include <com/sun/star/util/XNumberFormatTypes.hpp>
+#include <comphelper/diagnose_ex.hxx>
 #include <osl/thread.h>
 #include <osl/diagnose.h>
 #include <rtl/strbuf.hxx>
@@ -1149,6 +1150,27 @@ bool ObjectFormatter::isAutomaticFill( const ModelRef< 
Shape >& rxShapeProp )
     return !rxShapeProp || 
!rxShapeProp->getFillProperties().moFillType.has_value();
 }
 
+sal_Int32 ObjectFormatter::getNumberFormatKey(const OUString& sNumberFormat)
+{
+    if (!mxData->mxNumFmts.is() || sNumberFormat.isEmpty())
+        return -1;
+
+    sal_Int32 nIndex = -1;
+    try
+    {
+        const bool bGeneral = sNumberFormat.equalsIgnoreAsciiCase("general");
+        nIndex = bGeneral ? 
mxData->mxNumTypes->getStandardIndex(mxData->maFromLocale)
+                          : mxData->mxNumFmts->addNewConverted(sNumberFormat, 
mxData->maEnUsLocale,
+                                                               
mxData->maFromLocale);
+    }
+    catch (Exception&)
+    {
+        DBG_UNHANDLED_EXCEPTION("oox.drawingml");
+    }
+
+    return nIndex;
+}
+
 } // namespace oox
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index b5a3478f45b0..b6fa29c090fe 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -364,6 +364,7 @@ NamedRanges
 NegativeError
 NullDate
 NumberFormat
+NumberFormatKey
 NumberingIsNumber
 NumberingLevel
 NumberingRules

Reply via email to