Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
28 :
29 :
30 :
31 : using namespace com::sun::star;
32 :
33 :
34 :
35 : namespace drawinglayer
36 : {
37 : namespace primitive2d
38 : {
39 0 : Primitive2DSequence MarkerArrayPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
40 : {
41 0 : Primitive2DSequence xRetval;
42 0 : const std::vector< basegfx::B2DPoint >& rPositions = getPositions();
43 0 : const sal_uInt32 nMarkerCount(rPositions.size());
44 :
45 0 : if(nMarkerCount && !getMarker().IsEmpty())
46 : {
47 : // get pixel size
48 0 : Size aBitmapSize(getMarker().GetSizePixel());
49 :
50 0 : if(aBitmapSize.Width() && aBitmapSize.Height())
51 : {
52 : // get logic half pixel size
53 0 : basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() *
54 0 : basegfx::B2DVector(aBitmapSize.getWidth() - 1.0, aBitmapSize.getHeight() - 1.0));
55 :
56 : // use half size for expand
57 0 : aLogicHalfSize *= 0.5;
58 :
59 : // number of primitives is known; realloc accordingly
60 0 : xRetval.realloc(nMarkerCount);
61 :
62 0 : for(sal_uInt32 a(0); a < nMarkerCount; a++)
63 : {
64 0 : const basegfx::B2DPoint& rPosition(rPositions[a]);
65 0 : const basegfx::B2DRange aRange(rPosition - aLogicHalfSize, rPosition + aLogicHalfSize);
66 0 : basegfx::B2DHomMatrix aTransform;
67 :
68 0 : aTransform.set(0, 0, aRange.getWidth());
69 0 : aTransform.set(1, 1, aRange.getHeight());
70 0 : aTransform.set(0, 2, aRange.getMinX());
71 0 : aTransform.set(1, 2, aRange.getMinY());
72 :
73 0 : xRetval[a] = Primitive2DReference(new BitmapPrimitive2D(getMarker(), aTransform));
74 0 : }
75 : }
76 : }
77 :
78 0 : return xRetval;
79 : }
80 :
81 0 : MarkerArrayPrimitive2D::MarkerArrayPrimitive2D(
82 : const std::vector< basegfx::B2DPoint >& rPositions,
83 : const BitmapEx& rMarker)
84 : : BufferedDecompositionPrimitive2D(),
85 : maPositions(rPositions),
86 0 : maMarker(rMarker)
87 : {
88 0 : }
89 :
90 0 : bool MarkerArrayPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
91 : {
92 0 : if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
93 : {
94 0 : const MarkerArrayPrimitive2D& rCompare = static_cast<const MarkerArrayPrimitive2D&>(rPrimitive);
95 :
96 0 : return (getPositions() == rCompare.getPositions()
97 0 : && getMarker() == rCompare.getMarker());
98 : }
99 :
100 0 : return false;
101 : }
102 :
103 0 : basegfx::B2DRange MarkerArrayPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
104 : {
105 0 : basegfx::B2DRange aRetval;
106 :
107 0 : if(getPositions().size())
108 : {
109 : // get the basic range from the position vector
110 0 : for(std::vector< basegfx::B2DPoint >::const_iterator aIter(getPositions().begin()), aEnd(getPositions().end()); aIter != aEnd; ++aIter)
111 : {
112 0 : aRetval.expand(*aIter);
113 : }
114 :
115 0 : if(!getMarker().IsEmpty())
116 : {
117 : // get pixel size
118 0 : const Size aBitmapSize(getMarker().GetSizePixel());
119 :
120 0 : if(aBitmapSize.Width() && aBitmapSize.Height())
121 : {
122 : // get logic half size
123 0 : basegfx::B2DVector aLogicHalfSize(rViewInformation.getInverseObjectToViewTransformation() *
124 0 : basegfx::B2DVector(aBitmapSize.getWidth(), aBitmapSize.getHeight()));
125 :
126 : // use half size for expand
127 0 : aLogicHalfSize *= 0.5;
128 :
129 : // apply aLogicHalfSize
130 0 : aRetval.expand(aRetval.getMinimum() - aLogicHalfSize);
131 0 : aRetval.expand(aRetval.getMaximum() + aLogicHalfSize);
132 : }
133 : }
134 : }
135 :
136 0 : return aRetval;
137 : }
138 :
139 : // provide unique ID
140 0 : ImplPrimitive2DIDBlock(MarkerArrayPrimitive2D, PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D)
141 :
142 : } // end of namespace primitive2d
143 1143 : } // end of namespace drawinglayer
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|