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