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/texture/texture3d.hxx>
21 #include <vcl/bmpacc.hxx>
22 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
24 //////////////////////////////////////////////////////////////////////////////
26 namespace drawinglayer
30 GeoTexSvxMono::GeoTexSvxMono(const basegfx::BColor
& rSingleColor
, double fOpacity
)
31 : maSingleColor(rSingleColor
),
36 bool GeoTexSvxMono::operator==(const GeoTexSvx
& rGeoTexSvx
) const
38 const GeoTexSvxMono
* pCompare
= dynamic_cast< const GeoTexSvxMono
* >(&rGeoTexSvx
);
40 && maSingleColor
== pCompare
->maSingleColor
41 && mfOpacity
== pCompare
->mfOpacity
);
44 void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint
& /*rUV*/, basegfx::BColor
& rBColor
, double& /*rfOpacity*/) const
46 rBColor
= maSingleColor
;
49 void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint
& /*rUV*/, double& rfOpacity
) const
51 rfOpacity
= mfOpacity
;
53 } // end of namespace texture
54 } // end of namespace drawinglayer
56 //////////////////////////////////////////////////////////////////////////////
58 namespace drawinglayer
62 GeoTexSvxBitmap::GeoTexSvxBitmap(const Bitmap
& rBitmap
, const basegfx::B2DPoint
& rTopLeft
, const basegfx::B2DVector
& rSize
)
70 mpRead
= maBitmap
.AcquireReadAccess();
71 OSL_ENSURE(mpRead
, "GeoTexSvxBitmap: Got no read access to Bitmap (!)");
72 mfMulX
= (double)mpRead
->Width() / maSize
.getX();
73 mfMulY
= (double)mpRead
->Height() / maSize
.getY();
76 GeoTexSvxBitmap::~GeoTexSvxBitmap()
81 bool GeoTexSvxBitmap::impIsValid(const basegfx::B2DPoint
& rUV
, sal_Int32
& rX
, sal_Int32
& rY
) const
85 rX
= (sal_Int32
)((rUV
.getX() - maTopLeft
.getX()) * mfMulX
);
87 if(rX
>= 0L && rX
< mpRead
->Width())
89 rY
= (sal_Int32
)((rUV
.getY() - maTopLeft
.getY()) * mfMulY
);
91 return (rY
>= 0L && rY
< mpRead
->Height());
98 void GeoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
102 if(impIsValid(rUV
, nX
, nY
))
104 const double fConvertColor(1.0 / 255.0);
105 const BitmapColor
aBMCol(mpRead
->GetColor(nY
, nX
));
106 const basegfx::BColor
aBSource(
107 (double)aBMCol
.GetRed() * fConvertColor
,
108 (double)aBMCol
.GetGreen() * fConvertColor
,
109 (double)aBMCol
.GetBlue() * fConvertColor
);
119 void GeoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
123 if(impIsValid(rUV
, nX
, nY
))
125 const BitmapColor
aBMCol(mpRead
->GetColor(nY
, nX
));
126 const Color
aColor(aBMCol
.GetRed(), aBMCol
.GetGreen(), aBMCol
.GetBlue());
128 rfOpacity
= ((double)(0xff - aColor
.GetLuminance()) * (1.0 / 255.0));
135 } // end of namespace texture
136 } // end of namespace drawinglayer
138 //////////////////////////////////////////////////////////////////////////////
140 namespace drawinglayer
144 GeoTexSvxBitmapTiled::GeoTexSvxBitmapTiled(const Bitmap
& rBitmap
, const basegfx::B2DPoint
& rTopLeft
, const basegfx::B2DVector
& rSize
)
145 : GeoTexSvxBitmap(rBitmap
, rTopLeft
, rSize
)
149 void GeoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
153 GeoTexSvxBitmap::modifyBColor(impGetCorrected(rUV
), rBColor
, rfOpacity
);
157 void GeoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
161 GeoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV
), rfOpacity
);
164 } // end of namespace texture
165 } // end of namespace drawinglayer
167 //////////////////////////////////////////////////////////////////////////////
169 namespace drawinglayer
173 GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(const primitive3d::HatchTexturePrimitive3D
& rPrimitive
, double fLogicPixelSize
)
174 : mfLogicPixelSize(fLogicPixelSize
),
179 const attribute::FillHatchAttribute
& rHatch(rPrimitive
.getHatch());
180 const basegfx::B2DRange
aOutlineRange(0.0, 0.0, rPrimitive
.getTextureSize().getX(), rPrimitive
.getTextureSize().getY());
181 const double fAngleA(rHatch
.getAngle());
182 maColor
= rHatch
.getColor();
183 mbFillBackground
= rHatch
.isFillBackground();
184 mp0
= new GeoTexSvxHatch(aOutlineRange
, rHatch
.getDistance(), fAngleA
);
186 if(attribute::HATCHSTYLE_DOUBLE
== rHatch
.getStyle() || attribute::HATCHSTYLE_TRIPLE
== rHatch
.getStyle())
188 mp1
= new GeoTexSvxHatch(aOutlineRange
, rHatch
.getDistance(), fAngleA
+ F_PI2
);
191 if(attribute::HATCHSTYLE_TRIPLE
== rHatch
.getStyle())
193 mp2
= new GeoTexSvxHatch(aOutlineRange
, rHatch
.getDistance(), fAngleA
+ F_PI4
);
197 GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
204 bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint
& rUV
) const
206 if(mp0
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
211 if(mp1
&& mp1
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
216 if(mp2
&& mp2
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
224 void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
226 if(impIsOnHatch(rUV
))
230 else if(!mbFillBackground
)
236 void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
238 if(mbFillBackground
|| impIsOnHatch(rUV
))
247 } // end of namespace texture
248 } // end of namespace drawinglayer
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */