merge the formfield patch from ooo-build
[ooovba.git] / drawinglayer / source / texture / texture3d.cxx
blob062d7c67f009e24767f32c2441a6dee07b6722a6
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: texture3d.cxx,v $
7 * $Revision: 1.2 $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:34 $
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,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/texture/texture3d.hxx>
40 #include <vcl/bmpacc.hxx>
41 #include <drawinglayer/attribute/fillattribute.hxx>
42 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
44 //////////////////////////////////////////////////////////////////////////////
46 namespace drawinglayer
48 namespace texture
50 GeoTexSvxMono::GeoTexSvxMono(const basegfx::BColor& rSingleColor, double fOpacity)
51 : maSingleColor(rSingleColor),
52 mfOpacity(fOpacity)
56 bool GeoTexSvxMono::operator==(const GeoTexSvx& rGeoTexSvx) const
58 const GeoTexSvxMono* pCompare = dynamic_cast< const GeoTexSvxMono* >(&rGeoTexSvx);
59 return (pCompare
60 && maSingleColor == pCompare->maSingleColor
61 && mfOpacity == pCompare->mfOpacity);
64 void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
66 rBColor = maSingleColor;
69 void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint& /*rUV*/, double& rfOpacity) const
71 rfOpacity = mfOpacity;
73 } // end of namespace texture
74 } // end of namespace drawinglayer
76 //////////////////////////////////////////////////////////////////////////////
78 namespace drawinglayer
80 namespace texture
82 GeoTexSvxBitmap::GeoTexSvxBitmap(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
83 : maBitmap(rBitmap),
84 mpRead(0L),
85 maTopLeft(rTopLeft),
86 maSize(rSize),
87 mfMulX(0.0),
88 mfMulY(0.0)
90 mpRead = maBitmap.AcquireReadAccess();
91 OSL_ENSURE(mpRead, "GeoTexSvxBitmap: Got no read access to Bitmap (!)");
92 mfMulX = (double)mpRead->Width() / maSize.getX();
93 mfMulY = (double)mpRead->Height() / maSize.getY();
96 GeoTexSvxBitmap::~GeoTexSvxBitmap()
98 delete mpRead;
101 bool GeoTexSvxBitmap::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
103 if(mpRead)
105 rX = (sal_Int32)((rUV.getX() - maTopLeft.getX()) * mfMulX);
107 if(rX >= 0L && rX < mpRead->Width())
109 rY = (sal_Int32)((rUV.getY() - maTopLeft.getY()) * mfMulY);
111 return (rY >= 0L && rY < mpRead->Height());
115 return false;
118 void GeoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
120 sal_Int32 nX, nY;
122 if(impIsValid(rUV, nX, nY))
124 const double fConvertColor(1.0 / 255.0);
125 const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
126 const basegfx::BColor aBSource(
127 (double)aBMCol.GetRed() * fConvertColor,
128 (double)aBMCol.GetGreen() * fConvertColor,
129 (double)aBMCol.GetBlue() * fConvertColor);
131 rBColor = aBSource;
133 else
135 rfOpacity = 0.0;
139 void GeoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
141 sal_Int32 nX, nY;
143 if(impIsValid(rUV, nX, nY))
145 const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
146 const Color aColor(aBMCol.GetRed(), aBMCol.GetGreen(), aBMCol.GetBlue());
148 rfOpacity = ((double)(0xff - aColor.GetLuminance()) * (1.0 / 255.0));
150 else
152 rfOpacity = 0.0;
155 } // end of namespace texture
156 } // end of namespace drawinglayer
158 //////////////////////////////////////////////////////////////////////////////
160 namespace drawinglayer
162 namespace texture
164 GeoTexSvxBitmapTiled::GeoTexSvxBitmapTiled(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
165 : GeoTexSvxBitmap(rBitmap, rTopLeft, rSize)
169 void GeoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
171 if(mpRead)
173 GeoTexSvxBitmap::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
177 void GeoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
179 if(mpRead)
181 GeoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV), rfOpacity);
184 } // end of namespace texture
185 } // end of namespace drawinglayer
187 //////////////////////////////////////////////////////////////////////////////
189 namespace drawinglayer
191 namespace texture
193 GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(const primitive3d::HatchTexturePrimitive3D& rPrimitive, double fLogicPixelSize)
194 : mfLogicPixelSize(fLogicPixelSize),
195 mp0(0L),
196 mp1(0L),
197 mp2(0L)
199 const attribute::FillHatchAttribute& rHatch(rPrimitive.getHatch());
200 const basegfx::B2DRange aOutlineRange(0.0, 0.0, rPrimitive.getTextureSize().getX(), rPrimitive.getTextureSize().getY());
201 const double fAngleA(-rHatch.getAngle());
202 maColor = rHatch.getColor();
203 mbFillBackground = rHatch.isFillBackground();
204 mp0 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA);
206 if(attribute::HATCHSTYLE_DOUBLE == rHatch.getStyle() || attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
208 mp1 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI2);
211 if(attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
213 mp2 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI4);
217 GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
219 delete mp0;
220 delete mp1;
221 delete mp2;
224 bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint& rUV) const
226 if(mp0->getDistanceToHatch(rUV) < mfLogicPixelSize)
228 return true;
231 if(mp1 && mp1->getDistanceToHatch(rUV) < mfLogicPixelSize)
233 return true;
236 if(mp2 && mp2->getDistanceToHatch(rUV) < mfLogicPixelSize)
238 return true;
241 return false;
244 void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
246 if(impIsOnHatch(rUV))
248 rBColor = maColor;
250 else if(!mbFillBackground)
252 rfOpacity = 0.0;
256 void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
258 if(mbFillBackground || impIsOnHatch(rUV))
260 rfOpacity = 1.0;
262 else
264 rfOpacity = 0.0;
267 } // end of namespace texture
268 } // end of namespace drawinglayer
270 //////////////////////////////////////////////////////////////////////////////
271 // eof