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/discretebitmapprimitive2d.hxx> 26cdf0e10cSrcweir #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 27cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir namespace drawinglayer 30cdf0e10cSrcweir { 31cdf0e10cSrcweir namespace primitive2d 32cdf0e10cSrcweir { create2DDecomposition(const geometry::ViewInformation2D &) const33cdf0e10cSrcweir Primitive2DSequence DiscreteBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 34cdf0e10cSrcweir { 35cdf0e10cSrcweir // use getViewTransformation() and getObjectTransformation() from 36cdf0e10cSrcweir // ObjectAndViewTransformationDependentPrimitive2D to create a BitmapPrimitive2D 37cdf0e10cSrcweir // with the correct mapping 38cdf0e10cSrcweir Primitive2DSequence xRetval; 39cdf0e10cSrcweir 40cdf0e10cSrcweir if(!getBitmapEx().IsEmpty()) 41cdf0e10cSrcweir { 42cdf0e10cSrcweir // get discrete size 43cdf0e10cSrcweir const Size& rSizePixel = getBitmapEx().GetSizePixel(); 44cdf0e10cSrcweir const basegfx::B2DVector aDiscreteSize(rSizePixel.Width(), rSizePixel.Height()); 45cdf0e10cSrcweir 46cdf0e10cSrcweir // get inverse ViewTransformation 47cdf0e10cSrcweir basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation()); 48cdf0e10cSrcweir aInverseViewTransformation.invert(); 49cdf0e10cSrcweir 50cdf0e10cSrcweir // get size and position in world coordinates 51cdf0e10cSrcweir const basegfx::B2DVector aWorldSize(aInverseViewTransformation * aDiscreteSize); 52cdf0e10cSrcweir const basegfx::B2DPoint aWorldTopLeft(getObjectTransformation() * getTopLeft()); 53cdf0e10cSrcweir 54cdf0e10cSrcweir // build object matrix in world coordinates so that the top-left 55cdf0e10cSrcweir // position remains, but eventual transformations (e.g. rotations) 56cdf0e10cSrcweir // in the ObjectToView stack remain and get correctly applied 57cdf0e10cSrcweir basegfx::B2DHomMatrix aObjectTransform; 58cdf0e10cSrcweir 59cdf0e10cSrcweir aObjectTransform.set(0, 0, aWorldSize.getX()); 60cdf0e10cSrcweir aObjectTransform.set(1, 1, aWorldSize.getY()); 61cdf0e10cSrcweir aObjectTransform.set(0, 2, aWorldTopLeft.getX()); 62cdf0e10cSrcweir aObjectTransform.set(1, 2, aWorldTopLeft.getY()); 63cdf0e10cSrcweir 64cdf0e10cSrcweir // get inverse ObjectTransformation 65cdf0e10cSrcweir basegfx::B2DHomMatrix aInverseObjectTransformation(getObjectTransformation()); 66cdf0e10cSrcweir aInverseObjectTransformation.invert(); 67cdf0e10cSrcweir 68cdf0e10cSrcweir // transform to object coordinate system 69cdf0e10cSrcweir aObjectTransform = aInverseObjectTransformation * aObjectTransform; 70cdf0e10cSrcweir 71cdf0e10cSrcweir // create BitmapPrimitive2D with now object-local coordinate data 72cdf0e10cSrcweir const Primitive2DReference xRef(new BitmapPrimitive2D(getBitmapEx(), aObjectTransform)); 73cdf0e10cSrcweir xRetval = Primitive2DSequence(&xRef, 1); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir return xRetval; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir DiscreteBitmapPrimitive2D(const BitmapEx & rBitmapEx,const basegfx::B2DPoint & rTopLeft)79cdf0e10cSrcweir DiscreteBitmapPrimitive2D::DiscreteBitmapPrimitive2D( 80cdf0e10cSrcweir const BitmapEx& rBitmapEx, 81cdf0e10cSrcweir const basegfx::B2DPoint& rTopLeft) 82cdf0e10cSrcweir : ObjectAndViewTransformationDependentPrimitive2D(), 83cdf0e10cSrcweir maBitmapEx(rBitmapEx), 84cdf0e10cSrcweir maTopLeft(rTopLeft) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir } 87cdf0e10cSrcweir operator ==(const BasePrimitive2D & rPrimitive) const88cdf0e10cSrcweir bool DiscreteBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 89cdf0e10cSrcweir { 90cdf0e10cSrcweir if(ObjectAndViewTransformationDependentPrimitive2D::operator==(rPrimitive)) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir const DiscreteBitmapPrimitive2D& rCompare = (DiscreteBitmapPrimitive2D&)rPrimitive; 93cdf0e10cSrcweir 94cdf0e10cSrcweir return (getBitmapEx() == rCompare.getBitmapEx() 95cdf0e10cSrcweir && getTopLeft() == rCompare.getTopLeft()); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir return false; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir // provide unique ID 102cdf0e10cSrcweir ImplPrimitrive2DIDBlock(DiscreteBitmapPrimitive2D, PRIMITIVE2D_ID_DISCRETEBITMAPPRIMITIVE2D) 103cdf0e10cSrcweir 104cdf0e10cSrcweir } // end of namespace primitive2d 105cdf0e10cSrcweir } // end of namespace drawinglayer 106cdf0e10cSrcweir 107*a6c67450Smseidel /* vim: set noet sw=4 ts=4: */ 108