Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <drawinglayer/texture/texture3d.hxx>
21 : : #include <vcl/bmpacc.hxx>
22 : : #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
23 : :
24 : : //////////////////////////////////////////////////////////////////////////////
25 : :
26 : : namespace drawinglayer
27 : : {
28 : : namespace texture
29 : : {
30 : 0 : GeoTexSvxMono::GeoTexSvxMono(const basegfx::BColor& rSingleColor, double fOpacity)
31 : : : maSingleColor(rSingleColor),
32 : 0 : mfOpacity(fOpacity)
33 : : {
34 : 0 : }
35 : :
36 : 0 : bool GeoTexSvxMono::operator==(const GeoTexSvx& rGeoTexSvx) const
37 : : {
38 [ # # ]: 0 : const GeoTexSvxMono* pCompare = dynamic_cast< const GeoTexSvxMono* >(&rGeoTexSvx);
39 : : return (pCompare
40 : 0 : && maSingleColor == pCompare->maSingleColor
41 [ # # # # ]: 0 : && mfOpacity == pCompare->mfOpacity);
[ # # ]
42 : : }
43 : :
44 : 0 : void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
45 : : {
46 : 0 : rBColor = maSingleColor;
47 : 0 : }
48 : :
49 : 0 : void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint& /*rUV*/, double& rfOpacity) const
50 : : {
51 : 0 : rfOpacity = mfOpacity;
52 : 0 : }
53 : : } // end of namespace texture
54 : : } // end of namespace drawinglayer
55 : :
56 : : //////////////////////////////////////////////////////////////////////////////
57 : :
58 : : namespace drawinglayer
59 : : {
60 : : namespace texture
61 : : {
62 : 0 : GeoTexSvxBitmap::GeoTexSvxBitmap(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
63 : : : maBitmap(rBitmap),
64 : : mpRead(0L),
65 : : maTopLeft(rTopLeft),
66 : : maSize(rSize),
67 : : mfMulX(0.0),
68 [ # # ]: 0 : mfMulY(0.0)
69 : : {
70 [ # # ]: 0 : mpRead = maBitmap.AcquireReadAccess();
71 : : OSL_ENSURE(mpRead, "GeoTexSvxBitmap: Got no read access to Bitmap (!)");
72 : 0 : mfMulX = (double)mpRead->Width() / maSize.getX();
73 : 0 : mfMulY = (double)mpRead->Height() / maSize.getY();
74 : 0 : }
75 : :
76 [ # # ]: 0 : GeoTexSvxBitmap::~GeoTexSvxBitmap()
77 : : {
78 [ # # ][ # # ]: 0 : delete mpRead;
79 [ # # ]: 0 : }
80 : :
81 : 0 : bool GeoTexSvxBitmap::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
82 : : {
83 [ # # ]: 0 : if(mpRead)
84 : : {
85 : 0 : rX = (sal_Int32)((rUV.getX() - maTopLeft.getX()) * mfMulX);
86 : :
87 [ # # ][ # # ]: 0 : if(rX >= 0L && rX < mpRead->Width())
[ # # ]
88 : : {
89 : 0 : rY = (sal_Int32)((rUV.getY() - maTopLeft.getY()) * mfMulY);
90 : :
91 [ # # ][ # # ]: 0 : return (rY >= 0L && rY < mpRead->Height());
92 : : }
93 : : }
94 : :
95 : 0 : return false;
96 : : }
97 : :
98 : 0 : void GeoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
99 : : {
100 : : sal_Int32 nX, nY;
101 : :
102 [ # # ][ # # ]: 0 : if(impIsValid(rUV, nX, nY))
103 : : {
104 : 0 : const double fConvertColor(1.0 / 255.0);
105 [ # # ]: 0 : const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
106 : : const basegfx::BColor aBSource(
107 : 0 : (double)aBMCol.GetRed() * fConvertColor,
108 : 0 : (double)aBMCol.GetGreen() * fConvertColor,
109 : 0 : (double)aBMCol.GetBlue() * fConvertColor);
110 : :
111 [ # # ]: 0 : rBColor = aBSource;
112 : : }
113 : : else
114 : : {
115 : 0 : rfOpacity = 0.0;
116 : : }
117 : 0 : }
118 : :
119 : 0 : void GeoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
120 : : {
121 : : sal_Int32 nX, nY;
122 : :
123 [ # # ][ # # ]: 0 : if(impIsValid(rUV, nX, nY))
124 : : {
125 [ # # ]: 0 : const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
126 : 0 : const Color aColor(aBMCol.GetRed(), aBMCol.GetGreen(), aBMCol.GetBlue());
127 : :
128 [ # # ]: 0 : rfOpacity = ((double)(0xff - aColor.GetLuminance()) * (1.0 / 255.0));
129 : : }
130 : : else
131 : : {
132 : 0 : rfOpacity = 0.0;
133 : : }
134 : 0 : }
135 : : } // end of namespace texture
136 : : } // end of namespace drawinglayer
137 : :
138 : : //////////////////////////////////////////////////////////////////////////////
139 : :
140 : : namespace drawinglayer
141 : : {
142 : : namespace texture
143 : : {
144 : 0 : GeoTexSvxBitmapTiled::GeoTexSvxBitmapTiled(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
145 : 0 : : GeoTexSvxBitmap(rBitmap, rTopLeft, rSize)
146 : : {
147 : 0 : }
148 : :
149 : 0 : void GeoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
150 : : {
151 [ # # ]: 0 : if(mpRead)
152 : : {
153 [ # # ]: 0 : GeoTexSvxBitmap::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
154 : : }
155 : 0 : }
156 : :
157 : 0 : void GeoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
158 : : {
159 [ # # ]: 0 : if(mpRead)
160 : : {
161 [ # # ]: 0 : GeoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV), rfOpacity);
162 : : }
163 : 0 : }
164 : : } // end of namespace texture
165 : : } // end of namespace drawinglayer
166 : :
167 : : //////////////////////////////////////////////////////////////////////////////
168 : :
169 : : namespace drawinglayer
170 : : {
171 : : namespace texture
172 : : {
173 : 8 : GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(const primitive3d::HatchTexturePrimitive3D& rPrimitive, double fLogicPixelSize)
174 : : : mfLogicPixelSize(fLogicPixelSize),
175 : : mp0(0L),
176 : : mp1(0L),
177 : 8 : mp2(0L)
178 : : {
179 : 8 : const attribute::FillHatchAttribute& rHatch(rPrimitive.getHatch());
180 [ + - ]: 8 : const basegfx::B2DRange aOutlineRange(0.0, 0.0, rPrimitive.getTextureSize().getX(), rPrimitive.getTextureSize().getY());
181 [ + - ]: 8 : const double fAngleA(rHatch.getAngle());
182 [ + - ][ + - ]: 8 : maColor = rHatch.getColor();
183 [ + - ]: 8 : mbFillBackground = rHatch.isFillBackground();
184 [ + - ][ + - ]: 8 : mp0 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA);
[ + - ]
185 : :
186 [ + - ][ + - ]: 8 : if(attribute::HATCHSTYLE_DOUBLE == rHatch.getStyle() || attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
[ + - ][ - + ]
[ - + ]
187 : : {
188 [ # # ][ # # ]: 0 : mp1 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI2);
[ # # ]
189 : : }
190 : :
191 [ + - ][ - + ]: 8 : if(attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
192 : : {
193 [ # # ][ # # ]: 0 : mp2 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI4);
[ # # ]
194 : : }
195 : 8 : }
196 : :
197 : 8 : GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
198 : : {
199 [ + - ][ + - ]: 8 : delete mp0;
200 [ - + ][ # # ]: 8 : delete mp1;
201 [ - + ][ # # ]: 8 : delete mp2;
202 [ - + ]: 16 : }
203 : :
204 : 47800 : bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint& rUV) const
205 : : {
206 [ + - ]: 47800 : if(mp0->getDistanceToHatch(rUV) < mfLogicPixelSize)
207 : : {
208 : 47800 : return true;
209 : : }
210 : :
211 [ # # ][ # # ]: 0 : if(mp1 && mp1->getDistanceToHatch(rUV) < mfLogicPixelSize)
[ # # ]
212 : : {
213 : 0 : return true;
214 : : }
215 : :
216 [ # # ][ # # ]: 0 : if(mp2 && mp2->getDistanceToHatch(rUV) < mfLogicPixelSize)
[ # # ]
217 : : {
218 : 0 : return true;
219 : : }
220 : :
221 : 47800 : return false;
222 : : }
223 : :
224 : 47800 : void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
225 : : {
226 [ + - ]: 47800 : if(impIsOnHatch(rUV))
227 : : {
228 : 47800 : rBColor = maColor;
229 : : }
230 [ # # ]: 0 : else if(!mbFillBackground)
231 : : {
232 : 0 : rfOpacity = 0.0;
233 : : }
234 : 47800 : }
235 : :
236 : 0 : void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
237 : : {
238 [ # # ][ # # ]: 0 : if(mbFillBackground || impIsOnHatch(rUV))
[ # # ]
239 : : {
240 : 0 : rfOpacity = 1.0;
241 : : }
242 : : else
243 : : {
244 : 0 : rfOpacity = 0.0;
245 : : }
246 : 0 : }
247 : : } // end of namespace texture
248 : : } // end of namespace drawinglayer
249 : :
250 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|