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>
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"
35 using namespace ::com::sun::star
;
42 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr
& rParentCanvas
,
43 const uno::Reference
< rendering::XPolyPolygon2D
>& rPolyPoly
) :
44 CanvasGraphicHelper( rParentCanvas
),
45 mxPolyPoly( rPolyPoly
),
46 maStrokeAttributes(1.0,
48 uno::Sequence
< double >(),
49 uno::Sequence
< double >(),
50 rendering::PathCapType::ROUND
,
51 rendering::PathCapType::ROUND
,
52 rendering::PathJoinType::ROUND
),
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() )
73 uno::Reference
< rendering::XGraphicDevice
> xDevice( getGraphicDevice() );
75 OSL_ENSURE( xDevice
.is(),
76 "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
81 mxPolyPoly
->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
82 ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
87 void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon
& rPoly
)
89 OSL_ENSURE( mxPolyPoly
.is(),
90 "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
92 if( !mxPolyPoly
.is() )
95 uno::Reference
< rendering::XGraphicDevice
> xDevice( getGraphicDevice() );
97 OSL_ENSURE( xDevice
.is(),
98 "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
103 mxPolyPoly
->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
104 ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
109 void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor
)
111 maFillColor
= tools::intSRGBAToDoubleSequence( getGraphicDevice(),
113 mbFillColorSet
= true;
116 void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor
)
118 maStrokeColor
= tools::intSRGBAToDoubleSequence( getGraphicDevice(),
120 mbStrokeColorSet
= true;
123 Color::IntSRGBA
ImplPolyPolygon::getRGBAFillColor() const
125 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
129 Color::IntSRGBA
ImplPolyPolygon::getRGBALineColor() const
131 return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
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() )
159 rendering::RenderState
aLocalState( getRenderState() );
160 aLocalState
.DeviceColor
= maFillColor
;
162 pCanvas
->getUNOCanvas()->fillPolyPolygon( mxPolyPoly
,
163 pCanvas
->getViewState(),
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(),
177 pCanvas
->getUNOCanvas()->strokePolyPolygon( mxPolyPoly
,
178 pCanvas
->getViewState(),
180 maStrokeAttributes
);
186 uno::Reference
< rendering::XPolyPolygon2D
> ImplPolyPolygon::getUNOPolyPolygon() const
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */