update dev300-m58
[ooovba.git] / cppcanvas / source / wrapper / implpolypolygon.cxx
blob6b7755943f24ea9e2948b5f9e7b3c993199863ec
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: implpolypolygon.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppcanvas.hxx"
34 #include <rtl/math.hxx>
36 #include <com/sun/star/rendering/XCanvas.hpp>
37 #include <com/sun/star/rendering/PathJoinType.hpp>
38 #include <com/sun/star/rendering/PathCapType.hpp>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/tools/canvastools.hxx>
43 #include "implpolypolygon.hxx"
44 #include "tools.hxx"
47 using namespace ::com::sun::star;
50 namespace cppcanvas
52 namespace internal
54 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
55 const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) :
56 CanvasGraphicHelper( rParentCanvas ),
57 mxPolyPoly( rPolyPoly ),
58 maStrokeAttributes(1.0,
59 10.0,
60 uno::Sequence< double >(),
61 uno::Sequence< double >(),
62 rendering::PathCapType::ROUND,
63 rendering::PathCapType::ROUND,
64 rendering::PathJoinType::ROUND ),
65 maFillColor(),
66 maStrokeColor(),
67 mbFillColorSet( false ),
68 mbStrokeColorSet( false )
70 OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
73 ImplPolyPolygon::~ImplPolyPolygon()
77 void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly )
79 OSL_ENSURE( mxPolyPoly.is(),
80 "ImplPolyPolygon::addPolygon(): Invalid polygon" );
82 if( !mxPolyPoly.is() )
83 return;
85 uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
87 OSL_ENSURE( xDevice.is(),
88 "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
90 if( !xDevice.is() )
91 return;
93 mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
94 ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
95 xDevice,
96 rPoly) );
99 void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly )
101 OSL_ENSURE( mxPolyPoly.is(),
102 "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
104 if( !mxPolyPoly.is() )
105 return;
107 uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
109 OSL_ENSURE( xDevice.is(),
110 "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
112 if( !xDevice.is() )
113 return;
115 mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
116 ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
117 xDevice,
118 rPoly) );
121 void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor )
123 maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
124 aColor );
125 mbFillColorSet = true;
128 void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor )
130 maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
131 aColor );
132 mbStrokeColorSet = true;
135 Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const
137 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
138 maFillColor );
141 Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const
143 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
144 maStrokeColor );
147 void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
149 maStrokeAttributes.StrokeWidth = rStrokeWidth;
152 double ImplPolyPolygon::getStrokeWidth() const
154 return maStrokeAttributes.StrokeWidth;
157 bool ImplPolyPolygon::draw() const
159 CanvasSharedPtr pCanvas( getCanvas() );
161 OSL_ENSURE( pCanvas.get() != NULL &&
162 pCanvas->getUNOCanvas().is(),
163 "ImplBitmap::draw: invalid canvas" );
165 if( pCanvas.get() == NULL ||
166 !pCanvas->getUNOCanvas().is() )
167 return false;
169 if( mbFillColorSet )
171 rendering::RenderState aLocalState( getRenderState() );
172 aLocalState.DeviceColor = maFillColor;
174 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
175 pCanvas->getViewState(),
176 aLocalState );
179 if( mbStrokeColorSet )
181 rendering::RenderState aLocalState( getRenderState() );
182 aLocalState.DeviceColor = maStrokeColor;
184 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
185 pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
186 pCanvas->getViewState(),
187 aLocalState );
188 else
189 pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
190 pCanvas->getViewState(),
191 aLocalState,
192 maStrokeAttributes );
195 return true;
198 uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
200 return mxPolyPoly;