1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
21 #include <drawinglayer/geometry/viewinformation2d.hxx>
22 #include <basegfx/tools/canvastools.hxx>
24 //////////////////////////////////////////////////////////////////////////////
26 using namespace com::sun::star
;
28 //////////////////////////////////////////////////////////////////////////////
30 namespace drawinglayer
34 BasePrimitive2D::BasePrimitive2D()
35 : BasePrimitive2DImplBase(m_aMutex
)
39 BasePrimitive2D::~BasePrimitive2D()
43 bool BasePrimitive2D::operator==( const BasePrimitive2D
& rPrimitive
) const
45 return (getPrimitive2DID() == rPrimitive
.getPrimitive2DID());
48 basegfx::B2DRange
BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
50 return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation
), rViewInformation
);
53 Primitive2DSequence
BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
55 return Primitive2DSequence();
58 Primitive2DSequence SAL_CALL
BasePrimitive2D::getDecomposition( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
) throw ( uno::RuntimeException
)
60 const geometry::ViewInformation2D
aViewInformation(rViewParameters
);
61 return get2DDecomposition(aViewInformation
);
64 com::sun::star::geometry::RealRectangle2D SAL_CALL
BasePrimitive2D::getRange( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
) throw ( uno::RuntimeException
)
66 const geometry::ViewInformation2D
aViewInformation(rViewParameters
);
67 return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation
));
69 } // end of namespace primitive2d
70 } // end of namespace drawinglayer
72 //////////////////////////////////////////////////////////////////////////////
74 namespace drawinglayer
78 Primitive2DSequence
BufferedDecompositionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*rViewInformation*/) const
80 return Primitive2DSequence();
83 BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
85 maBuffered2DDecomposition()
89 Primitive2DSequence
BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
91 ::osl::MutexGuard
aGuard( m_aMutex
);
93 if(!getBuffered2DDecomposition().hasElements())
95 const Primitive2DSequence
aNewSequence(create2DDecomposition(rViewInformation
));
96 const_cast< BufferedDecompositionPrimitive2D
* >(this)->setBuffered2DDecomposition(aNewSequence
);
99 return getBuffered2DDecomposition();
101 } // end of namespace primitive2d
102 } // end of namespace drawinglayer
104 //////////////////////////////////////////////////////////////////////////////
107 namespace drawinglayer
109 namespace primitive2d
111 // convert helper stl vector of primitives to Primitive2DSequence
112 Primitive2DSequence
Primitive2DVectorToPrimitive2DSequence(const Primitive2DVector
& rSource
, bool bInvert
)
114 const sal_uInt32
nSize(rSource
.size());
115 Primitive2DSequence aRetval
;
117 aRetval
.realloc(nSize
);
119 for(sal_uInt32
a(0); a
< nSize
; a
++)
121 aRetval
[bInvert
? nSize
- 1 - a
: a
] = rSource
[a
];
124 // all entries taken over to Uno References as owners. To avoid
125 // errors with users of this mechanism to delete pointers to BasePrimitive2D
126 // itself, clear given vector
127 const_cast< Primitive2DVector
& >(rSource
).clear();
132 // get B2DRange from a given Primitive2DReference
133 basegfx::B2DRange
getB2DRangeFromPrimitive2DReference(const Primitive2DReference
& rCandidate
, const geometry::ViewInformation2D
& aViewInformation
)
135 basegfx::B2DRange aRetval
;
139 // try to get C++ implementation base
140 const BasePrimitive2D
* pCandidate(dynamic_cast< BasePrimitive2D
* >(rCandidate
.get()));
144 // use it if possible
145 aRetval
.expand(pCandidate
->getB2DRange(aViewInformation
));
149 // use UNO API call instead
150 const uno::Sequence
< beans::PropertyValue
>& rViewParameters(aViewInformation
.getViewInformationSequence());
151 aRetval
.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate
->getRange(rViewParameters
)));
158 // get B2DRange from a given Primitive2DSequence
159 basegfx::B2DRange
getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence
& rCandidate
, const geometry::ViewInformation2D
& aViewInformation
)
161 basegfx::B2DRange aRetval
;
163 if(rCandidate
.hasElements())
165 const sal_Int32
nCount(rCandidate
.getLength());
167 for(sal_Int32
a(0L); a
< nCount
; a
++)
169 aRetval
.expand(getB2DRangeFromPrimitive2DReference(rCandidate
[a
], aViewInformation
));
176 bool arePrimitive2DReferencesEqual(const Primitive2DReference
& rxA
, const Primitive2DReference
& rxB
)
178 const sal_Bool
bAIs(rxA
.is());
190 const BasePrimitive2D
* pA(dynamic_cast< const BasePrimitive2D
* >(rxA
.get()));
191 const BasePrimitive2D
* pB(dynamic_cast< const BasePrimitive2D
* >(rxB
.get()));
192 const bool bAEqualZero(pA
== 0L);
194 if(bAEqualZero
!= (pB
== 0L))
204 return (pA
->operator==(*pB
));
207 bool arePrimitive2DSequencesEqual(const Primitive2DSequence
& rA
, const Primitive2DSequence
& rB
)
209 const sal_Bool
bAHasElements(rA
.hasElements());
211 if(bAHasElements
!= rB
.hasElements())
221 const sal_Int32
nCount(rA
.getLength());
223 if(nCount
!= rB
.getLength())
228 for(sal_Int32
a(0L); a
< nCount
; a
++)
230 if(!arePrimitive2DReferencesEqual(rA
[a
], rB
[a
]))
239 // concatenate sequence
240 void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence
& rDest
, const Primitive2DSequence
& rSource
)
242 if(rSource
.hasElements())
244 if(rDest
.hasElements())
246 const sal_Int32
nSourceCount(rSource
.getLength());
247 const sal_Int32
nDestCount(rDest
.getLength());
248 const sal_Int32
nTargetCount(nSourceCount
+ nDestCount
);
249 sal_Int32
nInsertPos(nDestCount
);
251 rDest
.realloc(nTargetCount
);
253 for(sal_Int32
a(0L); a
< nSourceCount
; a
++)
257 rDest
[nInsertPos
++] = rSource
[a
];
261 if(nInsertPos
!= nTargetCount
)
263 rDest
.realloc(nInsertPos
);
273 // concatenate single Primitive2D
274 void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence
& rDest
, const Primitive2DReference
& rSource
)
278 const sal_Int32
nDestCount(rDest
.getLength());
279 rDest
.realloc(nDestCount
+ 1L);
280 rDest
[nDestCount
] = rSource
;
284 } // end of namespace primitive2d
285 } // end of namespace drawinglayer
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */