VML import: handle <v:imagedata gain="..." blacklevel="...">
[LibreOffice.git] / oox / qa / unit / vml.cxx
blob680e55fb093a2a5e53f7169832ee4c01dd1c33ce
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/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/drawing/LineStyle.hpp>
15 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
16 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
17 #include <com/sun/star/frame/Desktop.hpp>
18 #include <com/sun/star/lang/XServiceInfo.hpp>
19 #include <com/sun/star/text/WritingMode2.hpp>
20 #include <com/sun/star/drawing/ColorMode.hpp>
22 using namespace ::com::sun::star;
24 char const DATA_DIRECTORY[] = "/oox/qa/unit/data/";
26 /// oox vml tests.
27 class OoxVmlTest : public test::BootstrapFixture, public unotest::MacrosTest
29 private:
30 uno::Reference<lang::XComponent> mxComponent;
32 public:
33 void setUp() override;
34 void tearDown() override;
35 uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
36 void load(const OUString& rURL);
39 void OoxVmlTest::setUp()
41 test::BootstrapFixture::setUp();
43 mxDesktop.set(frame::Desktop::create(mxComponentContext));
46 void OoxVmlTest::tearDown()
48 if (mxComponent.is())
49 mxComponent->dispose();
51 test::BootstrapFixture::tearDown();
54 void OoxVmlTest::load(const OUString& rFileName)
56 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFileName;
57 mxComponent = loadFromDesktop(aURL);
60 CPPUNIT_TEST_FIXTURE(OoxVmlTest, tdf137314_vml_rotation_unit_fd)
62 // Load a document with a 30deg rotated arc on a drawing canvas. Rotation is given
63 // as 1966080fd. Error was, that the vml angle unit "fd" was not converted to Degree100.
64 load(u"tdf137314_vml_rotation_unit_fd.docx");
65 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
66 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
67 uno::UNO_QUERY);
68 uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY);
69 uno::Reference<drawing::XShape> xShape(xGroup->getByIndex(1), uno::UNO_QUERY);
70 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
71 drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords;
72 xShapeProps->getPropertyValue("PolyPolygonBezier") >>= aPolyPolygonBezierCoords;
73 drawing::PointSequence aPolygon = aPolyPolygonBezierCoords.Coordinates[1];
74 // Without fix in place, the vector was -1441|1490.
75 // [1] and [2] are Bezier-curve control points.
76 sal_Int32 nDiffX = aPolygon[3].X - aPolygon[0].X;
77 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1490), nDiffX, 1);
78 sal_Int32 nDiffY = aPolygon[3].Y - aPolygon[0].Y;
79 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1441), nDiffY, 1);
82 CPPUNIT_TEST_FIXTURE(OoxVmlTest, testSpt202ShapeType)
84 // Load a document with a groupshape, 2nd child is a <v:shape>, its type has o:spt set to 202
85 // (TextBox).
86 load("group-spt202.docx");
87 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
88 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
89 uno::UNO_QUERY);
90 uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY);
91 uno::Reference<drawing::XShape> xShape(xGroup->getByIndex(1), uno::UNO_QUERY);
93 // Without the accompanying fix in place, this test would have failed with:
94 // - Expected: com.sun.star.drawing.TextShape
95 // - Actual : com.sun.star.drawing.CustomShape
96 // and then the size of the group shape was incorrect, e.g. its right edge was outside the page
97 // boundaries.
98 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.TextShape"), xShape->getShapeType());
101 CPPUNIT_TEST_FIXTURE(OoxVmlTest, testShapeNonAutosizeWithText)
103 // Load a document which has a group shape, containing a single child.
104 // 17.78 cm is the full group shape width, 19431/64008 is the child shape's relative width inside
105 // that, so 5.3975 cm should be the shape width.
106 load("shape-non-autosize-with-text.docx");
107 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
108 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
109 uno::UNO_QUERY);
110 uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY);
111 uno::Reference<drawing::XShape> xShape(xGroup->getByIndex(0), uno::UNO_QUERY);
112 // Without the accompanying fix in place, this test would have failed with:
113 // - Actual : 1115
114 // - Expected: 5398
115 // because the width was determined using its text size, not using the explicit size.
116 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5398), xShape->getSize().Width);
119 CPPUNIT_TEST_FIXTURE(OoxVmlTest, testGraphicStroke)
121 load("graphic-stroke.pptx");
122 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
123 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
124 uno::UNO_QUERY);
126 uno::Reference<beans::XPropertySet> xShape;
127 for (sal_Int32 i = 0; i < xDrawPage->getCount(); ++i)
129 uno::Reference<lang::XServiceInfo> xInfo(xDrawPage->getByIndex(i), uno::UNO_QUERY);
130 if (!xInfo->supportsService("com.sun.star.drawing.GraphicObjectShape"))
132 continue;
135 xShape.set(xInfo, uno::UNO_QUERY);
136 break;
138 CPPUNIT_ASSERT(xShape.is());
140 drawing::LineStyle eLineStyle{};
141 xShape->getPropertyValue("LineStyle") >>= eLineStyle;
142 // Without the accompanying fix in place, this test would have failed with:
143 // - Expected: 1
144 // - Actual : 0
145 // i.e. line style was NONE, not SOLID.
146 CPPUNIT_ASSERT_EQUAL(drawing::LineStyle_SOLID, eLineStyle);
149 CPPUNIT_TEST_FIXTURE(OoxVmlTest, testWatermark)
151 // Given a document with a picture watermark, and the "washout" checkbox is ticked on the Word
152 // UI:
153 // When loading that document:
154 load(u"watermark.docx");
156 // Then make sure the watermark effect is not lost on import:
157 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
158 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
159 uno::UNO_QUERY);
160 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
161 drawing::ColorMode eMode{};
162 xShape->getPropertyValue("GraphicColorMode") >>= eMode;
163 // Without the accompanying fix in place, this test would have failed with:
164 // - Expected: 3
165 // - Actual : 0
166 // i.e. the color mode was STANDARD, not WATERMARK.
167 CPPUNIT_ASSERT_EQUAL(drawing::ColorMode_WATERMARK, eMode);
170 CPPUNIT_PLUGIN_IMPLEMENT();
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */