[Libreoffice-commits] core.git: chart2/qa include/oox oox/source

Balazs Varga (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 21 08:11:21 UTC 2019


 chart2/qa/extras/chart2export.cxx                       |   33 ++++++++++++++++
 chart2/qa/extras/data/ods/testChartMainWithSubTitle.ods |binary
 chart2/qa/extras/data/ods/testChartSubTitle.ods         |binary
 include/oox/export/chartexport.hxx                      |    4 -
 oox/source/export/chartexport.cxx                       |   33 ++++++++++++----
 5 files changed, 60 insertions(+), 10 deletions(-)

New commits:
commit 96a29c12a9d8734c9d2a812f38fc6654b5df9c48
Author:     Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Thu Aug 15 11:25:02 2019 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Wed Aug 21 10:10:08 2019 +0200

    tdf#101322 Chart OOXML Export: fix missing subtitle
    
    Concatenate subtitle and main title texts, if both exist, just like
    at the XLS/DOC export, because OOXML does not support subtitles.
    If we only have a subtitle, export the whole subtitle shape instead of
    the title shape, keeping its properties.
    
    Change-Id: If6a27c023fcce58f4549a0edad44027bb0348b93
    Reviewed-on: https://gerrit.libreoffice.org/77499
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Tested-by: László Németh <nemeth at numbertext.org>

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index ab932ac2bc68..78a763ee7bb6 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -103,6 +103,8 @@ public:
     void testTitleManualLayoutXLSX();
     void testPlotAreaManualLayoutXLSX();
     void testLegendManualLayoutXLSX();
+    void testChartSubTitle();
+    void testChartMainWithSubTitle();
     void testChartTitlePropertiesColorFillXLSX();
     void testChartTitlePropertiesGradientFillXLSX();
     void testChartTitlePropertiesBitmapFillXLSX();
@@ -203,6 +205,8 @@ public:
     CPPUNIT_TEST(testTitleManualLayoutXLSX);
     CPPUNIT_TEST(testPlotAreaManualLayoutXLSX);
     CPPUNIT_TEST(testLegendManualLayoutXLSX);
+    CPPUNIT_TEST(testChartSubTitle);
+    CPPUNIT_TEST(testChartMainWithSubTitle);
     CPPUNIT_TEST(testChartTitlePropertiesColorFillXLSX);
     CPPUNIT_TEST(testChartTitlePropertiesGradientFillXLSX);
     CPPUNIT_TEST(testChartTitlePropertiesBitmapFillXLSX);
@@ -1645,6 +1649,35 @@ void Chart2ExportTest::testLegendManualLayoutXLSX()
     assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:legend/c:txPr/a:p/a:pPr/a:defRPr", "sz", "900");
 }
 
+void Chart2ExportTest::testChartSubTitle()
+{
+    load("/chart2/qa/extras/data/ods/", "testChartSubTitle.ods");
+    xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
+    CPPUNIT_ASSERT(pXmlDoc);
+    // test properties of subtitle
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr", "sz", "1100");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr", "b", "1");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr/a:solidFill/a:srgbClr", "val", "00a933");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:rPr/a:latin", "typeface", "Times New Roman");
+    assertXPathContent(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:t", "It is a Subtitle");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:spPr/a:solidFill/a:srgbClr", "val", "b2b2b2");
+}
+
+void Chart2ExportTest::testChartMainWithSubTitle()
+{
+    load("/chart2/qa/extras/data/ods/", "testChartMainWithSubTitle.ods");
+    xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
+    CPPUNIT_ASSERT(pXmlDoc);
+    // test properties of title
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr", "sz", "1300");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr", "b", "0");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr", "i", "1");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr/a:solidFill/a:srgbClr", "val", "f10d0c");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:rPr/a:latin", "typeface", "Arial");
+    assertXPathContent(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:t", "It is a Maintitle\nIt is a Subtitle");
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:spPr/a:solidFill/a:srgbClr", "val", "81d41a");
+}
+
 void Chart2ExportTest::testChartTitlePropertiesColorFillXLSX()
 {
     load("/chart2/qa/extras/data/xlsx/", "testChartTitlePropertiesColorFill.xlsx");
diff --git a/chart2/qa/extras/data/ods/testChartMainWithSubTitle.ods b/chart2/qa/extras/data/ods/testChartMainWithSubTitle.ods
new file mode 100644
index 000000000000..5ae4fa7d99a7
Binary files /dev/null and b/chart2/qa/extras/data/ods/testChartMainWithSubTitle.ods differ
diff --git a/chart2/qa/extras/data/ods/testChartSubTitle.ods b/chart2/qa/extras/data/ods/testChartSubTitle.ods
new file mode 100644
index 000000000000..1c7814195d17
Binary files /dev/null and b/chart2/qa/extras/data/ods/testChartSubTitle.ods differ
diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx
index 584b448aed2c..a07a624d2b97 100644
--- a/include/oox/export/chartexport.hxx
+++ b/include/oox/export/chartexport.hxx
@@ -136,8 +136,8 @@ private:
                               css::chart::XChartDocument >& rChartDoc );
     void exportLegend( const css::uno::Reference<
                           css::chart::XChartDocument >& rChartDoc );
-    void exportTitle( const css::uno::Reference<
-                          css::drawing::XShape >& xShape );
+    void exportTitle( const css::uno::Reference< css::drawing::XShape >& xShape,
+                          const OUString* pSubText = nullptr );
     void exportPlotArea( const css::uno::Reference<
                              css::chart::XChartDocument >& rChartDoc );
     void exportFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 98d8724fe830..925afd0af96b 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -874,13 +874,13 @@ void ChartExport::exportChart( const Reference< css::chart::XChartDocument >& xC
 
     // get Properties of ChartDocument
     bool bHasMainTitle = false;
+    bool bHasSubTitle = false;
     bool bHasLegend = false;
     Reference< beans::XPropertySet > xDocPropSet( xChartDoc, uno::UNO_QUERY );
     if( xDocPropSet.is())
     {
         try
         {
-            bool bHasSubTitle = false;
             Any aAny( xDocPropSet->getPropertyValue("HasMainTitle"));
             aAny >>= bHasMainTitle;
             aAny = xDocPropSet->getPropertyValue("HasSubTitle");
@@ -899,15 +899,27 @@ void ChartExport::exportChart( const Reference< css::chart::XChartDocument >& xC
     FSHelperPtr pFS = GetFS();
     pFS->startElement(FSNS(XML_c, XML_chart));
 
-    // title
-    if( bHasMainTitle )
+    // titles
+    if( bHasMainTitle || bHasSubTitle )
     {
-        Reference< drawing::XShape > xShape = xChartDoc->getTitle();
-        if( xShape.is() )
+        OUString aSubText;
+        Reference< drawing::XShape > xShape;
+        if( bHasSubTitle )
         {
-            exportTitle( xShape );
-            pFS->singleElement(FSNS(XML_c, XML_autoTitleDeleted), XML_val, "0");
+            xShape = xChartDoc->getSubTitle();
+            if( bHasMainTitle )
+            {
+                // if we have a title and a subtitle too, we need only the subtitle text
+                Reference< beans::XPropertySet > xPropSet(xShape, uno::UNO_QUERY);
+                if( xPropSet.is() )
+                    xPropSet->getPropertyValue("String") >>= aSubText;
+            }
         }
+        if( bHasMainTitle )
+            xShape = xChartDoc->getTitle();
+
+        exportTitle( xShape, !aSubText.isEmpty() ? &aSubText : nullptr );
+        pFS->singleElement(FSNS(XML_c, XML_autoTitleDeleted), XML_val, "0");
     }
     InitPlotArea( );
     if( mbIs3DChart )
@@ -1086,7 +1098,7 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x
     pFS->endElement( FSNS( XML_c, XML_legend ) );
 }
 
-void ChartExport::exportTitle( const Reference< XShape >& xShape )
+void ChartExport::exportTitle( const Reference< XShape >& xShape, const OUString* pSubText)
 {
     OUString sText;
     Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY );
@@ -1094,6 +1106,11 @@ void ChartExport::exportTitle( const Reference< XShape >& xShape )
     {
         xPropSet->getPropertyValue("String") >>= sText;
     }
+
+    // tdf#101322: add subtitle to title
+    if( pSubText )
+        sText = sText.isEmpty() ? *pSubText : sText + "\n" + *pSubText;
+
     if( sText.isEmpty() )
         return;
 


More information about the Libreoffice-commits mailing list