1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
34 using namespace ::com::sun::star
;
41 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr
& rParentCanvas
,
42 const uno::Reference
< rendering::XPolyPolygon2D
>& rPolyPoly
) :
43 CanvasGraphicHelper( rParentCanvas
),
44 mxPolyPoly( rPolyPoly
),
45 maStrokeAttributes(1.0,
47 uno::Sequence
< double >(),
48 uno::Sequence
< double >(),
49 rendering::PathCapType::ROUND
,
50 rendering::PathCapType::ROUND
,
51 rendering::PathJoinType::ROUND
),
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() )
72 uno::Reference
< rendering::XGraphicDevice
> xDevice( getGraphicDevice() );
74 OSL_ENSURE( xDevice
.is(),
75 "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
80 mxPolyPoly
->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
81 ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
86 void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon
& rPoly
)
88 OSL_ENSURE( mxPolyPoly
.is(),
89 "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
91 if( !mxPolyPoly
.is() )
94 uno::Reference
< rendering::XGraphicDevice
> xDevice( getGraphicDevice() );
96 OSL_ENSURE( xDevice
.is(),
97 "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
102 mxPolyPoly
->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
103 ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
108 void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor
)
110 maFillColor
= tools::intSRGBAToDoubleSequence( getGraphicDevice(),
112 mbFillColorSet
= true;
115 void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor
)
117 maStrokeColor
= tools::intSRGBAToDoubleSequence( getGraphicDevice(),
119 mbStrokeColorSet
= true;
122 Color::IntSRGBA
ImplPolyPolygon::getRGBAFillColor() const
124 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
128 Color::IntSRGBA
ImplPolyPolygon::getRGBALineColor() const
130 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
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() )
158 rendering::RenderState
aLocalState( getRenderState() );
159 aLocalState
.DeviceColor
= maFillColor
;
161 pCanvas
->getUNOCanvas()->fillPolyPolygon( mxPolyPoly
,
162 pCanvas
->getViewState(),
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(),
176 pCanvas
->getUNOCanvas()->strokePolyPolygon( mxPolyPoly
,
177 pCanvas
->getViewState(),
179 maStrokeAttributes
);
185 uno::Reference
< rendering::XPolyPolygon2D
> ImplPolyPolygon::getUNOPolyPolygon() const
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */