diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2019-10-05 22:52:42 +0200 |
---|---|---|
committer | Regina Henschel <rb.henschel@t-online.de> | 2019-10-09 20:43:38 +0200 |
commit | 5e68f0e2a13cc21f95a875cf694e926e01642050 (patch) | |
tree | 38a0ac1af49d81db9c0c4b2d8c628870169496f0 | |
parent | 7d361e96c9ea822790db21806e9fc05279423833 (diff) |
tdf#127785 Apply 180deg compensation for flipV to text range
If a shape is vertically flipped, then the text is rotated by
180deg around the shape center. The rotation is done by SdrTextObj,
where text rectangle and shape rectangle are the same, so the
rotated text rectangle has the correct position despite flipping.
But the text rectangle for SdrObjCustomShape is set by the shape
author in the TextFrames attribute and might have an asymmetric
position. The patch compensates the flip-rotation by pre-rotate the
text rectangle.
This replaces commit caaa8fe7c4bb88185b5b11591ee8a619cff0eced.
The error in the old patch was, that it has uses a translation
instead of a rotation, and has used a wrong place. The result was,
that a text box, which has an own TextRotateAngle, had got a wrong
position.
Change-Id: Id38e8c1839afa5091cd251fc5237315ba7944263
Reviewed-on: https://gerrit.libreoffice.org/80310
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Tested-by: Regina Henschel <rb.henschel@t-online.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | svx/qa/unit/customshapes.cxx | 34 | ||||
-rw-r--r-- | svx/qa/unit/data/tdf127785_TextRotateAngle.odp | bin | 0 -> 12841 bytes | |||
-rw-r--r-- | svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx | 23 |
3 files changed, 44 insertions, 13 deletions
diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx index c1090f87109d..4a1f3cb39c46 100644 --- a/svx/qa/unit/customshapes.cxx +++ b/svx/qa/unit/customshapes.cxx @@ -539,6 +539,40 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf127785_Asymmetric) CPPUNIT_ASSERT_EQUAL(OUString(), sErrors); } + +CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf127785_TextRotateAngle) +{ + // The document contains a shapes with vertical flip and a text frame with own + // rotate angle. The shape has not stroke and no fill, so that the bounding box + // surrounds the text and therefore equals approximately the text frame. + // Error was, that the compensation for the 180° rotation added for vertical + // flip were not made to the text box position but to the text matrix. + const OUString sFileName("tdf127785_TextRotateAngle.odp"); + OUString sURL = m_directories.getURLFromSrc(sDataDirectory) + sFileName; + mxComponent = loadFromDesktop(sURL, "com.sun.star.comp.drawing.DrawingDocument"); + CPPUNIT_ASSERT_MESSAGE("Could not load document", mxComponent.is()); + OUString sErrors; // sErrors collects the errors and should be empty in case all is OK. + + uno::Reference<drawing::XShape> xShape(getShape(0)); + uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps.is()); + awt::Rectangle aBoundRect; + xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_BOUNDRECT) >>= aBoundRect; + const sal_Int32 nLeft = aBoundRect.X; + const sal_Int32 nTop = aBoundRect.Y; + const sal_Int32 nRight = aBoundRect.X + aBoundRect.Width - 1; + const sal_Int32 nBottom = aBoundRect.Y + aBoundRect.Height - 1; + if (abs(nLeft - 5054) > 5) + sErrors += "wrong left"; + if (abs(nRight - 6374) > 5) + sErrors += " wrong right"; + if (abs(nTop - 4516) > 5) + sErrors += " wrong top"; + if (abs(nBottom - 8930) > 5) + sErrors += " wrong bottom"; + + CPPUNIT_ASSERT_EQUAL(OUString(), sErrors); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/qa/unit/data/tdf127785_TextRotateAngle.odp b/svx/qa/unit/data/tdf127785_TextRotateAngle.odp Binary files differnew file mode 100644 index 000000000000..742f12d4d941 --- /dev/null +++ b/svx/qa/unit/data/tdf127785_TextRotateAngle.odp diff --git a/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx b/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx index 08771194e109..ada854fd5503 100644 --- a/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx +++ b/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx @@ -94,6 +94,16 @@ namespace sdr aTextRange.getMinX() + aTranslation.getX(), aTextRange.getMinY() + aTranslation.getY(), aTextRange.getMaxX() + aTranslation.getX(), aTextRange.getMaxY() + aTranslation.getY()); } + + // NbcMirror() of SdrTextObj (from which SdrObjCustomShape is derived), adds a + // 180deg rotation around the shape center to GeoStat.nRotationAngle. So remove here the + // 180° rotation, which was added by GetTextBounds(). + if(GetCustomShapeObj().IsMirroredY()) + { + basegfx::B2DHomMatrix aRotMatrix(basegfx::utils::createRotateAroundPoint( + aObjectRange.getCenterX(), aObjectRange.getCenterY(), F_PI)); + aTextRange.transform(aRotMatrix); + } } return aTextRange; @@ -168,19 +178,6 @@ namespace sdr // give text object a size aTextBoxMatrix.scale(aTextRange.getWidth(), aTextRange.getHeight()); - // NbcMirror() of SdrTextObj (from which SdrObjCustomShape is derived), adds a - // 180deg rotation around the shape center to the text box. If aTextRange differs - // from aObjectRange, that is not the position needed for mirroring. We - // translate the text box here so, that it is at the correct position after rotation. - if(GetCustomShapeObj().IsMirroredY()) - { - aTextBoxMatrix.translate( - aObjectRange.getWidth() - aTextRange.getWidth() - - 2 * (aTextRange.getMinX() - aObjectRange.getMinimum().getX()), - aObjectRange.getHeight() - aTextRange.getHeight() - - 2 * (aTextRange.getMinY() - aObjectRange.getMinimum().getY())); - } - // check if we have a rotation/shear at all to take care of const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation()); const GeoStat& rGeoStat(GetCustomShapeObj().GetGeoStat()); |