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_drawinglayer.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <drawinglayer/primitive2d/discreteshadowprimitive2d.hxx> 32*cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 33*cdf0e10cSrcweir #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 34*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 35*cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 36*cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir namespace drawinglayer 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir namespace primitive2d 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir DiscreteShadow::DiscreteShadow(const BitmapEx& rBitmapEx) 45*cdf0e10cSrcweir : maBitmapEx(rBitmapEx), 46*cdf0e10cSrcweir maTopLeft(), 47*cdf0e10cSrcweir maTop(), 48*cdf0e10cSrcweir maTopRight(), 49*cdf0e10cSrcweir maRight(), 50*cdf0e10cSrcweir maBottomRight(), 51*cdf0e10cSrcweir maBottom(), 52*cdf0e10cSrcweir maBottomLeft(), 53*cdf0e10cSrcweir maLeft() 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir const Size& rBitmapSize = getBitmapEx().GetSizePixel(); 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir if(rBitmapSize.Width() != rBitmapSize.Height() || rBitmapSize.Width() < 7) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir OSL_ENSURE(false, "DiscreteShadowPrimitive2D: wrong bitmap format (!)"); 60*cdf0e10cSrcweir maBitmapEx = BitmapEx(); 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir const BitmapEx& DiscreteShadow::getTopLeft() const 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir if(maTopLeft.IsEmpty()) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2); 69*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maTopLeft = getBitmapEx(); 70*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maTopLeft.Crop( 71*cdf0e10cSrcweir Rectangle(Point(0,0),Size(nQuarter*2+1,nQuarter*2+1))); 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir return maTopLeft; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir const BitmapEx& DiscreteShadow::getTop() const 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir if(maTop.IsEmpty()) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2); 82*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maTop = getBitmapEx(); 83*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maTop.Crop( 84*cdf0e10cSrcweir Rectangle(Point(nQuarter*2+1,0),Size(1,nQuarter+1))); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir return maTop; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir const BitmapEx& DiscreteShadow::getTopRight() const 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir if(maTopRight.IsEmpty()) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2); 95*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maTopRight = getBitmapEx(); 96*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maTopRight.Crop( 97*cdf0e10cSrcweir Rectangle(Point(nQuarter*2+2,0),Size(nQuarter*2+1,nQuarter*2+1))); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir return maTopRight; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir const BitmapEx& DiscreteShadow::getRight() const 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir if(maRight.IsEmpty()) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2); 108*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maRight = getBitmapEx(); 109*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maRight.Crop( 110*cdf0e10cSrcweir Rectangle(Point(nQuarter*3+2,nQuarter*2+1),Size(nQuarter+1,1))); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir return maRight; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir const BitmapEx& DiscreteShadow::getBottomRight() const 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir if(maBottomRight.IsEmpty()) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2); 121*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maBottomRight = getBitmapEx(); 122*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maBottomRight.Crop( 123*cdf0e10cSrcweir Rectangle(Point(nQuarter*2+2,nQuarter*2+2),Size(nQuarter*2+1,nQuarter*2+1))); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir return maBottomRight; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir const BitmapEx& DiscreteShadow::getBottom() const 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir if(maBottom.IsEmpty()) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2); 134*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maBottom = getBitmapEx(); 135*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maBottom.Crop( 136*cdf0e10cSrcweir Rectangle(Point(nQuarter*2+1,nQuarter*3+2),Size(1,nQuarter+1))); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir return maBottom; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir const BitmapEx& DiscreteShadow::getBottomLeft() const 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir if(maBottomLeft.IsEmpty()) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2); 147*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maBottomLeft = getBitmapEx(); 148*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maBottomLeft.Crop( 149*cdf0e10cSrcweir Rectangle(Point(0,nQuarter*2+2),Size(nQuarter*2+1,nQuarter*2+1))); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir return maBottomLeft; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir const BitmapEx& DiscreteShadow::getLeft() const 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir if(maLeft.IsEmpty()) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2); 160*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maLeft = getBitmapEx(); 161*cdf0e10cSrcweir const_cast< DiscreteShadow* >(this)->maLeft.Crop( 162*cdf0e10cSrcweir Rectangle(Point(0,nQuarter*2+1),Size(nQuarter+1,1))); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir return maLeft; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir } // end of namespace primitive2d 169*cdf0e10cSrcweir } // end of namespace drawinglayer 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir namespace drawinglayer 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir namespace primitive2d 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir Primitive2DSequence DiscreteShadowPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir Primitive2DSequence xRetval; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if(!getDiscreteShadow().getBitmapEx().IsEmpty()) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2); 184*cdf0e10cSrcweir const basegfx::B2DVector aScale(getTransform() * basegfx::B2DVector(1.0, 1.0)); 185*cdf0e10cSrcweir const double fSingleX(getDiscreteUnit() / aScale.getX()); 186*cdf0e10cSrcweir const double fSingleY(getDiscreteUnit() / aScale.getY()); 187*cdf0e10cSrcweir const double fBorderX(fSingleX * nQuarter); 188*cdf0e10cSrcweir const double fBorderY(fSingleY * nQuarter); 189*cdf0e10cSrcweir const double fBigLenX((fBorderX * 2.0) + fSingleX); 190*cdf0e10cSrcweir const double fBigLenY((fBorderY * 2.0) + fSingleY); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir xRetval.realloc(8); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir // TopLeft 195*cdf0e10cSrcweir xRetval[0] = Primitive2DReference( 196*cdf0e10cSrcweir new BitmapPrimitive2D( 197*cdf0e10cSrcweir getDiscreteShadow().getTopLeft(), 198*cdf0e10cSrcweir basegfx::tools::createScaleTranslateB2DHomMatrix( 199*cdf0e10cSrcweir fBigLenX, 200*cdf0e10cSrcweir fBigLenY, 201*cdf0e10cSrcweir -fBorderX, 202*cdf0e10cSrcweir -fBorderY))); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir // Top 205*cdf0e10cSrcweir xRetval[1] = Primitive2DReference( 206*cdf0e10cSrcweir new BitmapPrimitive2D( 207*cdf0e10cSrcweir getDiscreteShadow().getTop(), 208*cdf0e10cSrcweir basegfx::tools::createScaleTranslateB2DHomMatrix( 209*cdf0e10cSrcweir 1.0 - (2.0 * fBorderX) - fSingleX, 210*cdf0e10cSrcweir fBorderY + fSingleY, 211*cdf0e10cSrcweir fBorderX + fSingleX, 212*cdf0e10cSrcweir -fBorderY))); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir // TopRight 215*cdf0e10cSrcweir xRetval[2] = Primitive2DReference( 216*cdf0e10cSrcweir new BitmapPrimitive2D( 217*cdf0e10cSrcweir getDiscreteShadow().getTopRight(), 218*cdf0e10cSrcweir basegfx::tools::createScaleTranslateB2DHomMatrix( 219*cdf0e10cSrcweir fBigLenX, 220*cdf0e10cSrcweir fBigLenY, 221*cdf0e10cSrcweir 1.0 - fBorderX, 222*cdf0e10cSrcweir -fBorderY))); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // Right 225*cdf0e10cSrcweir xRetval[3] = Primitive2DReference( 226*cdf0e10cSrcweir new BitmapPrimitive2D( 227*cdf0e10cSrcweir getDiscreteShadow().getRight(), 228*cdf0e10cSrcweir basegfx::tools::createScaleTranslateB2DHomMatrix( 229*cdf0e10cSrcweir fBorderX + fSingleX, 230*cdf0e10cSrcweir 1.0 - (2.0 * fBorderY) - fSingleY, 231*cdf0e10cSrcweir 1.0, 232*cdf0e10cSrcweir fBorderY + fSingleY))); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir // BottomRight 235*cdf0e10cSrcweir xRetval[4] = Primitive2DReference( 236*cdf0e10cSrcweir new BitmapPrimitive2D( 237*cdf0e10cSrcweir getDiscreteShadow().getBottomRight(), 238*cdf0e10cSrcweir basegfx::tools::createScaleTranslateB2DHomMatrix( 239*cdf0e10cSrcweir fBigLenX, 240*cdf0e10cSrcweir fBigLenY, 241*cdf0e10cSrcweir 1.0 - fBorderX, 242*cdf0e10cSrcweir 1.0 - fBorderY))); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir // Bottom 245*cdf0e10cSrcweir xRetval[5] = Primitive2DReference( 246*cdf0e10cSrcweir new BitmapPrimitive2D( 247*cdf0e10cSrcweir getDiscreteShadow().getBottom(), 248*cdf0e10cSrcweir basegfx::tools::createScaleTranslateB2DHomMatrix( 249*cdf0e10cSrcweir 1.0 - (2.0 * fBorderX) - fSingleX, 250*cdf0e10cSrcweir fBorderY + fSingleY, 251*cdf0e10cSrcweir fBorderX + fSingleX, 252*cdf0e10cSrcweir 1.0))); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir // BottomLeft 255*cdf0e10cSrcweir xRetval[6] = Primitive2DReference( 256*cdf0e10cSrcweir new BitmapPrimitive2D( 257*cdf0e10cSrcweir getDiscreteShadow().getBottomLeft(), 258*cdf0e10cSrcweir basegfx::tools::createScaleTranslateB2DHomMatrix( 259*cdf0e10cSrcweir fBigLenX, 260*cdf0e10cSrcweir fBigLenY, 261*cdf0e10cSrcweir -fBorderX, 262*cdf0e10cSrcweir 1.0 - fBorderY))); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir // Left 265*cdf0e10cSrcweir xRetval[7] = Primitive2DReference( 266*cdf0e10cSrcweir new BitmapPrimitive2D( 267*cdf0e10cSrcweir getDiscreteShadow().getLeft(), 268*cdf0e10cSrcweir basegfx::tools::createScaleTranslateB2DHomMatrix( 269*cdf0e10cSrcweir fBorderX + fSingleX, 270*cdf0e10cSrcweir 1.0 - (2.0 * fBorderY) - fSingleY, 271*cdf0e10cSrcweir -fBorderX, 272*cdf0e10cSrcweir fBorderY + fSingleY))); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir // put all in object transformation to get to target positions 275*cdf0e10cSrcweir const Primitive2DReference xTransformed( 276*cdf0e10cSrcweir new TransformPrimitive2D( 277*cdf0e10cSrcweir getTransform(), 278*cdf0e10cSrcweir xRetval)); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir xRetval = Primitive2DSequence(&xTransformed, 1); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir return xRetval; 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir DiscreteShadowPrimitive2D::DiscreteShadowPrimitive2D( 287*cdf0e10cSrcweir const basegfx::B2DHomMatrix& rTransform, 288*cdf0e10cSrcweir const DiscreteShadow& rDiscreteShadow) 289*cdf0e10cSrcweir : DiscreteMetricDependentPrimitive2D(), 290*cdf0e10cSrcweir maTransform(rTransform), 291*cdf0e10cSrcweir maDiscreteShadow(rDiscreteShadow) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir bool DiscreteShadowPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive)) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir const DiscreteShadowPrimitive2D& rCompare = (DiscreteShadowPrimitive2D&)rPrimitive; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir return (getTransform() == rCompare.getTransform() 302*cdf0e10cSrcweir && getDiscreteShadow() == rCompare.getDiscreteShadow()); 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir return false; 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir basegfx::B2DRange DiscreteShadowPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir if(getDiscreteShadow().getBitmapEx().IsEmpty()) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir // no graphics without valid bitmap definition 313*cdf0e10cSrcweir return basegfx::B2DRange(); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir else 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir // prepare normal objectrange 318*cdf0e10cSrcweir basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0); 319*cdf0e10cSrcweir aRetval.transform(getTransform()); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir // extract discrete shadow size and grow 322*cdf0e10cSrcweir const basegfx::B2DVector aScale(rViewInformation.getViewTransformation() * basegfx::B2DVector(1.0, 1.0)); 323*cdf0e10cSrcweir const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2); 324*cdf0e10cSrcweir const double fGrowX((1.0 / aScale.getX()) * nQuarter); 325*cdf0e10cSrcweir const double fGrowY((1.0 / aScale.getY()) * nQuarter); 326*cdf0e10cSrcweir aRetval.grow(std::max(fGrowX, fGrowY)); 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir return aRetval; 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir // provide unique ID 333*cdf0e10cSrcweir ImplPrimitrive2DIDBlock(DiscreteShadowPrimitive2D, PRIMITIVE2D_ID_DISCRETESHADOWPRIMITIVE2D) 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir } // end of namespace primitive2d 336*cdf0e10cSrcweir } // end of namespace drawinglayer 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 339*cdf0e10cSrcweir // eof 340