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/drawing/XDrawPagesSupplier.hpp>
13 #include <com/sun/star/drawing/XDrawPage.hpp>
15 #include <drawinglayer/tools/primitive2dxmldump.hxx>
16 #include <rtl/ustring.hxx>
17 #include <svx/sdr/contact/displayinfo.hxx>
18 #include <svx/sdr/contact/viewcontact.hxx>
19 #include <svx/sdr/contact/viewobjectcontact.hxx>
20 #include <svx/svdpage.hxx>
21 #include <svx/unopage.hxx>
22 #include <vcl/virdev.hxx>
23 #include <sdr/contact/objectcontactofobjlistpainter.hxx>
24 #include <comphelper/propertyvalue.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <svx/svdview.hxx>
27 #include <svx/sdr/table/tablecontroller.hxx>
28 #include <editeng/editobj.hxx>
30 using namespace ::com::sun::star
;
34 /// Tests for svx/source/table/ code.
35 class Test
: public UnoApiXmlTest
39 : UnoApiXmlTest("svx/qa/unit/data/")
43 drawinglayer::primitive2d::Primitive2DContainer
44 renderPageToPrimitives(const uno::Reference
<drawing::XDrawPage
>& xDrawPage
);
47 drawinglayer::primitive2d::Primitive2DContainer
48 Test::renderPageToPrimitives(const uno::Reference
<drawing::XDrawPage
>& xDrawPage
)
50 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
51 CPPUNIT_ASSERT(pDrawPage
);
52 SdrPage
* pSdrPage
= pDrawPage
->GetSdrPage();
53 ScopedVclPtrInstance
<VirtualDevice
> aVirtualDevice
;
54 sdr::contact::ObjectContactOfObjListPainter
aObjectContact(*aVirtualDevice
,
55 { pSdrPage
->GetObj(0) }, nullptr);
56 const sdr::contact::ViewObjectContact
& rDrawPageVOContact
57 = pSdrPage
->GetViewContact().GetViewObjectContact(aObjectContact
);
58 sdr::contact::DisplayInfo aDisplayInfo
;
59 drawinglayer::primitive2d::Primitive2DContainer aContainer
;
60 rDrawPageVOContact
.getPrimitive2DSequenceHierarchy(aDisplayInfo
, aContainer
);
64 CPPUNIT_TEST_FIXTURE(Test
, testTableShadowBlur
)
66 // Given a document containing a table with a blurry shadow:
67 loadFromURL(u
"table-shadow-blur.pptx");
69 // When rendering the table shadow to primitives:
70 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
71 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
73 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
74 = renderPageToPrimitives(xDrawPage
);
76 // Then make sure that the cell fill part of the shadow is excluded from blurring:
77 drawinglayer::Primitive2dXmlDump aDumper
;
78 xmlDocUniquePtr pDocument
= aDumper
.dumpAndParse(xPrimitiveSequence
);
79 // Without the accompanying fix in place, this test would have failed with:
80 // - number of nodes is incorrect
83 // i.e. the shadow itself was not transparent and that resulted in a non-transparent rendering
84 // as well, while the rendering transparency should be based on the transparency of the shadow
85 // itself and the transparency of the cell fill.
86 assertXPath(pDocument
, "//objectinfo/unifiedtransparence[1]", "transparence", "80");
89 CPPUNIT_TEST_FIXTURE(Test
, testSvxTableControllerSetAttrToSelectedShape
)
91 // Given a document with a table shape, editing cell text:
92 mxComponent
= loadFromDesktop("private:factory/simpress",
93 "com.sun.star.presentation.PresentationDocument");
94 uno::Sequence
<beans::PropertyValue
> aArgs
95 = { comphelper::makePropertyValue("Rows", sal_Int32(2)),
96 comphelper::makePropertyValue("Columns", sal_Int32(2)) };
97 dispatchCommand(mxComponent
, ".uno:InsertTable", aArgs
);
98 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
99 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
101 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
102 CPPUNIT_ASSERT(pDrawPage
);
103 SdrPage
* pSdrPage
= pDrawPage
->GetSdrPage();
105 = dynamic_cast<sdr::table::SdrTableObj
*>(pSdrPage
->GetObj(pSdrPage
->GetObjCount() - 1));
106 SfxViewShell
* pViewShell
= SfxViewShell::Current();
107 SdrView
* pSdrView
= pViewShell
->GetDrawView();
108 pSdrView
->SdrBeginTextEdit(pSdrObject
);
109 CPPUNIT_ASSERT(pSdrView
->IsTextEdit());
110 const EditTextObject
& rEdit
= pSdrObject
->getText(0)->GetOutlinerParaObject()->GetTextObject();
111 SfxItemSet
aSet(rEdit
.GetParaAttribs(0));
112 auto pTableController
113 = dynamic_cast<sdr::table::SvxTableController
*>(pSdrView
->getSelectionController().get());
115 // When applying attributes which only affect the cell text, not the table shape:
116 pTableController
->SetAttrToSelectedShape(aSet
);
118 // Then make sure the text edit is not ended:
119 CPPUNIT_ASSERT(pSdrView
->IsTextEdit());
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */