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 "implpolypolygon.hxx"
33 using namespace ::com::sun::star
;
36 namespace cppcanvas::internal
38 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr
& rParentCanvas
,
39 uno::Reference
< rendering::XPolyPolygon2D
> xPolyPoly
) :
40 CanvasGraphicHelper( rParentCanvas
),
41 mxPolyPoly(std::move( xPolyPoly
)),
42 maStrokeAttributes(1.0,
44 uno::Sequence
< double >(),
45 uno::Sequence
< double >(),
46 rendering::PathCapType::ROUND
,
47 rendering::PathCapType::ROUND
,
48 rendering::PathJoinType::ROUND
),
49 mbFillColorSet( false ),
50 mbStrokeColorSet( false )
52 OSL_ENSURE( mxPolyPoly
.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
55 ImplPolyPolygon::~ImplPolyPolygon()
59 void ImplPolyPolygon::setRGBAFillColor( IntSRGBA aColor
)
61 maFillColor
= tools::intSRGBAToDoubleSequence( aColor
);
62 mbFillColorSet
= true;
65 void ImplPolyPolygon::setRGBALineColor( IntSRGBA aColor
)
67 maStrokeColor
= tools::intSRGBAToDoubleSequence( aColor
);
68 mbStrokeColorSet
= true;
71 IntSRGBA
ImplPolyPolygon::getRGBALineColor() const
73 return tools::doubleSequenceToIntSRGBA( maStrokeColor
);
76 void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth
)
78 maStrokeAttributes
.StrokeWidth
= rStrokeWidth
;
81 double ImplPolyPolygon::getStrokeWidth() const
83 return maStrokeAttributes
.StrokeWidth
;
86 bool ImplPolyPolygon::draw() const
88 CanvasSharedPtr
pCanvas( getCanvas() );
90 OSL_ENSURE( pCanvas
&& pCanvas
->getUNOCanvas().is(),
91 "ImplBitmap::draw: invalid canvas" );
94 !pCanvas
->getUNOCanvas().is() )
99 rendering::RenderState
aLocalState( getRenderState() );
100 aLocalState
.DeviceColor
= maFillColor
;
102 pCanvas
->getUNOCanvas()->fillPolyPolygon( mxPolyPoly
,
103 pCanvas
->getViewState(),
107 if( mbStrokeColorSet
)
109 rendering::RenderState
aLocalState( getRenderState() );
110 aLocalState
.DeviceColor
= maStrokeColor
;
112 if( ::rtl::math::approxEqual(maStrokeAttributes
.StrokeWidth
, 1.0) )
113 pCanvas
->getUNOCanvas()->drawPolyPolygon( mxPolyPoly
,
114 pCanvas
->getViewState(),
117 pCanvas
->getUNOCanvas()->strokePolyPolygon( mxPolyPoly
,
118 pCanvas
->getViewState(),
120 maStrokeAttributes
);
126 uno::Reference
< rendering::XPolyPolygon2D
> ImplPolyPolygon::getUNOPolyPolygon() const
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */