LibreOffice Module drawinglayer (master) 1
sdrfillgraphicattribute.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
20#include <sal/config.h>
21
22#include <algorithm>
23
26#include <utility>
27#include <vcl/graph.hxx>
28
29
31{
33 {
34 public:
35 // data definitions
42
43 bool mbTiling : 1;
44 bool mbStretch : 1;
45 bool mbLogSize : 1;
46
48 Graphic aFillGraphic,
49 const basegfx::B2DVector& rGraphicLogicSize,
50 const basegfx::B2DVector& rSize,
51 const basegfx::B2DVector& rOffset,
52 const basegfx::B2DVector& rOffsetPosition,
53 const basegfx::B2DVector& rRectPoint,
54 bool bTiling,
55 bool bStretch,
56 bool bLogSize)
57 : maFillGraphic(std::move(aFillGraphic)),
58 maGraphicLogicSize(rGraphicLogicSize),
59 maSize(rSize),
60 maOffset(rOffset),
61 maOffsetPosition(rOffsetPosition),
62 maRectPoint(rRectPoint),
63 mbTiling(bTiling),
64 mbStretch(bStretch),
65 mbLogSize(bLogSize)
66 {
67 }
68
70 : mbTiling(false),
71 mbStretch(false),
72 mbLogSize(false)
73 {
74 }
75
76 // data read access
77 const Graphic& getFillGraphic() const { return maFillGraphic; }
79 const basegfx::B2DVector& getSize() const { return maSize; }
80 const basegfx::B2DVector& getOffset() const { return maOffset; }
82 const basegfx::B2DVector& getRectPoint() const { return maRectPoint; }
83 bool getTiling() const { return mbTiling; }
84 bool getStretch() const { return mbStretch; }
85
86 bool operator==(const ImpSdrFillGraphicAttribute& rCandidate) const
87 {
88 return (getFillGraphic() == rCandidate.getFillGraphic()
89 && getGraphicLogicSize() == rCandidate.getGraphicLogicSize()
90 && getSize() == rCandidate.getSize()
91 && getOffset() == rCandidate.getOffset()
92 && getOffsetPosition() == rCandidate.getOffsetPosition()
93 && getRectPoint() == rCandidate.getRectPoint()
94 && getTiling() == rCandidate.getTiling()
95 && getStretch() == rCandidate.getStretch()
96 && mbLogSize == rCandidate.mbLogSize);
97 }
98 };
99
100 namespace
101 {
102 SdrFillGraphicAttribute::ImplType& theGlobalDefault()
103 {
104 static SdrFillGraphicAttribute::ImplType SINGLETON;
105 return SINGLETON;
106 }
107 }
108
110 const Graphic& rFillGraphic,
111 const basegfx::B2DVector& rGraphicLogicSize,
112 const basegfx::B2DVector& rSize,
113 const basegfx::B2DVector& rOffset,
114 const basegfx::B2DVector& rOffsetPosition,
115 const basegfx::B2DVector& rRectPoint,
116 bool bTiling,
117 bool bStretch,
118 bool bLogSize)
119 : mpSdrFillGraphicAttribute(
121 rFillGraphic,
122 rGraphicLogicSize,
123 rSize,
124 rOffset,
125 rOffsetPosition,
126 rRectPoint,
127 bTiling,
128 bStretch,
129 bLogSize))
130 {
131 }
132
134 : mpSdrFillGraphicAttribute(theGlobalDefault())
135 {
136 }
137
139
141
143
145 {
146 return mpSdrFillGraphicAttribute.same_object(theGlobalDefault());
147 }
148
150
152
154 {
155 // tdf#87509 default attr is always != non-default attr, even with same values
156 if(rCandidate.isDefault() != isDefault())
157 return false;
158
160 }
161
163 {
164 return mpSdrFillGraphicAttribute->getFillGraphic();
165 }
166
168 {
169 return mpSdrFillGraphicAttribute->getGraphicLogicSize();
170 }
171
173 {
174 return mpSdrFillGraphicAttribute->getSize();
175 }
176
178 {
179 return mpSdrFillGraphicAttribute->getOffset();
180 }
181
183 {
184 return mpSdrFillGraphicAttribute->getOffsetPosition();
185 }
186
188 {
189 return mpSdrFillGraphicAttribute->getRectPoint();
190 }
191
193 {
194 return mpSdrFillGraphicAttribute->getTiling();
195 }
196
198 {
199 // get logical size of bitmap (before possibly expanding it)
200 Graphic aGraphic(getFillGraphic());
201
202 // init values with defaults for stretched
203 basegfx::B2DPoint aBitmapSize(1.0, 1.0);
204 basegfx::B2DVector aBitmapTopLeft(0.0, 0.0);
205
206 // are changes needed? When stretched we are already done, all other values will have no influence
207 if(getTiling() || !mpSdrFillGraphicAttribute->getStretch())
208 {
209 // init values with range sizes
210 const double fRangeWidth(0.0 != rRange.getWidth() ? rRange.getWidth() : 1.0);
211 const double fRangeHeight(0.0 != rRange.getHeight() ? rRange.getHeight() : 1.0);
212 aBitmapSize = basegfx::B2DPoint(fRangeWidth, fRangeHeight);
213
214 // size changes
215 if(0.0 != getSize().getX())
216 {
217 if(getSize().getX() < 0.0)
218 {
219 aBitmapSize.setX(aBitmapSize.getX() * (getSize().getX() * -0.01));
220 }
221 else
222 {
223 aBitmapSize.setX(getSize().getX());
224 }
225 }
226 else
227 {
228 // #i124002# use GraphicLogicSize directly, do not try to use GetPrefSize
229 // of the graphic, that may not be adapted to the MapMode of the target
230 aBitmapSize.setX(getGraphicLogicSize().getX());
231 }
232
233 if(0.0 != getSize().getY())
234 {
235 if(getSize().getY() < 0.0)
236 {
237 aBitmapSize.setY(aBitmapSize.getY() * (getSize().getY() * -0.01));
238 }
239 else
240 {
241 aBitmapSize.setY(getSize().getY());
242 }
243 }
244 else
245 {
246 // #i124002# use GraphicLogicSize directly, do not try to use GetPrefSize
247 // of the graphic, that may not be adapted to the MapMode of the target
248 aBitmapSize.setY(getGraphicLogicSize().getY());
249 }
250
251 // position changes X
252 if(0.0 == getRectPoint().getX())
253 {
254 aBitmapTopLeft.setX((fRangeWidth - aBitmapSize.getX()) * 0.5);
255 }
256 else if(1.0 == getRectPoint().getX())
257 {
258 aBitmapTopLeft.setX(fRangeWidth - aBitmapSize.getX());
259 }
260
261 // offset positions are only meaningful when tiled
262 if(getTiling() && 0.0 != getOffsetPosition().getX())
263 {
264 aBitmapTopLeft.setX(aBitmapTopLeft.getX() + (aBitmapSize.getX() * (getOffsetPosition().getX() * 0.01)));
265 }
266
267 // position changes Y
268 if(0.0 == getRectPoint().getY())
269 {
270 aBitmapTopLeft.setY((fRangeHeight - aBitmapSize.getY()) * 0.5);
271 }
272 else if(1.0 == getRectPoint().getY())
273 {
274 aBitmapTopLeft.setY(fRangeHeight - aBitmapSize.getY());
275 }
276
277 // offset positions are only meaningful when tiled
278 if(getTiling() && 0.0 != getOffsetPosition().getY())
279 {
280 aBitmapTopLeft.setY(aBitmapTopLeft.getY() + (aBitmapSize.getY() * (getOffsetPosition().getY() * 0.01)));
281 }
282
283 // apply bitmap size scaling to unit rectangle
284 aBitmapTopLeft.setX(aBitmapTopLeft.getX() / fRangeWidth);
285 aBitmapTopLeft.setY(aBitmapTopLeft.getY() / fRangeHeight);
286 aBitmapSize.setX(aBitmapSize.getX() / fRangeWidth);
287 aBitmapSize.setY(aBitmapSize.getY() / fRangeHeight);
288 }
289
290 // get offset in percent
291 const double fOffsetX(std::clamp(getOffset().getX() * 0.01, 0.0, 1.0));
292 const double fOffsetY(std::clamp(getOffset().getY() * 0.01, 0.0, 1.0));
293
294 // create FillGraphicAttribute
296 aGraphic,
297 basegfx::B2DRange(aBitmapTopLeft, aBitmapTopLeft + aBitmapSize),
298 getTiling(),
299 fOffsetX,
300 fOffsetY);
301 }
302
303} // end of namespace
304
305/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TYPE getWidth() const
TYPE getHeight() const
TYPE getX() const
void setY(TYPE fY)
TYPE getY() const
void setX(TYPE fX)
bool operator==(const ImpSdrFillGraphicAttribute &rCandidate) const
ImpSdrFillGraphicAttribute(Graphic aFillGraphic, const basegfx::B2DVector &rGraphicLogicSize, const basegfx::B2DVector &rSize, const basegfx::B2DVector &rOffset, const basegfx::B2DVector &rOffsetPosition, const basegfx::B2DVector &rRectPoint, bool bTiling, bool bStretch, bool bLogSize)
o3tl::cow_wrapper< ImpSdrFillGraphicAttribute > ImplType
SdrFillGraphicAttribute & operator=(const SdrFillGraphicAttribute &)
FillGraphicAttribute createFillGraphicAttribute(const basegfx::B2DRange &rRange) const
bool operator==(const SdrFillGraphicAttribute &rCandidate) const
bool same_object(const cow_wrapper &rOther) const