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/markerarrayprimitive2d.hxx>
21 #include <basegfx/matrix/b2dhommatrix.hxx>
22 #include <drawinglayer/geometry/viewinformation2d.hxx>
23 #include <basegfx/polygon/b2dpolygon.hxx>
24 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
25 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
27 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
29 //////////////////////////////////////////////////////////////////////////////
31 using namespace com::sun::star
;
33 //////////////////////////////////////////////////////////////////////////////
35 namespace drawinglayer
39 Primitive2DSequence
MarkerArrayPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
41 Primitive2DSequence xRetval
;
42 const std::vector
< basegfx::B2DPoint
>& rPositions
= getPositions();
43 const sal_uInt32
nMarkerCount(rPositions
.size());
45 if(nMarkerCount
&& !getMarker().IsEmpty())
48 Size
aBitmapSize(getMarker().GetSizePixel());
50 if(aBitmapSize
.Width() && aBitmapSize
.Height())
52 // get logic half pixel size
53 basegfx::B2DVector
aLogicHalfSize(rViewInformation
.getInverseObjectToViewTransformation() *
54 basegfx::B2DVector(aBitmapSize
.getWidth() - 1.0, aBitmapSize
.getHeight() - 1.0));
56 // use half size for expand
57 aLogicHalfSize
*= 0.5;
59 // number of primitives is known; realloc accordingly
60 xRetval
.realloc(nMarkerCount
);
62 for(sal_uInt32
a(0); a
< nMarkerCount
; a
++)
64 const basegfx::B2DPoint
& rPosition(rPositions
[a
]);
65 const basegfx::B2DRange
aRange(rPosition
- aLogicHalfSize
, rPosition
+ aLogicHalfSize
);
66 basegfx::B2DHomMatrix aTransform
;
68 aTransform
.set(0, 0, aRange
.getWidth());
69 aTransform
.set(1, 1, aRange
.getHeight());
70 aTransform
.set(0, 2, aRange
.getMinX());
71 aTransform
.set(1, 2, aRange
.getMinY());
73 xRetval
[a
] = Primitive2DReference(new BitmapPrimitive2D(getMarker(), aTransform
));
81 MarkerArrayPrimitive2D::MarkerArrayPrimitive2D(
82 const std::vector
< basegfx::B2DPoint
>& rPositions
,
83 const BitmapEx
& rMarker
)
84 : BufferedDecompositionPrimitive2D(),
85 maPositions(rPositions
),
90 bool MarkerArrayPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
92 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
94 const MarkerArrayPrimitive2D
& rCompare
= (MarkerArrayPrimitive2D
&)rPrimitive
;
96 return (getPositions() == rCompare
.getPositions()
97 && getMarker() == rCompare
.getMarker());
103 basegfx::B2DRange
MarkerArrayPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
105 basegfx::B2DRange aRetval
;
107 if(getPositions().size())
109 // get the basic range from the position vector
110 for(std::vector
< basegfx::B2DPoint
>::const_iterator
aIter(getPositions().begin()), aEnd(getPositions().end()); aIter
!= aEnd
; ++aIter
)
112 aRetval
.expand(*aIter
);
115 if(!getMarker().IsEmpty())
118 const Size
aBitmapSize(getMarker().GetSizePixel());
120 if(aBitmapSize
.Width() && aBitmapSize
.Height())
122 // get logic half size
123 basegfx::B2DVector
aLogicHalfSize(rViewInformation
.getInverseObjectToViewTransformation() *
124 basegfx::B2DVector(aBitmapSize
.getWidth(), aBitmapSize
.getHeight()));
126 // use half size for expand
127 aLogicHalfSize
*= 0.5;
129 // apply aLogicHalfSize
130 aRetval
.expand(aRetval
.getMinimum() - aLogicHalfSize
);
131 aRetval
.expand(aRetval
.getMaximum() + aLogicHalfSize
);
140 ImplPrimitive2DIDBlock(MarkerArrayPrimitive2D
, PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D
)
142 } // end of namespace primitive2d
143 } // end of namespace drawinglayer
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */