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>
30 using namespace com::sun::star
;
33 namespace drawinglayer
37 void MarkerArrayPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& rViewInformation
) const
39 const std::vector
< basegfx::B2DPoint
>& rPositions
= getPositions();
40 const sal_uInt32
nMarkerCount(rPositions
.size());
42 if(nMarkerCount
&& !getMarker().IsEmpty())
45 Size
aBitmapSize(getMarker().GetSizePixel());
47 if(aBitmapSize
.Width() && aBitmapSize
.Height())
49 // get logic half pixel size
50 basegfx::B2DVector
aLogicHalfSize(rViewInformation
.getInverseObjectToViewTransformation() *
51 basegfx::B2DVector(aBitmapSize
.getWidth() - 1.0, aBitmapSize
.getHeight() - 1.0));
53 // use half size for expand
54 aLogicHalfSize
*= 0.5;
56 for(sal_uInt32
a(0); a
< nMarkerCount
; a
++)
58 const basegfx::B2DPoint
& rPosition(rPositions
[a
]);
59 const basegfx::B2DRange
aRange(rPosition
- aLogicHalfSize
, rPosition
+ aLogicHalfSize
);
60 basegfx::B2DHomMatrix aTransform
;
62 aTransform
.set(0, 0, aRange
.getWidth());
63 aTransform
.set(1, 1, aRange
.getHeight());
64 aTransform
.set(0, 2, aRange
.getMinX());
65 aTransform
.set(1, 2, aRange
.getMinY());
67 rContainer
.push_back(new BitmapPrimitive2D(getMarker(), aTransform
));
73 MarkerArrayPrimitive2D::MarkerArrayPrimitive2D(
74 const std::vector
< basegfx::B2DPoint
>& rPositions
,
75 const BitmapEx
& rMarker
)
76 : BufferedDecompositionPrimitive2D(),
77 maPositions(rPositions
),
82 bool MarkerArrayPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
84 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
86 const MarkerArrayPrimitive2D
& rCompare
= static_cast<const MarkerArrayPrimitive2D
&>(rPrimitive
);
88 return (getPositions() == rCompare
.getPositions()
89 && getMarker() == rCompare
.getMarker());
95 basegfx::B2DRange
MarkerArrayPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
97 basegfx::B2DRange aRetval
;
99 if(!getPositions().empty())
101 // get the basic range from the position vector
102 for (auto const& pos
: getPositions())
107 if(!getMarker().IsEmpty())
110 const Size
aBitmapSize(getMarker().GetSizePixel());
112 if(aBitmapSize
.Width() && aBitmapSize
.Height())
114 // get logic half size
115 basegfx::B2DVector
aLogicHalfSize(rViewInformation
.getInverseObjectToViewTransformation() *
116 basegfx::B2DVector(aBitmapSize
.getWidth(), aBitmapSize
.getHeight()));
118 // use half size for expand
119 aLogicHalfSize
*= 0.5;
121 // apply aLogicHalfSize
122 aRetval
.expand(aRetval
.getMinimum() - aLogicHalfSize
);
123 aRetval
.expand(aRetval
.getMaximum() + aLogicHalfSize
);
132 ImplPrimitive2DIDBlock(MarkerArrayPrimitive2D
, PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D
)
134 } // end of namespace primitive2d
135 } // end of namespace drawinglayer
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */