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 <sal/config.h>
12 #include <test/unoapi_test.hxx>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/drawing/LineStyle.hpp>
16 #include <com/sun/star/drawing/PointSequence.hpp>
17 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
18 #include <com/sun/star/drawing/PolygonKind.hpp>
19 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
20 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
21 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/drawing/ColorMode.hpp>
25 using namespace ::com::sun::star
;
28 class OoxVmlTest
: public UnoApiTest
32 : UnoApiTest("/oox/qa/unit/data/")
37 CPPUNIT_TEST_FIXTURE(OoxVmlTest
, tdf112450_vml_polyline
)
39 // Load a document with v:polyline shapes. Error was, that the size was set to zero and the
40 // points were zero because of missing decode from length with unit.
41 loadFromURL(u
"tdf112450_vml_polyline.docx");
42 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
43 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
46 // This tests a polyline shape which is not closed.
47 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
48 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
49 // Without fix in place, Geometry had 2 points, both 0|0.
50 drawing::PointSequenceSequence aGeometry
;
51 xShapeProps
->getPropertyValue("Geometry") >>= aGeometry
;
52 drawing::PointSequence aPolygon
= aGeometry
[0];
53 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6879), aPolygon
[3].X
, 1);
54 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(487), aPolygon
[3].Y
, 1);
55 // Without fix in place, width and height were zero
56 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6879), xShape
->getSize().Width
, 1);
57 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1926), xShape
->getSize().Height
, 1);
58 // After the fix the shape has still to be PolygonKind_PLIN
59 drawing::PolygonKind ePolygonKind
;
60 xShapeProps
->getPropertyValue("PolygonKind") >>= ePolygonKind
;
61 CPPUNIT_ASSERT_EQUAL(drawing::PolygonKind_PLIN
, ePolygonKind
);
64 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(1), uno::UNO_QUERY
);
65 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
66 // Without fix in place, Geometry had 2 points, both 0|0.
67 drawing::PointSequenceSequence aGeometry
;
68 xShapeProps
->getPropertyValue("Geometry") >>= aGeometry
;
69 drawing::PointSequence aPolygon
= aGeometry
[0];
70 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(5062), aPolygon
[2].X
, 1);
71 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(2247), aPolygon
[2].Y
, 1);
72 // Without fix in place, width and height were zero
73 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6163), xShape
->getSize().Width
, 1);
74 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(2247), xShape
->getSize().Height
, 1);
75 // Without fix in place the shape was not closed, it had PolygonKind_PLIN
76 drawing::PolygonKind ePolygonKind
;
77 xShapeProps
->getPropertyValue("PolygonKind") >>= ePolygonKind
;
78 CPPUNIT_ASSERT_EQUAL(drawing::PolygonKind_POLY
, ePolygonKind
);
81 // This tests a filled shape where v:polyline does not have attribute coordsize
82 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(2), uno::UNO_QUERY
);
83 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
84 // Without fix in place, Geometry had 2 points, both 0|0.
85 drawing::PointSequenceSequence aGeometry
;
86 xShapeProps
->getPropertyValue("Geometry") >>= aGeometry
;
87 drawing::PointSequence aPolygon
= aGeometry
[0];
88 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(2095), aPolygon
[3].X
, 1);
89 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(608), aPolygon
[3].Y
, 1);
90 // Without fix in place, width and height were zero
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(5634), xShape
->getSize().Width
, 1);
92 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(2485), xShape
->getSize().Height
, 1);
93 // Without fix in place the shape was not closed, it had PolygonKind_PLIN
94 drawing::PolygonKind ePolygonKind
;
95 xShapeProps
->getPropertyValue("PolygonKind") >>= ePolygonKind
;
96 CPPUNIT_ASSERT_EQUAL(drawing::PolygonKind_POLY
, ePolygonKind
);
100 CPPUNIT_TEST_FIXTURE(OoxVmlTest
, tdf137314_vml_rotation_unit_fd
)
102 // Load a document with a 30deg rotated arc on a drawing canvas. Rotation is given
103 // as 1966080fd. Error was, that the vml angle unit "fd" was not converted to Degree100.
104 loadFromURL(u
"tdf137314_vml_rotation_unit_fd.docx");
105 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
106 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
108 uno::Reference
<container::XIndexAccess
> xGroup(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
109 uno::Reference
<drawing::XShape
> xShape(xGroup
->getByIndex(1), uno::UNO_QUERY
);
110 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
111 drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords
;
112 xShapeProps
->getPropertyValue("PolyPolygonBezier") >>= aPolyPolygonBezierCoords
;
113 drawing::PointSequence aPolygon
= aPolyPolygonBezierCoords
.Coordinates
[1];
114 // Without fix in place, the vector was -1441|1490.
115 // [1] and [2] are Bezier-curve control points.
116 sal_Int32 nDiffX
= aPolygon
[3].X
- aPolygon
[0].X
;
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1490), nDiffX
, 1);
118 sal_Int32 nDiffY
= aPolygon
[3].Y
- aPolygon
[0].Y
;
119 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1441), nDiffY
, 1);
122 CPPUNIT_TEST_FIXTURE(OoxVmlTest
, testSpt202ShapeType
)
124 // Load a document with a groupshape, 2nd child is a <v:shape>, its type has o:spt set to 202
126 loadFromURL(u
"group-spt202.docx");
127 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
128 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
130 uno::Reference
<container::XIndexAccess
> xGroup(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
131 uno::Reference
<drawing::XShape
> xShape(xGroup
->getByIndex(1), uno::UNO_QUERY
);
133 // Without the accompanying fix in place, this test would have failed with:
134 // - Expected: com.sun.star.drawing.TextShape
135 // - Actual : com.sun.star.drawing.CustomShape
136 // and then the size of the group shape was incorrect, e.g. its right edge was outside the page
138 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.TextShape"), xShape
->getShapeType());
141 CPPUNIT_TEST_FIXTURE(OoxVmlTest
, testShapeNonAutosizeWithText
)
143 // Load a document which has a group shape, containing a single child.
144 // 17.78 cm is the full group shape width, 19431/64008 is the child shape's relative width inside
145 // that, so 5.3975 cm should be the shape width.
146 loadFromURL(u
"shape-non-autosize-with-text.docx");
147 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
148 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
150 uno::Reference
<container::XIndexAccess
> xGroup(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
151 uno::Reference
<drawing::XShape
> xShape(xGroup
->getByIndex(0), uno::UNO_QUERY
);
152 // Without the accompanying fix in place, this test would have failed with:
155 // because the width was determined using its text size, not using the explicit size.
156 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(5398), xShape
->getSize().Width
);
159 CPPUNIT_TEST_FIXTURE(OoxVmlTest
, testGraphicStroke
)
161 loadFromURL(u
"graphic-stroke.pptx");
162 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
163 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
166 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDrawPage
->getCount());
168 uno::Reference
<beans::XPropertySet
> xShape
;
169 uno::Reference
<lang::XServiceInfo
> xInfo(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
170 if (xInfo
->supportsService("com.sun.star.drawing.OLE2Shape"))
171 xShape
.set(xInfo
, uno::UNO_QUERY
);
173 CPPUNIT_ASSERT(xShape
.is());
175 drawing::LineStyle eLineStyle
{};
176 xShape
->getPropertyValue("LineStyle") >>= eLineStyle
;
177 // Without the accompanying fix in place, this test would have failed with:
180 // i.e. line style was NONE, not SOLID.
181 CPPUNIT_ASSERT_EQUAL(drawing::LineStyle_SOLID
, eLineStyle
);
184 CPPUNIT_TEST_FIXTURE(OoxVmlTest
, testWatermark
)
186 // Given a document with a picture watermark, and the "washout" checkbox is ticked on the Word
188 // When loading that document:
189 loadFromURL(u
"watermark.docx");
191 // Then make sure the watermark effect is not lost on import:
192 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
193 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
195 uno::Reference
<beans::XPropertySet
> xShape(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
196 drawing::ColorMode eMode
{};
197 xShape
->getPropertyValue("GraphicColorMode") >>= eMode
;
198 // Without the accompanying fix in place, this test would have failed with:
201 // i.e. the color mode was STANDARD, not WATERMARK.
202 CPPUNIT_ASSERT_EQUAL(drawing::ColorMode_WATERMARK
, eMode
);
205 CPPUNIT_TEST_FIXTURE(OoxVmlTest
, testWriterFontworkTrimTrue
)
207 // The document contains a shape, that will be exported as VML shape to docx. Error was that the
208 // attribute trim was not written out and thus import had treated it as the default 'false' and
209 // had reduced the shape height.
210 loadFromURL(u
"tdf153260_VML_trim_export.odt");
212 // FIXME: tdf#153183 validation error in OOXML export: Errors: 1
213 // Attribute 'ID' is not allowed to appear in element 'v:shape'.
215 saveAndReload("Office Open XML Text");
217 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
218 uno::Reference
<drawing::XShape
> xShape(xDrawPageSupplier
->getDrawPage()->getByIndex(0),
221 // Make sure the shape height is not changed.
222 // Without the fix the test would have failed with expected 4999 actual 1732.
223 awt::Size aSize
= xShape
->getSize();
224 CPPUNIT_ASSERT_DOUBLES_EQUAL(4999, aSize
.Height
, 2);
227 CPPUNIT_TEST_FIXTURE(OoxVmlTest
, testVMLDetectWordArtOnImport
)
229 // The document contains a WordArt shape with type other than "fontwork-foo". Error was that
230 // WordArt was not detected and thus shrinking shape to text content was not prevented.
231 loadFromURL(u
"tdf153258_VML_import_WordArt_detection.docx");
233 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
234 uno::Reference
<drawing::XShape
> xShape(xDrawPageSupplier
->getDrawPage()->getByIndex(0),
237 // Make sure the shape width and height is not changed.
238 awt::Size aSize
= xShape
->getSize();
239 // Without the fix the test would have failed with expected 7514 actual 1453.
240 CPPUNIT_ASSERT_DOUBLES_EQUAL(7514, aSize
.Width
, 2);
241 // Without the fix the test would have failed with expected 4540 actual 309.
242 CPPUNIT_ASSERT_DOUBLES_EQUAL(4540, aSize
.Height
, 2);
245 CPPUNIT_PLUGIN_IMPLEMENT();
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */