LibreOffice Module cppcanvas (master) 1
implpolypolygon.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <rtl/math.hxx>
22#include <osl/diagnose.h>
23
24#include <com/sun/star/rendering/XCanvas.hpp>
25#include <com/sun/star/rendering/PathJoinType.hpp>
26#include <com/sun/star/rendering/PathCapType.hpp>
27
28#include "implpolypolygon.hxx"
29#include <tools.hxx>
30#include <utility>
31
32
33using namespace ::com::sun::star;
34
35
36namespace cppcanvas::internal
37{
39 uno::Reference< rendering::XPolyPolygon2D > xPolyPoly ) :
40 CanvasGraphicHelper( rParentCanvas ),
41 mxPolyPoly(std::move( xPolyPoly )),
43 10.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 )
51 {
52 OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
53 }
54
55 ImplPolyPolygon::~ImplPolyPolygon()
56 {
57 }
58
59 void ImplPolyPolygon::setRGBAFillColor( IntSRGBA aColor )
60 {
62 mbFillColorSet = true;
63 }
64
65 void ImplPolyPolygon::setRGBALineColor( IntSRGBA aColor )
66 {
67 maStrokeColor = tools::intSRGBAToDoubleSequence( aColor );
68 mbStrokeColorSet = true;
69 }
70
71 IntSRGBA ImplPolyPolygon::getRGBALineColor() const
72 {
73 return tools::doubleSequenceToIntSRGBA( maStrokeColor );
74 }
75
76 void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
77 {
78 maStrokeAttributes.StrokeWidth = rStrokeWidth;
79 }
80
81 double ImplPolyPolygon::getStrokeWidth() const
82 {
83 return maStrokeAttributes.StrokeWidth;
84 }
85
86 bool ImplPolyPolygon::draw() const
87 {
88 CanvasSharedPtr pCanvas( getCanvas() );
89
90 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(),
91 "ImplBitmap::draw: invalid canvas" );
92
93 if( !pCanvas ||
94 !pCanvas->getUNOCanvas().is() )
95 return false;
96
97 if( mbFillColorSet )
98 {
99 rendering::RenderState aLocalState( getRenderState() );
100 aLocalState.DeviceColor = maFillColor;
101
102 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
103 pCanvas->getViewState(),
104 aLocalState );
105 }
106
107 if( mbStrokeColorSet )
108 {
109 rendering::RenderState aLocalState( getRenderState() );
110 aLocalState.DeviceColor = maStrokeColor;
111
112 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
113 pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
114 pCanvas->getViewState(),
115 aLocalState );
116 else
117 pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
118 pCanvas->getViewState(),
119 aLocalState,
121 }
122
123 return true;
124 }
125
126 uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
127 {
128 return mxPolyPoly;
129 }
130
131}
132
133/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ImplPolyPolygon(const CanvasSharedPtr &rParentCanvas, css::uno::Reference< css::rendering::XPolyPolygon2D > xPolyPoly)
#define ROUND(x)
css::uno::Sequence< double > intSRGBAToDoubleSequence(IntSRGBA)
Definition: tools.cxx:28
IntSRGBA doubleSequenceToIntSRGBA(const css::uno::Sequence< double > &rColor)
sal_uInt32 IntSRGBA
Color in the sRGB color space, plus alpha channel.
Definition: color.hxx:34
std::shared_ptr< Canvas > CanvasSharedPtr
const uno::Reference< rendering::XPolyPolygon2D > mxPolyPoly
uno::Sequence< double > maFillColor
const rendering::StrokeAttributes maStrokeAttributes