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

Balazs Varga (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 3 08:04:22 UTC 2019


 chart2/qa/extras/chart2import.cxx                     |   36 ++++++++++++++++++
 chart2/qa/extras/data/docx/testAxisTitlePosition.docx |binary
 oox/inc/drawingml/chart/converterbase.hxx             |    2 +
 oox/source/drawingml/chart/converterbase.cxx          |   15 ++++---
 4 files changed, 47 insertions(+), 6 deletions(-)

New commits:
commit 86e4d68e62c6291ef386b5fcf0f8912989f8e661
Author:     Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Tue Oct 1 15:37:17 2019 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Thu Oct 3 10:03:06 2019 +0200

    tdf#127907 tdf#126724 Chart DOCX import: fix axis title position
    
    Custom position of axis title reset to default when
    the document is opened in LibreOffice.
    
    Also fix tdf#126724 which was a regression from commit:
    48480d4f19d2fb92ca4ae0527eec4753cdc439c0
    (make tools::Rectangle::getBottom return 0 when empty)
    
    Note: The y coordinate of Y axis title position is still
    wrong because of another older bug.
    
    Change-Id: I449ad3b2252e05ab38d6752512d822c355ff8606
    Reviewed-on: https://gerrit.libreoffice.org/79966
    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/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index c0850820acc3..34477f69d6ac 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -21,6 +21,7 @@
 #include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/drawing/LineStyle.hpp>
 #include <com/sun/star/chart/XAxisXSupplier.hpp>
+#include <com/sun/star/chart/XAxisYSupplier.hpp>
 #include <com/sun/star/chart/MissingValueTreatment.hpp>
 #include <com/sun/star/chart2/TickmarkStyle.hpp>
 #include <com/sun/star/chart2/SymbolStyle.hpp>
@@ -108,6 +109,7 @@ public:
     void testAxisTitleDefaultRotationXLSX();
     void testSecondaryAxisTitleDefaultRotationXLSX();
     void testAxisTitleRotationXLSX();
+    void testAxisTitlePositionDOCX();
     void testCombinedChartAttachedAxisXLSX();
 
     void testTdf90510(); // Pie chart label placement settings(XLS)
@@ -200,6 +202,7 @@ public:
     CPPUNIT_TEST(testAxisTitleDefaultRotationXLSX);
     CPPUNIT_TEST(testSecondaryAxisTitleDefaultRotationXLSX);
     CPPUNIT_TEST(testAxisTitleRotationXLSX);
+    CPPUNIT_TEST(testAxisTitlePositionDOCX);
     CPPUNIT_TEST(testCombinedChartAttachedAxisXLSX);
     CPPUNIT_TEST(testTdf90510);
     CPPUNIT_TEST(testTdf109858);
@@ -1505,6 +1508,39 @@ void Chart2ImportTest::testAxisTitleRotationXLSX()
 
 }
 
+void Chart2ImportTest::testAxisTitlePositionDOCX()
+{
+    load("/chart2/qa/extras/data/docx/", "testAxisTitlePosition.docx");
+    uno::Reference< chart::XDiagram > mxDiagram;
+    uno::Reference< drawing::XShape > xAxisTitle;
+    uno::Reference< chart::XChartDocument > xChartDoc = getChartDocFromWriter(0);
+    CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
+    mxDiagram.set(xChartDoc->getDiagram());
+    CPPUNIT_ASSERT(mxDiagram.is());
+    // test X Axis title position
+    uno::Reference< chart::XAxisXSupplier > xAxisXSupp(mxDiagram, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xAxisXSupp.is());
+
+    xAxisTitle = xAxisXSupp->getXAxisTitle();
+    CPPUNIT_ASSERT(xAxisTitle.is());
+
+    awt::Point aPos = xAxisTitle->getPosition();
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(10640), static_cast<sal_Int32>(aPos.X));
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(7157), static_cast<sal_Int32>(aPos.Y));
+
+    // test Y Axis title position
+    uno::Reference< chart::XAxisYSupplier > xAxisYSupp(mxDiagram, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xAxisYSupp.is());
+
+    xAxisTitle = xAxisYSupp->getYAxisTitle();
+    CPPUNIT_ASSERT(xAxisTitle.is());
+
+    aPos = xAxisTitle->getPosition();
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(387), static_cast<sal_Int32>(aPos.X));
+    // y coordinate is still wrong because of another older bug!
+    /*CPPUNIT_ASSERT_EQUAL(sal_Int32(1535), static_cast<sal_Int32>(aPos.Y));*/
+}
+
 void Chart2ImportTest::testCombinedChartAttachedAxisXLSX()
 {
     load("/chart2/qa/extras/data/xlsx/", "testCombinedChartAxis.xlsx");
diff --git a/chart2/qa/extras/data/docx/testAxisTitlePosition.docx b/chart2/qa/extras/data/docx/testAxisTitlePosition.docx
new file mode 100644
index 000000000000..6abd37eec5a0
Binary files /dev/null and b/chart2/qa/extras/data/docx/testAxisTitlePosition.docx differ
diff --git a/oox/inc/drawingml/chart/converterbase.hxx b/oox/inc/drawingml/chart/converterbase.hxx
index 32e3e95d550e..6af038bb262f 100644
--- a/oox/inc/drawingml/chart/converterbase.hxx
+++ b/oox/inc/drawingml/chart/converterbase.hxx
@@ -85,6 +85,8 @@ protected:
                         getChartDocument() const;
     /** Returns the position and size of the chart shape in 1/100 mm. */
     const css::awt::Size& getChartSize() const;
+    /** Returns the default position and size of the chart shape in 1/100 mm. */
+    static css::awt::Size getDefaultPageSize() { return css::awt::Size(16000, 9000); }
     /** Returns the object formatter. */
     ObjectFormatter&    getFormatter() const;
 
diff --git a/oox/source/drawingml/chart/converterbase.cxx b/oox/source/drawingml/chart/converterbase.cxx
index 7f12741c568e..8acf77c619df 100644
--- a/oox/source/drawingml/chart/converterbase.cxx
+++ b/oox/source/drawingml/chart/converterbase.cxx
@@ -350,11 +350,10 @@ bool LayoutConverter::calcAbsRectangle( awt::Rectangle& orRect ) const
 {
     if( !mrModel.mbAutoLayout )
     {
-        awt::Size aChartSize=getChartSize();
+        awt::Size aChartSize = getChartSize();
         if( aChartSize.Width <= 0 || aChartSize.Height <= 0 )
         {
-            aChartSize.Width = 16000;
-            aChartSize.Height = 9000;
+            aChartSize = getDefaultPageSize();
         }
         orRect.X = lclCalcPosition( aChartSize.Width,  mrModel.mfX, mrModel.mnXMode );
         orRect.Y = lclCalcPosition( aChartSize.Height, mrModel.mfY, mrModel.mnYMode );
@@ -396,10 +395,14 @@ void LayoutConverter::convertFromModel( const Reference< XShape >& rxShape, doub
 {
     if( !mrModel.mbAutoLayout )
     {
-        const awt::Size& rChartSize = getChartSize();
+        awt::Size aChartSize = getChartSize();
+        if( aChartSize.Width <= 0 || aChartSize.Height <= 0 )
+        {
+            aChartSize = getDefaultPageSize();
+        }
         awt::Point aShapePos(
-            lclCalcPosition( rChartSize.Width,  mrModel.mfX, mrModel.mnXMode ),
-            lclCalcPosition( rChartSize.Height, mrModel.mfY, mrModel.mnYMode ) );
+            lclCalcPosition( aChartSize.Width,  mrModel.mfX, mrModel.mnXMode ),
+            lclCalcPosition( aChartSize.Height, mrModel.mfY, mrModel.mnYMode ) );
         if( (aShapePos.X >= 0) && (aShapePos.Y >= 0) )
         {
             // the call to XShape.getSize() may recalc the chart view


More information about the Libreoffice-commits mailing list