Bump for 3.6-28
[LibreOffice.git] / cppcanvas / source / wrapper / implpolypolygon.cxx
blob1777c81160f3d34cf2826920140097e6fd8a2af2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <rtl/math.hxx>
32 #include <com/sun/star/rendering/XCanvas.hpp>
33 #include <com/sun/star/rendering/PathJoinType.hpp>
34 #include <com/sun/star/rendering/PathCapType.hpp>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <basegfx/tools/canvastools.hxx>
39 #include "implpolypolygon.hxx"
40 #include "tools.hxx"
43 using namespace ::com::sun::star;
46 namespace cppcanvas
48 namespace internal
50 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
51 const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) :
52 CanvasGraphicHelper( rParentCanvas ),
53 mxPolyPoly( rPolyPoly ),
54 maStrokeAttributes(1.0,
55 10.0,
56 uno::Sequence< double >(),
57 uno::Sequence< double >(),
58 rendering::PathCapType::ROUND,
59 rendering::PathCapType::ROUND,
60 rendering::PathJoinType::ROUND ),
61 maFillColor(),
62 maStrokeColor(),
63 mbFillColorSet( false ),
64 mbStrokeColorSet( false )
66 OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
69 ImplPolyPolygon::~ImplPolyPolygon()
73 void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly )
75 OSL_ENSURE( mxPolyPoly.is(),
76 "ImplPolyPolygon::addPolygon(): Invalid polygon" );
78 if( !mxPolyPoly.is() )
79 return;
81 uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
83 OSL_ENSURE( xDevice.is(),
84 "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
86 if( !xDevice.is() )
87 return;
89 mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
90 ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
91 xDevice,
92 rPoly) );
95 void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly )
97 OSL_ENSURE( mxPolyPoly.is(),
98 "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
100 if( !mxPolyPoly.is() )
101 return;
103 uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
105 OSL_ENSURE( xDevice.is(),
106 "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
108 if( !xDevice.is() )
109 return;
111 mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
112 ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
113 xDevice,
114 rPoly) );
117 void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor )
119 maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
120 aColor );
121 mbFillColorSet = true;
124 void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor )
126 maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
127 aColor );
128 mbStrokeColorSet = true;
131 Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const
133 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
134 maFillColor );
137 Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const
139 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
140 maStrokeColor );
143 void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
145 maStrokeAttributes.StrokeWidth = rStrokeWidth;
148 double ImplPolyPolygon::getStrokeWidth() const
150 return maStrokeAttributes.StrokeWidth;
153 bool ImplPolyPolygon::draw() const
155 CanvasSharedPtr pCanvas( getCanvas() );
157 OSL_ENSURE( pCanvas.get() != NULL &&
158 pCanvas->getUNOCanvas().is(),
159 "ImplBitmap::draw: invalid canvas" );
161 if( pCanvas.get() == NULL ||
162 !pCanvas->getUNOCanvas().is() )
163 return false;
165 if( mbFillColorSet )
167 rendering::RenderState aLocalState( getRenderState() );
168 aLocalState.DeviceColor = maFillColor;
170 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
171 pCanvas->getViewState(),
172 aLocalState );
175 if( mbStrokeColorSet )
177 rendering::RenderState aLocalState( getRenderState() );
178 aLocalState.DeviceColor = maStrokeColor;
180 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
181 pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
182 pCanvas->getViewState(),
183 aLocalState );
184 else
185 pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
186 pCanvas->getViewState(),
187 aLocalState,
188 maStrokeAttributes );
191 return true;
194 uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
196 return mxPolyPoly;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */