1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove 25*b1cdbd2cSJim Jagielski #include "precompiled_drawinglayer.hxx" 26*b1cdbd2cSJim Jagielski 27*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx> 28*b1cdbd2cSJim Jagielski #include <basegfx/matrix/b2dhommatrix.hxx> 29*b1cdbd2cSJim Jagielski #include <drawinglayer/geometry/viewinformation2d.hxx> 30*b1cdbd2cSJim Jagielski #include <basegfx/polygon/b2dpolygon.hxx> 31*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 32*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 33*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 34*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 35*b1cdbd2cSJim Jagielski 36*b1cdbd2cSJim Jagielski ////////////////////////////////////////////////////////////////////////////// 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim Jagielski using namespace com::sun::star; 39*b1cdbd2cSJim Jagielski 40*b1cdbd2cSJim Jagielski ////////////////////////////////////////////////////////////////////////////// 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski namespace drawinglayer 43*b1cdbd2cSJim Jagielski { 44*b1cdbd2cSJim Jagielski namespace primitive2d 45*b1cdbd2cSJim Jagielski { create2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const46*b1cdbd2cSJim Jagielski Primitive2DSequence MarkerArrayPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 47*b1cdbd2cSJim Jagielski { 48*b1cdbd2cSJim Jagielski Primitive2DSequence xRetval; 49*b1cdbd2cSJim Jagielski const std::vector< basegfx::B2DPoint >& rPositions = getPositions(); 50*b1cdbd2cSJim Jagielski const sal_uInt32 nMarkerCount(rPositions.size()); 51*b1cdbd2cSJim Jagielski 52*b1cdbd2cSJim Jagielski if(nMarkerCount && !getMarker().IsEmpty()) 53*b1cdbd2cSJim Jagielski { 54*b1cdbd2cSJim Jagielski // get pixel size 55*b1cdbd2cSJim Jagielski Size aBitmapSize(getMarker().GetSizePixel()); 56*b1cdbd2cSJim Jagielski 57*b1cdbd2cSJim Jagielski if(aBitmapSize.Width() && aBitmapSize.Height()) 58*b1cdbd2cSJim Jagielski { 59*b1cdbd2cSJim Jagielski // get logic half pixel size 60*b1cdbd2cSJim Jagielski basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() * 61*b1cdbd2cSJim Jagielski basegfx::B2DVector(aBitmapSize.getWidth() - 1.0, aBitmapSize.getHeight() - 1.0)); 62*b1cdbd2cSJim Jagielski 63*b1cdbd2cSJim Jagielski // use half size for expand 64*b1cdbd2cSJim Jagielski aLogicHalfSize *= 0.5; 65*b1cdbd2cSJim Jagielski 66*b1cdbd2cSJim Jagielski // number of primitives is known; realloc accordingly 67*b1cdbd2cSJim Jagielski xRetval.realloc(nMarkerCount); 68*b1cdbd2cSJim Jagielski 69*b1cdbd2cSJim Jagielski for(sal_uInt32 a(0); a < nMarkerCount; a++) 70*b1cdbd2cSJim Jagielski { 71*b1cdbd2cSJim Jagielski const basegfx::B2DPoint& rPosition(rPositions[a]); 72*b1cdbd2cSJim Jagielski const basegfx::B2DRange aRange(rPosition - aLogicHalfSize, rPosition + aLogicHalfSize); 73*b1cdbd2cSJim Jagielski basegfx::B2DHomMatrix aTransform; 74*b1cdbd2cSJim Jagielski 75*b1cdbd2cSJim Jagielski aTransform.set(0, 0, aRange.getWidth()); 76*b1cdbd2cSJim Jagielski aTransform.set(1, 1, aRange.getHeight()); 77*b1cdbd2cSJim Jagielski aTransform.set(0, 2, aRange.getMinX()); 78*b1cdbd2cSJim Jagielski aTransform.set(1, 2, aRange.getMinY()); 79*b1cdbd2cSJim Jagielski 80*b1cdbd2cSJim Jagielski xRetval[a] = Primitive2DReference(new BitmapPrimitive2D(getMarker(), aTransform)); 81*b1cdbd2cSJim Jagielski } 82*b1cdbd2cSJim Jagielski } 83*b1cdbd2cSJim Jagielski } 84*b1cdbd2cSJim Jagielski 85*b1cdbd2cSJim Jagielski return xRetval; 86*b1cdbd2cSJim Jagielski } 87*b1cdbd2cSJim Jagielski MarkerArrayPrimitive2D(const std::vector<basegfx::B2DPoint> & rPositions,const BitmapEx & rMarker)88*b1cdbd2cSJim Jagielski MarkerArrayPrimitive2D::MarkerArrayPrimitive2D( 89*b1cdbd2cSJim Jagielski const std::vector< basegfx::B2DPoint >& rPositions, 90*b1cdbd2cSJim Jagielski const BitmapEx& rMarker) 91*b1cdbd2cSJim Jagielski : BufferedDecompositionPrimitive2D(), 92*b1cdbd2cSJim Jagielski maPositions(rPositions), 93*b1cdbd2cSJim Jagielski maMarker(rMarker) 94*b1cdbd2cSJim Jagielski { 95*b1cdbd2cSJim Jagielski } 96*b1cdbd2cSJim Jagielski operator ==(const BasePrimitive2D & rPrimitive) const97*b1cdbd2cSJim Jagielski bool MarkerArrayPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 98*b1cdbd2cSJim Jagielski { 99*b1cdbd2cSJim Jagielski if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 100*b1cdbd2cSJim Jagielski { 101*b1cdbd2cSJim Jagielski const MarkerArrayPrimitive2D& rCompare = (MarkerArrayPrimitive2D&)rPrimitive; 102*b1cdbd2cSJim Jagielski 103*b1cdbd2cSJim Jagielski return (getPositions() == rCompare.getPositions() 104*b1cdbd2cSJim Jagielski && getMarker() == rCompare.getMarker()); 105*b1cdbd2cSJim Jagielski } 106*b1cdbd2cSJim Jagielski 107*b1cdbd2cSJim Jagielski return false; 108*b1cdbd2cSJim Jagielski } 109*b1cdbd2cSJim Jagielski getB2DRange(const geometry::ViewInformation2D & rViewInformation) const110*b1cdbd2cSJim Jagielski basegfx::B2DRange MarkerArrayPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 111*b1cdbd2cSJim Jagielski { 112*b1cdbd2cSJim Jagielski basegfx::B2DRange aRetval; 113*b1cdbd2cSJim Jagielski 114*b1cdbd2cSJim Jagielski if(getPositions().size()) 115*b1cdbd2cSJim Jagielski { 116*b1cdbd2cSJim Jagielski // get the basic range from the position vector 117*b1cdbd2cSJim Jagielski for(std::vector< basegfx::B2DPoint >::const_iterator aIter(getPositions().begin()); aIter != getPositions().end(); aIter++) 118*b1cdbd2cSJim Jagielski { 119*b1cdbd2cSJim Jagielski aRetval.expand(*aIter); 120*b1cdbd2cSJim Jagielski } 121*b1cdbd2cSJim Jagielski 122*b1cdbd2cSJim Jagielski if(!getMarker().IsEmpty()) 123*b1cdbd2cSJim Jagielski { 124*b1cdbd2cSJim Jagielski // get pixel size 125*b1cdbd2cSJim Jagielski const Size aBitmapSize(getMarker().GetSizePixel()); 126*b1cdbd2cSJim Jagielski 127*b1cdbd2cSJim Jagielski if(aBitmapSize.Width() && aBitmapSize.Height()) 128*b1cdbd2cSJim Jagielski { 129*b1cdbd2cSJim Jagielski // get logic half size 130*b1cdbd2cSJim Jagielski basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() * 131*b1cdbd2cSJim Jagielski basegfx::B2DVector(aBitmapSize.getWidth(), aBitmapSize.getHeight())); 132*b1cdbd2cSJim Jagielski 133*b1cdbd2cSJim Jagielski // use half size for expand 134*b1cdbd2cSJim Jagielski aLogicHalfSize *= 0.5; 135*b1cdbd2cSJim Jagielski 136*b1cdbd2cSJim Jagielski // apply aLogicHalfSize 137*b1cdbd2cSJim Jagielski aRetval.expand(aRetval.getMinimum() - aLogicHalfSize); 138*b1cdbd2cSJim Jagielski aRetval.expand(aRetval.getMaximum() + aLogicHalfSize); 139*b1cdbd2cSJim Jagielski } 140*b1cdbd2cSJim Jagielski } 141*b1cdbd2cSJim Jagielski } 142*b1cdbd2cSJim Jagielski 143*b1cdbd2cSJim Jagielski return aRetval; 144*b1cdbd2cSJim Jagielski } 145*b1cdbd2cSJim Jagielski 146*b1cdbd2cSJim Jagielski // provide unique ID 147*b1cdbd2cSJim Jagielski ImplPrimitrive2DIDBlock(MarkerArrayPrimitive2D, PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D) 148*b1cdbd2cSJim Jagielski 149*b1cdbd2cSJim Jagielski } // end of namespace primitive2d 150*b1cdbd2cSJim Jagielski } // end of namespace drawinglayer 151*b1cdbd2cSJim Jagielski 152*b1cdbd2cSJim Jagielski ////////////////////////////////////////////////////////////////////////////// 153*b1cdbd2cSJim Jagielski // eof 154