Branch data 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/discreteshadowprimitive2d.hxx>
21 : : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22 : : #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
23 : : #include <basegfx/matrix/b2dhommatrixtools.hxx>
24 : : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
25 : : #include <drawinglayer/geometry/viewinformation2d.hxx>
26 : :
27 : : //////////////////////////////////////////////////////////////////////////////
28 : :
29 : : namespace drawinglayer
30 : : {
31 : : namespace primitive2d
32 : : {
33 : 87 : DiscreteShadow::DiscreteShadow(const BitmapEx& rBitmapEx)
34 : : : maBitmapEx(rBitmapEx),
35 : : maTopLeft(),
36 : : maTop(),
37 : : maTopRight(),
38 : : maRight(),
39 : : maBottomRight(),
40 : : maBottom(),
41 : : maBottomLeft(),
42 [ + - ][ + - ]: 87 : maLeft()
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
43 : : {
44 : 87 : const Size& rBitmapSize = getBitmapEx().GetSizePixel();
45 : :
46 [ + + ][ + + ]: 87 : if(rBitmapSize.Width() != rBitmapSize.Height() || rBitmapSize.Width() < 7)
[ + - ]
47 : : {
48 : : OSL_ENSURE(false, "DiscreteShadowPrimitive2D: wrong bitmap format (!)");
49 [ + - ][ + - ]: 23 : maBitmapEx = BitmapEx();
[ + - ]
50 : : }
51 : 87 : }
52 : :
53 : 210 : const BitmapEx& DiscreteShadow::getTopLeft() const
54 : : {
55 [ + + ]: 210 : if(maTopLeft.IsEmpty())
56 : : {
57 : 203 : const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
58 : 203 : const_cast< DiscreteShadow* >(this)->maTopLeft = getBitmapEx();
59 : : const_cast< DiscreteShadow* >(this)->maTopLeft.Crop(
60 [ + - ][ + - ]: 203 : Rectangle(Point(0,0),Size(nQuarter*2+1,nQuarter*2+1)));
61 : : }
62 : :
63 : 210 : return maTopLeft;
64 : : }
65 : :
66 : 210 : const BitmapEx& DiscreteShadow::getTop() const
67 : : {
68 [ + + ]: 210 : if(maTop.IsEmpty())
69 : : {
70 : 203 : const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
71 : 203 : const_cast< DiscreteShadow* >(this)->maTop = getBitmapEx();
72 : : const_cast< DiscreteShadow* >(this)->maTop.Crop(
73 [ + - ][ + - ]: 203 : Rectangle(Point(nQuarter*2+1,0),Size(1,nQuarter+1)));
74 : : }
75 : :
76 : 210 : return maTop;
77 : : }
78 : :
79 : 210 : const BitmapEx& DiscreteShadow::getTopRight() const
80 : : {
81 [ + + ]: 210 : if(maTopRight.IsEmpty())
82 : : {
83 : 203 : const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
84 : 203 : const_cast< DiscreteShadow* >(this)->maTopRight = getBitmapEx();
85 : : const_cast< DiscreteShadow* >(this)->maTopRight.Crop(
86 [ + - ][ + - ]: 203 : Rectangle(Point(nQuarter*2+2,0),Size(nQuarter*2+1,nQuarter*2+1)));
87 : : }
88 : :
89 : 210 : return maTopRight;
90 : : }
91 : :
92 : 210 : const BitmapEx& DiscreteShadow::getRight() const
93 : : {
94 [ + + ]: 210 : if(maRight.IsEmpty())
95 : : {
96 : 203 : const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
97 : 203 : const_cast< DiscreteShadow* >(this)->maRight = getBitmapEx();
98 : : const_cast< DiscreteShadow* >(this)->maRight.Crop(
99 [ + - ][ + - ]: 203 : Rectangle(Point(nQuarter*3+2,nQuarter*2+1),Size(nQuarter+1,1)));
100 : : }
101 : :
102 : 210 : return maRight;
103 : : }
104 : :
105 : 210 : const BitmapEx& DiscreteShadow::getBottomRight() const
106 : : {
107 [ + + ]: 210 : if(maBottomRight.IsEmpty())
108 : : {
109 : 203 : const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
110 : 203 : const_cast< DiscreteShadow* >(this)->maBottomRight = getBitmapEx();
111 : : const_cast< DiscreteShadow* >(this)->maBottomRight.Crop(
112 [ + - ][ + - ]: 203 : Rectangle(Point(nQuarter*2+2,nQuarter*2+2),Size(nQuarter*2+1,nQuarter*2+1)));
113 : : }
114 : :
115 : 210 : return maBottomRight;
116 : : }
117 : :
118 : 210 : const BitmapEx& DiscreteShadow::getBottom() const
119 : : {
120 [ + + ]: 210 : if(maBottom.IsEmpty())
121 : : {
122 : 203 : const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
123 : 203 : const_cast< DiscreteShadow* >(this)->maBottom = getBitmapEx();
124 : : const_cast< DiscreteShadow* >(this)->maBottom.Crop(
125 [ + - ][ + - ]: 203 : Rectangle(Point(nQuarter*2+1,nQuarter*3+2),Size(1,nQuarter+1)));
126 : : }
127 : :
128 : 210 : return maBottom;
129 : : }
130 : :
131 : 210 : const BitmapEx& DiscreteShadow::getBottomLeft() const
132 : : {
133 [ + + ]: 210 : if(maBottomLeft.IsEmpty())
134 : : {
135 : 203 : const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
136 : 203 : const_cast< DiscreteShadow* >(this)->maBottomLeft = getBitmapEx();
137 : : const_cast< DiscreteShadow* >(this)->maBottomLeft.Crop(
138 [ + - ][ + - ]: 203 : Rectangle(Point(0,nQuarter*2+2),Size(nQuarter*2+1,nQuarter*2+1)));
139 : : }
140 : :
141 : 210 : return maBottomLeft;
142 : : }
143 : :
144 : 210 : const BitmapEx& DiscreteShadow::getLeft() const
145 : : {
146 [ + + ]: 210 : if(maLeft.IsEmpty())
147 : : {
148 : 203 : const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
149 : 203 : const_cast< DiscreteShadow* >(this)->maLeft = getBitmapEx();
150 : : const_cast< DiscreteShadow* >(this)->maLeft.Crop(
151 [ + - ][ + - ]: 203 : Rectangle(Point(0,nQuarter*2+1),Size(nQuarter+1,1)));
152 : : }
153 : :
154 : 210 : return maLeft;
155 : : }
156 : :
157 : : } // end of namespace primitive2d
158 : : } // end of namespace drawinglayer
159 : :
160 : : //////////////////////////////////////////////////////////////////////////////
161 : :
162 : : namespace drawinglayer
163 : : {
164 : : namespace primitive2d
165 : : {
166 : 154 : Primitive2DSequence DiscreteShadowPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
167 : : {
168 : 154 : Primitive2DSequence xRetval;
169 : :
170 [ + - ][ + - ]: 154 : if(!getDiscreteShadow().getBitmapEx().IsEmpty())
171 : : {
172 : 154 : const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
173 [ + - ]: 154 : const basegfx::B2DVector aScale(getTransform() * basegfx::B2DVector(1.0, 1.0));
174 : 154 : const double fSingleX(getDiscreteUnit() / aScale.getX());
175 : 154 : const double fSingleY(getDiscreteUnit() / aScale.getY());
176 : 154 : const double fBorderX(fSingleX * nQuarter);
177 : 154 : const double fBorderY(fSingleY * nQuarter);
178 : 154 : const double fBigLenX((fBorderX * 2.0) + fSingleX);
179 : 154 : const double fBigLenY((fBorderY * 2.0) + fSingleY);
180 : :
181 [ + - ]: 154 : xRetval.realloc(8);
182 : :
183 : : // TopLeft
184 [ + - ]: 154 : xRetval[0] = Primitive2DReference(
185 : : new BitmapPrimitive2D(
186 : 154 : getDiscreteShadow().getTopLeft(),
187 : : basegfx::tools::createScaleTranslateB2DHomMatrix(
188 : : fBigLenX,
189 : : fBigLenY,
190 : : -fBorderX,
191 [ + - ][ + - ]: 308 : -fBorderY)));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
192 : :
193 : : // Top
194 [ + - ]: 154 : xRetval[1] = Primitive2DReference(
195 : : new BitmapPrimitive2D(
196 : 154 : getDiscreteShadow().getTop(),
197 : : basegfx::tools::createScaleTranslateB2DHomMatrix(
198 : : 1.0 - (2.0 * fBorderX) - fSingleX,
199 : : fBorderY + fSingleY,
200 : : fBorderX + fSingleX,
201 [ + - ][ + - ]: 308 : -fBorderY)));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
202 : :
203 : : // TopRight
204 [ + - ]: 154 : xRetval[2] = Primitive2DReference(
205 : : new BitmapPrimitive2D(
206 : 154 : getDiscreteShadow().getTopRight(),
207 : : basegfx::tools::createScaleTranslateB2DHomMatrix(
208 : : fBigLenX,
209 : : fBigLenY,
210 : : 1.0 - fBorderX,
211 [ + - ][ + - ]: 308 : -fBorderY)));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
212 : :
213 : : // Right
214 [ + - ]: 154 : xRetval[3] = Primitive2DReference(
215 : : new BitmapPrimitive2D(
216 : 154 : getDiscreteShadow().getRight(),
217 : : basegfx::tools::createScaleTranslateB2DHomMatrix(
218 : : fBorderX + fSingleX,
219 : : 1.0 - (2.0 * fBorderY) - fSingleY,
220 : : 1.0,
221 [ + - ][ + - ]: 308 : fBorderY + fSingleY)));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
222 : :
223 : : // BottomRight
224 [ + - ]: 154 : xRetval[4] = Primitive2DReference(
225 : : new BitmapPrimitive2D(
226 : 154 : getDiscreteShadow().getBottomRight(),
227 : : basegfx::tools::createScaleTranslateB2DHomMatrix(
228 : : fBigLenX,
229 : : fBigLenY,
230 : : 1.0 - fBorderX,
231 [ + - ][ + - ]: 308 : 1.0 - fBorderY)));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
232 : :
233 : : // Bottom
234 [ + - ]: 154 : xRetval[5] = Primitive2DReference(
235 : : new BitmapPrimitive2D(
236 : 154 : getDiscreteShadow().getBottom(),
237 : : basegfx::tools::createScaleTranslateB2DHomMatrix(
238 : : 1.0 - (2.0 * fBorderX) - fSingleX,
239 : : fBorderY + fSingleY,
240 : : fBorderX + fSingleX,
241 [ + - ][ + - ]: 308 : 1.0)));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
242 : :
243 : : // BottomLeft
244 [ + - ]: 154 : xRetval[6] = Primitive2DReference(
245 : : new BitmapPrimitive2D(
246 : 154 : getDiscreteShadow().getBottomLeft(),
247 : : basegfx::tools::createScaleTranslateB2DHomMatrix(
248 : : fBigLenX,
249 : : fBigLenY,
250 : : -fBorderX,
251 [ + - ][ + - ]: 308 : 1.0 - fBorderY)));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
252 : :
253 : : // Left
254 [ + - ]: 154 : xRetval[7] = Primitive2DReference(
255 : : new BitmapPrimitive2D(
256 : 154 : getDiscreteShadow().getLeft(),
257 : : basegfx::tools::createScaleTranslateB2DHomMatrix(
258 : : fBorderX + fSingleX,
259 : : 1.0 - (2.0 * fBorderY) - fSingleY,
260 : : -fBorderX,
261 [ + - ][ + - ]: 308 : fBorderY + fSingleY)));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
262 : :
263 : : // put all in object transformation to get to target positions
264 : : const Primitive2DReference xTransformed(
265 : : new TransformPrimitive2D(
266 : : getTransform(),
267 [ + - ][ + - ]: 154 : xRetval));
[ + - ]
268 : :
269 [ + - ][ + - ]: 154 : xRetval = Primitive2DSequence(&xTransformed, 1);
[ + - ]
270 : : }
271 : :
272 : 154 : return xRetval;
273 : : }
274 : :
275 : 1976 : DiscreteShadowPrimitive2D::DiscreteShadowPrimitive2D(
276 : : const basegfx::B2DHomMatrix& rTransform,
277 : : const DiscreteShadow& rDiscreteShadow)
278 : : : DiscreteMetricDependentPrimitive2D(),
279 : : maTransform(rTransform),
280 [ + - ][ + - ]: 1976 : maDiscreteShadow(rDiscreteShadow)
281 : : {
282 : 1976 : }
283 : :
284 : 3689 : bool DiscreteShadowPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
285 : : {
286 [ + - ]: 3689 : if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
287 : : {
288 : 3689 : const DiscreteShadowPrimitive2D& rCompare = (DiscreteShadowPrimitive2D&)rPrimitive;
289 : :
290 : 3689 : return (getTransform() == rCompare.getTransform()
291 [ + - ][ + + ]: 3689 : && getDiscreteShadow() == rCompare.getDiscreteShadow());
292 : : }
293 : :
294 : 3689 : return false;
295 : : }
296 : :
297 : 3776 : basegfx::B2DRange DiscreteShadowPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
298 : : {
299 [ + + ]: 3776 : if(getDiscreteShadow().getBitmapEx().IsEmpty())
300 : : {
301 : : // no graphics without valid bitmap definition
302 : 34 : return basegfx::B2DRange();
303 : : }
304 : : else
305 : : {
306 : : // prepare normal objectrange
307 [ + - ]: 3742 : basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
308 [ + - ]: 3742 : aRetval.transform(getTransform());
309 : :
310 : : // extract discrete shadow size and grow
311 [ + - ][ + - ]: 3742 : const basegfx::B2DVector aScale(rViewInformation.getViewTransformation() * basegfx::B2DVector(1.0, 1.0));
312 : 3742 : const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
313 : 3742 : const double fGrowX((1.0 / aScale.getX()) * nQuarter);
314 : 3742 : const double fGrowY((1.0 / aScale.getY()) * nQuarter);
315 [ + - ][ + - ]: 3742 : aRetval.grow(std::max(fGrowX, fGrowY));
316 : :
317 : 3776 : return aRetval;
318 : : }
319 : : }
320 : :
321 : : // provide unique ID
322 : 9178 : ImplPrimitrive2DIDBlock(DiscreteShadowPrimitive2D, PRIMITIVE2D_ID_DISCRETESHADOWPRIMITIVE2D)
323 : :
324 : : } // end of namespace primitive2d
325 : : } // end of namespace drawinglayer
326 : :
327 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|