Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
30 : : #include <drawinglayer/geometry/viewinformation2d.hxx>
31 : : #include <basegfx/tools/canvastools.hxx>
32 : :
33 : : //////////////////////////////////////////////////////////////////////////////
34 : :
35 : : using namespace com::sun::star;
36 : :
37 : : //////////////////////////////////////////////////////////////////////////////
38 : :
39 : : namespace drawinglayer
40 : : {
41 : : namespace primitive2d
42 : : {
43 : 672654 : BasePrimitive2D::BasePrimitive2D()
44 [ + - ]: 672654 : : BasePrimitive2DImplBase(m_aMutex)
45 : : {
46 : 672654 : }
47 : :
48 [ + - ][ + - ]: 672331 : BasePrimitive2D::~BasePrimitive2D()
49 : : {
50 [ - + ]: 672331 : }
51 : :
52 : 82148 : bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
53 : : {
54 : 82148 : return (getPrimitive2DID() == rPrimitive.getPrimitive2DID());
55 : : }
56 : :
57 : 969702 : basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
58 : : {
59 [ + - ]: 969702 : return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation), rViewInformation);
60 : : }
61 : :
62 : 0 : Primitive2DSequence BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
63 : : {
64 : 0 : return Primitive2DSequence();
65 : : }
66 : :
67 : 0 : Primitive2DSequence SAL_CALL BasePrimitive2D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
68 : : {
69 [ # # ]: 0 : const geometry::ViewInformation2D aViewInformation(rViewParameters);
70 [ # # ][ # # ]: 0 : return get2DDecomposition(aViewInformation);
71 : : }
72 : :
73 : 0 : com::sun::star::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
74 : : {
75 [ # # ]: 0 : const geometry::ViewInformation2D aViewInformation(rViewParameters);
76 [ # # ][ # # ]: 0 : return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation));
[ # # ]
77 : : }
78 : : } // end of namespace primitive2d
79 : : } // end of namespace drawinglayer
80 : :
81 : : //////////////////////////////////////////////////////////////////////////////
82 : :
83 : : namespace drawinglayer
84 : : {
85 : : namespace primitive2d
86 : : {
87 : 0 : Primitive2DSequence BufferedDecompositionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
88 : : {
89 : 0 : return Primitive2DSequence();
90 : : }
91 : :
92 : 244948 : BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
93 : : : BasePrimitive2D(),
94 [ + - ]: 244948 : maBuffered2DDecomposition()
95 : : {
96 : 244948 : }
97 : :
98 : 748831 : Primitive2DSequence BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
99 : : {
100 [ + - ]: 748831 : ::osl::MutexGuard aGuard( m_aMutex );
101 : :
102 [ + + ]: 748831 : if(!getBuffered2DDecomposition().hasElements())
103 : : {
104 [ + - ]: 125610 : const Primitive2DSequence aNewSequence(create2DDecomposition(rViewInformation));
105 [ + - ][ + - ]: 125610 : const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence);
106 : : }
107 : :
108 [ + - ][ + - ]: 748831 : return getBuffered2DDecomposition();
109 : : }
110 : : } // end of namespace primitive2d
111 : : } // end of namespace drawinglayer
112 : :
113 : : //////////////////////////////////////////////////////////////////////////////
114 : : // tooling
115 : :
116 : : namespace drawinglayer
117 : : {
118 : : namespace primitive2d
119 : : {
120 : : // get B2DRange from a given Primitive2DReference
121 : 2290350 : basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation)
122 : : {
123 : 2290350 : basegfx::B2DRange aRetval;
124 : :
125 [ + - ]: 2290350 : if(rCandidate.is())
126 : : {
127 : : // try to get C++ implementation base
128 [ + - ]: 2290350 : const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get()));
129 : :
130 [ + - ]: 2290350 : if(pCandidate)
131 : : {
132 : : // use it if possible
133 [ + - ]: 2290350 : aRetval.expand(pCandidate->getB2DRange(aViewInformation));
134 : : }
135 : : else
136 : : {
137 : : // use UNO API call instead
138 : 0 : const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence());
139 [ # # ][ # # ]: 0 : aRetval.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate->getRange(rViewParameters)));
140 : : }
141 : : }
142 : :
143 : 2290350 : return aRetval;
144 : : }
145 : :
146 : : // get B2DRange from a given Primitive2DSequence
147 : 1499456 : basegfx::B2DRange getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation)
148 : : {
149 : 1499456 : basegfx::B2DRange aRetval;
150 : :
151 [ + + ]: 1499456 : if(rCandidate.hasElements())
152 : : {
153 : 1496895 : const sal_Int32 nCount(rCandidate.getLength());
154 : :
155 [ + + ]: 3787245 : for(sal_Int32 a(0L); a < nCount; a++)
156 : : {
157 [ + - ]: 2290350 : aRetval.expand(getB2DRangeFromPrimitive2DReference(rCandidate[a], aViewInformation));
158 : : }
159 : : }
160 : :
161 : 1499456 : return aRetval;
162 : : }
163 : :
164 : 82148 : bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& rxB)
165 : : {
166 : 82148 : const sal_Bool bAIs(rxA.is());
167 : :
168 [ - + ]: 82148 : if(bAIs != rxB.is())
169 : : {
170 : 0 : return false;
171 : : }
172 : :
173 [ - + ]: 82148 : if(!bAIs)
174 : : {
175 : 0 : return true;
176 : : }
177 : :
178 [ - + ]: 82148 : const BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get()));
179 [ - + ]: 82148 : const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(rxB.get()));
180 : 82148 : const bool bAEqualZero(pA == 0L);
181 : :
182 [ - + ]: 82148 : if(bAEqualZero != (pB == 0L))
183 : : {
184 : 0 : return false;
185 : : }
186 : :
187 [ - + ]: 82148 : if(bAEqualZero)
188 : : {
189 : 0 : return false;
190 : : }
191 : :
192 : 82148 : return (pA->operator==(*pB));
193 : : }
194 : :
195 : 172354 : bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB)
196 : : {
197 : 172354 : const sal_Bool bAHasElements(rA.hasElements());
198 : :
199 [ + + ]: 172354 : if(bAHasElements != rB.hasElements())
200 : : {
201 : 87472 : return false;
202 : : }
203 : :
204 [ + + ]: 84882 : if(!bAHasElements)
205 : : {
206 : 6259 : return true;
207 : : }
208 : :
209 : 78623 : const sal_Int32 nCount(rA.getLength());
210 : :
211 [ + + ]: 78623 : if(nCount != rB.getLength())
212 : : {
213 : 46 : return false;
214 : : }
215 : :
216 [ + + ]: 154522 : for(sal_Int32 a(0L); a < nCount; a++)
217 : : {
218 [ + + ]: 82148 : if(!arePrimitive2DReferencesEqual(rA[a], rB[a]))
219 : : {
220 : 6203 : return false;
221 : : }
222 : : }
223 : :
224 : 172354 : return true;
225 : : }
226 : :
227 : : // concatenate sequence
228 : 627664 : void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& rSource)
229 : : {
230 [ + + ]: 627664 : if(rSource.hasElements())
231 : : {
232 [ + + ]: 93980 : if(rDest.hasElements())
233 : : {
234 : 50220 : const sal_Int32 nSourceCount(rSource.getLength());
235 : 50220 : const sal_Int32 nDestCount(rDest.getLength());
236 : 50220 : const sal_Int32 nTargetCount(nSourceCount + nDestCount);
237 : 50220 : sal_Int32 nInsertPos(nDestCount);
238 : :
239 : 50220 : rDest.realloc(nTargetCount);
240 : :
241 [ + + ]: 229215 : for(sal_Int32 a(0L); a < nSourceCount; a++)
242 : : {
243 [ + - ]: 178995 : if(rSource[a].is())
244 : : {
245 : 178995 : rDest[nInsertPos++] = rSource[a];
246 : : }
247 : : }
248 : :
249 [ - + ]: 50220 : if(nInsertPos != nTargetCount)
250 : : {
251 : 0 : rDest.realloc(nInsertPos);
252 : : }
253 : : }
254 : : else
255 : : {
256 : 43760 : rDest = rSource;
257 : : }
258 : : }
259 : 627664 : }
260 : :
261 : : // concatenate single Primitive2D
262 : 67427 : void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& rSource)
263 : : {
264 [ + - ]: 67427 : if(rSource.is())
265 : : {
266 : 67427 : const sal_Int32 nDestCount(rDest.getLength());
267 : 67427 : rDest.realloc(nDestCount + 1L);
268 : 67427 : rDest[nDestCount] = rSource;
269 : : }
270 : 67427 : }
271 : :
272 : : } // end of namespace primitive2d
273 : : } // end of namespace drawinglayer
274 : :
275 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|