Line data Source code
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 :
23 : #include <com/sun/star/rendering/XCanvas.hpp>
24 : #include <com/sun/star/rendering/PathJoinType.hpp>
25 : #include <com/sun/star/rendering/PathCapType.hpp>
26 :
27 : #include <basegfx/matrix/b2dhommatrix.hxx>
28 : #include <basegfx/tools/canvastools.hxx>
29 :
30 : #include "implpolypolygon.hxx"
31 : #include "tools.hxx"
32 :
33 :
34 : using namespace ::com::sun::star;
35 :
36 :
37 : namespace cppcanvas
38 : {
39 : namespace internal
40 : {
41 0 : ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
42 : const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) :
43 : CanvasGraphicHelper( rParentCanvas ),
44 : mxPolyPoly( rPolyPoly ),
45 : maStrokeAttributes(1.0,
46 : 10.0,
47 : uno::Sequence< double >(),
48 : uno::Sequence< double >(),
49 : rendering::PathCapType::ROUND,
50 : rendering::PathCapType::ROUND,
51 : rendering::PathJoinType::ROUND ),
52 : maFillColor(),
53 : maStrokeColor(),
54 : mbFillColorSet( false ),
55 0 : mbStrokeColorSet( false )
56 : {
57 : OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
58 0 : }
59 :
60 0 : ImplPolyPolygon::~ImplPolyPolygon()
61 : {
62 0 : }
63 :
64 0 : void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly )
65 : {
66 : OSL_ENSURE( mxPolyPoly.is(),
67 : "ImplPolyPolygon::addPolygon(): Invalid polygon" );
68 :
69 0 : if( !mxPolyPoly.is() )
70 : return;
71 :
72 0 : uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
73 :
74 : OSL_ENSURE( xDevice.is(),
75 : "ImplPolyPolygon::addPolygon(): Invalid graphic device" );
76 :
77 0 : if( !xDevice.is() )
78 : return;
79 :
80 0 : mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
81 : ::basegfx::unotools::xPolyPolygonFromB2DPolygon(
82 : xDevice,
83 0 : rPoly) );
84 : }
85 :
86 0 : void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly )
87 : {
88 : OSL_ENSURE( mxPolyPoly.is(),
89 : "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" );
90 :
91 0 : if( !mxPolyPoly.is() )
92 : return;
93 :
94 0 : uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() );
95 :
96 : OSL_ENSURE( xDevice.is(),
97 : "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" );
98 :
99 0 : if( !xDevice.is() )
100 : return;
101 :
102 0 : mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0),
103 : ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon(
104 : xDevice,
105 0 : rPoly) );
106 : }
107 :
108 0 : void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor )
109 : {
110 : maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
111 0 : aColor );
112 0 : mbFillColorSet = true;
113 0 : }
114 :
115 0 : void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor )
116 : {
117 : maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(),
118 0 : aColor );
119 0 : mbStrokeColorSet = true;
120 0 : }
121 :
122 0 : Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const
123 : {
124 : return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
125 0 : maFillColor );
126 : }
127 :
128 0 : Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const
129 : {
130 : return tools::doubleSequenceToIntSRGBA( getGraphicDevice(),
131 0 : maStrokeColor );
132 : }
133 :
134 0 : void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
135 : {
136 0 : maStrokeAttributes.StrokeWidth = rStrokeWidth;
137 0 : }
138 :
139 0 : double ImplPolyPolygon::getStrokeWidth() const
140 : {
141 0 : return maStrokeAttributes.StrokeWidth;
142 : }
143 :
144 0 : bool ImplPolyPolygon::draw() const
145 : {
146 0 : CanvasSharedPtr pCanvas( getCanvas() );
147 :
148 : OSL_ENSURE( pCanvas.get() != NULL &&
149 : pCanvas->getUNOCanvas().is(),
150 : "ImplBitmap::draw: invalid canvas" );
151 :
152 0 : if( pCanvas.get() == NULL ||
153 0 : !pCanvas->getUNOCanvas().is() )
154 0 : return false;
155 :
156 0 : if( mbFillColorSet )
157 : {
158 0 : rendering::RenderState aLocalState( getRenderState() );
159 0 : aLocalState.DeviceColor = maFillColor;
160 :
161 0 : pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
162 0 : pCanvas->getViewState(),
163 0 : aLocalState );
164 : }
165 :
166 0 : if( mbStrokeColorSet )
167 : {
168 0 : rendering::RenderState aLocalState( getRenderState() );
169 0 : aLocalState.DeviceColor = maStrokeColor;
170 :
171 0 : if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
172 0 : pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
173 0 : pCanvas->getViewState(),
174 0 : aLocalState );
175 : else
176 0 : pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
177 0 : pCanvas->getViewState(),
178 : aLocalState,
179 0 : maStrokeAttributes );
180 : }
181 :
182 0 : return true;
183 : }
184 :
185 0 : uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
186 : {
187 0 : return mxPolyPoly;
188 : }
189 :
190 : }
191 : }
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|