1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <test/unoapi_test.hxx>
11 #include <rtl/ustring.hxx>
12 #include <editeng/unoprnms.hxx>
14 #include <cppunit/TestAssert.h>
16 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
18 #include <com/sun/star/drawing/XDrawPage.hpp>
19 #include <com/sun/star/awt/Rectangle.hpp>
20 #include <com/sun/star/frame/Desktop.hpp>
22 using namespace ::com::sun::star
;
26 /// Tests not about special features of custom shapes, but about shapes in general.
27 class ClassicshapesTest
: public UnoApiTest
31 : UnoApiTest("svx/qa/unit/data/")
36 uno::Reference
<drawing::XShape
> getShape(sal_uInt8 nShapeIndex
, sal_uInt8 nPageIndex
);
39 uno::Reference
<drawing::XShape
> ClassicshapesTest::getShape(sal_uInt8 nShapeIndex
,
42 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
,
43 uno::UNO_QUERY_THROW
);
44 CPPUNIT_ASSERT_MESSAGE("Could not get XDrawPagesSupplier", xDrawPagesSupplier
.is());
45 uno::Reference
<drawing::XDrawPages
> xDrawPages(xDrawPagesSupplier
->getDrawPages());
46 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPages
->getByIndex(nPageIndex
),
47 uno::UNO_QUERY_THROW
);
48 CPPUNIT_ASSERT_MESSAGE("Could not get xDrawPage", xDrawPage
.is());
49 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(nShapeIndex
), uno::UNO_QUERY
);
50 CPPUNIT_ASSERT_MESSAGE("Could not get xShape", xShape
.is());
54 CPPUNIT_TEST_FIXTURE(ClassicshapesTest
, testTdf98584ShearVertical
)
56 // The document contains draw:rect, draw:polygon and draw:path objects.
57 // They are vertical sheared by skewY(-0.927295218002) or by matrix(1 2 0 1 1cm 1cm).
58 // Notice, skewY and matrix are interpreted on file open, but not written on file save.
59 // They are converted to rotate * shear horizontal * scale.
60 // Besides using a wrong sign in shear angle, error was, that TRSetGeometry of SdrPathObj did
61 // not consider the additional scaling (tdf#98565).
62 loadFromURL(u
"tdf98584_ShearVertical.odg");
65 for (sal_uInt8 nPageIndex
= 0; nPageIndex
< 3; ++nPageIndex
)
67 awt::Rectangle aFrameRect
;
68 uno::Reference
<drawing::XShape
> xShape(getShape(0, nPageIndex
));
69 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
70 CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps
.is());
71 xShapeProps
->getPropertyValue(UNO_NAME_MISC_OBJ_FRAMERECT
) >>= aFrameRect
;
72 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
73 OUString("Incorrect Width on skewY page " + OUString::number(nPageIndex
))
76 5001.0, aFrameRect
.Width
, 2.0);
78 CPPUNIT_ASSERT(xShapeProps
->getPropertyValue(UNO_NAME_MISC_OBJ_SHEARANGLE
) >>= nShearA
);
79 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
80 OUString("Incorrect Share angle on skewY page " + OUString::number(nPageIndex
))
83 -5313.0, nShearA
, 2.0);
85 CPPUNIT_ASSERT(xShapeProps
->getPropertyValue(UNO_NAME_MISC_OBJ_ROTATEANGLE
) >>= nRotA
);
86 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
87 OUString("Incorrect Rotate angle on skewY page " + OUString::number(nPageIndex
))
94 for (sal_uInt8 nPageIndex
= 3; nPageIndex
< 6; ++nPageIndex
)
96 awt::Rectangle aFrameRect
;
97 uno::Reference
<drawing::XShape
> xShape(getShape(0, nPageIndex
));
98 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
99 CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps
.is());
100 xShapeProps
->getPropertyValue(UNO_NAME_MISC_OBJ_FRAMERECT
) >>= aFrameRect
;
101 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
102 OUString("Incorrect Width on matrix page " + OUString::number(nPageIndex
))
105 5001.0, aFrameRect
.Width
, 2.0);
107 CPPUNIT_ASSERT(xShapeProps
->getPropertyValue(UNO_NAME_MISC_OBJ_SHEARANGLE
) >>= nShearA
);
108 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
109 OUString("Incorrect Share angle on matrix page " + OUString::number(nPageIndex
))
112 -6343.0, nShearA
, 2.0);
114 CPPUNIT_ASSERT(xShapeProps
->getPropertyValue(UNO_NAME_MISC_OBJ_ROTATEANGLE
) >>= nRotA
);
115 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
116 OUString("Incorrect Rotate angle on matrix page " + OUString::number(nPageIndex
))
119 29657.0, nRotA
, 2.0);
123 CPPUNIT_TEST_FIXTURE(ClassicshapesTest
, testTdf98583ShearHorizontal
)
125 // The document contains rectangles with LT 3000,5000 and RB 5000,9000.
126 // skewX (-0.78539816339744830961) = skewX(-45deg) is applied on the first page
127 // matrix(1 0 1 1 0cm 0cm) on the second page. Both should result in a parallelogram with
128 // LT 8000,5000 and RB 14000, 9000, which means width 6001, height 4001.
129 // Error was, that not the mathematical matrix was used, but the API matrix, which has
130 // wrong sign in shear angle.
131 loadFromURL(u
"tdf98583_ShearHorizontal.odp");
133 for (sal_uInt8 nPageIndex
= 0; nPageIndex
< 2; ++nPageIndex
)
135 awt::Rectangle aFrameRect
;
136 uno::Reference
<drawing::XShape
> xShape(getShape(0, nPageIndex
));
137 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
138 CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps
.is());
139 xShapeProps
->getPropertyValue(UNO_NAME_MISC_OBJ_FRAMERECT
) >>= aFrameRect
;
141 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
142 OUString("Incorrect Left Position on page " + OUString::number(nPageIndex
))
145 8000.0, aFrameRect
.X
, 2.0);
146 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
147 OUString("Incorrect Top Position on page " + OUString::number(nPageIndex
))
150 5000.0, aFrameRect
.Y
, 2.0);
151 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
152 OUString("Incorrect Width on page " + OUString::number(nPageIndex
)).toUtf8().getStr(),
153 6001.0, aFrameRect
.Width
, 2.0);
154 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
155 OUString("Incorrect Height on page " + OUString::number(nPageIndex
)).toUtf8().getStr(),
156 4001.0, aFrameRect
.Height
, 2.0);
160 CPPUNIT_TEST_FIXTURE(ClassicshapesTest
, testTdf130076Flip
)
162 // The document contains sections of a circle, one of which is scaled
163 // (1, -1), one of which is scaled (-1,1), one of which is transformed
164 // by a matrix equivalent to a vertical flip, and another which is
165 // transformed by a matrix equivalent to a horizontal flip. Error was
166 // that the transformation was made before the CircleKind was set,
167 // resulting in the flip being performed incorrectly.
168 loadFromURL(u
"tdf130076_FlipOnSectorSection.odg");
170 for (sal_uInt8 nPageIndex
= 0; nPageIndex
< 2; ++nPageIndex
)
172 double nAngle1(0.0), nAngle2(0.0);
173 uno::Reference
<drawing::XShape
> xShape(getShape(1, nPageIndex
));
174 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
175 uno::Reference
<drawing::XShape
> xShape2(getShape(2, nPageIndex
));
176 uno::Reference
<beans::XPropertySet
> xShapeProps2(xShape2
, uno::UNO_QUERY
);
177 CPPUNIT_ASSERT(xShapeProps
->getPropertyValue("CircleStartAngle") >>= nAngle1
);
178 CPPUNIT_ASSERT(xShapeProps2
->getPropertyValue("CircleStartAngle") >>= nAngle2
);
179 CPPUNIT_ASSERT_EQUAL_MESSAGE(OUString("Incorrect vertical flip starting angle on page "
180 + OUString::number(nPageIndex
))
184 CPPUNIT_ASSERT_EQUAL_MESSAGE(OUString("Incorrect horizontal flip starting angle on page "
185 + OUString::number(nPageIndex
))
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */