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/logfile.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/rendering/TexturingMode.hpp> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <tools/gen.hxx> 37*cdf0e10cSrcweir #include <vcl/canvastools.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx> 40*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 41*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 42*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 43*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 44*cdf0e10cSrcweir #include <canvas/canvastools.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <boost/utility.hpp> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include "cachedprimitivebase.hxx" 49*cdf0e10cSrcweir #include "polypolyaction.hxx" 50*cdf0e10cSrcweir #include "outdevstate.hxx" 51*cdf0e10cSrcweir #include "mtftools.hxx" 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace ::com::sun::star; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir namespace cppcanvas 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir namespace internal 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir namespace 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir class PolyPolyAction : public CachedPrimitiveBase 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir public: 65*cdf0e10cSrcweir PolyPolyAction( const ::basegfx::B2DPolyPolygon&, 66*cdf0e10cSrcweir const CanvasSharedPtr&, 67*cdf0e10cSrcweir const OutDevState&, 68*cdf0e10cSrcweir bool bFill, 69*cdf0e10cSrcweir bool bStroke ); 70*cdf0e10cSrcweir PolyPolyAction( const ::basegfx::B2DPolyPolygon&, 71*cdf0e10cSrcweir const CanvasSharedPtr&, 72*cdf0e10cSrcweir const OutDevState&, 73*cdf0e10cSrcweir bool bFill, 74*cdf0e10cSrcweir bool bStroke, 75*cdf0e10cSrcweir int nTransparency ); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 78*cdf0e10cSrcweir const Subset& rSubset ) const; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 81*cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 82*cdf0e10cSrcweir const Subset& rSubset ) const; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir private: 87*cdf0e10cSrcweir using Action::render; 88*cdf0e10cSrcweir virtual bool render( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive, 89*cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransformation ) const; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D > mxPolyPoly; 92*cdf0e10cSrcweir const ::basegfx::B2DRange maBounds; 93*cdf0e10cSrcweir const CanvasSharedPtr mpCanvas; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // stroke color is now implicit: the maState.DeviceColor member 96*cdf0e10cSrcweir rendering::RenderState maState; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir uno::Sequence< double > maFillColor; 99*cdf0e10cSrcweir }; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir PolyPolyAction::PolyPolyAction( const ::basegfx::B2DPolyPolygon& rPolyPoly, 102*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 103*cdf0e10cSrcweir const OutDevState& rState, 104*cdf0e10cSrcweir bool bFill, 105*cdf0e10cSrcweir bool bStroke ) : 106*cdf0e10cSrcweir CachedPrimitiveBase( rCanvas, false ), 107*cdf0e10cSrcweir mxPolyPoly( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( rCanvas->getUNOCanvas()->getDevice(), rPolyPoly) ), 108*cdf0e10cSrcweir maBounds( ::basegfx::tools::getRange(rPolyPoly) ), 109*cdf0e10cSrcweir mpCanvas( rCanvas ), 110*cdf0e10cSrcweir maState(), 111*cdf0e10cSrcweir maFillColor() 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir tools::initRenderState(maState,rState); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir if( bFill ) 116*cdf0e10cSrcweir maFillColor = rState.fillColor; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir if( bStroke ) 119*cdf0e10cSrcweir maState.DeviceColor = rState.lineColor; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir PolyPolyAction::PolyPolyAction( const ::basegfx::B2DPolyPolygon& rPolyPoly, 123*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 124*cdf0e10cSrcweir const OutDevState& rState, 125*cdf0e10cSrcweir bool bFill, 126*cdf0e10cSrcweir bool bStroke, 127*cdf0e10cSrcweir int nTransparency ) : 128*cdf0e10cSrcweir CachedPrimitiveBase( rCanvas, false ), 129*cdf0e10cSrcweir mxPolyPoly( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( rCanvas->getUNOCanvas()->getDevice(), rPolyPoly) ), 130*cdf0e10cSrcweir maBounds( ::basegfx::tools::getRange(rPolyPoly) ), 131*cdf0e10cSrcweir mpCanvas( rCanvas ), 132*cdf0e10cSrcweir maState(), 133*cdf0e10cSrcweir maFillColor() 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir tools::initRenderState(maState,rState); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir if( bFill ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir maFillColor = rState.fillColor; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir if( maFillColor.getLength() < 4 ) 142*cdf0e10cSrcweir maFillColor.realloc( 4 ); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // TODO(F1): Color management 145*cdf0e10cSrcweir // adapt fill color transparency 146*cdf0e10cSrcweir maFillColor[3] = 1.0 - nTransparency / 100.0; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir if( bStroke ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir maState.DeviceColor = rState.lineColor; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir if( maState.DeviceColor.getLength() < 4 ) 154*cdf0e10cSrcweir maState.DeviceColor.realloc( 4 ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // TODO(F1): Color management 157*cdf0e10cSrcweir // adapt fill color transparency 158*cdf0e10cSrcweir maState.DeviceColor[3] = 1.0 - nTransparency / 100.0; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir bool PolyPolyAction::render( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive, 163*cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransformation ) const 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::PolyPolyAction::render()" ); 166*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::PolyPolyAction: 0x%X", this ); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 169*cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir #ifdef SPECIAL_DEBUG 172*cdf0e10cSrcweir aLocalState.Clip.clear(); 173*cdf0e10cSrcweir aLocalState.DeviceColor = 174*cdf0e10cSrcweir ::vcl::unotools::colorToDoubleSequence( mpCanvas->getUNOCanvas()->getDevice(), 175*cdf0e10cSrcweir ::Color( 0x80FF0000 ) ); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir if( maState.Clip.is() ) 178*cdf0e10cSrcweir mpCanvas->getUNOCanvas()->fillPolyPolygon( maState.Clip, 179*cdf0e10cSrcweir mpCanvas->getViewState(), 180*cdf0e10cSrcweir aLocalState ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir aLocalState.DeviceColor = maState.DeviceColor; 183*cdf0e10cSrcweir #endif 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir if( maFillColor.getLength() ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir // TODO(E3): Use DBO's finalizer here, 188*cdf0e10cSrcweir // fillPolyPolygon() might throw 189*cdf0e10cSrcweir const uno::Sequence< double > aTmpColor( aLocalState.DeviceColor ); 190*cdf0e10cSrcweir aLocalState.DeviceColor = maFillColor; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir rCachedPrimitive = mpCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly, 193*cdf0e10cSrcweir mpCanvas->getViewState(), 194*cdf0e10cSrcweir aLocalState ); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir aLocalState.DeviceColor = aTmpColor; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir if( aLocalState.DeviceColor.getLength() ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir rCachedPrimitive = mpCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly, 202*cdf0e10cSrcweir mpCanvas->getViewState(), 203*cdf0e10cSrcweir aLocalState ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir return true; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir bool PolyPolyAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 210*cdf0e10cSrcweir const Subset& rSubset ) const 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 213*cdf0e10cSrcweir // line segments, when subsets are requested. 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // polygon only contains a single action, fail if subset 216*cdf0e10cSrcweir // requests different range 217*cdf0e10cSrcweir if( rSubset.mnSubsetBegin != 0 || 218*cdf0e10cSrcweir rSubset.mnSubsetEnd != 1 ) 219*cdf0e10cSrcweir return false; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir return CachedPrimitiveBase::render( rTransformation ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir ::basegfx::B2DRange PolyPolyAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 227*cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir return tools::calcDevicePixelBounds( 230*cdf0e10cSrcweir maBounds, 231*cdf0e10cSrcweir mpCanvas->getViewState(), 232*cdf0e10cSrcweir aLocalState ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir ::basegfx::B2DRange PolyPolyAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 236*cdf0e10cSrcweir const Subset& rSubset ) const 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 239*cdf0e10cSrcweir // line segments, when subsets are requested. 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir // polygon only contains a single action, empty bounds 242*cdf0e10cSrcweir // if subset requests different range 243*cdf0e10cSrcweir if( rSubset.mnSubsetBegin != 0 || 244*cdf0e10cSrcweir rSubset.mnSubsetEnd != 1 ) 245*cdf0e10cSrcweir return ::basegfx::B2DRange(); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir return getBounds( rTransformation ); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir sal_Int32 PolyPolyAction::getActionCount() const 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 253*cdf0e10cSrcweir // line segments, when subsets are requested. 254*cdf0e10cSrcweir return 1; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // ------------------------------------------------------------------------------- 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir class TexturedPolyPolyAction : public CachedPrimitiveBase 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir public: 263*cdf0e10cSrcweir TexturedPolyPolyAction( const ::basegfx::B2DPolyPolygon& rPoly, 264*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 265*cdf0e10cSrcweir const OutDevState& rState, 266*cdf0e10cSrcweir const rendering::Texture& rTexture ); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 269*cdf0e10cSrcweir const Subset& rSubset ) const; 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 272*cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 273*cdf0e10cSrcweir const Subset& rSubset ) const; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir private: 278*cdf0e10cSrcweir using Action::render; 279*cdf0e10cSrcweir virtual bool render( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive, 280*cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransformation ) const; 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D > mxPolyPoly; 283*cdf0e10cSrcweir const ::basegfx::B2DRectangle maBounds; 284*cdf0e10cSrcweir const CanvasSharedPtr mpCanvas; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // stroke color is now implicit: the maState.DeviceColor member 287*cdf0e10cSrcweir rendering::RenderState maState; 288*cdf0e10cSrcweir const rendering::Texture maTexture; 289*cdf0e10cSrcweir }; 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir TexturedPolyPolyAction::TexturedPolyPolyAction( const ::basegfx::B2DPolyPolygon& rPolyPoly, 292*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 293*cdf0e10cSrcweir const OutDevState& rState, 294*cdf0e10cSrcweir const rendering::Texture& rTexture ) : 295*cdf0e10cSrcweir CachedPrimitiveBase( rCanvas, true ), 296*cdf0e10cSrcweir mxPolyPoly( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( rCanvas->getUNOCanvas()->getDevice(), rPolyPoly) ), 297*cdf0e10cSrcweir maBounds( ::basegfx::tools::getRange(rPolyPoly) ), 298*cdf0e10cSrcweir mpCanvas( rCanvas ), 299*cdf0e10cSrcweir maState(), 300*cdf0e10cSrcweir maTexture( rTexture ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir tools::initRenderState(maState,rState); 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir bool TexturedPolyPolyAction::render( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive, 306*cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransformation ) const 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::PolyPolyAction::render()" ); 309*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::PolyPolyAction: 0x%X", this ); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 312*cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir uno::Sequence< rendering::Texture > aSeq(1); 315*cdf0e10cSrcweir aSeq[0] = maTexture; 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir rCachedPrimitive = mpCanvas->getUNOCanvas()->fillTexturedPolyPolygon( mxPolyPoly, 318*cdf0e10cSrcweir mpCanvas->getViewState(), 319*cdf0e10cSrcweir aLocalState, 320*cdf0e10cSrcweir aSeq ); 321*cdf0e10cSrcweir return true; 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir bool TexturedPolyPolyAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 325*cdf0e10cSrcweir const Subset& rSubset ) const 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 328*cdf0e10cSrcweir // line segments, when subsets are requested. 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir // polygon only contains a single action, fail if subset 331*cdf0e10cSrcweir // requests different range 332*cdf0e10cSrcweir if( rSubset.mnSubsetBegin != 0 || 333*cdf0e10cSrcweir rSubset.mnSubsetEnd != 1 ) 334*cdf0e10cSrcweir return false; 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir return CachedPrimitiveBase::render( rTransformation ); 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir ::basegfx::B2DRange TexturedPolyPolyAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 342*cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir return tools::calcDevicePixelBounds( 345*cdf0e10cSrcweir maBounds, 346*cdf0e10cSrcweir mpCanvas->getViewState(), 347*cdf0e10cSrcweir aLocalState ); 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir ::basegfx::B2DRange TexturedPolyPolyAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 351*cdf0e10cSrcweir const Subset& rSubset ) const 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 354*cdf0e10cSrcweir // line segments, when subsets are requested. 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir // polygon only contains a single action, empty bounds 357*cdf0e10cSrcweir // if subset requests different range 358*cdf0e10cSrcweir if( rSubset.mnSubsetBegin != 0 || 359*cdf0e10cSrcweir rSubset.mnSubsetEnd != 1 ) 360*cdf0e10cSrcweir return ::basegfx::B2DRange(); 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir return getBounds( rTransformation ); 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir sal_Int32 TexturedPolyPolyAction::getActionCount() const 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 368*cdf0e10cSrcweir // line segments, when subsets are requested. 369*cdf0e10cSrcweir return 1; 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir // ------------------------------------------------------------------------------- 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir class StrokedPolyPolyAction : public CachedPrimitiveBase 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir public: 377*cdf0e10cSrcweir StrokedPolyPolyAction( const ::basegfx::B2DPolyPolygon& rPoly, 378*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 379*cdf0e10cSrcweir const OutDevState& rState, 380*cdf0e10cSrcweir const rendering::StrokeAttributes& rStrokeAttributes ); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 383*cdf0e10cSrcweir const Subset& rSubset ) const; 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 386*cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 387*cdf0e10cSrcweir const Subset& rSubset ) const; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir private: 392*cdf0e10cSrcweir using Action::render; 393*cdf0e10cSrcweir virtual bool render( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive, 394*cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransformation ) const; 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D > mxPolyPoly; 397*cdf0e10cSrcweir const ::basegfx::B2DRectangle maBounds; 398*cdf0e10cSrcweir const CanvasSharedPtr mpCanvas; 399*cdf0e10cSrcweir rendering::RenderState maState; 400*cdf0e10cSrcweir const rendering::StrokeAttributes maStrokeAttributes; 401*cdf0e10cSrcweir }; 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir StrokedPolyPolyAction::StrokedPolyPolyAction( const ::basegfx::B2DPolyPolygon& rPolyPoly, 404*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 405*cdf0e10cSrcweir const OutDevState& rState, 406*cdf0e10cSrcweir const rendering::StrokeAttributes& rStrokeAttributes ) : 407*cdf0e10cSrcweir CachedPrimitiveBase( rCanvas, false ), 408*cdf0e10cSrcweir mxPolyPoly( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( rCanvas->getUNOCanvas()->getDevice(), rPolyPoly) ), 409*cdf0e10cSrcweir maBounds( ::basegfx::tools::getRange(rPolyPoly) ), 410*cdf0e10cSrcweir mpCanvas( rCanvas ), 411*cdf0e10cSrcweir maState(), 412*cdf0e10cSrcweir maStrokeAttributes( rStrokeAttributes ) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir tools::initRenderState(maState,rState); 415*cdf0e10cSrcweir maState.DeviceColor = rState.lineColor; 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir bool StrokedPolyPolyAction::render( uno::Reference< rendering::XCachedPrimitive >& rCachedPrimitive, 419*cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransformation ) const 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::PolyPolyAction::render()" ); 422*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::PolyPolyAction: 0x%X", this ); 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 425*cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir rCachedPrimitive = mpCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly, 428*cdf0e10cSrcweir mpCanvas->getViewState(), 429*cdf0e10cSrcweir aLocalState, 430*cdf0e10cSrcweir maStrokeAttributes ); 431*cdf0e10cSrcweir return true; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir bool StrokedPolyPolyAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 435*cdf0e10cSrcweir const Subset& rSubset ) const 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 438*cdf0e10cSrcweir // line segments, when subsets are requested. 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir // polygon only contains a single action, fail if subset 441*cdf0e10cSrcweir // requests different range 442*cdf0e10cSrcweir if( rSubset.mnSubsetBegin != 0 || 443*cdf0e10cSrcweir rSubset.mnSubsetEnd != 1 ) 444*cdf0e10cSrcweir return false; 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir return CachedPrimitiveBase::render( rTransformation ); 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir ::basegfx::B2DRange StrokedPolyPolyAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 452*cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir return tools::calcDevicePixelBounds( 455*cdf0e10cSrcweir maBounds, 456*cdf0e10cSrcweir mpCanvas->getViewState(), 457*cdf0e10cSrcweir aLocalState ); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir ::basegfx::B2DRange StrokedPolyPolyAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 461*cdf0e10cSrcweir const Subset& rSubset ) const 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 464*cdf0e10cSrcweir // line segments, when subsets are requested. 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir // polygon only contains a single action, empty bounds 467*cdf0e10cSrcweir // if subset requests different range 468*cdf0e10cSrcweir if( rSubset.mnSubsetBegin != 0 || 469*cdf0e10cSrcweir rSubset.mnSubsetEnd != 1 ) 470*cdf0e10cSrcweir return ::basegfx::B2DRange(); 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir return getBounds( rTransformation ); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir sal_Int32 StrokedPolyPolyAction::getActionCount() const 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir // TODO(F1): Split up poly-polygon into polygons, or even 478*cdf0e10cSrcweir // line segments, when subsets are requested. 479*cdf0e10cSrcweir return 1; 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir ActionSharedPtr PolyPolyActionFactory::createPolyPolyAction( const ::basegfx::B2DPolyPolygon& rPoly, 484*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 485*cdf0e10cSrcweir const OutDevState& rState ) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir OSL_ENSURE( rState.isLineColorSet || rState.isFillColorSet, 488*cdf0e10cSrcweir "PolyPolyActionFactory::createPolyPolyAction() with empty line and fill color" ); 489*cdf0e10cSrcweir return ActionSharedPtr( new PolyPolyAction( rPoly, rCanvas, rState, 490*cdf0e10cSrcweir rState.isFillColorSet, 491*cdf0e10cSrcweir rState.isLineColorSet ) ); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir ActionSharedPtr PolyPolyActionFactory::createPolyPolyAction( const ::basegfx::B2DPolyPolygon& rPoly, 495*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 496*cdf0e10cSrcweir const OutDevState& rState, 497*cdf0e10cSrcweir const rendering::Texture& rTexture ) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir return ActionSharedPtr( new TexturedPolyPolyAction( rPoly, rCanvas, rState, rTexture ) ); 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir ActionSharedPtr PolyPolyActionFactory::createLinePolyPolyAction( const ::basegfx::B2DPolyPolygon& rPoly, 503*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 504*cdf0e10cSrcweir const OutDevState& rState ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir OSL_ENSURE( rState.isLineColorSet, 507*cdf0e10cSrcweir "PolyPolyActionFactory::createLinePolyPolyAction() called with empty line color" ); 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir return ActionSharedPtr( new PolyPolyAction( rPoly, rCanvas, rState, 510*cdf0e10cSrcweir false, 511*cdf0e10cSrcweir rState.isLineColorSet ) ); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir ActionSharedPtr PolyPolyActionFactory::createPolyPolyAction( const ::basegfx::B2DPolyPolygon& rPoly, 515*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 516*cdf0e10cSrcweir const OutDevState& rState, 517*cdf0e10cSrcweir const rendering::StrokeAttributes& rStrokeAttributes ) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir OSL_ENSURE( rState.isLineColorSet, 520*cdf0e10cSrcweir "PolyPolyActionFactory::createPolyPolyAction() for strokes called with empty line color" ); 521*cdf0e10cSrcweir return ActionSharedPtr( new StrokedPolyPolyAction( rPoly, rCanvas, rState, rStrokeAttributes ) ); 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir ActionSharedPtr PolyPolyActionFactory::createPolyPolyAction( const ::basegfx::B2DPolyPolygon& rPoly, 525*cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 526*cdf0e10cSrcweir const OutDevState& rState, 527*cdf0e10cSrcweir int nTransparency ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir OSL_ENSURE( rState.isLineColorSet || rState.isFillColorSet, 530*cdf0e10cSrcweir "PolyPolyActionFactory::createPolyPolyAction() with empty line and fill color" ); 531*cdf0e10cSrcweir return ActionSharedPtr( new PolyPolyAction( rPoly, rCanvas, rState, 532*cdf0e10cSrcweir rState.isFillColorSet, 533*cdf0e10cSrcweir rState.isLineColorSet, 534*cdf0e10cSrcweir nTransparency ) ); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir } 539