chart2/source/view/axes/VCartesianAxis.cxx | 39 ++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-)
New commits: commit 20785cefb9e7da06d21437a338e589c66a46dab5 Author: Muthu Subramanian <sumu...@suse.com> Date: Thu May 2 17:06:48 2013 +0530 n#816939: Improved label overlap detection - Part 2 diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index 261b23e..eb7efa8 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -137,6 +137,19 @@ bool lcl_doesShapeOverlapWithTickmark( const Reference< drawing::XShape >& xShap return aShapeRect.isInside(aPosition); } +void lcl_getRotatedPolygon( B2DPolygon &aPoly, const ::basegfx::B2DRectangle &aRect, const awt::Point &aPos, const double fRotationAngleDegree ) +{ + ::basegfx::B2DHomMatrix aMatrix; + + aPoly = basegfx::tools::createPolygonFromRect( aRect ); + aMatrix.translate( -aRect.getWidth()/2, -aRect.getHeight()/2); + aMatrix.rotate( fRotationAngleDegree*M_PI/180.0 ); + aPoly.transform( aMatrix ); + aMatrix = ::basegfx::B2DHomMatrix(); + aMatrix.translate( aRect.getWidth()/2+aPos.X, aRect.getHeight()/2+aPos.Y); + aPoly.transform( aMatrix ); +} + bool doesOverlap( const Reference< drawing::XShape >& xShape1 , const Reference< drawing::XShape >& xShape2 , double fRotationAngleDegree ) @@ -144,15 +157,13 @@ bool doesOverlap( const Reference< drawing::XShape >& xShape1 if( !xShape1.is() || !xShape2.is() ) return false; - ::basegfx::B2DRectangle aRect1( BaseGFXHelper::makeRectangle( xShape1->getPosition(), ShapeFactory::getSizeAfterRotation( xShape1, 0 ) )); - ::basegfx::B2DRectangle aRect2( BaseGFXHelper::makeRectangle( xShape2->getPosition(), ShapeFactory::getSizeAfterRotation( xShape2, 0 ) )); + ::basegfx::B2DRectangle aRect1( BaseGFXHelper::makeRectangle( awt::Point(0,0), xShape1->getSize())); + ::basegfx::B2DRectangle aRect2( BaseGFXHelper::makeRectangle( awt::Point(0,0), xShape2->getSize())); - B2DPolygon aPoly1 = basegfx::tools::createPolygonFromRect( aRect1 ); - B2DPolygon aPoly2 = basegfx::tools::createPolygonFromRect( aRect2 ); - ::basegfx::B2DHomMatrix aMatrix; - aMatrix.rotate( fRotationAngleDegree ); - aPoly1.transform( aMatrix ); - aPoly2.transform( aMatrix ); + B2DPolygon aPoly1; + B2DPolygon aPoly2; + lcl_getRotatedPolygon( aPoly1, aRect1, xShape1->getPosition(), fRotationAngleDegree ); + lcl_getRotatedPolygon( aPoly2, aRect2, xShape2->getPosition(), fRotationAngleDegree ); B2DPolyPolygon aPolyPoly1, aPolyPoly2; aPolyPoly1.append( aPoly1 ); commit 4d19f82c97694db258c18959313f2b4f1842a5b5 Author: Muthu Subramanian <sumu...@suse.com> Date: Tue Apr 30 10:14:54 2013 +0530 n#816939: Improved label overlap detection. diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index 40b4886..261b23e 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -43,6 +43,11 @@ #include <algorithm> #include <boost/scoped_ptr.hpp> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolygonclipper.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> //............................................................................. namespace chart @@ -52,6 +57,8 @@ using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; using namespace ::rtl::math; using ::com::sun::star::uno::Reference; +using ::basegfx::B2DPolygon; +using ::basegfx::B2DPolyPolygon; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -137,14 +144,22 @@ bool doesOverlap( const Reference< drawing::XShape >& xShape1 if( !xShape1.is() || !xShape2.is() ) return false; - sal_Int32 nAngle = abs(fRotationAngleDegree); + ::basegfx::B2DRectangle aRect1( BaseGFXHelper::makeRectangle( xShape1->getPosition(), ShapeFactory::getSizeAfterRotation( xShape1, 0 ) )); + ::basegfx::B2DRectangle aRect2( BaseGFXHelper::makeRectangle( xShape2->getPosition(), ShapeFactory::getSizeAfterRotation( xShape2, 0 ) )); - if( ( nAngle >= 45 && nAngle <= 135 ) || ( nAngle >= 225 && nAngle <= 315 ) ) - return false; + B2DPolygon aPoly1 = basegfx::tools::createPolygonFromRect( aRect1 ); + B2DPolygon aPoly2 = basegfx::tools::createPolygonFromRect( aRect2 ); + ::basegfx::B2DHomMatrix aMatrix; + aMatrix.rotate( fRotationAngleDegree ); + aPoly1.transform( aMatrix ); + aPoly2.transform( aMatrix ); + + B2DPolyPolygon aPolyPoly1, aPolyPoly2; + aPolyPoly1.append( aPoly1 ); + aPolyPoly2.append( aPoly2 ); + B2DPolyPolygon overlapPoly = ::basegfx::tools::clipPolyPolygonOnPolyPolygon( aPolyPoly1, aPolyPoly2, true, false ); - ::basegfx::B2IRectangle aRect1( BaseGFXHelper::makeRectangle(xShape1->getPosition(),ShapeFactory::getSizeAfterRotation( xShape1, fRotationAngleDegree ))); - ::basegfx::B2IRectangle aRect2( BaseGFXHelper::makeRectangle(xShape2->getPosition(),ShapeFactory::getSizeAfterRotation( xShape2, fRotationAngleDegree ))); - return aRect1.overlaps(aRect2); + return (overlapPoly.count() > 0); } void removeShapesAtWrongRhythm( TickIter& rIter @@ -786,6 +801,7 @@ bool VCartesianAxis::createTextShapes( { rAxisLabelProperties.fRotationAngleDegree = 45; rAxisLabelProperties.bLineBreakAllowed = false; + rAxisLabelProperties.eStaggering = SIDE_BY_SIDE; m_aAxisLabelProperties.fRotationAngleDegree = rAxisLabelProperties.fRotationAngleDegree; removeTextShapesFromTicks(); return false; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits