1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_drawinglayer.hxx" 30 31 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx> 32 #include <basegfx/matrix/b2dhommatrix.hxx> 33 #include <drawinglayer/geometry/viewinformation2d.hxx> 34 #include <basegfx/polygon/b2dpolygon.hxx> 35 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 36 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 37 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 38 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 39 40 ////////////////////////////////////////////////////////////////////////////// 41 42 using namespace com::sun::star; 43 44 ////////////////////////////////////////////////////////////////////////////// 45 46 namespace drawinglayer 47 { 48 namespace primitive2d 49 { 50 Primitive2DSequence MarkerArrayPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 51 { 52 Primitive2DSequence xRetval; 53 const std::vector< basegfx::B2DPoint >& rPositions = getPositions(); 54 const sal_uInt32 nMarkerCount(rPositions.size()); 55 56 if(nMarkerCount && !getMarker().IsEmpty()) 57 { 58 // get pixel size 59 Size aBitmapSize(getMarker().GetSizePixel()); 60 61 if(aBitmapSize.Width() && aBitmapSize.Height()) 62 { 63 // get logic half pixel size 64 basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() * 65 basegfx::B2DVector(aBitmapSize.getWidth() - 1.0, aBitmapSize.getHeight() - 1.0)); 66 67 // use half size for expand 68 aLogicHalfSize *= 0.5; 69 70 // number of primitives is known; realloc accordingly 71 xRetval.realloc(nMarkerCount); 72 73 for(sal_uInt32 a(0); a < nMarkerCount; a++) 74 { 75 const basegfx::B2DPoint& rPosition(rPositions[a]); 76 const basegfx::B2DRange aRange(rPosition - aLogicHalfSize, rPosition + aLogicHalfSize); 77 basegfx::B2DHomMatrix aTransform; 78 79 aTransform.set(0, 0, aRange.getWidth()); 80 aTransform.set(1, 1, aRange.getHeight()); 81 aTransform.set(0, 2, aRange.getMinX()); 82 aTransform.set(1, 2, aRange.getMinY()); 83 84 xRetval[a] = Primitive2DReference(new BitmapPrimitive2D(getMarker(), aTransform)); 85 } 86 } 87 } 88 89 return xRetval; 90 } 91 92 MarkerArrayPrimitive2D::MarkerArrayPrimitive2D( 93 const std::vector< basegfx::B2DPoint >& rPositions, 94 const BitmapEx& rMarker) 95 : BufferedDecompositionPrimitive2D(), 96 maPositions(rPositions), 97 maMarker(rMarker) 98 { 99 } 100 101 bool MarkerArrayPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 102 { 103 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 104 { 105 const MarkerArrayPrimitive2D& rCompare = (MarkerArrayPrimitive2D&)rPrimitive; 106 107 return (getPositions() == rCompare.getPositions() 108 && getMarker() == rCompare.getMarker()); 109 } 110 111 return false; 112 } 113 114 basegfx::B2DRange MarkerArrayPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 115 { 116 basegfx::B2DRange aRetval; 117 118 if(getPositions().size()) 119 { 120 // get the basic range from the position vector 121 for(std::vector< basegfx::B2DPoint >::const_iterator aIter(getPositions().begin()); aIter != getPositions().end(); aIter++) 122 { 123 aRetval.expand(*aIter); 124 } 125 126 if(!getMarker().IsEmpty()) 127 { 128 // get pixel size 129 const Size aBitmapSize(getMarker().GetSizePixel()); 130 131 if(aBitmapSize.Width() && aBitmapSize.Height()) 132 { 133 // get logic half size 134 basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() * 135 basegfx::B2DVector(aBitmapSize.getWidth(), aBitmapSize.getHeight())); 136 137 // use half size for expand 138 aLogicHalfSize *= 0.5; 139 140 // apply aLogicHalfSize 141 aRetval.expand(aRetval.getMinimum() - aLogicHalfSize); 142 aRetval.expand(aRetval.getMaximum() + aLogicHalfSize); 143 } 144 } 145 } 146 147 return aRetval; 148 } 149 150 // provide unique ID 151 ImplPrimitrive2DIDBlock(MarkerArrayPrimitive2D, PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D) 152 153 } // end of namespace primitive2d 154 } // end of namespace drawinglayer 155 156 ////////////////////////////////////////////////////////////////////////////// 157 // eof 158