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 <sal/config.h>
25 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
27 #include <drawinglayer/geometry/viewinformation2d.hxx>
28 #include <basegfx/utils/canvastools.hxx>
29 #include <comphelper/sequence.hxx>
32 using namespace com::sun::star
;
35 namespace drawinglayer
39 Primitive2DDecompositionVisitor::~Primitive2DDecompositionVisitor() {}
41 BasePrimitive2D::BasePrimitive2D()
42 : BasePrimitive2DImplBase(m_aMutex
)
46 BasePrimitive2D::~BasePrimitive2D()
50 bool BasePrimitive2D::operator==( const BasePrimitive2D
& rPrimitive
) const
52 return (getPrimitive2DID() == rPrimitive
.getPrimitive2DID());
55 // Visitor class to get the B2D range from a tree of Primitive2DReference's
57 class B2DRangeVisitor
: public Primitive2DDecompositionVisitor
{
59 const geometry::ViewInformation2D
& mrViewInformation
;
60 basegfx::B2DRange maRetval
;
61 B2DRangeVisitor(const geometry::ViewInformation2D
& rViewInformation
) : mrViewInformation(rViewInformation
) {}
62 virtual void append(const Primitive2DReference
& r
) override
{
63 maRetval
.expand(getB2DRangeFromPrimitive2DReference(r
, mrViewInformation
));
65 virtual void append(const Primitive2DContainer
& r
) override
{
66 maRetval
.expand(r
.getB2DRange(mrViewInformation
));
68 virtual void append(Primitive2DContainer
&& r
) override
{
69 maRetval
.expand(r
.getB2DRange(mrViewInformation
));
72 basegfx::B2DRange
BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
74 B2DRangeVisitor
aVisitor(rViewInformation
);
75 get2DDecomposition(aVisitor
, rViewInformation
);
76 return aVisitor
.maRetval
;
79 void BasePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& /*rVisitor*/, const geometry::ViewInformation2D
& /*rViewInformation*/) const
83 css::uno::Sequence
< ::css::uno::Reference
< ::css::graphic::XPrimitive2D
> > SAL_CALL
BasePrimitive2D::getDecomposition( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
)
85 const geometry::ViewInformation2D
aViewInformation(rViewParameters
);
86 Primitive2DContainer aContainer
;
87 get2DDecomposition(aContainer
, aViewInformation
);
88 return comphelper::containerToSequence(aContainer
);
91 css::geometry::RealRectangle2D SAL_CALL
BasePrimitive2D::getRange( const uno::Sequence
< beans::PropertyValue
>& rViewParameters
)
93 const geometry::ViewInformation2D
aViewInformation(rViewParameters
);
94 return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation
));
97 sal_Int64 SAL_CALL
BasePrimitive2D::estimateUsage()
99 return 0; // for now ignore the objects themselves
101 } // end of namespace primitive2d
102 } // end of namespace drawinglayer
105 namespace drawinglayer
107 namespace primitive2d
109 void BufferedDecompositionPrimitive2D::create2DDecomposition(Primitive2DContainer
& /*rContainer*/, const geometry::ViewInformation2D
& /*rViewInformation*/) const
113 BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
115 maBuffered2DDecomposition()
119 void BufferedDecompositionPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
121 ::osl::MutexGuard
aGuard( m_aMutex
);
123 if(getBuffered2DDecomposition().empty())
125 Primitive2DContainer aNewSequence
;
126 create2DDecomposition(aNewSequence
, rViewInformation
);
127 const_cast< BufferedDecompositionPrimitive2D
* >(this)->setBuffered2DDecomposition(aNewSequence
);
130 rVisitor
.append(getBuffered2DDecomposition());
132 } // end of namespace primitive2d
133 } // end of namespace drawinglayer
138 namespace drawinglayer
140 namespace primitive2d
142 Primitive2DContainer
Primitive2DContainer::maybeInvert(bool bInvert
) const
144 const sal_uInt32
nSize(size());
145 Primitive2DContainer aRetval
;
147 aRetval
.resize(nSize
);
149 for(sal_uInt32
a(0); a
< nSize
; a
++)
151 aRetval
[bInvert
? nSize
- 1 - a
: a
] = (*this)[a
];
154 // all entries taken over to Uno References as owners. To avoid
155 // errors with users of this mechanism to delete pointers to BasePrimitive2D
156 // itself, clear given vector
157 const_cast< Primitive2DContainer
& >(*this).clear();
162 // get B2DRange from a given Primitive2DReference
163 basegfx::B2DRange
getB2DRangeFromPrimitive2DReference(const Primitive2DReference
& rCandidate
, const geometry::ViewInformation2D
& aViewInformation
)
165 basegfx::B2DRange aRetval
;
169 // try to get C++ implementation base
170 const BasePrimitive2D
* pCandidate(dynamic_cast< BasePrimitive2D
* >(rCandidate
.get()));
174 // use it if possible
175 aRetval
.expand(pCandidate
->getB2DRange(aViewInformation
));
179 // use UNO API call instead
180 const uno::Sequence
< beans::PropertyValue
>& rViewParameters(aViewInformation
.getViewInformationSequence());
181 aRetval
.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate
->getRange(rViewParameters
)));
188 // get B2DRange from a given Primitive2DSequence
189 basegfx::B2DRange
Primitive2DContainer::getB2DRange(const geometry::ViewInformation2D
& aViewInformation
) const
191 basegfx::B2DRange aRetval
;
195 const sal_Int32
nCount(size());
197 for(sal_Int32
a(0); a
< nCount
; a
++)
199 aRetval
.expand(getB2DRangeFromPrimitive2DReference((*this)[a
], aViewInformation
));
206 bool arePrimitive2DReferencesEqual(const Primitive2DReference
& rxA
, const Primitive2DReference
& rxB
)
208 const bool bAIs(rxA
.is());
220 const BasePrimitive2D
* pA(dynamic_cast< const BasePrimitive2D
* >(rxA
.get()));
221 const BasePrimitive2D
* pB(dynamic_cast< const BasePrimitive2D
* >(rxB
.get()));
228 return pA
->operator==(*pB
);
231 bool Primitive2DContainer::operator==(const Primitive2DContainer
& rB
) const
233 const bool bAHasElements(!empty());
235 if(bAHasElements
!= !rB
.empty())
245 const size_t nCount(size());
247 if(nCount
!= rB
.size())
252 for(size_t a(0); a
< nCount
; a
++)
254 if(!arePrimitive2DReferencesEqual((*this)[a
], rB
[a
]))
263 Primitive2DContainer::~Primitive2DContainer() {}
265 void Primitive2DContainer::append(const Primitive2DReference
& rSource
)
270 void Primitive2DContainer::append(const Primitive2DContainer
& rSource
)
272 insert(end(), rSource
.begin(), rSource
.end());
275 void Primitive2DContainer::append(Primitive2DContainer
&& rSource
)
278 resize(n
+ rSource
.size());
279 for (size_t i
= 0; i
<rSource
.size(); ++i
)
281 (*this)[n
+ i
] = std::move( rSource
[i
] );
285 void Primitive2DContainer::append(const Primitive2DSequence
& rSource
)
287 std::copy(rSource
.begin(), rSource
.end(), std::back_inserter(*this));
290 OUString
idToString(sal_uInt32 nId
)
294 case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D
: return "TRANSPARENCE";
295 case PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D
: return "ANIMATEDSWITCH";
296 case PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D
: return "ANIMATEDBLINK";
297 case PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D
: return "ANIMATEDINTERPOLATE";
298 case PRIMITIVE2D_ID_BACKGROUNDCOLORPRIMITIVE2D
: return "BACKGROUNDCOLOR";
299 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D
: return "BITMAP";
300 case PRIMITIVE2D_ID_CONTROLPRIMITIVE2D
: return "CONTROL";
301 case PRIMITIVE2D_ID_EMBEDDED3DPRIMITIVE2D
: return "EMBEDDED3D";
302 case PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D
: return "FILLGRAPHIC";
303 case PRIMITIVE2D_ID_FILLGRADIENTPRIMITIVE2D
: return "FILLGRADIENT";
304 case PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D
: return "FILLHATCH";
305 case PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D
: return "GRAPHIC";
306 case PRIMITIVE2D_ID_GRIDPRIMITIVE2D
: return "GRID";
307 case PRIMITIVE2D_ID_GROUPPRIMITIVE2D
: return "GROUP";
308 case PRIMITIVE2D_ID_HELPLINEPRIMITIVE2D
: return "HELPLINE";
309 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D
: return "MARKERARRAY";
310 case PRIMITIVE2D_ID_MASKPRIMITIVE2D
: return "MASK";
311 case PRIMITIVE2D_ID_MEDIAPRIMITIVE2D
: return "MEDIA";
312 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D
: return "METAFILE";
313 case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D
: return "MODIFIEDCOLOR";
314 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D
: return "POLYGONHAIRLINE";
315 case PRIMITIVE2D_ID_POLYGONMARKERPRIMITIVE2D
: return "POLYGONMARKER";
316 case PRIMITIVE2D_ID_POLYGONSTROKEPRIMITIVE2D
: return "POLYGONSTROKE";
317 case PRIMITIVE2D_ID_POLYGONSTROKEARROWPRIMITIVE2D
: return "POLYGONSTROKEARROW";
318 case PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D
: return "POLYPOLYGONSTROKE";
319 case PRIMITIVE2D_ID_POLYPOLYGONSTROKEARROWPRIMITIVE2D
: return "POLYPOLYGONSTROKEARROW";
320 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D
: return "POLYPOLYGONCOLOR";
321 case PRIMITIVE2D_ID_POLYPOLYGONGRADIENTPRIMITIVE2D
: return "POLYPOLYGONGRADIENT";
322 case PRIMITIVE2D_ID_POLYPOLYGONHATCHPRIMITIVE2D
: return "POLYPOLYGONHATCH";
323 case PRIMITIVE2D_ID_POLYPOLYGONGRAPHICPRIMITIVE2D
: return "POLYPOLYGONGRAPHIC";
324 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D
: return "SCENE";
325 case PRIMITIVE2D_ID_SHADOWPRIMITIVE2D
: return "SHADOW";
326 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D
: return "TEXTSIMPLEPORTION";
327 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D
: return "TEXTDECORATEDPORTION";
328 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D
: return "TRANSFORM";
329 case PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D
: return "UNIFIEDTRANSPARENCE";
330 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D
: return "POINTARRAY";
331 case PRIMITIVE2D_ID_TEXTHIERARCHYFIELDPRIMITIVE2D
: return "TEXTHIERARCHYFIELD";
332 case PRIMITIVE2D_ID_TEXTHIERARCHYLINEPRIMITIVE2D
: return "TEXTHIERARCHYLINE";
333 case PRIMITIVE2D_ID_TEXTHIERARCHYPARAGRAPHPRIMITIVE2D
: return "TEXTHIERARCHYPARAGRAPH";
334 case PRIMITIVE2D_ID_TEXTHIERARCHYBLOCKPRIMITIVE2D
: return "TEXTHIERARCHYBLOCK";
335 case PRIMITIVE2D_ID_TEXTHIERARCHYEDITPRIMITIVE2D
: return "TEXTHIERARCHYEDIT";
336 case PRIMITIVE2D_ID_POLYGONWAVEPRIMITIVE2D
: return "POLYGONWAVE";
337 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D
: return "WRONGSPELL";
338 case PRIMITIVE2D_ID_TEXTEFFECTPRIMITIVE2D
: return "TEXTEFFECT";
339 case PRIMITIVE2D_ID_TEXTHIERARCHYBULLETPRIMITIVE2D
: return "TEXTHIERARCHYBULLET";
340 case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D
: return "POLYPOLYGONHAIRLINE";
341 case PRIMITIVE2D_ID_EXECUTEPRIMITIVE2D
: return "EXECUTE";
342 case PRIMITIVE2D_ID_PAGEPREVIEWPRIMITIVE2D
: return "PAGEPREVIEW";
343 case PRIMITIVE2D_ID_STRUCTURETAGPRIMITIVE2D
: return "STRUCTURETAG";
344 case PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D
: return "BORDERLINE";
345 case PRIMITIVE2D_ID_POLYPOLYGONMARKERPRIMITIVE2D
: return "POLYPOLYGONMARKER";
346 case PRIMITIVE2D_ID_HITTESTPRIMITIVE2D
: return "HITTEST";
347 case PRIMITIVE2D_ID_INVERTPRIMITIVE2D
: return "INVERT";
348 case PRIMITIVE2D_ID_DISCRETEBITMAPPRIMITIVE2D
: return "DISCRETEBITMAP";
349 case PRIMITIVE2D_ID_WALLPAPERBITMAPPRIMITIVE2D
: return "WALLPAPERBITMAP";
350 case PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D
: return "TEXTLINE";
351 case PRIMITIVE2D_ID_TEXTCHARACTERSTRIKEOUTPRIMITIVE2D
: return "TEXTCHARACTERSTRIKEOUT";
352 case PRIMITIVE2D_ID_TEXTGEOMETRYSTRIKEOUTPRIMITIVE2D
: return "TEXTGEOMETRYSTRIKEOUT";
353 case PRIMITIVE2D_ID_EPSPRIMITIVE2D
: return "EPS";
354 case PRIMITIVE2D_ID_DISCRETESHADOWPRIMITIVE2D
: return "DISCRETESHADOW";
355 case PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D
: return "HIDDENGEOMETRY";
356 case PRIMITIVE2D_ID_SVGLINEARGRADIENTPRIMITIVE2D
: return "SVGLINEARGRADIENT";
357 case PRIMITIVE2D_ID_SVGRADIALGRADIENTPRIMITIVE2D
: return "SVGRADIALGRADIENT";
358 case PRIMITIVE2D_ID_SVGLINEARATOMPRIMITIVE2D
: return "SVGLINEARATOM";
359 case PRIMITIVE2D_ID_SVGRADIALATOMPRIMITIVE2D
: return "SVGRADIALATOM";
360 case PRIMITIVE2D_ID_CROPPRIMITIVE2D
: return "CROP";
361 case PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D
: return "PATTERNFILL";
362 case PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D
: return "OBJECTINFO";
363 case PRIMITIVE2D_ID_POLYPOLYGONSELECTIONPRIMITIVE2D
: return "POLYPOLYGONSELECTION";
364 case PRIMITIVE2D_ID_PAGEHIERARCHYPRIMITIVE2D
: return "PAGEHIERARCHY";
365 default: return OUString::number((nId
>> 16) & 0xFF) + "|" + OUString::number(nId
& 0xFF);
368 } // end of namespace primitive2d
369 } // end of namespace drawinglayer
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */