Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <test/bootstrapfixture.hxx>
11 :
12 : #include <osl/file.hxx>
13 : #include <osl/process.h>
14 : #include <vcl/svapp.hxx>
15 : #include <vcl/wrkwin.hxx>
16 : #include <vcl/canvastools.hxx>
17 :
18 : #include <comphelper/processfactory.hxx>
19 : #include <com/sun/star/lang/XInitialization.hpp>
20 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
21 :
22 : #include <com/sun/star/rendering/XBitmap.hpp>
23 : #include <com/sun/star/rendering/XCanvas.hpp>
24 : #include <com/sun/star/rendering/XBitmapCanvas.hpp>
25 :
26 : using namespace ::com::sun::star;
27 :
28 2 : class CanvasTest : public test::BootstrapFixture
29 : {
30 : public:
31 1 : CanvasTest() : BootstrapFixture(true, false) {}
32 :
33 : void testComposite();
34 :
35 2 : CPPUNIT_TEST_SUITE(CanvasTest);
36 1 : CPPUNIT_TEST(testComposite);
37 2 : CPPUNIT_TEST_SUITE_END();
38 : };
39 :
40 1 : void CanvasTest::testComposite()
41 : {
42 : #ifdef LINUX
43 1 : Window* pWin = new WorkWindow( (Window *)NULL );
44 1 : CPPUNIT_ASSERT( pWin != NULL );
45 :
46 1 : uno::Reference<rendering::XCanvas> xCanvas = pWin->GetCanvas ();
47 1 : if( !xCanvas.is() )
48 2 : return; // can't get a canvas working at all - truly headless ?
49 :
50 : // a huge canvas ...
51 0 : Size aSize (1, 1);
52 0 : uno::Reference<rendering::XBitmap> xBitmap;
53 0 : xBitmap = xCanvas->getDevice ()->createCompatibleAlphaBitmap(
54 0 : vcl::unotools::integerSize2DFromSize( aSize ) );
55 0 : CPPUNIT_ASSERT( xBitmap.is() );
56 :
57 0 : uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( xBitmap, uno::UNO_QUERY );
58 0 : CPPUNIT_ASSERT( xBitmapCanvas.is() );
59 :
60 0 : BitmapEx aBitmapEx;
61 : {
62 : // clear the canvas and basic sanity check ...
63 0 : xBitmapCanvas->clear();
64 0 : CPPUNIT_ASSERT( aBitmapEx.Create( xBitmapCanvas, aSize ) );
65 0 : CPPUNIT_ASSERT( aBitmapEx.IsAlpha() );
66 0 : CPPUNIT_ASSERT( aBitmapEx.GetAlpha() );
67 : }
68 :
69 : {
70 : // render something
71 0 : rendering::RenderState aDefaultState;
72 0 : uno::Sequence< double > aRedTransparent( 4 );
73 0 : aRedTransparent[0] = 1.0; // R
74 0 : aRedTransparent[1] = 0.0; // G
75 0 : aRedTransparent[2] = 0.0; // B
76 0 : aRedTransparent[3] = 0.5; // A
77 0 : aDefaultState.DeviceColor = aRedTransparent;
78 : #if 0
79 : // words fail me to describe the sheer beauty of allocating an UNO
80 : // object to represent a polygon, and manually handling the ViewState
81 : // and there being no public helper for this - to render ... a rectangle.
82 : XCachedPrimitive fillPolyPolygon( [in] XPolyPolygon2D xPolyPolygon, [in] ViewState aViewState, [in] RenderState aRenderState )
83 : #endif
84 0 : }
85 :
86 : #endif
87 : }
88 :
89 1 : CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);
90 :
91 4 : CPPUNIT_PLUGIN_IMPLEMENT();
92 :
93 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|