update emoji autocorrect entries from po-files
[LibreOffice.git] / drawinglayer / source / texture / texture3d.cxx
blob5902188068c1835c4c1a11ccf70b2ccf8744c18e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/texture/texture3d.hxx>
21 #include <vcl/bmpacc.hxx>
22 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
26 namespace drawinglayer
28 namespace texture
30 GeoTexSvxMono::GeoTexSvxMono(
31 const basegfx::BColor& rSingleColor,
32 double fOpacity)
33 : maSingleColor(rSingleColor),
34 mfOpacity(fOpacity)
38 bool GeoTexSvxMono::operator==(const GeoTexSvx& rGeoTexSvx) const
40 const GeoTexSvxMono* pCompare = dynamic_cast< const GeoTexSvxMono* >(&rGeoTexSvx);
42 return (pCompare
43 && maSingleColor == pCompare->maSingleColor
44 && mfOpacity == pCompare->mfOpacity);
47 void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
49 rBColor = maSingleColor;
52 void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint& /*rUV*/, double& rfOpacity) const
54 rfOpacity = mfOpacity;
56 } // end of namespace texture
57 } // end of namespace drawinglayer
61 namespace drawinglayer
63 namespace texture
65 GeoTexSvxBitmapEx::GeoTexSvxBitmapEx(
66 const BitmapEx& rBitmapEx,
67 const basegfx::B2DRange& rRange)
68 : maBitmapEx(rBitmapEx),
69 mpReadBitmap(0),
70 maTransparence(),
71 mpReadTransparence(0),
72 maTopLeft(rRange.getMinimum()),
73 maSize(rRange.getRange()),
74 mfMulX(0.0),
75 mfMulY(0.0),
76 mbIsAlpha(false),
77 mbIsTransparent(maBitmapEx.IsTransparent())
79 // #121194# Todo: use alpha channel, too (for 3d)
80 mpReadBitmap = maBitmapEx.GetBitmap().AcquireReadAccess();
81 OSL_ENSURE(mpReadBitmap, "GeoTexSvxBitmapEx: Got no read access to Bitmap (!)");
83 if(mbIsTransparent)
85 if(maBitmapEx.IsAlpha())
87 mbIsAlpha = true;
88 maTransparence = rBitmapEx.GetAlpha().GetBitmap();
90 else
92 maTransparence = rBitmapEx.GetMask();
95 mpReadTransparence = maTransparence.AcquireReadAccess();
98 mfMulX = (double)mpReadBitmap->Width() / maSize.getX();
99 mfMulY = (double)mpReadBitmap->Height() / maSize.getY();
101 if(maSize.getX() <= 1.0)
103 maSize.setX(1.0);
106 if(maSize.getY() <= 1.0)
108 maSize.setY(1.0);
112 GeoTexSvxBitmapEx::~GeoTexSvxBitmapEx()
114 delete mpReadTransparence;
115 delete mpReadBitmap;
118 sal_uInt8 GeoTexSvxBitmapEx::impGetTransparence(sal_Int32& rX, sal_Int32& rY) const
120 switch(maBitmapEx.GetTransparentType())
122 case TRANSPARENT_NONE:
124 break;
126 case TRANSPARENT_COLOR:
128 const BitmapColor aBitmapColor(mpReadBitmap->GetColor(rY, rX));
130 if(maBitmapEx.GetTransparentColor() == aBitmapColor.operator Color())
132 return 255;
135 break;
137 case TRANSPARENT_BITMAP:
139 OSL_ENSURE(mpReadTransparence, "OOps, transparence type Bitmap, but no read access created in the constructor (?)");
140 const BitmapColor aBitmapColor(mpReadTransparence->GetPixel(rY, rX));
142 if(mbIsAlpha)
144 return aBitmapColor.GetIndex();
146 else
148 if(0x00 != aBitmapColor.GetIndex())
150 return 255;
153 break;
157 return 0;
160 bool GeoTexSvxBitmapEx::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
162 if(mpReadBitmap)
164 rX = (sal_Int32)((rUV.getX() - maTopLeft.getX()) * mfMulX);
166 if(rX >= 0L && rX < mpReadBitmap->Width())
168 rY = (sal_Int32)((rUV.getY() - maTopLeft.getY()) * mfMulY);
170 return (rY >= 0L && rY < mpReadBitmap->Height());
174 return false;
177 void GeoTexSvxBitmapEx::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
179 sal_Int32 nX, nY;
181 if(impIsValid(rUV, nX, nY))
183 const double fConvertColor(1.0 / 255.0);
184 const BitmapColor aBMCol(mpReadBitmap->GetColor(nY, nX));
185 const basegfx::BColor aBSource(
186 (double)aBMCol.GetRed() * fConvertColor,
187 (double)aBMCol.GetGreen() * fConvertColor,
188 (double)aBMCol.GetBlue() * fConvertColor);
190 rBColor = aBSource;
192 if(mbIsTransparent)
194 // when we have a transparence, make use of it
195 const sal_uInt8 aLuminance(impGetTransparence(nX, nY));
197 rfOpacity = ((double)(0xff - aLuminance) * (1.0 / 255.0));
199 else
201 rfOpacity = 1.0;
204 else
206 rfOpacity = 0.0;
210 void GeoTexSvxBitmapEx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
212 sal_Int32 nX, nY;
214 if(impIsValid(rUV, nX, nY))
216 if(mbIsTransparent)
218 // this texture has an alpha part, use it
219 const sal_uInt8 aLuminance(impGetTransparence(nX, nY));
220 const double fNewOpacity((double)(0xff - aLuminance) * (1.0 / 255.0));
222 rfOpacity = 1.0 - ((1.0 - fNewOpacity) * (1.0 - rfOpacity));
224 else
226 // this texture is a color bitmap used as transparence map
227 const BitmapColor aBMCol(mpReadBitmap->GetColor(nY, nX));
228 const Color aColor(aBMCol.GetRed(), aBMCol.GetGreen(), aBMCol.GetBlue());
230 rfOpacity = ((double)(0xff - aColor.GetLuminance()) * (1.0 / 255.0));
233 else
235 rfOpacity = 0.0;
238 } // end of namespace texture
239 } // end of namespace drawinglayer
243 namespace drawinglayer
245 namespace texture
247 basegfx::B2DPoint GeoTexSvxBitmapExTiled::impGetCorrected(const basegfx::B2DPoint& rUV) const
249 double fX(rUV.getX() - maTopLeft.getX());
250 double fY(rUV.getY() - maTopLeft.getY());
252 if(mbUseOffsetX)
254 const sal_Int32 nCol(static_cast< sal_Int32 >((fY < 0.0 ? maSize.getY() -fY : fY) / maSize.getY()));
256 if(nCol % 2)
258 fX += mfOffsetX * maSize.getX();
261 else if(mbUseOffsetY)
263 const sal_Int32 nRow(static_cast< sal_Int32 >((fX < 0.0 ? maSize.getX() -fX : fX) / maSize.getX()));
265 if(nRow % 2)
267 fY += mfOffsetY * maSize.getY();
271 fX = fmod(fX, maSize.getX());
272 fY = fmod(fY, maSize.getY());
274 if(fX < 0.0)
276 fX += maSize.getX();
279 if(fY < 0.0)
281 fY += maSize.getY();
284 return basegfx::B2DPoint(fX + maTopLeft.getX(), fY + maTopLeft.getY());
287 GeoTexSvxBitmapExTiled::GeoTexSvxBitmapExTiled(
288 const BitmapEx& rBitmapEx,
289 const basegfx::B2DRange& rRange,
290 double fOffsetX,
291 double fOffsetY)
292 : GeoTexSvxBitmapEx(rBitmapEx, rRange),
293 mfOffsetX(basegfx::clamp(fOffsetX, 0.0, 1.0)),
294 mfOffsetY(basegfx::clamp(fOffsetY, 0.0, 1.0)),
295 mbUseOffsetX(!basegfx::fTools::equalZero(mfOffsetX)),
296 mbUseOffsetY(!mbUseOffsetX && !basegfx::fTools::equalZero(mfOffsetY))
300 void GeoTexSvxBitmapExTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
302 if(mpReadBitmap)
304 GeoTexSvxBitmapEx::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
308 void GeoTexSvxBitmapExTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
310 if(mpReadBitmap)
312 GeoTexSvxBitmapEx::modifyOpacity(impGetCorrected(rUV), rfOpacity);
315 } // end of namespace texture
316 } // end of namespace drawinglayer
320 namespace drawinglayer
322 namespace texture
324 GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(
325 const primitive3d::HatchTexturePrimitive3D& rPrimitive,
326 double fLogicPixelSize)
327 : mfLogicPixelSize(fLogicPixelSize),
328 mp0(0L),
329 mp1(0L),
330 mp2(0L)
332 const attribute::FillHatchAttribute& rHatch(rPrimitive.getHatch());
333 const basegfx::B2DRange aOutlineRange(0.0, 0.0, rPrimitive.getTextureSize().getX(), rPrimitive.getTextureSize().getY());
334 const double fAngleA(rHatch.getAngle());
335 maColor = rHatch.getColor();
336 mbFillBackground = rHatch.isFillBackground();
337 mp0 = new GeoTexSvxHatch(
338 aOutlineRange,
339 aOutlineRange,
340 rHatch.getDistance(),
341 fAngleA);
343 if(attribute::HATCHSTYLE_DOUBLE == rHatch.getStyle() || attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
345 mp1 = new GeoTexSvxHatch(
346 aOutlineRange,
347 aOutlineRange,
348 rHatch.getDistance(),
349 fAngleA + F_PI2);
352 if(attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
354 mp2 = new GeoTexSvxHatch(
355 aOutlineRange,
356 aOutlineRange,
357 rHatch.getDistance(),
358 fAngleA + F_PI4);
362 GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
364 delete mp0;
365 delete mp1;
366 delete mp2;
369 bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint& rUV) const
371 if(mp0->getDistanceToHatch(rUV) < mfLogicPixelSize)
373 return true;
376 if(mp1 && mp1->getDistanceToHatch(rUV) < mfLogicPixelSize)
378 return true;
381 if(mp2 && mp2->getDistanceToHatch(rUV) < mfLogicPixelSize)
383 return true;
386 return false;
389 void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
391 if(impIsOnHatch(rUV))
393 rBColor = maColor;
395 else if(!mbFillBackground)
397 rfOpacity = 0.0;
401 void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
403 if(mbFillBackground || impIsOnHatch(rUV))
405 rfOpacity = 1.0;
407 else
409 rfOpacity = 0.0;
412 } // end of namespace texture
413 } // end of namespace drawinglayer
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */