svx/qa/unit/customshapes.cxx                              |   34 ++++++++++++++
 svx/qa/unit/data/tdf127785_asymmetricTextBoxFlipV.odg     |binary
 svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx |   13 +++++
 3 files changed, 47 insertions(+)

New commits:
commit caaa8fe7c4bb88185b5b11591ee8a619cff0eced
Author:     Regina Henschel <rb.hensc...@t-online.de>
AuthorDate: Tue Oct 1 18:20:53 2019 +0200
Commit:     Regina Henschel <rb.hensc...@t-online.de>
CommitDate: Wed Oct 2 13:36:17 2019 +0200

    tdf#127785 compensate 180deg rotation for position of text box
    
    If a shape is vertically flipped, then the text is rotated by 180deg
    around the shape center. The rotation is done by SdrTextObj. There
    text rectangle and shape rectangle are the same, so the rotated text
    rectangle has the correct position in regard to 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 translates the text rectangle so, that is will be at the
    correct position after the 180deg rotation.
    
    Change-Id: I42e552394cc4b0103530eab48750dd621c52cc5e
    Reviewed-on: https://gerrit.libreoffice.org/79984
    Tested-by: Jenkins
    Reviewed-by: Regina Henschel <rb.hensc...@t-online.de>

diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx
index 5ad16cc5ea53..c1090f87109d 100644
--- a/svx/qa/unit/customshapes.cxx
+++ b/svx/qa/unit/customshapes.cxx
@@ -505,6 +505,40 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, 
testTdf127785_Mirror)
 
     CPPUNIT_ASSERT_EQUAL(OUString(), sErrors);
 }
+
+CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf127785_Asymmetric)
+{
+    // The document contains a shapes with vertical flip and text frame 
asymmetrical
+    // to shape. 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 180deg text rotation was not compensated for the 
position of
+    // the flipped text box.
+    const OUString sFileName("tdf127785_asymmetricTextBoxFlipV.odg");
+    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 - 10034) > 5)
+        sErrors += "wrong left";
+    if (abs(nRight - 12973) > 5)
+        sErrors += " wrong right";
+    if (abs(nTop - 7892) > 5)
+        sErrors += " wrong top";
+    if (abs(nBottom - 14884) > 5)
+        sErrors += " wrong bottom";
+
+    CPPUNIT_ASSERT_EQUAL(OUString(), sErrors);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/qa/unit/data/tdf127785_asymmetricTextBoxFlipV.odg 
b/svx/qa/unit/data/tdf127785_asymmetricTextBoxFlipV.odg
new file mode 100644
index 000000000000..ea700eaf7e49
Binary files /dev/null and 
b/svx/qa/unit/data/tdf127785_asymmetricTextBoxFlipV.odg differ
diff --git a/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx 
b/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
index c88644acb6e1..08771194e109 100644
--- a/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
+++ b/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
@@ -168,6 +168,19 @@ 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());
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to