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/unoapixml_test.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
14 #include <com/sun/star/drawing/XDrawPage.hpp>
15 #include <com/sun/star/text/XTextRange.hpp>
16 #include <com/sun/star/drawing/FillStyle.hpp>
17 #include <com/sun/star/drawing/LineStyle.hpp>
18 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
19 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
21 #include <drawinglayer/tools/primitive2dxmldump.hxx>
22 #include <rtl/ustring.hxx>
23 #include <vcl/virdev.hxx>
24 #include <svx/sdr/contact/displayinfo.hxx>
25 #include <svx/sdr/contact/viewcontact.hxx>
26 #include <svx/sdr/contact/viewobjectcontact.hxx>
27 #include <svx/svdtrans.hxx>
28 #include <svx/svdorect.hxx>
29 #include <svx/unopage.hxx>
30 #include <svx/svdview.hxx>
31 #include <svx/xlineit0.hxx>
32 #include <svx/xlnstwit.hxx>
33 #include <comphelper/propertyvalue.hxx>
34 #include <sfx2/viewsh.hxx>
35 #include <svl/itempool.hxx>
36 #include <svx/svdomedia.hxx>
37 #include <vcl/filter/PDFiumLibrary.hxx>
39 #include <sdr/contact/objectcontactofobjlistpainter.hxx>
41 using namespace ::com::sun::star
;
45 /// Tests for svx/source/svdraw/ code.
46 class SvdrawTest
: public UnoApiXmlTest
50 : UnoApiXmlTest("svx/qa/unit/data/")
55 SdrPage
* getFirstDrawPageWithAssert();
58 SdrPage
* SvdrawTest::getFirstDrawPageWithAssert()
60 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
,
61 uno::UNO_QUERY_THROW
);
62 CPPUNIT_ASSERT(xDrawPagesSupplier
.is());
63 uno::Reference
<drawing::XDrawPages
> xDrawPages(xDrawPagesSupplier
->getDrawPages());
64 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPages
->getByIndex(0), uno::UNO_QUERY_THROW
);
65 CPPUNIT_ASSERT(xDrawPage
.is());
67 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
68 CPPUNIT_ASSERT(pDrawPage
);
69 return pDrawPage
->GetSdrPage();
72 xmlDocUniquePtr
lcl_dumpAndParseFirstObjectWithAssert(SdrPage
* pSdrPage
)
74 ScopedVclPtrInstance
<VirtualDevice
> aVirtualDevice
;
75 sdr::contact::ObjectContactOfObjListPainter
aObjectContact(*aVirtualDevice
,
76 { pSdrPage
->GetObj(0) }, nullptr);
77 const auto& rDrawPageVOContact
78 = pSdrPage
->GetViewContact().GetViewObjectContact(aObjectContact
);
79 sdr::contact::DisplayInfo aDisplayInfo
;
80 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
;
81 rDrawPageVOContact
.getPrimitive2DSequenceHierarchy(aDisplayInfo
, xPrimitiveSequence
);
83 drawinglayer::Primitive2dXmlDump aDumper
;
84 xmlDocUniquePtr pXmlDoc
= aDumper
.dumpAndParse(xPrimitiveSequence
);
85 CPPUNIT_ASSERT(pXmlDoc
);
89 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testSemiTransparentText
)
91 // Create a new Draw document with a rectangle.
92 mxComponent
= loadFromDesktop("private:factory/sdraw");
93 uno::Reference
<lang::XMultiServiceFactory
> xFactory(mxComponent
, uno::UNO_QUERY
);
94 uno::Reference
<drawing::XShape
> xShape(
95 xFactory
->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY
);
96 xShape
->setSize(awt::Size(10000, 10000));
97 xShape
->setPosition(awt::Point(1000, 1000));
99 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
100 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
102 xDrawPage
->add(xShape
);
104 // Add semi-transparent text on the rectangle.
105 uno::Reference
<text::XTextRange
> xShapeText(xShape
, uno::UNO_QUERY
);
106 xShapeText
->getText()->setString("hello");
108 uno::Reference
<beans::XPropertySet
> xShapeProperties(xShape
, uno::UNO_QUERY
);
109 xShapeProperties
->setPropertyValue("CharColor", uno::Any(COL_RED
));
110 sal_Int16 nTransparence
= 75;
111 xShapeProperties
->setPropertyValue("CharTransparence", uno::Any(nTransparence
));
113 // Generates drawinglayer primitives for the page.
114 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
115 CPPUNIT_ASSERT(pDrawPage
);
116 SdrPage
* pSdrPage
= pDrawPage
->GetSdrPage();
117 xmlDocUniquePtr pDocument
= lcl_dumpAndParseFirstObjectWithAssert(pSdrPage
);
119 // Make sure the text is semi-transparent.
120 // Without the accompanying fix in place, this test would have failed with:
123 // - XPath '//unifiedtransparence' number of nodes is incorrect
124 // i.e. the text was just plain red, not semi-transparent.
125 sal_Int16 fTransparence
126 = getXPath(pDocument
, "//unifiedtransparence", "transparence").toInt32();
127 CPPUNIT_ASSERT_EQUAL(nTransparence
, fTransparence
);
130 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testHandlePathObjScale
)
132 // Given a path object:
133 mxComponent
= loadFromDesktop("private:factory/sdraw");
134 uno::Reference
<lang::XMultiServiceFactory
> xFactory(mxComponent
, uno::UNO_QUERY
);
135 uno::Reference
<drawing::XShape
> xShape(
136 xFactory
->createInstance("com.sun.star.drawing.ClosedBezierShape"), uno::UNO_QUERY
);
138 // When setting its scale by both using setSize() and scaling in a transform matrix:
139 // Set size and basic properties.
140 xShape
->setPosition(awt::Point(2512, 6062));
141 xShape
->setSize(awt::Size(112, 112));
142 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
143 xShapeProps
->setPropertyValue("FillStyle", uno::Any(drawing::FillStyle_SOLID
));
144 xShapeProps
->setPropertyValue("LineStyle", uno::Any(drawing::LineStyle_SOLID
));
145 xShapeProps
->setPropertyValue("FillColor", uno::Any(static_cast<sal_Int32
>(0)));
146 // Add it to the draw page.
147 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
148 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
150 xDrawPage
->add(xShape
);
151 // Set polygon coordinates.
152 drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords
;
153 aPolyPolygonBezierCoords
.Coordinates
= {
155 awt::Point(2624, 6118),
156 awt::Point(2624, 6087),
157 awt::Point(2599, 6062),
158 awt::Point(2568, 6062),
159 awt::Point(2537, 6062),
160 awt::Point(2512, 6087),
161 awt::Point(2512, 6118),
162 awt::Point(2512, 6149),
163 awt::Point(2537, 6175),
164 awt::Point(2568, 6174),
165 awt::Point(2599, 6174),
166 awt::Point(2625, 6149),
167 awt::Point(2624, 6118),
170 aPolyPolygonBezierCoords
.Flags
= {
172 drawing::PolygonFlags_NORMAL
,
173 drawing::PolygonFlags_CONTROL
,
174 drawing::PolygonFlags_CONTROL
,
175 drawing::PolygonFlags_NORMAL
,
176 drawing::PolygonFlags_CONTROL
,
177 drawing::PolygonFlags_CONTROL
,
178 drawing::PolygonFlags_NORMAL
,
179 drawing::PolygonFlags_CONTROL
,
180 drawing::PolygonFlags_CONTROL
,
181 drawing::PolygonFlags_NORMAL
,
182 drawing::PolygonFlags_CONTROL
,
183 drawing::PolygonFlags_CONTROL
,
184 drawing::PolygonFlags_NORMAL
,
187 xShapeProps
->setPropertyValue("PolyPolygonBezier", uno::Any(aPolyPolygonBezierCoords
));
188 drawing::HomogenMatrix3 aMatrix
;
189 aMatrix
.Line1
.Column1
= 56;
190 aMatrix
.Line2
.Column1
= -97;
191 aMatrix
.Line3
.Column1
= 0;
192 aMatrix
.Line1
.Column2
= 97;
193 aMatrix
.Line2
.Column2
= 56;
194 aMatrix
.Line3
.Column2
= 0;
195 aMatrix
.Line1
.Column3
= 3317;
196 aMatrix
.Line2
.Column3
= 5583;
197 aMatrix
.Line3
.Column3
= 1;
198 xShapeProps
->setPropertyValue("Transformation", uno::Any(aMatrix
));
200 // Then make sure the scaling is only applied once:
201 // Without the accompanying fix in place, this test would have failed with:
204 // i.e. the scaling was applied twice.
205 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(113), xShape
->getSize().Width
);
208 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testTextEditEmptyGrabBag
)
210 // Given a document with a groupshape, which has 2 children.
211 mxComponent
= loadFromDesktop("private:factory/sdraw");
212 uno::Reference
<lang::XMultiServiceFactory
> xFactory(mxComponent
, uno::UNO_QUERY
);
213 uno::Reference
<drawing::XShape
> xRect1(
214 xFactory
->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY
);
215 xRect1
->setPosition(awt::Point(1000, 1000));
216 xRect1
->setSize(awt::Size(10000, 10000));
217 uno::Reference
<drawing::XShape
> xRect2(
218 xFactory
->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY
);
219 xRect2
->setPosition(awt::Point(1000, 1000));
220 xRect2
->setSize(awt::Size(10000, 10000));
221 uno::Reference
<drawing::XShapes
> xGroup(
222 xFactory
->createInstance("com.sun.star.drawing.GroupShape"), uno::UNO_QUERY
);
223 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
224 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
226 uno::Reference
<drawing::XShape
> xGroupShape(xGroup
, uno::UNO_QUERY
);
227 xDrawPage
->add(xGroupShape
);
230 uno::Reference
<text::XTextRange
> xRect2Text(xRect2
, uno::UNO_QUERY
);
231 xRect2Text
->setString("x");
232 uno::Sequence
<beans::PropertyValue
> aGrabBag
= {
233 comphelper::makePropertyValue("OOXLayout", true),
235 uno::Reference
<beans::XPropertySet
> xGroupProps(xGroup
, uno::UNO_QUERY
);
236 xGroupProps
->setPropertyValue("InteropGrabBag", uno::Any(aGrabBag
));
238 // When editing the shape text of the 2nd rectangle (insert a char at the start).
239 SfxViewShell
* pViewShell
= SfxViewShell::Current();
240 SdrView
* pSdrView
= pViewShell
->GetDrawView();
241 SdrObject
* pObject
= SdrObject::getSdrObjectFromXShape(xRect2
);
242 pSdrView
->SdrBeginTextEdit(pObject
);
243 EditView
& rEditView
= pSdrView
->GetTextEditOutlinerView()->GetEditView();
244 rEditView
.InsertText("y");
245 pSdrView
->SdrEndTextEdit();
247 // Then make sure that grab-bag is empty to avoid losing the new text.
248 xGroupProps
->getPropertyValue("InteropGrabBag") >>= aGrabBag
;
249 // Without the accompanying fix in place, this test would have failed with:
251 // - Expression: !aGrabBag.hasElements()
252 // i.e. the grab-bag was still around after modifying the shape, and that grab-bag contained the
254 CPPUNIT_ASSERT(!aGrabBag
.hasElements());
257 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testRectangleObject
)
259 std::unique_ptr
<SdrModel
> pModel(new SdrModel(nullptr, nullptr, true));
260 pModel
->GetItemPool().FreezeIdRanges();
262 rtl::Reference
<SdrPage
> pPage(new SdrPage(*pModel
, false));
263 pPage
->SetSize(Size(1000, 1000));
264 pModel
->InsertPage(pPage
.get(), 0);
266 tools::Rectangle
aSize(Point(), Size(100, 100));
267 rtl::Reference
<SdrRectObj
> pRectangle
= new SdrRectObj(*pModel
, aSize
);
268 pPage
->NbcInsertObject(pRectangle
.get());
269 pRectangle
->SetMergedItem(XLineStyleItem(drawing::LineStyle_SOLID
));
270 pRectangle
->SetMergedItem(XLineStartWidthItem(200));
272 ScopedVclPtrInstance
<VirtualDevice
> aVirtualDevice
;
273 aVirtualDevice
->SetOutputSize(Size(2000, 2000));
275 SdrView
aView(*pModel
, aVirtualDevice
);
276 aView
.hideMarkHandles();
277 aView
.ShowSdrPage(pPage
.get());
279 sdr::contact::ObjectContactOfObjListPainter
aObjectContact(*aVirtualDevice
,
280 { pPage
->GetObj(0) }, nullptr);
281 const sdr::contact::ViewObjectContact
& rDrawPageVOContact
282 = pPage
->GetViewContact().GetViewObjectContact(aObjectContact
);
284 sdr::contact::DisplayInfo aDisplayInfo
;
285 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
;
286 rDrawPageVOContact
.getPrimitive2DSequenceHierarchy(aDisplayInfo
, xPrimitiveSequence
);
288 drawinglayer::Primitive2dXmlDump aDumper
;
289 xmlDocUniquePtr pXmlDoc
= aDumper
.dumpAndParse(xPrimitiveSequence
);
291 assertXPath(pXmlDoc
, "/primitive2D", 1);
293 OString
aBasePath("/primitive2D/sdrrectangle/polypolygoncolor");
294 assertXPath(pXmlDoc
, aBasePath
, "color", "#729fcf");
296 assertXPath(pXmlDoc
, aBasePath
+ "/polypolygon", "height",
297 "99"); // weird Rectangle is created with size 100
298 assertXPath(pXmlDoc
, aBasePath
+ "/polypolygon", "width", "99");
299 assertXPath(pXmlDoc
, aBasePath
+ "/polypolygon", "minx", "0");
300 assertXPath(pXmlDoc
, aBasePath
+ "/polypolygon", "miny", "0");
301 assertXPath(pXmlDoc
, aBasePath
+ "/polypolygon", "maxx", "99");
302 assertXPath(pXmlDoc
, aBasePath
+ "/polypolygon", "maxy", "99");
304 aBasePath
= "/primitive2D/sdrrectangle/polypolygoncolor/polypolygon/polygon";
306 assertXPath(pXmlDoc
, aBasePath
+ "/point", 5);
307 assertXPath(pXmlDoc
, aBasePath
+ "/point[1]", "x", "49.5"); // hmm, weird, why?
308 assertXPath(pXmlDoc
, aBasePath
+ "/point[1]", "y", "99");
309 assertXPath(pXmlDoc
, aBasePath
+ "/point[2]", "x", "0");
310 assertXPath(pXmlDoc
, aBasePath
+ "/point[2]", "y", "99");
311 assertXPath(pXmlDoc
, aBasePath
+ "/point[3]", "x", "0");
312 assertXPath(pXmlDoc
, aBasePath
+ "/point[3]", "y", "0");
313 assertXPath(pXmlDoc
, aBasePath
+ "/point[4]", "x", "99");
314 assertXPath(pXmlDoc
, aBasePath
+ "/point[4]", "y", "0");
315 assertXPath(pXmlDoc
, aBasePath
+ "/point[5]", "x", "99");
316 assertXPath(pXmlDoc
, aBasePath
+ "/point[5]", "y", "99");
318 aBasePath
= "/primitive2D/sdrrectangle/polygonstroke";
319 assertXPath(pXmlDoc
, aBasePath
, 1);
321 assertXPath(pXmlDoc
, aBasePath
+ "/line", "color", "#3465a4");
322 assertXPath(pXmlDoc
, aBasePath
+ "/line", "width", "0");
323 assertXPath(pXmlDoc
, aBasePath
+ "/line", "linejoin", "Round");
324 assertXPath(pXmlDoc
, aBasePath
+ "/line", "linecap", "BUTT");
326 assertXPathContent(pXmlDoc
, aBasePath
+ "/polygon", "49.5,99 0,99 0,0 99,0 99,99");
328 // If solid line, then there is no line stroke information
329 assertXPath(pXmlDoc
, aBasePath
+ "/stroke", 0);
331 pPage
->RemoveObject(0);
334 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testAutoHeightMultiColShape
)
336 // Given a document containing a shape that has:
337 // 1) automatic height (resize shape to fix text)
338 // 2) multiple columns (2)
339 loadFromURL(u
"auto-height-multi-col-shape.pptx");
341 // Make sure the in-file shape height is kept, even if nominally the shape height is
343 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
344 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
346 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
347 // Without the accompanying fix in place, this test would have failed with:
350 // i.e. the shape height was smaller than expected, leading to a 2 columns layout instead of
351 // laying out all the text in the first column.
352 // 2477601 is from slide1.xml, <a:ext cx="4229467" cy="2477601"/>.
353 CPPUNIT_ASSERT_DOUBLES_EQUAL(
354 static_cast<sal_Int32
>(o3tl::convert(2477601, o3tl::Length::emu
, o3tl::Length::mm100
)),
355 xShape
->getSize().Height
, 1);
358 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testFontWorks
)
360 loadFromURL(u
"FontWork.odg");
362 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
,
363 uno::UNO_QUERY_THROW
);
364 CPPUNIT_ASSERT(xDrawPagesSupplier
.is());
365 uno::Reference
<drawing::XDrawPages
> xDrawPages(xDrawPagesSupplier
->getDrawPages());
366 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPages
->getByIndex(0), uno::UNO_QUERY_THROW
);
367 CPPUNIT_ASSERT(xDrawPage
.is());
368 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
369 CPPUNIT_ASSERT(xShape
.is());
371 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
372 CPPUNIT_ASSERT(pDrawPage
);
373 SdrPage
* pSdrPage
= pDrawPage
->GetSdrPage();
374 xmlDocUniquePtr pXmlDoc
= lcl_dumpAndParseFirstObjectWithAssert(pSdrPage
);
376 assertXPath(pXmlDoc
, "/primitive2D", 1);
378 assertXPath(pXmlDoc
, "//scene", "projectionMode", "Perspective");
379 assertXPath(pXmlDoc
, "//scene/extrude3D[1]/fill", "color", "#ff0000");
380 assertXPath(pXmlDoc
, "//scene/extrude3D[1]/object3Dattributes/material", "color", "#ff0000");
381 // ODF default 50% is represented by Specular Intensity = 2^5. The relationship is not linear.
382 assertXPath(pXmlDoc
, "//scene/extrude3D[1]/object3Dattributes/material", "specularIntensity",
386 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testTdf148000_EOLinCurvedText
)
388 std::vector
<OUString
> aFilenames
389 = { u
"tdf148000_EOLinCurvedText.pptx", u
"tdf148000_EOLinCurvedText_New.odp",
390 u
"tdf148000_EOLinCurvedText_Legacy.odp" };
392 for (int i
= 0; i
< 3; i
++)
394 loadFromURL(aFilenames
[i
]);
396 SdrPage
* pSdrPage
= getFirstDrawPageWithAssert();
398 xmlDocUniquePtr pXmlDoc
= lcl_dumpAndParseFirstObjectWithAssert(pSdrPage
);
400 // this is a group shape, hence 2 nested objectinfo
401 OString aBasePath
= "/primitive2D/objectinfo[4]/objectinfo/unhandled/unhandled/"
402 "polypolygoncolor/polypolygon/";
404 // The text is: "O" + eop + "O" + eol + "O"
405 // It should be displayed as 3 line of text. (1 "O" letter in every line)
406 sal_Int32 nY1
= getXPath(pXmlDoc
, aBasePath
+ "polygon[1]/point[1]", "y").toInt32();
407 sal_Int32 nY2
= getXPath(pXmlDoc
, aBasePath
+ "polygon[3]/point[1]", "y").toInt32();
408 sal_Int32 nY3
= getXPath(pXmlDoc
, aBasePath
+ "polygon[5]/point[1]", "y").toInt32();
410 sal_Int32 nDiff21
= nY2
- nY1
;
411 sal_Int32 nDiff32
= nY3
- nY2
;
413 // the 2. "O" must be positioned much lower as the 1. "O". (the eop break the line)
414 CPPUNIT_ASSERT_GREATER(sal_Int32(300), nDiff21
);
417 // the 3. "O" must be positioned even lower with 1 line. (the eol must break the line as well)
418 CPPUNIT_ASSERT_LESS(sal_Int32(50), abs(nDiff32
- nDiff21
));
422 // In legacy mode, the 3. "O" must be positioned about the same high as the 2. "O"
423 // the eol not break the line.
424 CPPUNIT_ASSERT_LESS(sal_Int32(50), nDiff32
);
429 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testSurfaceMetal
)
431 loadFromURL(u
"tdf140321_metal.odp");
433 SdrPage
* pSdrPage
= getFirstDrawPageWithAssert();
435 xmlDocUniquePtr pXmlDoc
= lcl_dumpAndParseFirstObjectWithAssert(pSdrPage
);
437 // ODF specifies for metal = true specular color as rgb(200,200,200) and adding 15 to specularity
438 // Together with extrusion-first-light-level 67% and extrusion-specularity 80% factor is
439 // 0.67*0.8 * 200/255 = 0.42 and color #6b6b6b
440 assertXPath(pXmlDoc
, "(//material)[1]", "specular", "#6b6b6b");
441 // 3D specularIntensity = 2^(50/10) + 15 = 47, with default extrusion-shininess 50%
442 assertXPath(pXmlDoc
, "(//material)[1]", "specularIntensity", "47");
445 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testExtrusionPhong
)
447 loadFromURL(u
"tdf140321_phong.odp");
449 SdrPage
* pSdrPage
= getFirstDrawPageWithAssert();
451 xmlDocUniquePtr pXmlDoc
= lcl_dumpAndParseFirstObjectWithAssert(pSdrPage
);
453 // The rendering method and normals kind were always 'Flat' without the patch.
454 assertXPath(pXmlDoc
, "//scene", "shadeMode", "Phong");
455 assertXPath(pXmlDoc
, "//object3Dattributes", "normalsKind", "Specific");
458 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testSurfaceMattePPT
)
460 loadFromURL(u
"tdf140321_Matte_import.ppt");
462 SdrPage
* pSdrPage
= getFirstDrawPageWithAssert();
464 xmlDocUniquePtr pXmlDoc
= lcl_dumpAndParseFirstObjectWithAssert(pSdrPage
);
466 // The preset 'matte' sets the specularity of material to 0. But that alone does not make the
467 // rendering 'matte' in LO. To get a 'matte' effect in LO, specularity of the light need to be
468 // false in addition. To get this, first light is set off and values from first light are copied
469 // to forth light, as only first light is specular. Because first and third lights are off, the
470 // forth light is the second one in the dump. The gray color corresponding to
471 // FirstLightLevel = 38000/2^16 is #949494.
472 assertXPath(pXmlDoc
, "(//material)[1]", "specular", "#000000");
473 assertXPath(pXmlDoc
, "(//light)[2]", "color", "#949494");
474 // To make the second light soft, part of its intensity is moved to lights 5,6,7 and 8.
475 assertXPath(pXmlDoc
, "(//light)[1]", "color", "#1e1e1e");
476 assertXPath(pXmlDoc
, "(//light)[3]", "color", "#3b3b3b");
477 // The 3D property specularIntensity is not related to 'extrusion-specularity' but to
478 // 'extrusion-shininess'. specularIntensity = 2^(shininess/10), here default 32.
479 assertXPath(pXmlDoc
, "(//material)[1]", "specularIntensity", "32");
482 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testMaterialSpecular
)
484 loadFromURL(u
"tdf140321_material_specular.odp");
486 SdrPage
* pSdrPage
= getFirstDrawPageWithAssert();
488 xmlDocUniquePtr pXmlDoc
= lcl_dumpAndParseFirstObjectWithAssert(pSdrPage
);
489 CPPUNIT_ASSERT(pXmlDoc
);
491 // 3D specular color is derived from properties 'extrusion-specularity' and 'extrusion-first-light
492 // -level'. 3D specularIntensity is derived from property 'draw:extrusion-shininess'. Both are
493 // object properties, not scene properties. Those were wrong in various forms before the patch.
494 // Specularity = 77% * first-light-level 67% = 0.5159, which corresponds to gray color #848484.
495 assertXPath(pXmlDoc
, "(//material)[1]", "specular", "#848484");
496 // extrusion-shininess 50% corresponds to 3D specularIntensity 32, use 2^(50/10).
497 assertXPath(pXmlDoc
, "(//material)[1]", "specularIntensity", "32");
498 // extrusion-first-light-level 67% corresponds to gray color #ababab, use 255 * 0.67.
499 assertXPath(pXmlDoc
, "(//light)[1]", "color", "#ababab");
500 // The first light is harsh, the second light soft. So the 3D scene should have 6 lights (1+1+4).
501 assertXPath(pXmlDoc
, "//light", 6);
504 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testVideoSnapshot
)
506 // Given a slide with a media shape, containing a 4 sec video, red-green-blue-black being the 4
508 loadFromURL(u
"video-snapshot.pptx");
509 SdrPage
* pSdrPage
= getFirstDrawPageWithAssert();
510 auto pSdrMediaObj
= dynamic_cast<SdrMediaObj
*>(pSdrPage
->GetObj(0));
512 // When getting the red snapshot of the video:
513 Graphic
aSnapshot(pSdrMediaObj
->getSnapshot());
515 // Then make sure the color is correct:
516 const BitmapEx
& rBitmap
= aSnapshot
.GetBitmapExRef();
517 // Without the accompanying fix in place, this test would have failed with:
518 // - Expected: rgba[ff0000ff]
519 // - Actual : rgba[000000ff]
520 // i.e. the preview was black, not ~red; since we seeked 3 secs into the video, while PowerPoint
522 CPPUNIT_ASSERT_EQUAL(Color(0xfe, 0x0, 0x0), rBitmap
.GetPixelColor(0, 0));
524 // Without the accompanying fix in place, this test would have failed with:
527 // i.e. ~25% crop from left and right should result in half width, but it was not reduced.
528 CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long
>(321), rBitmap
.GetSizePixel().getWidth());
531 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testPageViewDrawLayerClip
)
533 // Given a document with 2 pages, first page footer has an off-page line shape:
534 loadFromURL(u
"page-view-draw-layer-clip.docx");
536 // When saving that document to PDF:
537 save("writer_pdf_Export");
539 // Then make sure that line shape gets clipped:
540 std::unique_ptr
<vcl::pdf::PDFiumDocument
> pDoc
= parsePDFExport();
545 std::unique_ptr
<vcl::pdf::PDFiumPage
> pPage1
= pDoc
->openPage(0);
546 CPPUNIT_ASSERT_EQUAL(3, pPage1
->getObjectCount());
547 std::unique_ptr
<vcl::pdf::PDFiumPage
> pPage2
= pDoc
->openPage(1);
548 // Without the accompanying fix in place, this test would have failed with:
551 // i.e. the 2nd page had a line shape from the first page's footer.
552 CPPUNIT_ASSERT_EQUAL(2, pPage2
->getObjectCount());
555 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testRectangleObjectMove
)
557 std::unique_ptr
<SdrModel
> pModel(new SdrModel(nullptr, nullptr, true));
558 pModel
->GetItemPool().FreezeIdRanges();
560 rtl::Reference
<SdrPage
> pPage(new SdrPage(*pModel
, false));
561 pPage
->SetSize(Size(50000, 50000));
562 pModel
->InsertPage(pPage
.get(), 0);
564 tools::Rectangle
aRect(Point(), Size(100, 100));
565 rtl::Reference
<SdrRectObj
> pRectangleObject
= new SdrRectObj(*pModel
, aRect
);
566 pPage
->NbcInsertObject(pRectangleObject
.get());
568 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(), Size(100, 100)),
569 pRectangleObject
->GetLogicRect());
570 pRectangleObject
->NbcMove({ 100, 100 });
571 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(100, 100), Size(100, 100)),
572 pRectangleObject
->GetLogicRect());
574 pPage
->RemoveObject(0);
577 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testRectangleObjectRotate
)
579 std::unique_ptr
<SdrModel
> pModel(new SdrModel(nullptr, nullptr, true));
580 pModel
->GetItemPool().FreezeIdRanges();
582 rtl::Reference
<SdrPage
> pPage(new SdrPage(*pModel
, false));
583 pPage
->SetSize(Size(50000, 50000));
584 pModel
->InsertPage(pPage
.get(), 0);
587 tools::Rectangle
aObjectSize(Point(), Size(100, 100));
588 rtl::Reference
<SdrRectObj
> pRectangleObject
= new SdrRectObj(*pModel
, aObjectSize
);
589 pPage
->NbcInsertObject(pRectangleObject
.get());
591 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 0), Size(100, 100)),
592 pRectangleObject
->GetLogicRect());
593 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 0), Size(100, 100)),
594 pRectangleObject
->GetSnapRect());
595 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(-1, -1), Size(102, 102)),
596 pRectangleObject
->GetCurrentBoundRect());
598 auto angle
= 9000_deg100
;
599 double angleRadians
= toRadians(angle
);
600 pRectangleObject
->NbcRotate(aObjectSize
.Center(), angle
, std::sin(angleRadians
),
601 std::cos(angleRadians
));
603 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 98), Size(100, 100)),
604 pRectangleObject
->GetLogicRect());
605 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, -1), Size(100, 100)),
606 pRectangleObject
->GetSnapRect());
607 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(-1, -2), Size(102, 102)),
608 pRectangleObject
->GetCurrentBoundRect());
610 pPage
->RemoveObject(0);
614 tools::Rectangle
aObjectSize(Point(), Size(100, 100));
615 rtl::Reference
<SdrRectObj
> pRectangleObject
= new SdrRectObj(*pModel
, aObjectSize
);
616 pPage
->NbcInsertObject(pRectangleObject
.get());
618 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 0), Size(100, 100)),
619 pRectangleObject
->GetLogicRect());
620 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 0), Size(100, 100)),
621 pRectangleObject
->GetSnapRect());
622 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(-1, -1), Size(102, 102)),
623 pRectangleObject
->GetCurrentBoundRect());
625 auto angle
= -4500_deg100
;
626 double angleRadians
= toRadians(angle
);
627 pRectangleObject
->NbcRotate(aObjectSize
.Center(), angle
, std::sin(angleRadians
),
628 std::cos(angleRadians
));
630 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(49, -20), Size(100, 100)),
631 pRectangleObject
->GetLogicRect());
632 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(-21, -20), Size(141, 141)),
633 pRectangleObject
->GetSnapRect());
634 CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(-22, -21), Size(143, 143)),
635 pRectangleObject
->GetCurrentBoundRect());
637 pPage
->RemoveObject(0);
641 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testRotatePoint
)
644 auto angle
= 18000_deg100
;
645 double angleRadians
= toRadians(angle
);
646 Point
aPoint(2000, 1000);
647 Point
aReference(1000, 1000);
648 RotatePoint(aPoint
, aReference
, std::sin(angleRadians
), std::cos(angleRadians
));
650 CPPUNIT_ASSERT_EQUAL(Point(0, 1000), aPoint
);
654 auto angle
= 9000_deg100
;
655 double angleRadians
= toRadians(angle
);
656 Point
aPoint(2000, 1000);
657 Point
aReference(1000, 1000);
658 RotatePoint(aPoint
, aReference
, std::sin(angleRadians
), std::cos(angleRadians
));
660 CPPUNIT_ASSERT_EQUAL(Point(1000, 0), aPoint
);
664 auto angle
= 18000_deg100
;
665 double angleRadians
= toRadians(angle
);
666 Point
aPoint(100, 100);
667 Point
aReference(200, 200);
668 RotatePoint(aPoint
, aReference
, std::sin(angleRadians
), std::cos(angleRadians
));
670 CPPUNIT_ASSERT_EQUAL(Point(300, 300), aPoint
);
674 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testClipVerticalTextOverflow
)
676 // File contains a slide with 4 rectangle shapes with text inside
677 // each have <a:bodyPr vertOverflow="clip">
678 // 1-) Text overflowing the rectangle
679 // 2-) Text not overflowing the rectangle
680 // 3-) (Vertical text) Text overflowing the rectangle
681 // 4-) (Vertical text) Text not overflowing the rectangle
682 loadFromURL(u
"clip-vertical-overflow.pptx");
684 SdrPage
* pSdrPage
= getFirstDrawPageWithAssert();
685 xmlDocUniquePtr pDocument
= lcl_dumpAndParseFirstObjectWithAssert(pSdrPage
);
687 // Test vertically overflowing text
688 // Without the accompanying fix in place, this test would have failed with:
689 // equality assertion failed
692 // - In <>, XPath contents of child does not match
693 // i.e. the vertically overflowing text wasn't clipped & overflowing text
694 // was drawn anyways.
695 assertXPathContent(pDocument
, "count((//sdrblocktext)[4]//textsimpleportion)", "6");
697 // make sure text is aligned correctly after the overflowing text is clipped
698 assertXPath(pDocument
, "((//sdrblocktext)[4]//textsimpleportion)[1]", "y", "3749");
699 assertXPath(pDocument
, "((//sdrblocktext)[4]//textsimpleportion)[6]", "y", "7559");
701 // make sure the text that isn't overflowing is still aligned properly
702 assertXPathContent(pDocument
, "count((//sdrblocktext)[5]//textsimpleportion)", "3");
703 assertXPath(pDocument
, "((//sdrblocktext)[5]//textsimpleportion)[1]", "y", "5073");
704 assertXPath(pDocument
, "((//sdrblocktext)[5]//textsimpleportion)[3]", "y", "6597");
706 // Test vertically overflowing text, with vertical text direction
707 assertXPathContent(pDocument
, "count((//sdrblocktext)[6]//textsimpleportion)", "12");
708 // make sure text is aligned correctly after the overflowing text is clipped
709 assertXPath(pDocument
, "((//sdrblocktext)[6]//textsimpleportion)[1]", "x", "13093");
710 assertXPath(pDocument
, "((//sdrblocktext)[6]//textsimpleportion)[12]", "x", "4711");
712 // make sure the text that isn't overflowing is still aligned properly
713 assertXPathContent(pDocument
, "count((//sdrblocktext)[7]//textsimpleportion)", "3");
714 assertXPath(pDocument
, "((//sdrblocktext)[7]//textsimpleportion)[1]", "x", "25417");
715 assertXPath(pDocument
, "((//sdrblocktext)[7]//textsimpleportion)[3]", "x", "23893");
719 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */