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