diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2018-03-02 10:39:33 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2018-03-19 10:20:33 +0100 |
commit | b87dee0394f3159c690aa2b7756ab930566fe961 (patch) | |
tree | a60d2944fdbba7fbf9981aa133f4a3d81054fe34 /chart2/source/view/axes/VCartesianAxis.cxx | |
parent | bdc8127c4ec3c62da63e7cbafe07b76b32b58f18 (diff) |
tdf#116163: Limit label height in chart if needed
Change-Id: Ia84fd0c3b76886bc6124dc3b59035465aa31b020
Reviewed-on: https://gerrit.libreoffice.org/50700
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/50830
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
(cherry picked from commit 87d8df83efd210a322b42f590aaff3d2e8efe2bc)
Diffstat (limited to 'chart2/source/view/axes/VCartesianAxis.cxx')
-rw-r--r-- | chart2/source/view/axes/VCartesianAxis.cxx | 50 |
1 files changed, 50 insertions, 0 deletions
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 ); |