xref: /AOO41X/main/cppcanvas/source/wrapper/implpolypolygon.cxx (revision 25b1114295101a2e8c55dab9e4c2ddcafdffc2eb)
1*25b11142SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25b11142SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25b11142SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25b11142SAndrew Rist  * distributed with this work for additional information
6*25b11142SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25b11142SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25b11142SAndrew Rist  * "License"); you may not use this file except in compliance
9*25b11142SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*25b11142SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*25b11142SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25b11142SAndrew Rist  * software distributed under the License is distributed on an
15*25b11142SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25b11142SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25b11142SAndrew Rist  * specific language governing permissions and limitations
18*25b11142SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*25b11142SAndrew Rist  *************************************************************/
21*25b11142SAndrew Rist 
22*25b11142SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cppcanvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/math.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp>
30cdf0e10cSrcweir #include <com/sun/star/rendering/PathJoinType.hpp>
31cdf0e10cSrcweir #include <com/sun/star/rendering/PathCapType.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
34cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "implpolypolygon.hxx"
37cdf0e10cSrcweir #include "tools.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::com::sun::star;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace cppcanvas
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     namespace internal
46cdf0e10cSrcweir     {
ImplPolyPolygon(const CanvasSharedPtr & rParentCanvas,const uno::Reference<rendering::XPolyPolygon2D> & rPolyPoly)47cdf0e10cSrcweir         ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
48cdf0e10cSrcweir                                           const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) :
49cdf0e10cSrcweir             CanvasGraphicHelper( rParentCanvas ),
50cdf0e10cSrcweir             mxPolyPoly( rPolyPoly ),
51cdf0e10cSrcweir             maStrokeAttributes(1.0,
52cdf0e10cSrcweir                                10.0,
53cdf0e10cSrcweir                                uno::Sequence< double >(),
54cdf0e10cSrcweir                                uno::Sequence< double >(),
55cdf0e10cSrcweir                                rendering::PathCapType::ROUND,
56cdf0e10cSrcweir                                rendering::PathCapType::ROUND,
57cdf0e10cSrcweir                                rendering::PathJoinType::ROUND ),
58cdf0e10cSrcweir             maFillColor(),
59cdf0e10cSrcweir             maStrokeColor(),
60cdf0e10cSrcweir             mbFillColorSet( false ),
61cdf0e10cSrcweir             mbStrokeColorSet( false )
62cdf0e10cSrcweir         {
63cdf0e10cSrcweir             OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
64cdf0e10cSrcweir         }
65cdf0e10cSrcweir 
~ImplPolyPolygon()66cdf0e10cSrcweir         ImplPolyPolygon::~ImplPolyPolygon()
67cdf0e10cSrcweir         {
68cdf0e10cSrcweir         }
69cdf0e10cSrcweir 
addPolygon(const::basegfx::B2DPolygon & rPoly)70cdf0e10cSrcweir         void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly )
71cdf0e10cSrcweir         {
72cdf0e10cSrcweir             OSL_ENSURE( mxPolyPoly.is(),
73cdf0e10cSrcweir                         "ImplPolyPolygon::addPolygon(): Invalid polygon" );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir             if( !mxPolyPoly.is() )
76cdf0e10cSrcweir                 return;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir             uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir             OSL_ENSURE( xDevice.is(),
81cdf0e10cSrcweir                         "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir             if( !xDevice.is() )
84cdf0e10cSrcweir                 return;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir             mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
87cdf0e10cSrcweir                                         ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
88cdf0e10cSrcweir                                             xDevice,
89cdf0e10cSrcweir                                             rPoly) );
90cdf0e10cSrcweir         }
91cdf0e10cSrcweir 
addPolyPolygon(const::basegfx::B2DPolyPolygon & rPoly)92cdf0e10cSrcweir         void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly )
93cdf0e10cSrcweir         {
94cdf0e10cSrcweir             OSL_ENSURE( mxPolyPoly.is(),
95cdf0e10cSrcweir                         "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             if( !mxPolyPoly.is() )
98cdf0e10cSrcweir                 return;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir             OSL_ENSURE( xDevice.is(),
103cdf0e10cSrcweir                         "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir             if( !xDevice.is() )
106cdf0e10cSrcweir                 return;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir             mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
109cdf0e10cSrcweir                                         ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
110cdf0e10cSrcweir                                             xDevice,
111cdf0e10cSrcweir                                             rPoly) );
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir 
setRGBAFillColor(Color::IntSRGBA aColor)114cdf0e10cSrcweir         void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor )
115cdf0e10cSrcweir         {
116cdf0e10cSrcweir             maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
117cdf0e10cSrcweir                                                            aColor );
118cdf0e10cSrcweir             mbFillColorSet = true;
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir 
setRGBALineColor(Color::IntSRGBA aColor)121cdf0e10cSrcweir         void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor )
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
124cdf0e10cSrcweir                                                              aColor );
125cdf0e10cSrcweir             mbStrokeColorSet = true;
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir 
getRGBAFillColor() const128cdf0e10cSrcweir         Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const
129cdf0e10cSrcweir         {
130cdf0e10cSrcweir             return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
131cdf0e10cSrcweir                                                     maFillColor );
132cdf0e10cSrcweir         }
133cdf0e10cSrcweir 
getRGBALineColor() const134cdf0e10cSrcweir         Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
137cdf0e10cSrcweir                                                     maStrokeColor );
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir 
setStrokeWidth(const double & rStrokeWidth)140cdf0e10cSrcweir         void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
141cdf0e10cSrcweir         {
142cdf0e10cSrcweir             maStrokeAttributes.StrokeWidth = rStrokeWidth;
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
getStrokeWidth() const145cdf0e10cSrcweir         double ImplPolyPolygon::getStrokeWidth() const
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             return maStrokeAttributes.StrokeWidth;
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir 
draw() const150cdf0e10cSrcweir         bool ImplPolyPolygon::draw() const
151cdf0e10cSrcweir         {
152cdf0e10cSrcweir             CanvasSharedPtr pCanvas( getCanvas() );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir             OSL_ENSURE( pCanvas.get() != NULL &&
155cdf0e10cSrcweir                         pCanvas->getUNOCanvas().is(),
156cdf0e10cSrcweir                         "ImplBitmap::draw: invalid canvas" );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             if( pCanvas.get() == NULL ||
159cdf0e10cSrcweir                 !pCanvas->getUNOCanvas().is() )
160cdf0e10cSrcweir                 return false;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir             if( mbFillColorSet )
163cdf0e10cSrcweir             {
164cdf0e10cSrcweir                 rendering::RenderState aLocalState( getRenderState() );
165cdf0e10cSrcweir                 aLocalState.DeviceColor = maFillColor;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir                 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
168cdf0e10cSrcweir                                                           pCanvas->getViewState(),
169cdf0e10cSrcweir                                                           aLocalState );
170cdf0e10cSrcweir             }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir             if( mbStrokeColorSet )
173cdf0e10cSrcweir             {
174cdf0e10cSrcweir                 rendering::RenderState aLocalState( getRenderState() );
175cdf0e10cSrcweir                 aLocalState.DeviceColor = maStrokeColor;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir                 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
178cdf0e10cSrcweir                     pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
179cdf0e10cSrcweir                                                               pCanvas->getViewState(),
180cdf0e10cSrcweir                                                               aLocalState );
181cdf0e10cSrcweir                 else
182cdf0e10cSrcweir                     pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
183cdf0e10cSrcweir                                                                 pCanvas->getViewState(),
184cdf0e10cSrcweir                                                                 aLocalState,
185cdf0e10cSrcweir                                                                 maStrokeAttributes );
186cdf0e10cSrcweir             }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             return true;
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir 
getUNOPolyPolygon() const191cdf0e10cSrcweir         uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
192cdf0e10cSrcweir         {
193cdf0e10cSrcweir             return mxPolyPoly;
194cdf0e10cSrcweir         }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir }
198