chart2/source/tools/ChartTypeHelper.cxx     |    3 ++-
 chart2/source/view/charttypes/AreaChart.cxx |   14 ++++++++++----
 sw/qa/extras/layout/data/tdf130031.docx     |binary
 sw/qa/extras/layout/layout.cxx              |   14 ++++++++++++++
 4 files changed, 26 insertions(+), 5 deletions(-)

New commits:
commit f8966bb398cf0623be841c618b123866801a063c
Author:     Tünde Tóth <tund...@gmail.com>
AuthorDate: Thu Jan 16 12:10:24 2020 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Jan 28 09:51:07 2020 +0100

    tdf#130031 Chart OOXML import: fix area chart data label position
    
    Default data label positioning of area charts in Excel is vertically
    centered between the X axes and the data point. In LibreOffice
    the data labels positioning was above the data point.
    
    Change-Id: Icff3e2554dee7b5ee264bc6f9579a84852da6f7b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86927
    Reviewed-by: László Németh <nem...@numbertext.org>
    Tested-by: László Németh <nem...@numbertext.org>

diff --git a/chart2/source/tools/ChartTypeHelper.cxx 
b/chart2/source/tools/ChartTypeHelper.cxx
index ebd2af04ab45..b7b3e889e1a1 100644
--- a/chart2/source/tools/ChartTypeHelper.cxx
+++ b/chart2/source/tools/ChartTypeHelper.cxx
@@ -314,9 +314,10 @@ uno::Sequence < sal_Int32 > 
ChartTypeHelper::getSupportedLabelPlacements( const
     }
     else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) )
     {
-        aRet.realloc(1);
+        aRet.realloc(2);
         sal_Int32* pSeq = aRet.getArray();
         *pSeq++ = css::chart::DataLabelPlacement::TOP;
+        *pSeq++ = css::chart::DataLabelPlacement::CENTER;
     }
     else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
     {
diff --git a/chart2/source/view/charttypes/AreaChart.cxx 
b/chart2/source/view/charttypes/AreaChart.cxx
index 6d67d0b6a94c..158d3f21bca6 100644
--- a/chart2/source/view/charttypes/AreaChart.cxx
+++ b/chart2/source/view/charttypes/AreaChart.cxx
@@ -750,6 +750,7 @@ void AreaChart::createShapes()
                     if( rLogicYForNextSeriesMap.find(nAttachedAxisIndex) == 
rLogicYForNextSeriesMap.end() )
                         rLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0;
 
+                    double fPreviousYValue = 
rLogicYForNextSeriesMap[nAttachedAxisIndex];
                     fLogicY += rLogicYForNextSeriesMap[nAttachedAxisIndex];
                     rLogicYForNextSeriesMap[nAttachedAxisIndex] = fLogicY;
 
@@ -897,13 +898,19 @@ void AreaChart::createShapes()
                         if( pSeries->getDataPointLabelIfLabel(nIndex) )
                         {
                             LabelAlignment eAlignment = LABEL_ALIGN_TOP;
+                            sal_Int32 nLabelPlacement = 
pSeries->getLabelPlacement(
+                                nIndex, m_xChartTypeModel, 
rPosHelper.isSwapXAndY());
+
+                            if (m_bArea && nLabelPlacement == 
css::chart::DataLabelPlacement::CENTER)
+                            {
+                                fLogicY -= (fLogicY - fPreviousYValue) / 2.0;
+                                aScenePosition = 
rPosHelper.transformLogicToScene(fLogicX, fLogicY, fLogicZ, false);
+                            }
+
                             drawing::Position3D aScenePosition3D( 
aScenePosition.PositionX
                                     , aScenePosition.PositionY
                                     , 
aScenePosition.PositionZ+getTransformedDepth() );
 
-                            sal_Int32 nLabelPlacement = 
pSeries->getLabelPlacement(
-                                nIndex, m_xChartTypeModel, 
rPosHelper.isSwapXAndY());
-
                             switch(nLabelPlacement)
                             {
                                 case css::chart::DataLabelPlacement::TOP:
@@ -924,7 +931,6 @@ void AreaChart::createShapes()
                                     break;
                                 case css::chart::DataLabelPlacement::CENTER:
                                     eAlignment = LABEL_ALIGN_CENTER;
-                                    //todo implement this different for area 
charts
                                     break;
                                 default:
                                     OSL_FAIL("this label alignment is not 
implemented yet");
diff --git a/sw/qa/extras/layout/data/tdf130031.docx 
b/sw/qa/extras/layout/data/tdf130031.docx
new file mode 100644
index 000000000000..4ac420a83c8e
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf130031.docx differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 862f4a30eb41..567fdea446f0 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -2504,6 +2504,20 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf129173)
         pXmlDoc, 
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/textarray[22]/text", "56");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf130031)
+{
+    SwDoc* pDoc = createDoc("tdf130031.docx");
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocPtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+    sal_Int32 nY = getXPath(pXmlDoc, "//textarray[11]", "y").toInt32();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(4339, nY, 50);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf116925)
 {
     SwDoc* pDoc = createDoc("tdf116925.docx");
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to