1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_drawinglayer.hxx" 26 27 #include <drawinglayer/primitive2d/baseprimitive2d.hxx> 28 #include <drawinglayer/geometry/viewinformation2d.hxx> 29 #include <basegfx/tools/canvastools.hxx> 30 31 ////////////////////////////////////////////////////////////////////////////// 32 33 using namespace com::sun::star; 34 35 ////////////////////////////////////////////////////////////////////////////// 36 37 namespace drawinglayer 38 { 39 namespace primitive2d 40 { 41 BasePrimitive2D::BasePrimitive2D() 42 : BasePrimitive2DImplBase(m_aMutex) 43 { 44 } 45 46 BasePrimitive2D::~BasePrimitive2D() 47 { 48 } 49 50 bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const 51 { 52 return (getPrimitive2DID() == rPrimitive.getPrimitive2DID()); 53 } 54 55 basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 56 { 57 return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation), rViewInformation); 58 } 59 60 Primitive2DSequence BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 61 { 62 return Primitive2DSequence(); 63 } 64 65 Primitive2DSequence SAL_CALL BasePrimitive2D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException ) 66 { 67 const geometry::ViewInformation2D aViewInformation(rViewParameters); 68 return get2DDecomposition(aViewInformation); 69 } 70 71 com::sun::star::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException ) 72 { 73 const geometry::ViewInformation2D aViewInformation(rViewParameters); 74 return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation)); 75 } 76 } // end of namespace primitive2d 77 } // end of namespace drawinglayer 78 79 ////////////////////////////////////////////////////////////////////////////// 80 81 namespace drawinglayer 82 { 83 namespace primitive2d 84 { 85 Primitive2DSequence BufferedDecompositionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 86 { 87 return Primitive2DSequence(); 88 } 89 90 BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D() 91 : BasePrimitive2D(), 92 maBuffered2DDecomposition() 93 { 94 } 95 96 Primitive2DSequence BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 97 { 98 ::osl::MutexGuard aGuard( m_aMutex ); 99 100 if(!getBuffered2DDecomposition().hasElements()) 101 { 102 const Primitive2DSequence aNewSequence(create2DDecomposition(rViewInformation)); 103 const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence); 104 } 105 106 return getBuffered2DDecomposition(); 107 } 108 } // end of namespace primitive2d 109 } // end of namespace drawinglayer 110 111 ////////////////////////////////////////////////////////////////////////////// 112 // tooling 113 114 namespace drawinglayer 115 { 116 namespace primitive2d 117 { 118 // get B2DRange from a given Primitive2DReference 119 basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation) 120 { 121 basegfx::B2DRange aRetval; 122 123 if(rCandidate.is()) 124 { 125 // try to get C++ implementation base 126 const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get())); 127 128 if(pCandidate) 129 { 130 // use it if possible 131 aRetval.expand(pCandidate->getB2DRange(aViewInformation)); 132 } 133 else 134 { 135 // use UNO API call instead 136 const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence()); 137 aRetval.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate->getRange(rViewParameters))); 138 } 139 } 140 141 return aRetval; 142 } 143 144 // get B2DRange from a given Primitive2DSequence 145 basegfx::B2DRange getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation) 146 { 147 basegfx::B2DRange aRetval; 148 149 if(rCandidate.hasElements()) 150 { 151 const sal_Int32 nCount(rCandidate.getLength()); 152 153 for(sal_Int32 a(0L); a < nCount; a++) 154 { 155 aRetval.expand(getB2DRangeFromPrimitive2DReference(rCandidate[a], aViewInformation)); 156 } 157 } 158 159 return aRetval; 160 } 161 162 bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& rxB) 163 { 164 const sal_Bool bAIs(rxA.is()); 165 166 if(bAIs != rxB.is()) 167 { 168 return false; 169 } 170 171 if(!bAIs) 172 { 173 return true; 174 } 175 176 const BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get())); 177 const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(rxB.get())); 178 const bool bAEqualZero(pA == 0L); 179 180 if(bAEqualZero != (pB == 0L)) 181 { 182 return false; 183 } 184 185 if(bAEqualZero) 186 { 187 return false; 188 } 189 190 return (pA->operator==(*pB)); 191 } 192 193 bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB) 194 { 195 const sal_Bool bAHasElements(rA.hasElements()); 196 197 if(bAHasElements != rB.hasElements()) 198 { 199 return false; 200 } 201 202 if(!bAHasElements) 203 { 204 return true; 205 } 206 207 const sal_Int32 nCount(rA.getLength()); 208 209 if(nCount != rB.getLength()) 210 { 211 return false; 212 } 213 214 for(sal_Int32 a(0L); a < nCount; a++) 215 { 216 if(!arePrimitive2DReferencesEqual(rA[a], rB[a])) 217 { 218 return false; 219 } 220 } 221 222 return true; 223 } 224 225 // concatenate sequence 226 void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& rSource) 227 { 228 if(rSource.hasElements()) 229 { 230 if(rDest.hasElements()) 231 { 232 const sal_Int32 nSourceCount(rSource.getLength()); 233 const sal_Int32 nDestCount(rDest.getLength()); 234 const sal_Int32 nTargetCount(nSourceCount + nDestCount); 235 sal_Int32 nInsertPos(nDestCount); 236 237 rDest.realloc(nTargetCount); 238 239 for(sal_Int32 a(0L); a < nSourceCount; a++) 240 { 241 if(rSource[a].is()) 242 { 243 rDest[nInsertPos++] = rSource[a]; 244 } 245 } 246 247 if(nInsertPos != nTargetCount) 248 { 249 rDest.realloc(nInsertPos); 250 } 251 } 252 else 253 { 254 rDest = rSource; 255 } 256 } 257 } 258 259 // concatenate single Primitive2D 260 void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& rSource) 261 { 262 if(rSource.is()) 263 { 264 const sal_Int32 nDestCount(rDest.getLength()); 265 rDest.realloc(nDestCount + 1L); 266 rDest[nDestCount] = rSource; 267 } 268 } 269 270 } // end of namespace primitive2d 271 } // end of namespace drawinglayer 272 273 ////////////////////////////////////////////////////////////////////////////// 274 // eof 275