1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawinglayer/attribute/sdrfillgraphicattribute.hxx>
21 #include <drawinglayer/attribute/fillgraphicattribute.hxx>
22 #include <rtl/instance.hxx>
23 #include <vcl/graph.hxx>
27 namespace drawinglayer
31 class ImpSdrFillGraphicAttribute
35 Graphic maFillGraphic
;
36 basegfx::B2DVector maGraphicLogicSize
;
37 basegfx::B2DVector maSize
;
38 basegfx::B2DVector maOffset
;
39 basegfx::B2DVector maOffsetPosition
;
40 basegfx::B2DVector maRectPoint
;
47 ImpSdrFillGraphicAttribute(
48 const Graphic
& rFillGraphic
,
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
,
57 : maFillGraphic(rFillGraphic
),
58 maGraphicLogicSize(rGraphicLogicSize
),
61 maOffsetPosition(rOffsetPosition
),
62 maRectPoint(rRectPoint
),
69 ImpSdrFillGraphicAttribute()
70 : maFillGraphic(Graphic()),
71 maGraphicLogicSize(basegfx::B2DVector()),
72 maSize(basegfx::B2DVector()),
73 maOffset(basegfx::B2DVector()),
74 maOffsetPosition(basegfx::B2DVector()),
75 maRectPoint(basegfx::B2DVector()),
83 const Graphic
& getFillGraphic() const { return maFillGraphic
; }
84 const basegfx::B2DVector
& getGraphicLogicSize() const { return maGraphicLogicSize
; }
85 const basegfx::B2DVector
& getSize() const { return maSize
; }
86 const basegfx::B2DVector
& getOffset() const { return maOffset
; }
87 const basegfx::B2DVector
& getOffsetPosition() const { return maOffsetPosition
; }
88 const basegfx::B2DVector
& getRectPoint() const { return maRectPoint
; }
89 bool getTiling() const { return mbTiling
; }
90 bool getStretch() const { return mbStretch
; }
91 bool getLogSize() const { return mbLogSize
; }
93 bool operator==(const ImpSdrFillGraphicAttribute
& rCandidate
) const
95 return (getFillGraphic() == rCandidate
.getFillGraphic()
96 && getGraphicLogicSize() == rCandidate
.getGraphicLogicSize()
97 && getSize() == rCandidate
.getSize()
98 && getOffset() == rCandidate
.getOffset()
99 && getOffsetPosition() == rCandidate
.getOffsetPosition()
100 && getRectPoint() == rCandidate
.getRectPoint()
101 && getTiling() == rCandidate
.getTiling()
102 && getStretch() == rCandidate
.getStretch()
103 && getLogSize() == rCandidate
.getLogSize());
109 struct theGlobalDefault
:
110 public rtl::Static
< SdrFillGraphicAttribute::ImplType
, theGlobalDefault
> {};
113 SdrFillGraphicAttribute::SdrFillGraphicAttribute(
114 const Graphic
& rFillGraphic
,
115 const basegfx::B2DVector
& rGraphicLogicSize
,
116 const basegfx::B2DVector
& rSize
,
117 const basegfx::B2DVector
& rOffset
,
118 const basegfx::B2DVector
& rOffsetPosition
,
119 const basegfx::B2DVector
& rRectPoint
,
123 : mpSdrFillGraphicAttribute(
124 ImpSdrFillGraphicAttribute(
137 SdrFillGraphicAttribute::SdrFillGraphicAttribute()
138 : mpSdrFillGraphicAttribute(theGlobalDefault::get())
142 SdrFillGraphicAttribute::SdrFillGraphicAttribute(const SdrFillGraphicAttribute
& rCandidate
)
143 : mpSdrFillGraphicAttribute(rCandidate
.mpSdrFillGraphicAttribute
)
147 SdrFillGraphicAttribute::~SdrFillGraphicAttribute()
151 bool SdrFillGraphicAttribute::isDefault() const
153 return mpSdrFillGraphicAttribute
.same_object(theGlobalDefault::get());
156 SdrFillGraphicAttribute
& SdrFillGraphicAttribute::operator=(const SdrFillGraphicAttribute
& rCandidate
)
158 mpSdrFillGraphicAttribute
= rCandidate
.mpSdrFillGraphicAttribute
;
162 bool SdrFillGraphicAttribute::operator==(const SdrFillGraphicAttribute
& rCandidate
) const
164 // tdf#87509 default attr is always != non-default attr, even with same values
165 if(rCandidate
.isDefault() != isDefault())
168 return rCandidate
.mpSdrFillGraphicAttribute
== mpSdrFillGraphicAttribute
;
171 const Graphic
& SdrFillGraphicAttribute::getFillGraphic() const
173 return mpSdrFillGraphicAttribute
->getFillGraphic();
176 const basegfx::B2DVector
& SdrFillGraphicAttribute::getGraphicLogicSize() const
178 return mpSdrFillGraphicAttribute
->getGraphicLogicSize();
181 const basegfx::B2DVector
& SdrFillGraphicAttribute::getSize() const
183 return mpSdrFillGraphicAttribute
->getSize();
186 const basegfx::B2DVector
& SdrFillGraphicAttribute::getOffset() const
188 return mpSdrFillGraphicAttribute
->getOffset();
191 const basegfx::B2DVector
& SdrFillGraphicAttribute::getOffsetPosition() const
193 return mpSdrFillGraphicAttribute
->getOffsetPosition();
196 const basegfx::B2DVector
& SdrFillGraphicAttribute::getRectPoint() const
198 return mpSdrFillGraphicAttribute
->getRectPoint();
201 bool SdrFillGraphicAttribute::getTiling() const
203 return mpSdrFillGraphicAttribute
->getTiling();
206 bool SdrFillGraphicAttribute::getStretch() const
208 return mpSdrFillGraphicAttribute
->getStretch();
211 FillGraphicAttribute
SdrFillGraphicAttribute::createFillGraphicAttribute(const basegfx::B2DRange
& rRange
) const
213 // get logical size of bitmap (before expanding eventually)
214 Graphic
aGraphic(getFillGraphic());
216 // init values with defaults for stretched
217 basegfx::B2DPoint
aBitmapSize(1.0, 1.0);
218 basegfx::B2DVector
aBitmapTopLeft(0.0, 0.0);
220 //UUUU are changes needed? When stretched we are already done, all other values will have no influence
221 if(getTiling() || !getStretch())
223 // init values with range sizes
224 const double fRangeWidth(0.0 != rRange
.getWidth() ? rRange
.getWidth() : 1.0);
225 const double fRangeHeight(0.0 != rRange
.getHeight() ? rRange
.getHeight() : 1.0);
226 aBitmapSize
= basegfx::B2DPoint(fRangeWidth
, fRangeHeight
);
229 if(0.0 != getSize().getX())
231 if(getSize().getX() < 0.0)
233 aBitmapSize
.setX(aBitmapSize
.getX() * (getSize().getX() * -0.01));
237 aBitmapSize
.setX(getSize().getX());
242 // #i124002# use GraphicLogicSize directly, do not try to use GetPrefSize
243 // of the graphic, that may not be adapted to the MapMode of the target
244 aBitmapSize
.setX(getGraphicLogicSize().getX());
247 if(0.0 != getSize().getY())
249 if(getSize().getY() < 0.0)
251 aBitmapSize
.setY(aBitmapSize
.getY() * (getSize().getY() * -0.01));
255 aBitmapSize
.setY(getSize().getY());
260 // #i124002# use GraphicLogicSize directly, do not try to use GetPrefSize
261 // of the graphic, that may not be adapted to the MapMode of the target
262 aBitmapSize
.setY(getGraphicLogicSize().getY());
265 // position changes X
266 if(0.0 == getRectPoint().getX())
268 aBitmapTopLeft
.setX((fRangeWidth
- aBitmapSize
.getX()) * 0.5);
270 else if(1.0 == getRectPoint().getX())
272 aBitmapTopLeft
.setX(fRangeWidth
- aBitmapSize
.getX());
275 // offset positions are only meaningful when tiled
276 if(getTiling() && 0.0 != getOffsetPosition().getX())
278 aBitmapTopLeft
.setX(aBitmapTopLeft
.getX() + (aBitmapSize
.getX() * (getOffsetPosition().getX() * 0.01)));
281 // position changes Y
282 if(0.0 == getRectPoint().getY())
284 aBitmapTopLeft
.setY((fRangeHeight
- aBitmapSize
.getY()) * 0.5);
286 else if(1.0 == getRectPoint().getY())
288 aBitmapTopLeft
.setY(fRangeHeight
- aBitmapSize
.getY());
291 // offset positions are only meaningful when tiled
292 if(getTiling() && 0.0 != getOffsetPosition().getY())
294 aBitmapTopLeft
.setY(aBitmapTopLeft
.getY() + (aBitmapSize
.getY() * (getOffsetPosition().getY() * 0.01)));
297 // apply bitmap size scaling to unit rectangle
298 aBitmapTopLeft
.setX(aBitmapTopLeft
.getX() / fRangeWidth
);
299 aBitmapTopLeft
.setY(aBitmapTopLeft
.getY() / fRangeHeight
);
300 aBitmapSize
.setX(aBitmapSize
.getX() / fRangeWidth
);
301 aBitmapSize
.setY(aBitmapSize
.getY() / fRangeHeight
);
304 // get offset in percent
305 const double fOffsetX(basegfx::clamp(getOffset().getX() * 0.01, 0.0, 1.0));
306 const double fOffsetY(basegfx::clamp(getOffset().getY() * 0.01, 0.0, 1.0));
308 // create FillGraphicAttribute
309 return FillGraphicAttribute(
311 basegfx::B2DRange(aBitmapTopLeft
, aBitmapTopLeft
+ aBitmapSize
),
316 } // end of namespace attribute
317 } // end of namespace drawinglayer
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */