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 <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
24 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
28 using namespace com::sun::star
;
31 namespace drawinglayer::primitive2d
33 void MarkerArrayPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& rViewInformation
) const
35 const std::vector
< basegfx::B2DPoint
>& rPositions
= getPositions();
36 const sal_uInt32
nMarkerCount(rPositions
.size());
38 if(!nMarkerCount
|| getMarker().IsEmpty())
42 Size
aBitmapSize(getMarker().GetSizePixel());
44 if(!(aBitmapSize
.Width() && aBitmapSize
.Height()))
47 // get logic half pixel size
48 basegfx::B2DVector
aLogicHalfSize(rViewInformation
.getInverseObjectToViewTransformation() *
49 basegfx::B2DVector(aBitmapSize
.getWidth() - 1.0, aBitmapSize
.getHeight() - 1.0));
51 // use half size for expand
52 aLogicHalfSize
*= 0.5;
54 for(const auto& rPosition
: rPositions
)
56 const basegfx::B2DRange
aRange(rPosition
- aLogicHalfSize
, rPosition
+ aLogicHalfSize
);
57 basegfx::B2DHomMatrix aTransform
;
59 aTransform
.set(0, 0, aRange
.getWidth());
60 aTransform
.set(1, 1, aRange
.getHeight());
61 aTransform
.set(0, 2, aRange
.getMinX());
62 aTransform
.set(1, 2, aRange
.getMinY());
65 new BitmapPrimitive2D(
71 MarkerArrayPrimitive2D::MarkerArrayPrimitive2D(
72 std::vector
< basegfx::B2DPoint
>&& rPositions
,
73 const BitmapEx
& rMarker
)
74 : maPositions(std::move(rPositions
)),
79 bool MarkerArrayPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
81 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
83 const MarkerArrayPrimitive2D
& rCompare
= static_cast<const MarkerArrayPrimitive2D
&>(rPrimitive
);
85 return (getPositions() == rCompare
.getPositions()
86 && getMarker() == rCompare
.getMarker());
92 basegfx::B2DRange
MarkerArrayPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& rViewInformation
) const
94 basegfx::B2DRange aRetval
;
96 if(!getPositions().empty())
98 // get the basic range from the position vector
99 for (auto const& pos
: getPositions())
104 if(!getMarker().IsEmpty())
107 const Size
aBitmapSize(getMarker().GetSizePixel());
109 if(aBitmapSize
.Width() && aBitmapSize
.Height())
111 // get logic half size
112 basegfx::B2DVector
aLogicHalfSize(rViewInformation
.getInverseObjectToViewTransformation() *
113 basegfx::B2DVector(aBitmapSize
.getWidth(), aBitmapSize
.getHeight()));
115 // use half size for expand
116 aLogicHalfSize
*= 0.5;
118 // apply aLogicHalfSize
119 aRetval
.expand(aRetval
.getMinimum() - aLogicHalfSize
);
120 aRetval
.expand(aRetval
.getMaximum() + aLogicHalfSize
);
129 sal_uInt32
MarkerArrayPrimitive2D::getPrimitive2DID() const
131 return PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D
;
134 } // end of namespace
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */