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/markerarrayprimitive2d.hxx> 28cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 29cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.hxx> 30cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 31cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 32cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 33cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 34cdf0e10cSrcweir #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace com::sun::star; 39cdf0e10cSrcweir 40cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace drawinglayer 43cdf0e10cSrcweir { 44cdf0e10cSrcweir namespace primitive2d 45cdf0e10cSrcweir { create2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const46cdf0e10cSrcweir Primitive2DSequence MarkerArrayPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 47cdf0e10cSrcweir { 48cdf0e10cSrcweir Primitive2DSequence xRetval; 49cdf0e10cSrcweir const std::vector< basegfx::B2DPoint >& rPositions = getPositions(); 50cdf0e10cSrcweir const sal_uInt32 nMarkerCount(rPositions.size()); 51cdf0e10cSrcweir 52cdf0e10cSrcweir if(nMarkerCount && !getMarker().IsEmpty()) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir // get pixel size 55cdf0e10cSrcweir Size aBitmapSize(getMarker().GetSizePixel()); 56cdf0e10cSrcweir 57cdf0e10cSrcweir if(aBitmapSize.Width() && aBitmapSize.Height()) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir // get logic half pixel size 60cdf0e10cSrcweir basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() * 61cdf0e10cSrcweir basegfx::B2DVector(aBitmapSize.getWidth() - 1.0, aBitmapSize.getHeight() - 1.0)); 62cdf0e10cSrcweir 63cdf0e10cSrcweir // use half size for expand 64cdf0e10cSrcweir aLogicHalfSize *= 0.5; 65cdf0e10cSrcweir 66cdf0e10cSrcweir // number of primitives is known; realloc accordingly 67cdf0e10cSrcweir xRetval.realloc(nMarkerCount); 68cdf0e10cSrcweir 69cdf0e10cSrcweir for(sal_uInt32 a(0); a < nMarkerCount; a++) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir const basegfx::B2DPoint& rPosition(rPositions[a]); 72cdf0e10cSrcweir const basegfx::B2DRange aRange(rPosition - aLogicHalfSize, rPosition + aLogicHalfSize); 73cdf0e10cSrcweir basegfx::B2DHomMatrix aTransform; 74cdf0e10cSrcweir 75cdf0e10cSrcweir aTransform.set(0, 0, aRange.getWidth()); 76cdf0e10cSrcweir aTransform.set(1, 1, aRange.getHeight()); 77cdf0e10cSrcweir aTransform.set(0, 2, aRange.getMinX()); 78cdf0e10cSrcweir aTransform.set(1, 2, aRange.getMinY()); 79cdf0e10cSrcweir 80cdf0e10cSrcweir xRetval[a] = Primitive2DReference(new BitmapPrimitive2D(getMarker(), aTransform)); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir } 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir return xRetval; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir MarkerArrayPrimitive2D(const std::vector<basegfx::B2DPoint> & rPositions,const BitmapEx & rMarker)88cdf0e10cSrcweir MarkerArrayPrimitive2D::MarkerArrayPrimitive2D( 89cdf0e10cSrcweir const std::vector< basegfx::B2DPoint >& rPositions, 90cdf0e10cSrcweir const BitmapEx& rMarker) 91cdf0e10cSrcweir : BufferedDecompositionPrimitive2D(), 92cdf0e10cSrcweir maPositions(rPositions), 93cdf0e10cSrcweir maMarker(rMarker) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir } 96cdf0e10cSrcweir operator ==(const BasePrimitive2D & rPrimitive) const97cdf0e10cSrcweir bool MarkerArrayPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 98cdf0e10cSrcweir { 99cdf0e10cSrcweir if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir const MarkerArrayPrimitive2D& rCompare = (MarkerArrayPrimitive2D&)rPrimitive; 102cdf0e10cSrcweir 103cdf0e10cSrcweir return (getPositions() == rCompare.getPositions() 104cdf0e10cSrcweir && getMarker() == rCompare.getMarker()); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir return false; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir getB2DRange(const geometry::ViewInformation2D & rViewInformation) const110cdf0e10cSrcweir basegfx::B2DRange MarkerArrayPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 111cdf0e10cSrcweir { 112cdf0e10cSrcweir basegfx::B2DRange aRetval; 113cdf0e10cSrcweir 114cdf0e10cSrcweir if(getPositions().size()) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir // get the basic range from the position vector 117cdf0e10cSrcweir for(std::vector< basegfx::B2DPoint >::const_iterator aIter(getPositions().begin()); aIter != getPositions().end(); aIter++) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir aRetval.expand(*aIter); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir if(!getMarker().IsEmpty()) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir // get pixel size 125cdf0e10cSrcweir const Size aBitmapSize(getMarker().GetSizePixel()); 126cdf0e10cSrcweir 127cdf0e10cSrcweir if(aBitmapSize.Width() && aBitmapSize.Height()) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir // get logic half size 130cdf0e10cSrcweir basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() * 131cdf0e10cSrcweir basegfx::B2DVector(aBitmapSize.getWidth(), aBitmapSize.getHeight())); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // use half size for expand 134cdf0e10cSrcweir aLogicHalfSize *= 0.5; 135cdf0e10cSrcweir 136cdf0e10cSrcweir // apply aLogicHalfSize 137cdf0e10cSrcweir aRetval.expand(aRetval.getMinimum() - aLogicHalfSize); 138cdf0e10cSrcweir aRetval.expand(aRetval.getMaximum() + aLogicHalfSize); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir return aRetval; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir // provide unique ID 147cdf0e10cSrcweir ImplPrimitrive2DIDBlock(MarkerArrayPrimitive2D, PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D) 148cdf0e10cSrcweir 149cdf0e10cSrcweir } // end of namespace primitive2d 150cdf0e10cSrcweir } // end of namespace drawinglayer 151cdf0e10cSrcweir 152cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 153cdf0e10cSrcweir // eof 154