xref: /AOO41X/main/cppcanvas/source/wrapper/implpolypolygon.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppcanvas.hxx"
30 
31 #include <rtl/math.hxx>
32 
33 #include <com/sun/star/rendering/XCanvas.hpp>
34 #include <com/sun/star/rendering/PathJoinType.hpp>
35 #include <com/sun/star/rendering/PathCapType.hpp>
36 
37 #include <basegfx/matrix/b2dhommatrix.hxx>
38 #include <basegfx/tools/canvastools.hxx>
39 
40 #include "implpolypolygon.hxx"
41 #include "tools.hxx"
42 
43 
44 using namespace ::com::sun::star;
45 
46 
47 namespace cppcanvas
48 {
49     namespace internal
50     {
51         ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
52                                           const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) :
53             CanvasGraphicHelper( rParentCanvas ),
54             mxPolyPoly( rPolyPoly ),
55             maStrokeAttributes(1.0,
56                                10.0,
57                                uno::Sequence< double >(),
58                                uno::Sequence< double >(),
59                                rendering::PathCapType::ROUND,
60                                rendering::PathCapType::ROUND,
61                                rendering::PathJoinType::ROUND ),
62             maFillColor(),
63             maStrokeColor(),
64             mbFillColorSet( false ),
65             mbStrokeColorSet( false )
66         {
67             OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
68         }
69 
70         ImplPolyPolygon::~ImplPolyPolygon()
71         {
72         }
73 
74         void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly )
75         {
76             OSL_ENSURE( mxPolyPoly.is(),
77                         "ImplPolyPolygon::addPolygon(): Invalid polygon" );
78 
79             if( !mxPolyPoly.is() )
80                 return;
81 
82             uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
83 
84             OSL_ENSURE( xDevice.is(),
85                         "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
86 
87             if( !xDevice.is() )
88                 return;
89 
90             mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
91                                         ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
92                                             xDevice,
93                                             rPoly) );
94         }
95 
96         void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly )
97         {
98             OSL_ENSURE( mxPolyPoly.is(),
99                         "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
100 
101             if( !mxPolyPoly.is() )
102                 return;
103 
104             uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
105 
106             OSL_ENSURE( xDevice.is(),
107                         "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
108 
109             if( !xDevice.is() )
110                 return;
111 
112             mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
113                                         ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
114                                             xDevice,
115                                             rPoly) );
116         }
117 
118         void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor )
119         {
120             maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
121                                                            aColor );
122             mbFillColorSet = true;
123         }
124 
125         void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor )
126         {
127             maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
128                                                              aColor );
129             mbStrokeColorSet = true;
130         }
131 
132         Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const
133         {
134             return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
135                                                     maFillColor );
136         }
137 
138         Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const
139         {
140             return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
141                                                     maStrokeColor );
142         }
143 
144         void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
145         {
146             maStrokeAttributes.StrokeWidth = rStrokeWidth;
147         }
148 
149         double ImplPolyPolygon::getStrokeWidth() const
150         {
151             return maStrokeAttributes.StrokeWidth;
152         }
153 
154         bool ImplPolyPolygon::draw() const
155         {
156             CanvasSharedPtr pCanvas( getCanvas() );
157 
158             OSL_ENSURE( pCanvas.get() != NULL &&
159                         pCanvas->getUNOCanvas().is(),
160                         "ImplBitmap::draw: invalid canvas" );
161 
162             if( pCanvas.get() == NULL ||
163                 !pCanvas->getUNOCanvas().is() )
164                 return false;
165 
166             if( mbFillColorSet )
167             {
168                 rendering::RenderState aLocalState( getRenderState() );
169                 aLocalState.DeviceColor = maFillColor;
170 
171                 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
172                                                           pCanvas->getViewState(),
173                                                           aLocalState );
174             }
175 
176             if( mbStrokeColorSet )
177             {
178                 rendering::RenderState aLocalState( getRenderState() );
179                 aLocalState.DeviceColor = maStrokeColor;
180 
181                 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
182                     pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
183                                                               pCanvas->getViewState(),
184                                                               aLocalState );
185                 else
186                     pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
187                                                                 pCanvas->getViewState(),
188                                                                 aLocalState,
189                                                                 maStrokeAttributes );
190             }
191 
192             return true;
193         }
194 
195         uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
196         {
197             return mxPolyPoly;
198         }
199 
200     }
201 }
202