[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - chart2/qa chart2/source include/oox oox/source
Szymon Kłos
szymon.klos at collabora.com
Thu Mar 22 09:30:39 UTC 2018
chart2/qa/extras/chart2export.cxx | 11 +++
chart2/qa/extras/data/pptx/tdf116163.pptx |binary
chart2/source/view/axes/VAxisProperties.cxx | 2
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 +++++-
14 files changed, 94 insertions(+), 8 deletions(-)
New commits:
commit 7b80e54640e20657402656614228998e0544a842
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/50913
Reviewed-by: Andras Timar <andras.timar at collabora.com>
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index bb90d5201167..9eca3309fac4 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:
@@ -1574,6 +1576,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.cxx b/chart2/source/view/axes/VAxisProperties.cxx
index 786e8a3d73aa..89f933b0a2a9 100644
--- a/chart2/source/view/axes/VAxisProperties.cxx
+++ b/chart2/source/view/axes/VAxisProperties.cxx
@@ -175,6 +175,7 @@ AxisProperties::AxisProperties( const uno::Reference< XAxis >& xAxisModel
, m_bComplexCategories(false)
, m_pExplicitCategoriesProvider(pExplicitCategoriesProvider)
, m_xAxisTextProvider(nullptr)
+ , m_bLimitSpaceForLabels(false)
{
}
@@ -201,6 +202,7 @@ AxisProperties::AxisProperties( const AxisProperties& rAxisProperties )
, m_bComplexCategories( rAxisProperties.m_bComplexCategories )
, m_pExplicitCategoriesProvider( rAxisProperties.m_pExplicitCategoriesProvider )
, m_xAxisTextProvider( rAxisProperties.m_xAxisTextProvider )
+ , m_bLimitSpaceForLabels( rAxisProperties.m_bLimitSpaceForLabels )
{
if( rAxisProperties.m_pfMainLinePositionAtOtherAxis )
m_pfMainLinePositionAtOtherAxis.reset(*rAxisProperties.m_pfMainLinePositionAtOtherAxis);
diff --git a/chart2/source/view/axes/VAxisProperties.hxx b/chart2/source/view/axes/VAxisProperties.hxx
index 8948a91fe073..2ebbf3967450 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 89bd3536d2ce..156d764a6c28 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -75,6 +75,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
@@ -97,6 +144,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 934d17046ea3..aeab22fefea0 100644
--- a/chart2/source/view/axes/VCartesianCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VCartesianCoordinateSystem.cxx
@@ -94,6 +94,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
@@ -126,6 +127,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 a7da0e2579a9..e4784badb9fd 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 0cafa1560f5e..31051e354815 100644
--- a/chart2/source/view/axes/VCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VCoordinateSystem.cxx
@@ -344,6 +344,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 f0e20c47d898..7bac25f7d1af 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 bc93c717d017..7ab535b30e08 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 9ce1c9a57f58..c6d8c33dcbb9 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 67ad6e497e90..515c610bdd5c 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -1602,7 +1602,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 9055e99002f0..1378d48a6623 100644
--- a/include/oox/export/chartexport.hxx
+++ b/include/oox/export/chartexport.hxx
@@ -173,7 +173,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 );
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index b9a703cafd4b..c4c979df04bb 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -2417,11 +2417,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);
@@ -2829,7 +2843,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