Bump version to 5.0-14
[LibreOffice.git] / cppcanvas / source / wrapper / implpolypolygon.cxx
blob927377811c421cc5aa4f24861f93ff98b5affe04
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>
22 #include <osl/diagnose.h>
24 #include <com/sun/star/rendering/XCanvas.hpp>
25 #include <com/sun/star/rendering/PathJoinType.hpp>
26 #include <com/sun/star/rendering/PathCapType.hpp>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
29 #include <basegfx/tools/canvastools.hxx>
31 #include "implpolypolygon.hxx"
32 #include "tools.hxx"
35 using namespace ::com::sun::star;
38 namespace cppcanvas
40 namespace internal
42 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
43 const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) :
44 CanvasGraphicHelper( rParentCanvas ),
45 mxPolyPoly( rPolyPoly ),
46 maStrokeAttributes(1.0,
47 10.0,
48 uno::Sequence< double >(),
49 uno::Sequence< double >(),
50 rendering::PathCapType::ROUND,
51 rendering::PathCapType::ROUND,
52 rendering::PathJoinType::ROUND ),
53 maFillColor(),
54 maStrokeColor(),
55 mbFillColorSet( false ),
56 mbStrokeColorSet( false )
58 OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
61 ImplPolyPolygon::~ImplPolyPolygon()
65 void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly )
67 OSL_ENSURE( mxPolyPoly.is(),
68 "ImplPolyPolygon::addPolygon(): Invalid polygon" );
70 if( !mxPolyPoly.is() )
71 return;
73 uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
75 OSL_ENSURE( xDevice.is(),
76 "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
78 if( !xDevice.is() )
79 return;
81 mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
82 ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
83 xDevice,
84 rPoly) );
87 void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly )
89 OSL_ENSURE( mxPolyPoly.is(),
90 "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
92 if( !mxPolyPoly.is() )
93 return;
95 uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
97 OSL_ENSURE( xDevice.is(),
98 "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
100 if( !xDevice.is() )
101 return;
103 mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
104 ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
105 xDevice,
106 rPoly) );
109 void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor )
111 maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
112 aColor );
113 mbFillColorSet = true;
116 void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor )
118 maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
119 aColor );
120 mbStrokeColorSet = true;
123 Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const
125 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
126 maFillColor );
129 Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const
131 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
132 maStrokeColor );
135 void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
137 maStrokeAttributes.StrokeWidth = rStrokeWidth;
140 double ImplPolyPolygon::getStrokeWidth() const
142 return maStrokeAttributes.StrokeWidth;
145 bool ImplPolyPolygon::draw() const
147 CanvasSharedPtr pCanvas( getCanvas() );
149 OSL_ENSURE( pCanvas.get() != NULL &&
150 pCanvas->getUNOCanvas().is(),
151 "ImplBitmap::draw: invalid canvas" );
153 if( pCanvas.get() == NULL ||
154 !pCanvas->getUNOCanvas().is() )
155 return false;
157 if( mbFillColorSet )
159 rendering::RenderState aLocalState( getRenderState() );
160 aLocalState.DeviceColor = maFillColor;
162 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
163 pCanvas->getViewState(),
164 aLocalState );
167 if( mbStrokeColorSet )
169 rendering::RenderState aLocalState( getRenderState() );
170 aLocalState.DeviceColor = maStrokeColor;
172 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
173 pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
174 pCanvas->getViewState(),
175 aLocalState );
176 else
177 pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
178 pCanvas->getViewState(),
179 aLocalState,
180 maStrokeAttributes );
183 return true;
186 uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
188 return mxPolyPoly;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */