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_basegfx.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/geometry/AffineMatrix2D.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/rendering/RenderState.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/rendering/ViewState.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 38*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx> 39*cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx> 40*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx> 41*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 42*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 43*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 44*cdf0e10cSrcweir #include <basegfx/tools/unopolypolygon.hxx> 45*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir using namespace ::com::sun::star; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir namespace basegfx 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir namespace unotools 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir UnoPolyPolygon::UnoPolyPolygon( const B2DPolyPolygon& rPolyPoly ) : 55*cdf0e10cSrcweir UnoPolyPolygonBase( m_aMutex ), 56*cdf0e10cSrcweir maPolyPoly( rPolyPoly ), 57*cdf0e10cSrcweir meFillRule( rendering::FillRule_EVEN_ODD ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir // or else races will haunt us. 60*cdf0e10cSrcweir maPolyPoly.makeUnique(); 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir void SAL_CALL UnoPolyPolygon::addPolyPolygon( 64*cdf0e10cSrcweir const geometry::RealPoint2D& position, 65*cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& polyPolygon ) throw (lang::IllegalArgumentException,uno::RuntimeException) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 68*cdf0e10cSrcweir modifying(); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // TODO(F1): Correctly fulfill the UNO API 71*cdf0e10cSrcweir // specification. This will probably result in a vector of 72*cdf0e10cSrcweir // poly-polygons to be stored in this object. 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir const sal_Int32 nPolys( polyPolygon->getNumberOfPolygons() ); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir if( !polyPolygon.is() || !nPolys ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir // invalid or empty polygon - nothing to do. 79*cdf0e10cSrcweir return; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir B2DPolyPolygon aSrcPoly; 83*cdf0e10cSrcweir const UnoPolyPolygon* pSrc( dynamic_cast< UnoPolyPolygon* >(polyPolygon.get()) ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir // try to extract polygon data from interface. First, 86*cdf0e10cSrcweir // check whether it's the same implementation object, 87*cdf0e10cSrcweir // which we can tunnel then. 88*cdf0e10cSrcweir if( pSrc ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir aSrcPoly = pSrc->getPolyPolygon(); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir else 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir // not a known implementation object - try data source 95*cdf0e10cSrcweir // interfaces 96*cdf0e10cSrcweir uno::Reference< rendering::XBezierPolyPolygon2D > xBezierPoly( 97*cdf0e10cSrcweir polyPolygon, 98*cdf0e10cSrcweir uno::UNO_QUERY ); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir if( xBezierPoly.is() ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir aSrcPoly = unotools::polyPolygonFromBezier2DSequenceSequence( 103*cdf0e10cSrcweir xBezierPoly->getBezierSegments( 0, 104*cdf0e10cSrcweir nPolys, 105*cdf0e10cSrcweir 0, 106*cdf0e10cSrcweir -1 ) ); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir else 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir uno::Reference< rendering::XLinePolyPolygon2D > xLinePoly( 111*cdf0e10cSrcweir polyPolygon, 112*cdf0e10cSrcweir uno::UNO_QUERY ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // no implementation class and no data provider 115*cdf0e10cSrcweir // found - contract violation. 116*cdf0e10cSrcweir if( !xLinePoly.is() ) 117*cdf0e10cSrcweir throw lang::IllegalArgumentException( 118*cdf0e10cSrcweir ::rtl::OUString( 119*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 120*cdf0e10cSrcweir "UnoPolyPolygon::addPolyPolygon(): Invalid input " 121*cdf0e10cSrcweir "poly-polygon, cannot retrieve vertex data")), 122*cdf0e10cSrcweir static_cast<cppu::OWeakObject*>(this), 1); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir aSrcPoly = unotools::polyPolygonFromPoint2DSequenceSequence( 125*cdf0e10cSrcweir xLinePoly->getPoints( 0, 126*cdf0e10cSrcweir nPolys, 127*cdf0e10cSrcweir 0, 128*cdf0e10cSrcweir -1 ) ); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir const B2DRange aBounds( tools::getRange( aSrcPoly ) ); 133*cdf0e10cSrcweir const B2DVector aOffset( unotools::b2DPointFromRealPoint2D( position ) - 134*cdf0e10cSrcweir aBounds.getMinimum() ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir if( !aOffset.equalZero() ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir const B2DHomMatrix aTranslate(tools::createTranslateB2DHomMatrix(aOffset)); 139*cdf0e10cSrcweir aSrcPoly.transform( aTranslate ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir maPolyPoly.append( aSrcPoly ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir sal_Int32 SAL_CALL UnoPolyPolygon::getNumberOfPolygons() throw (uno::RuntimeException) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 148*cdf0e10cSrcweir return maPolyPoly.count(); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir sal_Int32 SAL_CALL UnoPolyPolygon::getNumberOfPolygonPoints( 152*cdf0e10cSrcweir sal_Int32 polygon ) throw (lang::IndexOutOfBoundsException,uno::RuntimeException) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 155*cdf0e10cSrcweir checkIndex( polygon ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir return maPolyPoly.getB2DPolygon(polygon).count(); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir rendering::FillRule SAL_CALL UnoPolyPolygon::getFillRule() throw (uno::RuntimeException) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 163*cdf0e10cSrcweir return meFillRule; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir void SAL_CALL UnoPolyPolygon::setFillRule( 167*cdf0e10cSrcweir rendering::FillRule fillRule ) throw (uno::RuntimeException) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 170*cdf0e10cSrcweir modifying(); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir meFillRule = fillRule; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir sal_Bool SAL_CALL UnoPolyPolygon::isClosed( 176*cdf0e10cSrcweir sal_Int32 index ) throw (lang::IndexOutOfBoundsException,uno::RuntimeException) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 179*cdf0e10cSrcweir checkIndex( index ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir return maPolyPoly.getB2DPolygon(index).isClosed(); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir void SAL_CALL UnoPolyPolygon::setClosed( 185*cdf0e10cSrcweir sal_Int32 index, 186*cdf0e10cSrcweir sal_Bool closedState ) throw (lang::IndexOutOfBoundsException,uno::RuntimeException) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 189*cdf0e10cSrcweir modifying(); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir if( index == -1L ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir // set all 194*cdf0e10cSrcweir maPolyPoly.setClosed( closedState ); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir else 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir checkIndex( index ); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir // fetch referenced polygon, change state 201*cdf0e10cSrcweir B2DPolygon aTmp( maPolyPoly.getB2DPolygon(index) ); 202*cdf0e10cSrcweir aTmp.setClosed( closedState ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir // set back to container 205*cdf0e10cSrcweir maPolyPoly.setB2DPolygon( index, aTmp ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir uno::Sequence< uno::Sequence< geometry::RealPoint2D > > SAL_CALL UnoPolyPolygon::getPoints( 210*cdf0e10cSrcweir sal_Int32 nPolygonIndex, 211*cdf0e10cSrcweir sal_Int32 nNumberOfPolygons, 212*cdf0e10cSrcweir sal_Int32 nPointIndex, 213*cdf0e10cSrcweir sal_Int32 nNumberOfPoints ) throw (lang::IndexOutOfBoundsException,uno::RuntimeException) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir return unotools::pointSequenceSequenceFromB2DPolyPolygon( 218*cdf0e10cSrcweir getSubsetPolyPolygon( nPolygonIndex, 219*cdf0e10cSrcweir nNumberOfPolygons, 220*cdf0e10cSrcweir nPointIndex, 221*cdf0e10cSrcweir nNumberOfPoints ) ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir void SAL_CALL UnoPolyPolygon::setPoints( 225*cdf0e10cSrcweir const uno::Sequence< uno::Sequence< geometry::RealPoint2D > >& points, 226*cdf0e10cSrcweir sal_Int32 nPolygonIndex ) throw (lang::IndexOutOfBoundsException,uno::RuntimeException) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 229*cdf0e10cSrcweir modifying(); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir const B2DPolyPolygon& rNewPolyPoly( 232*cdf0e10cSrcweir unotools::polyPolygonFromPoint2DSequenceSequence( points ) ); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir if( nPolygonIndex == -1 ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir maPolyPoly = rNewPolyPoly; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir else 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir checkIndex( nPolygonIndex ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir maPolyPoly.insert( nPolygonIndex, rNewPolyPoly ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir geometry::RealPoint2D SAL_CALL UnoPolyPolygon::getPoint( 247*cdf0e10cSrcweir sal_Int32 nPolygonIndex, 248*cdf0e10cSrcweir sal_Int32 nPointIndex ) throw (lang::IndexOutOfBoundsException,uno::RuntimeException) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 251*cdf0e10cSrcweir checkIndex( nPolygonIndex ); 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir const B2DPolygon& rPoly( maPolyPoly.getB2DPolygon( nPolygonIndex ) ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if( nPointIndex < 0 || nPointIndex >= static_cast<sal_Int32>(rPoly.count()) ) 256*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir return unotools::point2DFromB2DPoint( rPoly.getB2DPoint( nPointIndex ) ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir void SAL_CALL UnoPolyPolygon::setPoint( 262*cdf0e10cSrcweir const geometry::RealPoint2D& point, 263*cdf0e10cSrcweir sal_Int32 nPolygonIndex, 264*cdf0e10cSrcweir sal_Int32 nPointIndex ) throw (lang::IndexOutOfBoundsException,uno::RuntimeException) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 267*cdf0e10cSrcweir checkIndex( nPolygonIndex ); 268*cdf0e10cSrcweir modifying(); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir B2DPolygon aPoly( maPolyPoly.getB2DPolygon( nPolygonIndex ) ); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir if( nPointIndex < 0 || nPointIndex >= static_cast<sal_Int32>(aPoly.count()) ) 273*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir aPoly.setB2DPoint( nPointIndex, 276*cdf0e10cSrcweir unotools::b2DPointFromRealPoint2D( point ) ); 277*cdf0e10cSrcweir maPolyPoly.setB2DPolygon( nPolygonIndex, aPoly ); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > SAL_CALL UnoPolyPolygon::getBezierSegments( 281*cdf0e10cSrcweir sal_Int32 nPolygonIndex, 282*cdf0e10cSrcweir sal_Int32 nNumberOfPolygons, 283*cdf0e10cSrcweir sal_Int32 nPointIndex, 284*cdf0e10cSrcweir sal_Int32 nNumberOfPoints ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 287*cdf0e10cSrcweir return unotools::bezierSequenceSequenceFromB2DPolyPolygon( 288*cdf0e10cSrcweir getSubsetPolyPolygon( nPolygonIndex, 289*cdf0e10cSrcweir nNumberOfPolygons, 290*cdf0e10cSrcweir nPointIndex, 291*cdf0e10cSrcweir nNumberOfPoints ) ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir void SAL_CALL UnoPolyPolygon::setBezierSegments( 295*cdf0e10cSrcweir const uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > >& points, 296*cdf0e10cSrcweir sal_Int32 nPolygonIndex ) throw (lang::IndexOutOfBoundsException, 297*cdf0e10cSrcweir uno::RuntimeException) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 300*cdf0e10cSrcweir modifying(); 301*cdf0e10cSrcweir const B2DPolyPolygon& rNewPolyPoly( 302*cdf0e10cSrcweir unotools::polyPolygonFromBezier2DSequenceSequence( points ) ); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir if( nPolygonIndex == -1 ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir maPolyPoly = rNewPolyPoly; 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir else 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir checkIndex( nPolygonIndex ); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir maPolyPoly.insert( nPolygonIndex, rNewPolyPoly ); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir geometry::RealBezierSegment2D SAL_CALL UnoPolyPolygon::getBezierSegment( sal_Int32 nPolygonIndex, 317*cdf0e10cSrcweir sal_Int32 nPointIndex ) throw (lang::IndexOutOfBoundsException, 318*cdf0e10cSrcweir uno::RuntimeException) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 321*cdf0e10cSrcweir checkIndex( nPolygonIndex ); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir const B2DPolygon& rPoly( maPolyPoly.getB2DPolygon( nPolygonIndex ) ); 324*cdf0e10cSrcweir const sal_uInt32 nPointCount(rPoly.count()); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir if( nPointIndex < 0 || nPointIndex >= static_cast<sal_Int32>(nPointCount) ) 327*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir const B2DPoint& rPt( rPoly.getB2DPoint( nPointIndex ) ); 330*cdf0e10cSrcweir const B2DPoint& rCtrl0( rPoly.getNextControlPoint(nPointIndex) ); 331*cdf0e10cSrcweir const B2DPoint& rCtrl1( rPoly.getPrevControlPoint((nPointIndex + 1) % nPointCount) ); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir return geometry::RealBezierSegment2D( rPt.getX(), 334*cdf0e10cSrcweir rPt.getY(), 335*cdf0e10cSrcweir rCtrl0.getX(), 336*cdf0e10cSrcweir rCtrl0.getY(), 337*cdf0e10cSrcweir rCtrl1.getX(), 338*cdf0e10cSrcweir rCtrl1.getY() ); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir void SAL_CALL UnoPolyPolygon::setBezierSegment( const geometry::RealBezierSegment2D& segment, 342*cdf0e10cSrcweir sal_Int32 nPolygonIndex, 343*cdf0e10cSrcweir sal_Int32 nPointIndex ) throw (lang::IndexOutOfBoundsException, 344*cdf0e10cSrcweir uno::RuntimeException) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 347*cdf0e10cSrcweir checkIndex( nPolygonIndex ); 348*cdf0e10cSrcweir modifying(); 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir B2DPolygon aPoly( maPolyPoly.getB2DPolygon( nPolygonIndex ) ); 351*cdf0e10cSrcweir const sal_uInt32 nPointCount(aPoly.count()); 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir if( nPointIndex < 0 || nPointIndex >= static_cast<sal_Int32>(nPointCount) ) 354*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir aPoly.setB2DPoint( nPointIndex, 357*cdf0e10cSrcweir B2DPoint( segment.Px, 358*cdf0e10cSrcweir segment.Py ) ); 359*cdf0e10cSrcweir aPoly.setNextControlPoint(nPointIndex, 360*cdf0e10cSrcweir B2DPoint(segment.C1x, segment.C1y)); 361*cdf0e10cSrcweir aPoly.setPrevControlPoint((nPointIndex + 1) % nPointCount, 362*cdf0e10cSrcweir B2DPoint(segment.C2x, segment.C2y)); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir maPolyPoly.setB2DPolygon( nPolygonIndex, aPoly ); 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir B2DPolyPolygon UnoPolyPolygon::getSubsetPolyPolygon( 368*cdf0e10cSrcweir sal_Int32 nPolygonIndex, 369*cdf0e10cSrcweir sal_Int32 nNumberOfPolygons, 370*cdf0e10cSrcweir sal_Int32 nPointIndex, 371*cdf0e10cSrcweir sal_Int32 nNumberOfPoints ) const 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 374*cdf0e10cSrcweir checkIndex( nPolygonIndex ); 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir const sal_Int32 nPolyCount( maPolyPoly.count() ); 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir // check for "full polygon" case 379*cdf0e10cSrcweir if( !nPolygonIndex && 380*cdf0e10cSrcweir !nPointIndex && 381*cdf0e10cSrcweir nNumberOfPolygons == nPolyCount && 382*cdf0e10cSrcweir nNumberOfPoints == -1 ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir return maPolyPoly; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir B2DPolyPolygon aSubsetPoly; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir // create temporary polygon (as an extract from maPoly, 390*cdf0e10cSrcweir // which contains the requested subset) 391*cdf0e10cSrcweir for( sal_Int32 i=nPolygonIndex; i<nNumberOfPolygons; ++i ) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir checkIndex(i); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir const B2DPolygon& rCurrPoly( maPolyPoly.getB2DPolygon(i) ); 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir sal_Int32 nFirstPoint(0); 398*cdf0e10cSrcweir sal_Int32 nLastPoint(nPolyCount-1); 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir if( nPointIndex && i==nPolygonIndex ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir // very first polygon - respect nPointIndex, if 403*cdf0e10cSrcweir // not zero 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir // empty polygon - impossible to specify _any_ 406*cdf0e10cSrcweir // legal value except 0 here! 407*cdf0e10cSrcweir if( !nPolyCount && nPointIndex ) 408*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir nFirstPoint = nPointIndex; 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir if( i==nNumberOfPolygons-1 && nNumberOfPoints != -1 ) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir // very last polygon - respect nNumberOfPoints 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir // empty polygon - impossible to specify _any_ 418*cdf0e10cSrcweir // legal value except -1 here! 419*cdf0e10cSrcweir if( !nPolyCount ) 420*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir nLastPoint = nFirstPoint+nNumberOfPoints; 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir if( !nPolyCount ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir // empty polygon - index checks already performed 428*cdf0e10cSrcweir // above, now simply append empty polygon 429*cdf0e10cSrcweir aSubsetPoly.append( rCurrPoly ); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir else 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir if( nFirstPoint < 0 || nFirstPoint >= nPolyCount ) 434*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir if( nLastPoint < 0 || nLastPoint >= nPolyCount ) 437*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir B2DPolygon aTmp; 440*cdf0e10cSrcweir for( sal_Int32 j=nFirstPoint; j<nLastPoint; ++j ) 441*cdf0e10cSrcweir aTmp.append( rCurrPoly.getB2DPoint(j) ); 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir aSubsetPoly.append( aTmp ); 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir return aSubsetPoly; 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir B2DPolyPolygon UnoPolyPolygon::getPolyPolygonUnsafe() const 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir return maPolyPoly; 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir #define IMPLEMENTATION_NAME "gfx::internal::UnoPolyPolygon" 456*cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.PolyPolygon2D" 457*cdf0e10cSrcweir ::rtl::OUString SAL_CALL UnoPolyPolygon::getImplementationName() throw( uno::RuntimeException ) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir sal_Bool SAL_CALL UnoPolyPolygon::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL UnoPolyPolygon::getSupportedServiceNames() throw( uno::RuntimeException ) 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(1); 470*cdf0e10cSrcweir aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir return aRet; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir B2DPolyPolygon UnoPolyPolygon::getPolyPolygon() const 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir osl::MutexGuard const guard( m_aMutex ); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir // detach result from us 480*cdf0e10cSrcweir B2DPolyPolygon aRet( maPolyPoly ); 481*cdf0e10cSrcweir aRet.makeUnique(); 482*cdf0e10cSrcweir return aRet; 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir } 487