1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: sdrfillbitmapattribute.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
40 #include <drawinglayer/attribute/fillbitmapattribute.hxx>
41 #include <basegfx/numeric/ftools.hxx>
42 #include <basegfx/range/b2drange.hxx>
44 //////////////////////////////////////////////////////////////////////////////
46 namespace drawinglayer
50 SdrFillBitmapAttribute::SdrFillBitmapAttribute(
51 const Bitmap
& rBitmap
, const basegfx::B2DVector
& rSize
, const basegfx::B2DVector
& rOffset
,
52 const basegfx::B2DVector
& rOffsetPosition
, const basegfx::B2DVector
& rRectPoint
,
53 bool bTiling
, bool bStretch
, bool bLogSize
)
57 maOffsetPosition(rOffsetPosition
),
58 maRectPoint(rRectPoint
),
65 bool SdrFillBitmapAttribute::operator==(const SdrFillBitmapAttribute
& rCandidate
) const
67 return (maBitmap
== rCandidate
.maBitmap
68 && maSize
== rCandidate
.maSize
69 && maOffset
== rCandidate
.maOffset
70 && maOffsetPosition
== rCandidate
.maOffsetPosition
71 && maRectPoint
== rCandidate
.maRectPoint
72 && mbTiling
== rCandidate
.mbTiling
73 && mbStretch
== rCandidate
.mbStretch
74 && mbLogSize
== rCandidate
.mbLogSize
);
77 FillBitmapAttribute
SdrFillBitmapAttribute::getFillBitmapAttribute(const basegfx::B2DRange
& rRange
) const
79 // get logical size of bitmap (before expanding eventually)
80 Bitmap
aBitmap(maBitmap
);
81 const basegfx::B2DVector
aLogicalSize(aBitmap
.GetPrefSize().getWidth(), aBitmap
.GetPrefSize().getHeight());
83 // get hor/ver shiftings and apply them eventually to the bitmap, but only
85 bool bExpandWidth(false);
86 bool bExpandHeight(false);
90 if(0.0 != maOffset
.getX() || 0.0 != maOffset
.getY())
92 const sal_uInt32
nWidth(aBitmap
.GetSizePixel().getWidth());
93 const sal_uInt32
nHeight(aBitmap
.GetSizePixel().getHeight());
95 if(0.0 != maOffset
.getX())
98 const sal_uInt32
nOffset(basegfx::fround(((double)nWidth
* maOffset
.getX()) / 100.0));
99 aBitmap
.Expand(0L, nHeight
);
101 const Size
aSizeA(nOffset
, nHeight
);
102 const Rectangle
aDstA(Point(0L, nHeight
), aSizeA
);
103 const Rectangle
aSrcA(Point(nWidth
- nOffset
, 0L), aSizeA
);
104 aBitmap
.CopyPixel(aDstA
, aSrcA
);
106 const Size
aSizeB(nWidth
- nOffset
, nHeight
);
107 const Rectangle
aDstB(Point(nOffset
, nHeight
), aSizeB
);
108 const Rectangle
aSrcB(Point(0L, 0L), aSizeB
);
109 aBitmap
.CopyPixel(aDstB
, aSrcB
);
114 const sal_uInt32
nOffset(basegfx::fround(((double)nHeight
* maOffset
.getY()) / 100.0));
115 aBitmap
.Expand(nWidth
, 0L);
117 const Size
aSize(nWidth
, nHeight
);
118 const Rectangle
aDst(Point(nWidth
, 0L), aSize
);
119 const Rectangle
aSrc(Point(0L, 0L), aSize
);
120 aBitmap
.CopyPixel(aDst
, aSrc
);
122 const Size
aSizeA(nWidth
, nOffset
);
123 const Rectangle
aDstA(Point(0L, 0L), aSizeA
);
124 const Rectangle
aSrcA(Point(nWidth
, nHeight
- nOffset
), aSizeA
);
125 aBitmap
.CopyPixel(aDstA
, aSrcA
);
127 const Size
aSizeB(nWidth
, nHeight
- nOffset
);
128 const Rectangle
aDstB(Point(0L, nOffset
), aSizeB
);
129 const Rectangle
aSrcB(Point(nWidth
, 0L), aSizeB
);
130 aBitmap
.CopyPixel(aDstB
, aSrcB
);
135 // init values with defaults
136 basegfx::B2DPoint
aBitmapSize(1.0, 1.0);
137 basegfx::B2DVector
aBitmapTopLeft(0.0, 0.0);
139 // are canges needed?
140 if(mbTiling
|| !mbStretch
)
142 // init values with range sizes
143 const double fRangeWidth(0.0 != rRange
.getWidth() ? rRange
.getWidth() : 1.0);
144 const double fRangeHeight(0.0 != rRange
.getHeight() ? rRange
.getHeight() : 1.0);
145 aBitmapSize
= basegfx::B2DPoint(fRangeWidth
, fRangeHeight
);
148 if(0.0 != maSize
.getX())
150 if(maSize
.getX() < 0.0)
152 aBitmapSize
.setX(aBitmapSize
.getX() * (maSize
.getX() * -0.01));
156 aBitmapSize
.setX(maSize
.getX());
161 aBitmapSize
.setX(aLogicalSize
.getX());
164 if(0.0 != maSize
.getY())
166 if(maSize
.getY() < 0.0)
168 aBitmapSize
.setY(aBitmapSize
.getY() * (maSize
.getY() * -0.01));
172 aBitmapSize
.setY(maSize
.getY());
177 aBitmapSize
.setY(aLogicalSize
.getY());
180 // get values, force to centered if necessary
181 const basegfx::B2DVector
aRectPoint(mbTiling
? maRectPoint
: basegfx::B2DVector(0.0, 0.0));
183 // position changes X
184 if(0.0 == aRectPoint
.getX())
186 aBitmapTopLeft
.setX((fRangeWidth
- aBitmapSize
.getX()) * 0.5);
188 else if(1.0 == aRectPoint
.getX())
190 aBitmapTopLeft
.setX(fRangeWidth
- aBitmapSize
.getX());
193 if(mbTiling
&& 0.0 != maOffsetPosition
.getX())
195 aBitmapTopLeft
.setX(aBitmapTopLeft
.getX() + (aBitmapSize
.getX() * (maOffsetPosition
.getX() * 0.01)));
198 // position changes Y
199 if(0.0 == aRectPoint
.getY())
201 aBitmapTopLeft
.setY((fRangeHeight
- aBitmapSize
.getY()) * 0.5);
203 else if(1.0 == aRectPoint
.getY())
205 aBitmapTopLeft
.setY(fRangeHeight
- aBitmapSize
.getY());
208 if(mbTiling
&& 0.0 != maOffsetPosition
.getY())
210 aBitmapTopLeft
.setY(aBitmapTopLeft
.getY() + (aBitmapSize
.getY() * (maOffsetPosition
.getY() * 0.01)));
216 aBitmapSize
.setX(aBitmapSize
.getX() * 2.0);
221 aBitmapSize
.setY(aBitmapSize
.getY() * 2.0);
224 // apply bitmap size scaling to unit rectangle
225 aBitmapTopLeft
.setX(aBitmapTopLeft
.getX() / fRangeWidth
);
226 aBitmapTopLeft
.setY(aBitmapTopLeft
.getY() / fRangeHeight
);
227 aBitmapSize
.setX(aBitmapSize
.getX() / fRangeWidth
);
228 aBitmapSize
.setY(aBitmapSize
.getY() / fRangeHeight
);
231 return FillBitmapAttribute(aBitmap
, aBitmapTopLeft
, aBitmapSize
, mbTiling
);
233 } // end of namespace attribute
234 } // end of namespace drawinglayer
236 //////////////////////////////////////////////////////////////////////////////