xref: /AOO41X/main/drawinglayer/source/primitive2d/markerarrayprimitive2d.cxx (revision 464702f4578bd67db020a330afd07883930c5e07)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_drawinglayer.hxx"
26 
27 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
29 #include <drawinglayer/geometry/viewinformation2d.hxx>
30 #include <basegfx/polygon/b2dpolygon.hxx>
31 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
32 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
33 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
34 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 using namespace com::sun::star;
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 namespace drawinglayer
43 {
44     namespace primitive2d
45     {
create2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const46         Primitive2DSequence MarkerArrayPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
47         {
48             Primitive2DSequence xRetval;
49             const std::vector< basegfx::B2DPoint >& rPositions = getPositions();
50             const sal_uInt32 nMarkerCount(rPositions.size());
51 
52             if(nMarkerCount && !getMarker().IsEmpty())
53             {
54                 // get pixel size
55                 Size aBitmapSize(getMarker().GetSizePixel());
56 
57                 if(aBitmapSize.Width() && aBitmapSize.Height())
58                 {
59                     // get logic half pixel size
60                     basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() *
61                         basegfx::B2DVector(aBitmapSize.getWidth() - 1.0, aBitmapSize.getHeight() - 1.0));
62 
63                     // use half size for expand
64                     aLogicHalfSize *= 0.5;
65 
66                     // number of primitives is known; realloc accordingly
67                     xRetval.realloc(nMarkerCount);
68 
69                     for(sal_uInt32 a(0); a < nMarkerCount; a++)
70                     {
71                         const basegfx::B2DPoint& rPosition(rPositions[a]);
72                         const basegfx::B2DRange aRange(rPosition - aLogicHalfSize, rPosition + aLogicHalfSize);
73                         basegfx::B2DHomMatrix aTransform;
74 
75                         aTransform.set(0, 0, aRange.getWidth());
76                         aTransform.set(1, 1, aRange.getHeight());
77                         aTransform.set(0, 2, aRange.getMinX());
78                         aTransform.set(1, 2, aRange.getMinY());
79 
80                         xRetval[a] = Primitive2DReference(new BitmapPrimitive2D(getMarker(), aTransform));
81                     }
82                 }
83             }
84 
85             return xRetval;
86         }
87 
MarkerArrayPrimitive2D(const std::vector<basegfx::B2DPoint> & rPositions,const BitmapEx & rMarker)88         MarkerArrayPrimitive2D::MarkerArrayPrimitive2D(
89             const std::vector< basegfx::B2DPoint >& rPositions,
90             const BitmapEx& rMarker)
91         :   BufferedDecompositionPrimitive2D(),
92             maPositions(rPositions),
93             maMarker(rMarker)
94         {
95         }
96 
operator ==(const BasePrimitive2D & rPrimitive) const97         bool MarkerArrayPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
98         {
99             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
100             {
101                 const MarkerArrayPrimitive2D& rCompare = (MarkerArrayPrimitive2D&)rPrimitive;
102 
103                 return (getPositions() == rCompare.getPositions()
104                     && getMarker() == rCompare.getMarker());
105             }
106 
107             return false;
108         }
109 
getB2DRange(const geometry::ViewInformation2D & rViewInformation) const110         basegfx::B2DRange MarkerArrayPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
111         {
112             basegfx::B2DRange aRetval;
113 
114             if(getPositions().size())
115             {
116                 // get the basic range from the position vector
117                 for(std::vector< basegfx::B2DPoint >::const_iterator aIter(getPositions().begin()); aIter != getPositions().end(); aIter++)
118                 {
119                     aRetval.expand(*aIter);
120                 }
121 
122                 if(!getMarker().IsEmpty())
123                 {
124                     // get pixel size
125                     const Size aBitmapSize(getMarker().GetSizePixel());
126 
127                     if(aBitmapSize.Width() && aBitmapSize.Height())
128                     {
129                         // get logic half size
130                         basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() *
131                             basegfx::B2DVector(aBitmapSize.getWidth(), aBitmapSize.getHeight()));
132 
133                         // use half size for expand
134                         aLogicHalfSize *= 0.5;
135 
136                         // apply aLogicHalfSize
137                         aRetval.expand(aRetval.getMinimum() - aLogicHalfSize);
138                         aRetval.expand(aRetval.getMaximum() + aLogicHalfSize);
139                     }
140                 }
141             }
142 
143             return aRetval;
144         }
145 
146         // provide unique ID
147         ImplPrimitrive2DIDBlock(MarkerArrayPrimitive2D, PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D)
148 
149     } // end of namespace primitive2d
150 } // end of namespace drawinglayer
151 
152 //////////////////////////////////////////////////////////////////////////////
153 // eof
154