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