Debian Codegraph @

cppcanvas/source/wrapper/implpolypolygon.cxx

raw
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
33 using namespace ::com::sun::star;
34
35
36 namespace cppcanvas::internal
37 {
38 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
39 uno::Reference< rendering::XPolyPolygon2D > xPolyPoly ) :
40 CanvasGraphicHelper( rParentCanvas ),
41 mxPolyPoly(std::move( xPolyPoly )),
42 maStrokeAttributes(1.0,
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 mbIsFromPreviousSlideshow(false)
52 {
53 OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
54 }
55
56 ImplPolyPolygon::~ImplPolyPolygon()
57 {
58 }
59
60 void ImplPolyPolygon::setRGBAFillColor( IntSRGBA aColor )
61 {
62 maFillColor = cppcanvastools::intSRGBAToDoubleSequence( aColor );
63 mbFillColorSet = true;
64 }
65
66 void ImplPolyPolygon::setRGBALineColor( IntSRGBA aColor )
67 {
68 maStrokeColor = cppcanvastools::intSRGBAToDoubleSequence( aColor );
69 mbStrokeColorSet = true;
70 }
71
72 IntSRGBA ImplPolyPolygon::getRGBALineColor() const
73 {
74 return cppcanvastools::doubleSequenceToIntSRGBA( maStrokeColor );
75 }
76
77 void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
78 {
79 maStrokeAttributes.StrokeWidth = rStrokeWidth;
80 }
81
82 double ImplPolyPolygon::getStrokeWidth() const
83 {
84 return maStrokeAttributes.StrokeWidth;
85 }
86
87 bool ImplPolyPolygon::draw() const
88 {
89 CanvasSharedPtr pCanvas( getCanvas() );
90
91 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(),
92 "ImplBitmap::draw: invalid canvas" );
93
94 if( !pCanvas ||
95 !pCanvas->getUNOCanvas().is() )
96 return false;
97
98 if( mbFillColorSet )
99 {
100 rendering::RenderState aLocalState( getRenderState() );
101 aLocalState.DeviceColor = maFillColor;
102
103 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
104 pCanvas->getViewState(),
105 aLocalState );
106 }
107
108 if( mbStrokeColorSet )
109 {
110 rendering::RenderState aLocalState( getRenderState() );
111 aLocalState.DeviceColor = maStrokeColor;
112
113 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
114 pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
115 pCanvas->getViewState(),
116 aLocalState );
117 else
118 pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
119 pCanvas->getViewState(),
120 aLocalState,
121 maStrokeAttributes );
122 }
123
124 return true;
125 }
126
127 uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
128 {
129 return mxPolyPoly;
130 }
131
132 void ImplPolyPolygon::setIsFromPreviousSlideshow(const bool& rFlag)
133 {
134 mbIsFromPreviousSlideshow = rFlag;
135 }
136
137 bool ImplPolyPolygon::getIsFromPreviousSlideshow() const
138 {
139 return mbIsFromPreviousSlideshow;
140 }
141 }
142
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */