tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / svx / qa / unit / classicshapes.cxx
blob07a4b9f916ab6378abfd32855e860ae4f608481e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
21 using namespace ::com::sun::star;
23 namespace
25 /// Tests not about special features of custom shapes, but about shapes in general.
26 class ClassicshapesTest : public UnoApiTest
28 public:
29 ClassicshapesTest()
30 : UnoApiTest(u"svx/qa/unit/data/"_ustr)
34 protected:
35 uno::Reference<drawing::XShape> getShape(sal_uInt8 nShapeIndex, sal_uInt8 nPageIndex);
38 uno::Reference<drawing::XShape> ClassicshapesTest::getShape(sal_uInt8 nShapeIndex,
39 sal_uInt8 nPageIndex)
41 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
42 uno::UNO_QUERY_THROW);
43 CPPUNIT_ASSERT_MESSAGE("Could not get XDrawPagesSupplier", xDrawPagesSupplier.is());
44 uno::Reference<drawing::XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages());
45 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(nPageIndex),
46 uno::UNO_QUERY_THROW);
47 CPPUNIT_ASSERT_MESSAGE("Could not get xDrawPage", xDrawPage.is());
48 uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(nShapeIndex), uno::UNO_QUERY);
49 CPPUNIT_ASSERT_MESSAGE("Could not get xShape", xShape.is());
50 return xShape;
53 CPPUNIT_TEST_FIXTURE(ClassicshapesTest, testTdf98584ShearVertical)
55 // The document contains draw:rect, draw:polygon and draw:path objects.
56 // They are vertical sheared by skewY(-0.927295218002) or by matrix(1 2 0 1 1cm 1cm).
57 // Notice, skewY and matrix are interpreted on file open, but not written on file save.
58 // They are converted to rotate * shear horizontal * scale.
59 // Besides using a wrong sign in shear angle, error was, that TRSetGeometry of SdrPathObj did
60 // not consider the additional scaling (tdf#98565).
61 loadFromFile(u"tdf98584_ShearVertical.odg");
63 // Tests skewY
64 for (sal_uInt8 nPageIndex = 0; nPageIndex < 3; ++nPageIndex)
66 awt::Rectangle aFrameRect;
67 uno::Reference<drawing::XShape> xShape(getShape(0, nPageIndex));
68 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
69 CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps.is());
70 xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_FRAMERECT) >>= aFrameRect;
71 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
72 OUString("Incorrect Width on skewY page " + OUString::number(nPageIndex))
73 .toUtf8()
74 .getStr(),
75 5001.0, aFrameRect.Width, 2.0);
76 double nShearA = {};
77 CPPUNIT_ASSERT(xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_SHEARANGLE) >>= nShearA);
78 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
79 OUString("Incorrect Share angle on skewY page " + OUString::number(nPageIndex))
80 .toUtf8()
81 .getStr(),
82 -5313.0, nShearA, 2.0);
83 double nRotA = {};
84 CPPUNIT_ASSERT(xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_ROTATEANGLE) >>= nRotA);
85 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
86 OUString("Incorrect Rotate angle on skewY page " + OUString::number(nPageIndex))
87 .toUtf8()
88 .getStr(),
89 30687.0, nRotA, 2.0);
92 // Tests matrix
93 for (sal_uInt8 nPageIndex = 3; nPageIndex < 6; ++nPageIndex)
95 awt::Rectangle aFrameRect;
96 uno::Reference<drawing::XShape> xShape(getShape(0, nPageIndex));
97 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
98 CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps.is());
99 xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_FRAMERECT) >>= aFrameRect;
100 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
101 OUString("Incorrect Width on matrix page " + OUString::number(nPageIndex))
102 .toUtf8()
103 .getStr(),
104 5001.0, aFrameRect.Width, 2.0);
105 double nShearA = {};
106 CPPUNIT_ASSERT(xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_SHEARANGLE) >>= nShearA);
107 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
108 OUString("Incorrect Share angle on matrix page " + OUString::number(nPageIndex))
109 .toUtf8()
110 .getStr(),
111 -6343.0, nShearA, 2.0);
112 double nRotA = {};
113 CPPUNIT_ASSERT(xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_ROTATEANGLE) >>= nRotA);
114 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
115 OUString("Incorrect Rotate angle on matrix page " + OUString::number(nPageIndex))
116 .toUtf8()
117 .getStr(),
118 29657.0, nRotA, 2.0);
122 CPPUNIT_TEST_FIXTURE(ClassicshapesTest, testTdf98583ShearHorizontal)
124 // The document contains rectangles with LT 3000,5000 and RB 5000,9000.
125 // skewX (-0.78539816339744830961) = skewX(-45deg) is applied on the first page
126 // matrix(1 0 1 1 0cm 0cm) on the second page. Both should result in a parallelogram with
127 // LT 8000,5000 and RB 14000, 9000, which means width 6001, height 4001.
128 // Error was, that not the mathematical matrix was used, but the API matrix, which has
129 // wrong sign in shear angle.
130 loadFromFile(u"tdf98583_ShearHorizontal.odp");
132 for (sal_uInt8 nPageIndex = 0; nPageIndex < 2; ++nPageIndex)
134 awt::Rectangle aFrameRect;
135 uno::Reference<drawing::XShape> xShape(getShape(0, nPageIndex));
136 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
137 CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps.is());
138 xShapeProps->getPropertyValue(UNO_NAME_MISC_OBJ_FRAMERECT) >>= aFrameRect;
140 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
141 OUString("Incorrect Left Position on page " + OUString::number(nPageIndex))
142 .toUtf8()
143 .getStr(),
144 8000.0, aFrameRect.X, 2.0);
145 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
146 OUString("Incorrect Top Position on page " + OUString::number(nPageIndex))
147 .toUtf8()
148 .getStr(),
149 5000.0, aFrameRect.Y, 2.0);
150 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
151 OUString("Incorrect Width on page " + OUString::number(nPageIndex)).toUtf8().getStr(),
152 6001.0, aFrameRect.Width, 2.0);
153 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
154 OUString("Incorrect Height on page " + OUString::number(nPageIndex)).toUtf8().getStr(),
155 4001.0, aFrameRect.Height, 2.0);
159 CPPUNIT_TEST_FIXTURE(ClassicshapesTest, testTdf130076Flip)
161 // The document contains sections of a circle, one of which is scaled
162 // (1, -1), one of which is scaled (-1,1), one of which is transformed
163 // by a matrix equivalent to a vertical flip, and another which is
164 // transformed by a matrix equivalent to a horizontal flip. Error was
165 // that the transformation was made before the CircleKind was set,
166 // resulting in the flip being performed incorrectly.
167 loadFromFile(u"tdf130076_FlipOnSectorSection.odg");
169 for (sal_uInt8 nPageIndex = 0; nPageIndex < 2; ++nPageIndex)
171 double nAngle1(0.0), nAngle2(0.0);
172 uno::Reference<drawing::XShape> xShape(getShape(1, nPageIndex));
173 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
174 uno::Reference<drawing::XShape> xShape2(getShape(2, nPageIndex));
175 uno::Reference<beans::XPropertySet> xShapeProps2(xShape2, uno::UNO_QUERY);
176 CPPUNIT_ASSERT(xShapeProps->getPropertyValue(u"CircleStartAngle"_ustr) >>= nAngle1);
177 CPPUNIT_ASSERT(xShapeProps2->getPropertyValue(u"CircleStartAngle"_ustr) >>= nAngle2);
178 CPPUNIT_ASSERT_EQUAL_MESSAGE(OUString("Incorrect vertical flip starting angle on page "
179 + OUString::number(nPageIndex))
180 .toUtf8()
181 .getStr(),
182 26000.0, nAngle1);
183 CPPUNIT_ASSERT_EQUAL_MESSAGE(OUString("Incorrect horizontal flip starting angle on page "
184 + OUString::number(nPageIndex))
185 .toUtf8()
186 .getStr(),
187 26000.0, nAngle2);
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */