Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / cppcanvas / source / wrapper / implpolypolygon.cxx
blobf390ed6c011575714f324409dc9ae3219ca2b9be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <rtl/math.hxx>
23 #include <com/sun/star/rendering/XCanvas.hpp>
24 #include <com/sun/star/rendering/PathJoinType.hpp>
25 #include <com/sun/star/rendering/PathCapType.hpp>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <basegfx/tools/canvastools.hxx>
30 #include "implpolypolygon.hxx"
31 #include "tools.hxx"
34 using namespace ::com::sun::star;
37 namespace cppcanvas
39 namespace internal
41 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
42 const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) :
43 CanvasGraphicHelper( rParentCanvas ),
44 mxPolyPoly( rPolyPoly ),
45 maStrokeAttributes(1.0,
46 10.0,
47 uno::Sequence< double >(),
48 uno::Sequence< double >(),
49 rendering::PathCapType::ROUND,
50 rendering::PathCapType::ROUND,
51 rendering::PathJoinType::ROUND ),
52 maFillColor(),
53 maStrokeColor(),
54 mbFillColorSet( false ),
55 mbStrokeColorSet( false )
57 OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
60 ImplPolyPolygon::~ImplPolyPolygon()
64 void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly )
66 OSL_ENSURE( mxPolyPoly.is(),
67 "ImplPolyPolygon::addPolygon(): Invalid polygon" );
69 if( !mxPolyPoly.is() )
70 return;
72 uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
74 OSL_ENSURE( xDevice.is(),
75 "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
77 if( !xDevice.is() )
78 return;
80 mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
81 ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
82 xDevice,
83 rPoly) );
86 void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly )
88 OSL_ENSURE( mxPolyPoly.is(),
89 "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
91 if( !mxPolyPoly.is() )
92 return;
94 uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
96 OSL_ENSURE( xDevice.is(),
97 "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
99 if( !xDevice.is() )
100 return;
102 mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
103 ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
104 xDevice,
105 rPoly) );
108 void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor )
110 maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
111 aColor );
112 mbFillColorSet = true;
115 void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor )
117 maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
118 aColor );
119 mbStrokeColorSet = true;
122 Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const
124 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
125 maFillColor );
128 Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const
130 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
131 maStrokeColor );
134 void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
136 maStrokeAttributes.StrokeWidth = rStrokeWidth;
139 double ImplPolyPolygon::getStrokeWidth() const
141 return maStrokeAttributes.StrokeWidth;
144 bool ImplPolyPolygon::draw() const
146 CanvasSharedPtr pCanvas( getCanvas() );
148 OSL_ENSURE( pCanvas.get() != NULL &&
149 pCanvas->getUNOCanvas().is(),
150 "ImplBitmap::draw: invalid canvas" );
152 if( pCanvas.get() == NULL ||
153 !pCanvas->getUNOCanvas().is() )
154 return false;
156 if( mbFillColorSet )
158 rendering::RenderState aLocalState( getRenderState() );
159 aLocalState.DeviceColor = maFillColor;
161 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
162 pCanvas->getViewState(),
163 aLocalState );
166 if( mbStrokeColorSet )
168 rendering::RenderState aLocalState( getRenderState() );
169 aLocalState.DeviceColor = maStrokeColor;
171 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
172 pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
173 pCanvas->getViewState(),
174 aLocalState );
175 else
176 pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
177 pCanvas->getViewState(),
178 aLocalState,
179 maStrokeAttributes );
182 return true;
185 uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
187 return mxPolyPoly;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */