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/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
12 #include <test/xmltesttools.hxx>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
16 #include <com/sun/star/drawing/XDrawPage.hpp>
17 #include <com/sun/star/frame/Desktop.hpp>
18 #include <com/sun/star/text/XTextRange.hpp>
20 #include <drawinglayer/tools/primitive2dxmldump.hxx>
21 #include <rtl/ustring.hxx>
22 #include <svx/sdr/contact/displayinfo.hxx>
23 #include <svx/sdr/contact/viewcontact.hxx>
24 #include <svx/sdr/contact/viewobjectcontact.hxx>
25 #include <svx/sdrpagewindow.hxx>
26 #include <svx/svdpage.hxx>
27 #include <svx/svdpagv.hxx>
28 #include <svx/svdview.hxx>
29 #include <svx/unopage.hxx>
30 #include <vcl/virdev.hxx>
32 using namespace ::com::sun::star
;
36 /// Tests for svx/source/svdraw/ code.
37 class SvdrawTest
: public test::BootstrapFixture
, public unotest::MacrosTest
, public XmlTestTools
40 uno::Reference
<lang::XComponent
> mxComponent
;
43 virtual void setUp() override
45 test::BootstrapFixture::setUp();
46 mxDesktop
.set(frame::Desktop::create(m_xContext
));
49 virtual void tearDown() override
53 mxComponent
->dispose();
55 test::BootstrapFixture::tearDown();
57 uno::Reference
<lang::XComponent
>& getComponent() { return mxComponent
; }
60 CPPUNIT_TEST_FIXTURE(SvdrawTest
, testSemiTransparentText
)
62 // Create a new Draw document with a rectangle.
63 getComponent() = loadFromDesktop("private:factory/sdraw");
64 uno::Reference
<lang::XMultiServiceFactory
> xFactory(getComponent(), uno::UNO_QUERY
);
65 uno::Reference
<drawing::XShape
> xShape(
66 xFactory
->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY
);
67 xShape
->setSize(awt::Size(10000, 10000));
68 xShape
->setPosition(awt::Point(1000, 1000));
70 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY
);
71 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
73 xDrawPage
->add(xShape
);
75 // Add semi-transparent text on the rectangle.
76 uno::Reference
<text::XTextRange
> xShapeText(xShape
, uno::UNO_QUERY
);
77 xShapeText
->getText()->setString("hello");
79 uno::Reference
<beans::XPropertySet
> xShapeProperties(xShape
, uno::UNO_QUERY
);
80 xShapeProperties
->setPropertyValue("CharColor", uno::makeAny(COL_RED
));
81 sal_Int16 nTransparence
= 75;
82 xShapeProperties
->setPropertyValue("CharTransparence", uno::makeAny(nTransparence
));
84 // Generates drawinglayer primitives for the page.
85 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
86 CPPUNIT_ASSERT(pDrawPage
);
87 SdrPage
* pSdrPage
= pDrawPage
->GetSdrPage();
88 ScopedVclPtrInstance
<VirtualDevice
> aVirtualDevice
;
89 SdrView
aSdrView(pSdrPage
->getSdrModelFromSdrPage(), aVirtualDevice
);
90 SdrPageView
aSdrPageView(pSdrPage
, aSdrView
);
91 SdrPageWindow
* pSdrPageWindow
= aSdrPageView
.GetPageWindow(0);
92 sdr::contact::ObjectContact
& rObjectContactOfPageView
= pSdrPageWindow
->GetObjectContact();
93 const sdr::contact::ViewObjectContact
& rDrawPageVOContact
94 = pSdrPage
->GetViewContact().GetViewObjectContact(rObjectContactOfPageView
);
95 sdr::contact::DisplayInfo aDisplayInfo
;
96 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
97 = rDrawPageVOContact
.getPrimitive2DSequenceHierarchy(aDisplayInfo
);
99 // Make sure the text is semi-transparent.
100 drawinglayer::tools::Primitive2dXmlDump aDumper
;
101 xmlDocPtr pDocument
= aDumper
.dumpAndParse(xPrimitiveSequence
);
103 // Without the accompanying fix in place, this test would have failed with:
106 // - XPath '//unifiedtransparence' number of nodes is incorrect
107 // i.e. the text was just plain red, not semi-transparent.
108 double fTransparence
= getXPath(pDocument
, "//unifiedtransparence", "transparence").toDouble();
109 CPPUNIT_ASSERT_EQUAL(nTransparence
,
110 static_cast<sal_Int16
>(basegfx::fround(fTransparence
* 100)));
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */