[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - chart2/qa chart2/source include/oox oox/source

Szymon Kłos szymon.klos at collabora.com
Fri Mar 16 01:53:25 UTC 2018


 chart2/qa/extras/chart2export.cxx                      |   11 +++
 chart2/qa/extras/data/pptx/tdf116163.pptx              |binary
 chart2/source/view/axes/VAxisProperties.hxx            |    2 
 chart2/source/view/axes/VCartesianAxis.cxx             |   50 +++++++++++++++++
 chart2/source/view/axes/VCartesianCoordinateSystem.cxx |    2 
 chart2/source/view/axes/VCartesianCoordinateSystem.hxx |    3 -
 chart2/source/view/axes/VCoordinateSystem.cxx          |    1 
 chart2/source/view/axes/VPolarCoordinateSystem.cxx     |    1 
 chart2/source/view/axes/VPolarCoordinateSystem.hxx     |    3 -
 chart2/source/view/inc/VCoordinateSystem.hxx           |    3 -
 chart2/source/view/main/ChartView.cxx                  |    2 
 include/oox/export/chartexport.hxx                     |    2 
 oox/source/export/chartexport.cxx                      |   20 +++++-
 13 files changed, 92 insertions(+), 8 deletions(-)

New commits:
commit 87d8df83efd210a322b42f590aaff3d2e8efe2bc
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Fri Mar 2 10:39:33 2018 +0100

    tdf#116163: Limit label height in chart if needed
    
    Change-Id: Ia84fd0c3b76886bc6124dc3b59035465aa31b020
    Reviewed-on: https://gerrit.libreoffice.org/50700
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/50830
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 4b21f18f7248..9b9e75c868c2 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -102,6 +102,7 @@ public:
     void testAxisTitleRotationXLSX();
     void testAxisCrossBetweenXSLX();
     void testNumberFormatExportPPTX();
+    void testTdf116163();
 
     CPPUNIT_TEST_SUITE(Chart2ExportTest);
     CPPUNIT_TEST(testErrorBarXLSX);
@@ -168,6 +169,7 @@ public:
     CPPUNIT_TEST(testAxisTitleRotationXLSX);
     CPPUNIT_TEST(testAxisCrossBetweenXSLX);
     CPPUNIT_TEST(testNumberFormatExportPPTX);
+    CPPUNIT_TEST(testTdf116163);
     CPPUNIT_TEST_SUITE_END();
 
 protected:
@@ -1573,6 +1575,15 @@ void Chart2ExportTest::testNumberFormatExportPPTX()
     assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:numFmt", "sourceLinked", "0");
 }
 
+void Chart2ExportTest::testTdf116163()
+{
+    load("/chart2/qa/extras/data/pptx/", "tdf116163.pptx");
+    xmlDocPtr pXmlDoc = parseExport("ppt/charts/chart", "Impress MS PowerPoint 2007 XML");
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:txPr/a:bodyPr", "rot", "-5400000");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/pptx/tdf116163.pptx b/chart2/qa/extras/data/pptx/tdf116163.pptx
new file mode 100644
index 000000000000..5fbee8304a52
Binary files /dev/null and b/chart2/qa/extras/data/pptx/tdf116163.pptx differ
diff --git a/chart2/source/view/axes/VAxisProperties.hxx b/chart2/source/view/axes/VAxisProperties.hxx
index 20f648d4fe8d..9a10c94f4719 100644
--- a/chart2/source/view/axes/VAxisProperties.hxx
+++ b/chart2/source/view/axes/VAxisProperties.hxx
@@ -137,6 +137,8 @@ struct AxisProperties final
     css::uno::Reference<css::chart2::data::XTextualDataSequence> m_xAxisTextProvider; //for categories or series names
     //<- category axes
 
+    bool                                m_bLimitSpaceForLabels;
+
     //methods:
 
     AxisProperties( const css::uno::Reference< css::chart2::XAxis >& xAxisModel
diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx
index 9493102a93c4..5e702f85dbed 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -74,6 +74,53 @@ VCartesianAxis::~VCartesianAxis()
     m_pPosHelper = nullptr;
 }
 
+void lcl_ResizeTextShapeToFitAvailableSpace( Reference< drawing::XShape >& xShape2DText,
+                                             const AxisLabelProperties& rAxisLabelProperties,
+                                             const OUString& rLabel,
+                                             const tNameSequence& rPropNames,
+                                             const tAnySequence& rPropValues )
+{
+    uno::Reference< text::XTextRange > xTextRange( xShape2DText, uno::UNO_QUERY );
+
+    if( !xTextRange.is() )
+        return;
+
+    const sal_Int32 nFullHeight = rAxisLabelProperties.m_aFontReferenceSize.Height;
+
+    if( !nFullHeight || !rLabel.getLength() )
+        return;
+
+    sal_Int32 nMaxLabelsHeight = nFullHeight - rAxisLabelProperties.m_aMaximumSpaceForLabels.Height - rAxisLabelProperties.m_aMaximumSpaceForLabels.Y;
+    const sal_Int32 nAvgCharWidth = xShape2DText->getSize().Width / rLabel.getLength();
+    const sal_Int32 nTextSize = AbstractShapeFactory::getSizeAfterRotation( xShape2DText,
+                                            rAxisLabelProperties.fRotationAngleDegree ).Height;
+
+    if( !nAvgCharWidth )
+        return;
+
+    const OUString sDots = "...";
+    const sal_Int32 nCharsToRemove = ( nTextSize - nMaxLabelsHeight ) / nAvgCharWidth + 1;
+    sal_Int32 nNewLen = rLabel.getLength() - nCharsToRemove - sDots.getLength();
+    // Prevent from showing only dots
+    if (nNewLen < 0)
+        nNewLen = ( rLabel.getLength() >= sDots.getLength() ) ? sDots.getLength() : rLabel.getLength();
+
+    bool bCrop = nCharsToRemove > 0;
+    if( bCrop )
+    {
+        OUString aNewLabel = rLabel.copy( 0, nNewLen );
+        if( nNewLen > sDots.getLength() )
+            aNewLabel += sDots;
+        xTextRange->setString( aNewLabel );
+
+        uno::Reference< beans::XPropertySet > xProp( xTextRange, uno::UNO_QUERY );
+        if( xProp.is() )
+        {
+            PropertyMapper::setMultiProperties( rPropNames, rPropValues, xProp );
+        }
+    }
+}
+
 Reference< drawing::XShape > createSingleLabel(
             const Reference< lang::XMultiServiceFactory>& xShapeFactory
           , const Reference< drawing::XShapes >& xTarget
@@ -96,6 +143,9 @@ Reference< drawing::XShape > createSingleLabel(
     Reference< drawing::XShape > xShape2DText = AbstractShapeFactory::getOrCreateShapeFactory(xShapeFactory)
                     ->createText( xTarget, aLabel, rPropNames, rPropValues, aATransformation );
 
+    if( rAxisProperties.m_bLimitSpaceForLabels )
+        lcl_ResizeTextShapeToFitAvailableSpace(xShape2DText, rAxisLabelProperties, aLabel, rPropNames, rPropValues);
+
     LabelPositionHelper::correctPositionForRotation( xShape2DText
         , rAxisProperties.maLabelAlignment.meAlignment, rAxisLabelProperties.fRotationAngleDegree, rAxisProperties.m_bComplexCategories );
 
diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx
index 8e777f351bf1..d4cd7ec0cf2c 100644
--- a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx
@@ -93,6 +93,7 @@ void VCartesianCoordinateSystem::createVAxisList(
               const uno::Reference<chart2::XChartDocument> & xChartDoc
             , const awt::Size& rFontReferenceSize
             , const awt::Rectangle& rMaximumSpaceForLabels
+            , bool bLimitSpaceForLabels
             )
 {
     // note: using xChartDoc itself as XNumberFormatsSupplier would cause
@@ -125,6 +126,7 @@ void VCartesianCoordinateSystem::createVAxisList(
             aAxisProperties.m_nDimensionIndex = nDimensionIndex;
             aAxisProperties.m_bSwapXAndY = bSwapXAndY;
             aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
+            aAxisProperties.m_bLimitSpaceForLabels = bLimitSpaceForLabels;
             Reference< XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel ) );
             if( xCrossingMainAxis.is() )
             {
diff --git a/chart2/source/view/axes/VCartesianCoordinateSystem.hxx b/chart2/source/view/axes/VCartesianCoordinateSystem.hxx
index c61768f5ee5c..e959dbc5d5ef 100644
--- a/chart2/source/view/axes/VCartesianCoordinateSystem.hxx
+++ b/chart2/source/view/axes/VCartesianCoordinateSystem.hxx
@@ -34,7 +34,8 @@ public:
     virtual void createVAxisList(
             const css::uno::Reference< css::chart2::XChartDocument> &ChartDoc
             , const css::awt::Size& rFontReferenceSize
-            , const css::awt::Rectangle& rMaximumSpaceForLabels ) override;
+            , const css::awt::Rectangle& rMaximumSpaceForLabels
+            , bool bLimitSpaceForLabels ) override;
 
     virtual void initVAxisInList() override;
     virtual void updateScalesAndIncrementsOnAxes() override;
diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx
index 2b0830d0dfee..1099f497a850 100644
--- a/chart2/source/view/axes/VCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VCoordinateSystem.cxx
@@ -343,6 +343,7 @@ void VCoordinateSystem::createVAxisList(
               const uno::Reference<chart2::XChartDocument> & /* xChartDoc */
             , const awt::Size& /* rFontReferenceSize */
             , const awt::Rectangle& /* rMaximumSpaceForLabels */
+            , bool /* bLimitSpaceForLabels */
             )
 {
 }
diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.cxx b/chart2/source/view/axes/VPolarCoordinateSystem.cxx
index 49eb8763cd12..f947686c3a28 100644
--- a/chart2/source/view/axes/VPolarCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VPolarCoordinateSystem.cxx
@@ -65,6 +65,7 @@ void VPolarCoordinateSystem::createVAxisList(
               const uno::Reference<chart2::XChartDocument> & xChartDoc
             , const awt::Size& rFontReferenceSize
             , const awt::Rectangle& rMaximumSpaceForLabels
+            , bool //bLimitSpaceForLabels
             )
 {
     // note: using xChartDoc itself as XNumberFormatsSupplier would cause
diff --git a/chart2/source/view/axes/VPolarCoordinateSystem.hxx b/chart2/source/view/axes/VPolarCoordinateSystem.hxx
index e7941484e23b..4976672963c8 100644
--- a/chart2/source/view/axes/VPolarCoordinateSystem.hxx
+++ b/chart2/source/view/axes/VPolarCoordinateSystem.hxx
@@ -38,7 +38,8 @@ public:
     virtual void createVAxisList(
             const css::uno::Reference< css::chart2::XChartDocument> & xChartDoc
             , const css::awt::Size& rFontReferenceSize
-            , const css::awt::Rectangle& rMaximumSpaceForLabels ) override;
+            , const css::awt::Rectangle& rMaximumSpaceForLabels
+            , bool bLimitSpaceForLabels ) override;
 
     virtual void initVAxisInList() override;
     virtual void updateScalesAndIncrementsOnAxes() override;
diff --git a/chart2/source/view/inc/VCoordinateSystem.hxx b/chart2/source/view/inc/VCoordinateSystem.hxx
index 6b115d3d7715..7a4a7110a2e4 100644
--- a/chart2/source/view/inc/VCoordinateSystem.hxx
+++ b/chart2/source/view/inc/VCoordinateSystem.hxx
@@ -111,7 +111,8 @@ public:
     virtual void createVAxisList(
             const css::uno::Reference< css::chart2::XChartDocument> & xChartDoc
             , const css::awt::Size& rFontReferenceSize
-            , const css::awt::Rectangle& rMaximumSpaceForLabels );
+            , const css::awt::Rectangle& rMaximumSpaceForLabels
+            , bool bLimitSpaceForLabels );
 
     virtual void initVAxisInList();
     virtual void updateScalesAndIncrementsOnAxes();
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 97a51c55c961..49c598709280 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -1600,7 +1600,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D
             pVCooSys->set3DWallPositions( eLeftWallPos, eBackWallPos, eBottomPos );
         }
 
-        pVCooSys->createVAxisList(xChartDoc, rPageSize, rParam.maRemainingSpace);
+        pVCooSys->createVAxisList(xChartDoc, rPageSize, rParam.maRemainingSpace, rParam.mbUseFixedInnerSize);
     }
 
     // - prepare list of all axis and how they are used
diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx
index e1ae1f4f0a9b..9bbf1d3e16f9 100644
--- a/include/oox/export/chartexport.hxx
+++ b/include/oox/export/chartexport.hxx
@@ -172,7 +172,7 @@ private:
     void exportSeriesValues(
         const css::uno::Reference< css::chart2::data::XDataSequence >& xValueSeq, sal_Int32 nValueType = XML_val );
     void exportShapeProps( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
-    void exportTextProps(const css::uno::Reference< css::beans::XPropertySet >& xPropSet);
+    void exportTextProps(const css::uno::Reference< css::beans::XPropertySet >& xPropSet, bool bAxis = false);
     void exportDataPoints(
         const css::uno::Reference< css::beans::XPropertySet >& xSeriesProperties,
         sal_Int32 nSeriesLength, sal_Int32 eChartType );
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 4e789f9b3c97..2456b6c0dca0 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -2270,11 +2270,25 @@ void ChartExport::exportShapeProps( const Reference< XPropertySet >& xPropSet )
     pFS->endElement( FSNS( XML_c, XML_spPr ) );
 }
 
-void ChartExport::exportTextProps(const Reference<XPropertySet>& xPropSet)
+void ChartExport::exportTextProps(const Reference<XPropertySet>& xPropSet, bool bAxis)
 {
     FSHelperPtr pFS = GetFS();
     pFS->startElement(FSNS(XML_c, XML_txPr), FSEND);
-    pFS->singleElement( FSNS( XML_a, XML_bodyPr ), FSEND );
+
+    sal_Int32 nRotation = 0;
+    if (bAxis)
+    {
+        double fTextRotation = 0;
+        uno::Any aAny = xPropSet->getPropertyValue("TextRotation");
+        if (aAny.hasValue() && (aAny >>= fTextRotation))
+            nRotation = fTextRotation * -600.0;
+    }
+
+    if (nRotation)
+        pFS->singleElement(FSNS(XML_a, XML_bodyPr), XML_rot, I32S(nRotation), FSEND);
+    else
+        pFS->singleElement(FSNS(XML_a, XML_bodyPr), FSEND);
+
     pFS->singleElement( FSNS( XML_a, XML_lstStyle ), FSEND );
 
     pFS->startElement(FSNS(XML_a, XML_p), FSEND);
@@ -2681,7 +2695,7 @@ void ChartExport::_exportAxis(
     // shape properties
     exportShapeProps( xAxisProp );
 
-    exportTextProps(xAxisProp);
+    exportTextProps(xAxisProp, true);
 
     pFS->singleElement( FSNS( XML_c, XML_crossAx ),
             XML_val, I32S( rAxisIdPair.nCrossAx ),


More information about the Libreoffice-commits mailing list