[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - chart2/source
Marco Cecchetti
marco.cecchetti at collabora.com
Mon Dec 29 15:31:57 PST 2014
chart2/source/view/axes/VCartesianAxis.cxx | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
New commits:
commit 5bde87b62028ea9ff0df801eedaf1cc54dda6df5
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date: Wed Dec 24 20:56:55 2014 +0100
bnc#830738 Now all axis labels of a chart are displaied.
Problem:
Some axis labels of a chart are missing, when they should not.
Analysis and solution:
The current implementation is affected by the following issues:
1) When the method switches to the 45-degrees layout the
`nRhythm` parameter is not reset to 1.
2) The bounding boxes computed by the `doesOverlap` test routine
for the 45-degrees layout are wrong.
Because of the first issue only one label every `nRhythm` is showed
even if in the 45-degrees layout no overlap occurs.
The second issue is located inside the `lcl_getRotatedPolygon`
routine which is used by the `doesOverlap` routine for building a
polygon representing the bb for a text label. The polygon is created
in the following way: a new rectangle is created: the top-left vertex is
placed at axes origin and it is initialized with the same width and
height of the bb of the passed text label. Later several
transformations are performed on the new rectangle:
1) the rectangle is rotated by a 45-degrees angle respect with its
center; 2) the rectangle is translated by a vector equals to the
top-left vertex of the bb of the passed text label.
There are 2 errors in this sequence of transformations:
1) The `B2DHomMatrix` class used for representing the
transformation, performs rotations in the positive direction (from
the X axis to the Y axis). However since the coordinate system used
by the chart has the Y-axis pointing downward, a rotation in the
positive direction means a clockwise rotation. On the contrary text
labels are rotated counterclockwise. This can be easily fixed by
using the opposite angle. 2) Rotating the rectangle respect with its
center is wrong since the fixed point of the rotation must be the
top-left corner of the rectangle: in this way when the final
translation is performed the top-left vertex of the transformed
rectangle will be coincident with the top-left vertex of the text label
bb, and so the transformed rectangle will be coincident with the text
label bb.
Change-Id: Ia8072c3d5bd6c1a11f66c33d45d56e55634edf4c
diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx
index 1209664..957b9af 100644
--- a/chart2/source/view/axes/VCartesianAxis.cxx
+++ b/chart2/source/view/axes/VCartesianAxis.cxx
@@ -132,14 +132,21 @@ bool lcl_doesShapeOverlapWithTickmark( const Reference< drawing::XShape >& xShap
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);
+
+ // For rotating the rectangle we use the opposite angle,
+ // since `B2DHomMatrix` class used for
+ // representing the transformation, performs rotations in the positive
+ // direction (from the X axis to the Y axis). However since the coordinate
+ // system used by the chart has the Y-axis pointing downward, a rotation in
+ // the positive direction means a clockwise rotation. On the contrary text
+ // labels are rotated counterclockwise.
+ // The rotation is performed around the top-left vertex of the rectangle
+ // which is then moved to its final position by using the top-left
+ // vertex of the text label bounding box (aPos) as the translation vector.
+ ::basegfx::B2DHomMatrix aMatrix;
+ aMatrix.rotate( -fRotationAngleDegree*M_PI/180.0 );
+ aMatrix.translate( aPos.X, aPos.Y);
aPoly.transform( aMatrix );
}
@@ -839,9 +846,12 @@ bool VCartesianAxis::createTextShapes(
// Try auto-rotating the labels at 45 degrees and
// start over. This rotation angle will be stored for
// all future text shape creation runs.
+ // The nRhythm parameter is reset to 1 since the layout
+ // used for text labels is changed.
rAxisLabelProperties.autoRotate45();
m_aAxisLabelProperties.fRotationAngleDegree = rAxisLabelProperties.fRotationAngleDegree; // Store it for future runs.
removeTextShapesFromTicks();
+ rAxisLabelProperties.nRhythm = 1;
return false;
}
@@ -980,9 +990,12 @@ bool VCartesianAxis::createTextShapesSimple(
// Try auto-rotating the labels at 45 degrees and
// start over. This rotation angle will be stored for
// all future text shape creation runs.
+ // The nRhythm parameter is reset to 1 since the layout
+ // used for text labels is changed.
rAxisLabelProperties.autoRotate45();
m_aAxisLabelProperties.fRotationAngleDegree = rAxisLabelProperties.fRotationAngleDegree; // Store it for future runs.
removeTextShapesFromTicks();
+ rAxisLabelProperties.nRhythm = 1;
return false;
}
More information about the Libreoffice-commits
mailing list