LibreOffice Module drawinglayer (master) 1
discreteshadowprimitive2d.cxx
Go to the documentation of this file.
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
26#include <osl/diagnose.h>
28
29
31{
33 : maBitmapEx(rBitmapEx)
34 {
35 maBitmapEx.Invert(); // convert transparency to alpha
36 const Size& rBitmapSize = getBitmapEx().GetSizePixel();
37
38 if(rBitmapSize.Width() != rBitmapSize.Height() || rBitmapSize.Width() < 7)
39 {
40 OSL_ENSURE(false, "DiscreteShadowPrimitive2D: wrong bitmap format (!)");
42 }
43 }
44
46 {
47 if(maTopLeft.IsEmpty())
48 {
49 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
50 const_cast< DiscreteShadow* >(this)->maTopLeft = getBitmapEx();
51 const_cast< DiscreteShadow* >(this)->maTopLeft.Crop(
52 ::tools::Rectangle(Point(0, 0), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
53 }
54
55 return maTopLeft;
56 }
57
59 {
60 if(maTop.IsEmpty())
61 {
62 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
63 const_cast< DiscreteShadow* >(this)->maTop = getBitmapEx();
64 const_cast< DiscreteShadow* >(this)->maTop.Crop(
65 ::tools::Rectangle(Point((nQuarter * 2) + 1, 0), Size(1, nQuarter)));
66 }
67
68 return maTop;
69 }
70
72 {
74 {
75 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
76 const_cast< DiscreteShadow* >(this)->maTopRight = getBitmapEx();
77 const_cast< DiscreteShadow* >(this)->maTopRight.Crop(
78 ::tools::Rectangle(Point((nQuarter * 2) + 2, 0), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
79 }
80
81 return maTopRight;
82 }
83
85 {
86 if(maRight.IsEmpty())
87 {
88 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
89 const_cast< DiscreteShadow* >(this)->maRight = getBitmapEx();
90 const_cast< DiscreteShadow* >(this)->maRight.Crop(
91 ::tools::Rectangle(Point((nQuarter * 3) + 3, (nQuarter * 2) + 1), Size(nQuarter, 1)));
92 }
93
94 return maRight;
95 }
96
98 {
100 {
101 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
102 const_cast< DiscreteShadow* >(this)->maBottomRight = getBitmapEx();
103 const_cast< DiscreteShadow* >(this)->maBottomRight.Crop(
104 ::tools::Rectangle(Point((nQuarter * 2) + 2, (nQuarter * 2) + 2), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
105 }
106
107 return maBottomRight;
108 }
109
111 {
112 if(maBottom.IsEmpty())
113 {
114 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
115 const_cast< DiscreteShadow* >(this)->maBottom = getBitmapEx();
116 const_cast< DiscreteShadow* >(this)->maBottom.Crop(
117 ::tools::Rectangle(Point((nQuarter * 2) + 1, (nQuarter * 3) + 3), Size(1, nQuarter)));
118 }
119
120 return maBottom;
121 }
122
124 {
126 {
127 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
128 const_cast< DiscreteShadow* >(this)->maBottomLeft = getBitmapEx();
129 const_cast< DiscreteShadow* >(this)->maBottomLeft.Crop(
130 ::tools::Rectangle(Point(0, (nQuarter * 2) + 2), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
131 }
132
133 return maBottomLeft;
134 }
135
137 {
138 if(maLeft.IsEmpty())
139 {
140 const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
141 const_cast< DiscreteShadow* >(this)->maLeft = getBitmapEx();
142 const_cast< DiscreteShadow* >(this)->maLeft.Crop(
143 ::tools::Rectangle(Point(0, (nQuarter * 2) + 1), Size(nQuarter, 1)));
144 }
145
146 return maLeft;
147 }
148
149} // end of namespace
150
151
153{
155 {
156 Primitive2DContainer xRetval;
157
158 if(getDiscreteShadow().getBitmapEx().IsEmpty())
159 return;
160
161 const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
162 const basegfx::B2DVector aScale(getTransform() * basegfx::B2DVector(1.0, 1.0));
163 const double fSingleX(getDiscreteUnit() / aScale.getX());
164 const double fSingleY(getDiscreteUnit() / aScale.getY());
165 const double fBorderX(fSingleX * nQuarter);
166 const double fBorderY(fSingleY * nQuarter);
167 const double fBigLenX((fBorderX * 2.0) + fSingleX);
168 const double fBigLenY((fBorderY * 2.0) + fSingleY);
169
170 xRetval.resize(8);
171
172 // TopLeft
173 xRetval[0] = Primitive2DReference(
175 getDiscreteShadow().getTopLeft(),
177 fBigLenX,
178 fBigLenY,
179 -fBorderX,
180 -fBorderY)));
181
182 // Top
183 xRetval[1] = Primitive2DReference(
185 getDiscreteShadow().getTop(),
187 1.0 - (2.0 * (fBorderX + fSingleX)) + fSingleX,
188 fBorderY,
189 fBorderX + fSingleX,
190 -fBorderY)));
191
192 // TopRight
193 xRetval[2] = Primitive2DReference(
195 getDiscreteShadow().getTopRight(),
197 fBigLenX,
198 fBigLenY,
199 1.0 - fBorderX,
200 -fBorderY)));
201
202 // Right
203 xRetval[3] = Primitive2DReference(
205 getDiscreteShadow().getRight(),
207 fBorderX,
208 1.0 - (2.0 * (fBorderY + fSingleY)) + fSingleY,
209 1.0 + fSingleX,
210 fBorderY + fSingleY)));
211
212 // BottomRight
213 xRetval[4] = Primitive2DReference(
215 getDiscreteShadow().getBottomRight(),
217 fBigLenX,
218 fBigLenY,
219 1.0 - (fBorderX + fSingleX) + fSingleX,
220 1.0 - (fBorderY + fSingleY) + fSingleY)));
221
222 // Bottom
223 xRetval[5] = Primitive2DReference(
225 getDiscreteShadow().getBottom(),
227 1.0 - (2.0 * (fBorderX + fSingleX)) + fSingleX,
228 fBorderY,
229 fBorderX + fSingleX,
230 1.0 + fSingleY)));
231
232 // BottomLeft
233 xRetval[6] = Primitive2DReference(
235 getDiscreteShadow().getBottomLeft(),
237 fBigLenX,
238 fBigLenY,
239 -fBorderX,
240 1.0 - fBorderY)));
241
242 // Left
243 xRetval[7] = Primitive2DReference(
245 getDiscreteShadow().getLeft(),
247 fBorderX,
248 1.0 - (2.0 * (fBorderY + fSingleY)) + fSingleY,
249 -fBorderX,
250 fBorderY + fSingleY)));
251
252 // put all in object transformation to get to target positions
253 rContainer.push_back(
255 getTransform(),
256 std::move(xRetval)));
257 }
258
260 const basegfx::B2DHomMatrix& rTransform,
261 const DiscreteShadow& rDiscreteShadow)
262 : maTransform(rTransform),
263 maDiscreteShadow(rDiscreteShadow)
264 {
265 }
266
268 {
269 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
270 {
271 const DiscreteShadowPrimitive2D& rCompare = static_cast<const DiscreteShadowPrimitive2D&>(rPrimitive);
272
273 return (getTransform() == rCompare.getTransform()
274 && getDiscreteShadow() == rCompare.getDiscreteShadow());
275 }
276
277 return false;
278 }
279
281 {
282 if(getDiscreteShadow().getBitmapEx().IsEmpty())
283 {
284 // no graphics without valid bitmap definition
285 return basegfx::B2DRange();
286 }
287 else
288 {
289 // prepare normal objectrange
290 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
291 aRetval.transform(getTransform());
292
293 // extract discrete shadow size and grow
294 const basegfx::B2DVector aScale(rViewInformation.getViewTransformation() * basegfx::B2DVector(1.0, 1.0));
295 const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
296 const double fGrowX((1.0 / aScale.getX()) * nQuarter);
297 const double fGrowY((1.0 / aScale.getY()) * nQuarter);
298 aRetval.grow(std::max(fGrowX, fGrowY));
299
300 return aRetval;
301 }
302 }
303
304 // provide unique ID
306 {
308 }
309
310} // end of namespace
311
312/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Invert()
bool IsEmpty() const
bool Crop(const tools::Rectangle &rRectPixel)
const Size & GetSizePixel() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
void grow(TYPE fValue)
TYPE getX() const
TYPE getY() const
const basegfx::B2DHomMatrix & getViewTransformation() const
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
create local decomposition
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
get range
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
const basegfx::B2DHomMatrix & getTransform() const
data read access
DiscreteShadowPrimitive2D(const basegfx::B2DHomMatrix &rTransform, const DiscreteShadow &rDiscreteShadow)
constructor
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
BitmapEx maTopLeft
buffered extracted parts of CombinedShadow for easier usage
BitmapEx maBitmapEx
the original shadow BitmapEx in a special form
DiscreteShadow(const BitmapEx &rBitmapEx)
constructor
const BitmapEx & getBitmapEx() const
data read access
const BitmapEx & getTopLeft() const
helper accesses which create on-demand needed segments
#define PRIMITIVE2D_ID_DISCRETESHADOWPRIMITIVE2D
basegfx::B2DHomMatrix maTransform
the geometric definition
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
rtl::Reference< BasePrimitive2D > Primitive2DReference
Definition: CommonTypes.hxx:27