Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
30 : : #include <basegfx/polygon/b3dpolygon.hxx>
31 : : #include <drawinglayer/attribute/strokeattribute.hxx>
32 : : #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
33 : : #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
34 : : #include <basegfx/polygon/b3dpolypolygon.hxx>
35 : : #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
36 : : #include <vcl/vclenum.hxx>
37 : : #include <drawinglayer/attribute/fillbitmapattribute.hxx>
38 : : #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
39 : : #include <vcl/bmpacc.hxx>
40 : : #include <basegfx/polygon/b3dpolypolygontools.hxx>
41 : : #include <drawinglayer/primitive3d/textureprimitive3d.hxx>
42 : : #include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx>
43 : : #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
44 : : #include <drawinglayer/primitive3d/shadowprimitive3d.hxx>
45 : : #include <basegfx/range/b2drange.hxx>
46 : : #include <drawinglayer/attribute/sdrlineattribute.hxx>
47 : : #include <drawinglayer/attribute/sdrobjectattribute3d.hxx>
48 : : #include <drawinglayer/attribute/sdrfillattribute.hxx>
49 : : #include <drawinglayer/attribute/sdrshadowattribute.hxx>
50 : : #include <drawinglayer/primitive3d/hiddengeometryprimitive3d.hxx>
51 : :
52 : : //////////////////////////////////////////////////////////////////////////////
53 : :
54 : : namespace drawinglayer
55 : : {
56 : : namespace primitive3d
57 : : {
58 : 303 : basegfx::B3DRange getRangeFrom3DGeometry(::std::vector< basegfx::B3DPolyPolygon >& rFill)
59 : : {
60 : 303 : basegfx::B3DRange aRetval;
61 : :
62 [ + + ]: 726 : for(sal_uInt32 a(0); a < rFill.size(); a++)
63 : : {
64 [ + - ]: 423 : aRetval.expand(basegfx::tools::getRange(rFill[a]));
65 : : }
66 : :
67 : 303 : return aRetval;
68 : : }
69 : :
70 : 0 : void applyNormalsKindSphereTo3DGeometry(::std::vector< basegfx::B3DPolyPolygon >& rFill, const basegfx::B3DRange& rRange)
71 : : {
72 : : // create sphere normals
73 [ # # ]: 0 : const basegfx::B3DPoint aCenter(rRange.getCenter());
74 : :
75 [ # # ]: 0 : for(sal_uInt32 a(0); a < rFill.size(); a++)
76 : : {
77 [ # # ][ # # ]: 0 : rFill[a] = basegfx::tools::applyDefaultNormalsSphere(rFill[a], aCenter);
[ # # ][ # # ]
[ # # ]
78 : 0 : }
79 : 0 : }
80 : :
81 : 265 : void applyNormalsKindFlatTo3DGeometry(::std::vector< basegfx::B3DPolyPolygon >& rFill)
82 : : {
83 [ + + ]: 530 : for(sal_uInt32 a(0); a < rFill.size(); a++)
84 : : {
85 : 265 : rFill[a].clearNormals();
86 : : }
87 : 265 : }
88 : :
89 : 0 : void applyNormalsInvertTo3DGeometry(::std::vector< basegfx::B3DPolyPolygon >& rFill)
90 : : {
91 : : // invert normals
92 [ # # ]: 0 : for(sal_uInt32 a(0); a < rFill.size(); a++)
93 : : {
94 [ # # ][ # # ]: 0 : rFill[a] = basegfx::tools::invertNormals(rFill[a]);
95 : : }
96 : 0 : }
97 : :
98 : 289 : void applyTextureTo3DGeometry(
99 : : ::com::sun::star::drawing::TextureProjectionMode eModeX,
100 : : ::com::sun::star::drawing::TextureProjectionMode eModeY,
101 : : ::std::vector< basegfx::B3DPolyPolygon >& rFill,
102 : : const basegfx::B3DRange& rRange,
103 : : const basegfx::B2DVector& rTextureSize)
104 : : {
105 : : sal_uInt32 a;
106 : :
107 : : // handle texture coordinates X
108 : 289 : const bool bParallelX(::com::sun::star::drawing::TextureProjectionMode_PARALLEL == eModeX);
109 [ + + ][ - + ]: 289 : const bool bSphereX(!bParallelX && (::com::sun::star::drawing::TextureProjectionMode_SPHERE == eModeX));
110 : :
111 : : // handle texture coordinates Y
112 : 289 : const bool bParallelY(::com::sun::star::drawing::TextureProjectionMode_PARALLEL == eModeY);
113 [ + + ][ - + ]: 289 : const bool bSphereY(!bParallelY && (::com::sun::star::drawing::TextureProjectionMode_SPHERE == eModeY));
114 : :
115 [ + + ][ - + ]: 289 : if(bParallelX || bParallelY)
116 : : {
117 : : // apply parallel texture coordinates in X and/or Y
118 [ + + ]: 168 : for(a = 0; a < rFill.size(); a++)
119 : : {
120 [ + - ][ + - ]: 144 : rFill[a] = basegfx::tools::applyDefaultTextureCoordinatesParallel(rFill[a], rRange, bParallelX, bParallelY);
[ + - ][ + - ]
[ + - ]
121 : : }
122 : : }
123 : :
124 [ + - ][ - + ]: 289 : if(bSphereX || bSphereY)
125 : : {
126 : : // apply spherical texture coordinates in X and/or Y
127 [ # # ]: 0 : const basegfx::B3DPoint aCenter(rRange.getCenter());
128 : :
129 [ # # ]: 0 : for(a = 0; a < rFill.size(); a++)
130 : : {
131 [ # # ][ # # ]: 0 : rFill[a] = basegfx::tools::applyDefaultTextureCoordinatesSphere(rFill[a], aCenter, bSphereX, bSphereY);
[ # # ][ # # ]
[ # # ]
132 : 0 : }
133 : : }
134 : :
135 : : // transform texture coordinates to texture size
136 [ + - ]: 289 : basegfx::B2DHomMatrix aTexMatrix;
137 [ + - ]: 289 : aTexMatrix.scale(rTextureSize.getX(), rTextureSize.getY());
138 : :
139 [ + + ]: 698 : for(a = 0; a < rFill.size(); a++)
140 : : {
141 [ + - ][ + - ]: 409 : rFill[a].transformTextureCoordiantes(aTexMatrix);
142 [ + - ]: 289 : }
143 : 289 : }
144 : :
145 : 18 : Primitive3DSequence create3DPolyPolygonLinePrimitives(
146 : : const basegfx::B3DPolyPolygon& rUnitPolyPolygon,
147 : : const basegfx::B3DHomMatrix& rObjectTransform,
148 : : const attribute::SdrLineAttribute& rLine)
149 : : {
150 : : // prepare fully scaled polyPolygon
151 [ + - ]: 18 : basegfx::B3DPolyPolygon aScaledPolyPolygon(rUnitPolyPolygon);
152 [ + - ]: 18 : aScaledPolyPolygon.transform(rObjectTransform);
153 : :
154 : : // create line and stroke attribute
155 [ + - ][ + - ]: 18 : const attribute::LineAttribute aLineAttribute(rLine.getColor(), rLine.getWidth(), rLine.getJoin());
[ + - ][ + - ]
156 [ + - ][ + - ]: 18 : const attribute::StrokeAttribute aStrokeAttribute(rLine.getDotDashArray(), rLine.getFullDotDashLen());
[ + - ]
157 : :
158 : : // create primitives
159 [ + - ][ + - ]: 18 : Primitive3DSequence aRetval(aScaledPolyPolygon.count());
160 : :
161 [ + - ][ + + ]: 36 : for(sal_uInt32 a(0L); a < aScaledPolyPolygon.count(); a++)
162 : : {
163 [ + - ][ + - ]: 18 : const Primitive3DReference xRef(new PolygonStrokePrimitive3D(aScaledPolyPolygon.getB3DPolygon(a), aLineAttribute, aStrokeAttribute));
[ + - ][ + - ]
[ + - ]
164 [ + - ][ + - ]: 18 : aRetval[a] = xRef;
165 : 18 : }
166 : :
167 [ + - ][ - + ]: 18 : if(0.0 != rLine.getTransparence())
168 : : {
169 : : // create UnifiedTransparenceTexturePrimitive3D, add created primitives and exchange
170 [ # # ][ # # ]: 0 : const Primitive3DReference xRef(new UnifiedTransparenceTexturePrimitive3D(rLine.getTransparence(), aRetval));
[ # # ][ # # ]
171 [ # # ][ # # ]: 0 : aRetval = Primitive3DSequence(&xRef, 1L);
[ # # ]
172 : : }
173 : :
174 [ + - ][ + - ]: 18 : return aRetval;
[ + - ]
175 : : }
176 : :
177 : 303 : Primitive3DSequence create3DPolyPolygonFillPrimitives(
178 : : const ::std::vector< basegfx::B3DPolyPolygon >& r3DPolyPolygonVector,
179 : : const basegfx::B3DHomMatrix& rObjectTransform,
180 : : const basegfx::B2DVector& rTextureSize,
181 : : const attribute::Sdr3DObjectAttribute& aSdr3DObjectAttribute,
182 : : const attribute::SdrFillAttribute& rFill,
183 : : const attribute::FillGradientAttribute& rFillGradient)
184 : : {
185 : 303 : Primitive3DSequence aRetval;
186 : :
187 [ + - ]: 303 : if(r3DPolyPolygonVector.size())
188 : : {
189 : : // create list of simple fill primitives
190 [ + - ]: 303 : aRetval.realloc(r3DPolyPolygonVector.size());
191 : :
192 [ + + ]: 726 : for(sal_uInt32 a(0L); a < r3DPolyPolygonVector.size(); a++)
193 : : {
194 : : // get scaled PolyPolygon
195 [ + - ][ + - ]: 423 : basegfx::B3DPolyPolygon aScaledPolyPolygon(r3DPolyPolygonVector[a]);
196 [ + - ]: 423 : aScaledPolyPolygon.transform(rObjectTransform);
197 : :
198 [ + - ][ + + ]: 423 : if(aScaledPolyPolygon.areNormalsUsed())
199 : : {
200 [ + - ]: 158 : aScaledPolyPolygon.transformNormals(rObjectTransform);
201 : : }
202 : :
203 : : const Primitive3DReference xRef(new PolyPolygonMaterialPrimitive3D(
204 : : aScaledPolyPolygon,
205 : : aSdr3DObjectAttribute.getMaterial(),
206 [ + - ][ + - ]: 423 : aSdr3DObjectAttribute.getDoubleSided()));
[ + - ][ + - ]
[ + - ]
207 [ + - ][ + - ]: 423 : aRetval[a] = xRef;
208 [ + - ]: 423 : }
209 : :
210 : : // look for and evtl. build texture sub-group primitive
211 [ + - ][ + - ]: 901 : if(!rFill.getGradient().isDefault()
[ + - ][ + + ]
[ - + ][ + + ]
212 [ + - ][ + - ]: 303 : || !rFill.getHatch().isDefault()
213 [ + - ][ + - ]: 295 : || !rFill.getBitmap().isDefault())
214 : : {
215 [ + - ]: 8 : bool bModulate(::com::sun::star::drawing::TextureMode_MODULATE == aSdr3DObjectAttribute.getTextureMode());
216 [ + - ]: 8 : bool bFilter(aSdr3DObjectAttribute.getTextureFilter());
217 : 8 : BasePrimitive3D* pNewTexturePrimitive3D = 0;
218 : :
219 [ + - ][ + - ]: 8 : if(!rFill.getGradient().isDefault())
[ - + ]
220 : : {
221 : : // create gradientTexture3D with sublist, add to local aRetval
222 : : pNewTexturePrimitive3D = new GradientTexturePrimitive3D(
223 : : rFill.getGradient(),
224 : : aRetval,
225 : : rTextureSize,
226 : : bModulate,
227 [ # # ][ # # ]: 0 : bFilter);
228 : : }
229 [ + - ][ + - ]: 8 : else if(!rFill.getHatch().isDefault())
[ + - ]
230 : : {
231 : : // create hatchTexture3D with sublist, add to local aRetval
232 : : pNewTexturePrimitive3D = new HatchTexturePrimitive3D(
233 : : rFill.getHatch(),
234 : : aRetval,
235 : : rTextureSize,
236 : : bModulate,
237 [ + - ][ + - ]: 8 : bFilter);
238 : : }
239 : : else // if(!rFill.getBitmap().isDefault())
240 : : {
241 : : // create bitmapTexture3D with sublist, add to local aRetval
242 [ # # ]: 0 : basegfx::B2DRange aTexRange(0.0, 0.0, rTextureSize.getX(), rTextureSize.getY());
243 : :
244 : : pNewTexturePrimitive3D = new BitmapTexturePrimitive3D(
245 [ # # ]: 0 : rFill.getBitmap().getFillBitmapAttribute(aTexRange),
246 : : aRetval,
247 : : rTextureSize,
248 : : bModulate,
249 [ # # ][ # # ]: 0 : bFilter);
[ # # ]
250 : : }
251 : :
252 : : // exchange aRetval content with texture group
253 [ + - ][ + - ]: 8 : const Primitive3DReference xRef(pNewTexturePrimitive3D);
254 [ + - ][ + - ]: 8 : aRetval = Primitive3DSequence(&xRef, 1L);
[ + - ]
255 : :
256 [ + - ][ - + ]: 8 : if(::com::sun::star::drawing::TextureKind2_LUMINANCE == aSdr3DObjectAttribute.getTextureKind())
257 : : {
258 : : // use modified color primitive to force textures to gray
259 : 0 : const basegfx::BColorModifier aBColorModifier(basegfx::BColor(), 0.0, basegfx::BCOLORMODIFYMODE_GRAY);
260 [ # # ][ # # ]: 0 : const Primitive3DReference xRef2(new ModifiedColorPrimitive3D(aRetval, aBColorModifier));
[ # # ]
261 [ # # ][ # # ]: 0 : aRetval = Primitive3DSequence(&xRef2, 1L);
[ # # ][ # # ]
262 : 8 : }
263 : : }
264 : :
265 [ + - ][ - + ]: 303 : if(0.0 != rFill.getTransparence())
266 : : {
267 : : // create UnifiedTransparenceTexturePrimitive3D with sublist and exchange
268 [ # # ][ # # ]: 0 : const Primitive3DReference xRef(new UnifiedTransparenceTexturePrimitive3D(rFill.getTransparence(), aRetval));
[ # # ][ # # ]
269 [ # # ][ # # ]: 0 : aRetval = Primitive3DSequence(&xRef, 1L);
[ # # ]
270 : : }
271 [ + - ][ + + ]: 303 : else if(!rFillGradient.isDefault())
272 : : {
273 : : // create TransparenceTexturePrimitive3D with sublist and exchange
274 [ + - ][ + - ]: 16 : const Primitive3DReference xRef(new TransparenceTexturePrimitive3D(rFillGradient, aRetval, rTextureSize));
[ + - ]
275 [ + - ][ + - ]: 16 : aRetval = Primitive3DSequence(&xRef, 1L);
[ + - ]
276 : : }
277 : : }
278 : :
279 : 303 : return aRetval;
280 : : }
281 : :
282 : 0 : Primitive3DSequence createShadowPrimitive3D(
283 : : const Primitive3DSequence& rSource,
284 : : const attribute::SdrShadowAttribute& rShadow,
285 : : bool bShadow3D)
286 : : {
287 : : // create Shadow primitives. Uses already created primitives
288 [ # # ][ # # ]: 0 : if(rSource.hasElements() && !basegfx::fTools::moreOrEqual(rShadow.getTransparence(), 1.0))
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
289 : : {
290 : : // prepare new list for shadow geometry
291 [ # # ]: 0 : basegfx::B2DHomMatrix aShadowOffset;
292 [ # # ][ # # ]: 0 : aShadowOffset.set(0, 2, rShadow.getOffset().getX());
293 [ # # ][ # # ]: 0 : aShadowOffset.set(1, 2, rShadow.getOffset().getY());
294 : :
295 : : // create shadow primitive and add primitives
296 [ # # ][ # # ]: 0 : const Primitive3DReference xRef(new ShadowPrimitive3D(aShadowOffset, rShadow.getColor(), rShadow.getTransparence(), bShadow3D, rSource));
[ # # ][ # # ]
[ # # ]
297 [ # # ][ # # ]: 0 : return Primitive3DSequence(&xRef, 1L);
298 : : }
299 : : else
300 : : {
301 : 0 : return Primitive3DSequence();
302 : : }
303 : : }
304 : :
305 : 14 : Primitive3DSequence createHiddenGeometryPrimitives3D(
306 : : const ::std::vector< basegfx::B3DPolyPolygon >& r3DPolyPolygonVector,
307 : : const basegfx::B3DHomMatrix& rObjectTransform,
308 : : const basegfx::B2DVector& rTextureSize,
309 : : const attribute::Sdr3DObjectAttribute& aSdr3DObjectAttribute)
310 : : {
311 : : // create hidden sub-geometry which can be used for HitTest
312 : : // and BoundRect calculations, but will not be visualized
313 : : const attribute::SdrFillAttribute aSimplifiedFillAttribute(
314 : : 0.0,
315 : : basegfx::BColor(),
316 : : attribute::FillGradientAttribute(),
317 : : attribute::FillHatchAttribute(),
318 [ + - ][ + - ]: 14 : attribute::SdrFillBitmapAttribute());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
319 : :
320 : : const Primitive3DReference aHidden(
321 : : new HiddenGeometryPrimitive3D(
322 : : create3DPolyPolygonFillPrimitives(
323 : : r3DPolyPolygonVector,
324 : : rObjectTransform,
325 : : rTextureSize,
326 : : aSdr3DObjectAttribute,
327 : : aSimplifiedFillAttribute,
328 [ + - ][ + - ]: 14 : attribute::FillGradientAttribute())));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
329 : :
330 [ + - ][ + - ]: 14 : return Primitive3DSequence(&aHidden, 1);
331 : : }
332 : :
333 : : } // end of namespace primitive3d
334 : : } // end of namespace drawinglayer
335 : :
336 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|