1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_cppcanvas.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <rtl/math.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/rendering/PathJoinType.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/rendering/PathCapType.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 38*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include "implpolypolygon.hxx" 41*cdf0e10cSrcweir #include "tools.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir using namespace ::com::sun::star; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir namespace cppcanvas 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir namespace internal 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas, 52*cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& rPolyPoly ) : 53*cdf0e10cSrcweir CanvasGraphicHelper( rParentCanvas ), 54*cdf0e10cSrcweir mxPolyPoly( rPolyPoly ), 55*cdf0e10cSrcweir maStrokeAttributes(1.0, 56*cdf0e10cSrcweir 10.0, 57*cdf0e10cSrcweir uno::Sequence< double >(), 58*cdf0e10cSrcweir uno::Sequence< double >(), 59*cdf0e10cSrcweir rendering::PathCapType::ROUND, 60*cdf0e10cSrcweir rendering::PathCapType::ROUND, 61*cdf0e10cSrcweir rendering::PathJoinType::ROUND ), 62*cdf0e10cSrcweir maFillColor(), 63*cdf0e10cSrcweir maStrokeColor(), 64*cdf0e10cSrcweir mbFillColorSet( false ), 65*cdf0e10cSrcweir mbStrokeColorSet( false ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" ); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir ImplPolyPolygon::~ImplPolyPolygon() 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir void ImplPolyPolygon::addPolygon( const ::basegfx::B2DPolygon& rPoly ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir OSL_ENSURE( mxPolyPoly.is(), 77*cdf0e10cSrcweir "ImplPolyPolygon::addPolygon(): Invalid polygon" ); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir if( !mxPolyPoly.is() ) 80*cdf0e10cSrcweir return; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() ); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir OSL_ENSURE( xDevice.is(), 85*cdf0e10cSrcweir "ImplPolyPolygon::addPolygon(): Invalid graphic device" ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir if( !xDevice.is() ) 88*cdf0e10cSrcweir return; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0), 91*cdf0e10cSrcweir ::basegfx::unotools::xPolyPolygonFromB2DPolygon( 92*cdf0e10cSrcweir xDevice, 93*cdf0e10cSrcweir rPoly) ); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir void ImplPolyPolygon::addPolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir OSL_ENSURE( mxPolyPoly.is(), 99*cdf0e10cSrcweir "ImplPolyPolygon::addPolyPolygon(): Invalid polygon" ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir if( !mxPolyPoly.is() ) 102*cdf0e10cSrcweir return; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir uno::Reference< rendering::XGraphicDevice > xDevice( getGraphicDevice() ); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir OSL_ENSURE( xDevice.is(), 107*cdf0e10cSrcweir "ImplPolyPolygon::addPolyPolygon(): Invalid graphic device" ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir if( !xDevice.is() ) 110*cdf0e10cSrcweir return; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir mxPolyPoly->addPolyPolygon( geometry::RealPoint2D(0.0, 0.0), 113*cdf0e10cSrcweir ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 114*cdf0e10cSrcweir xDevice, 115*cdf0e10cSrcweir rPoly) ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir void ImplPolyPolygon::setRGBAFillColor( Color::IntSRGBA aColor ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir maFillColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(), 121*cdf0e10cSrcweir aColor ); 122*cdf0e10cSrcweir mbFillColorSet = true; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir void ImplPolyPolygon::setRGBALineColor( Color::IntSRGBA aColor ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir maStrokeColor = tools::intSRGBAToDoubleSequence( getGraphicDevice(), 128*cdf0e10cSrcweir aColor ); 129*cdf0e10cSrcweir mbStrokeColorSet = true; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir Color::IntSRGBA ImplPolyPolygon::getRGBAFillColor() const 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir return tools::doubleSequenceToIntSRGBA( getGraphicDevice(), 135*cdf0e10cSrcweir maFillColor ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir Color::IntSRGBA ImplPolyPolygon::getRGBALineColor() const 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir return tools::doubleSequenceToIntSRGBA( getGraphicDevice(), 141*cdf0e10cSrcweir maStrokeColor ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir maStrokeAttributes.StrokeWidth = rStrokeWidth; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir double ImplPolyPolygon::getStrokeWidth() const 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir return maStrokeAttributes.StrokeWidth; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir bool ImplPolyPolygon::draw() const 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir CanvasSharedPtr pCanvas( getCanvas() ); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir OSL_ENSURE( pCanvas.get() != NULL && 159*cdf0e10cSrcweir pCanvas->getUNOCanvas().is(), 160*cdf0e10cSrcweir "ImplBitmap::draw: invalid canvas" ); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir if( pCanvas.get() == NULL || 163*cdf0e10cSrcweir !pCanvas->getUNOCanvas().is() ) 164*cdf0e10cSrcweir return false; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir if( mbFillColorSet ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir rendering::RenderState aLocalState( getRenderState() ); 169*cdf0e10cSrcweir aLocalState.DeviceColor = maFillColor; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly, 172*cdf0e10cSrcweir pCanvas->getViewState(), 173*cdf0e10cSrcweir aLocalState ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir if( mbStrokeColorSet ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir rendering::RenderState aLocalState( getRenderState() ); 179*cdf0e10cSrcweir aLocalState.DeviceColor = maStrokeColor; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) ) 182*cdf0e10cSrcweir pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly, 183*cdf0e10cSrcweir pCanvas->getViewState(), 184*cdf0e10cSrcweir aLocalState ); 185*cdf0e10cSrcweir else 186*cdf0e10cSrcweir pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly, 187*cdf0e10cSrcweir pCanvas->getViewState(), 188*cdf0e10cSrcweir aLocalState, 189*cdf0e10cSrcweir maStrokeAttributes ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir return true; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir return mxPolyPoly; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202