1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_drawinglayer.hxx"
26 
27 #include <drawinglayer/processor2d/vclprocessor2d.hxx>
28 #include <drawinglayer/primitive2d/textprimitive2d.hxx>
29 #include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
30 #include <tools/debug.hxx>
31 #include <vcl/outdev.hxx>
32 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
33 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
34 #include <vclhelperbitmaptransform.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <vclhelperbitmaprender.hxx>
37 #include <drawinglayer/attribute/sdrfillgraphicattribute.hxx>
38 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
39 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
40 #include <vclhelpergradient.hxx>
41 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
42 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
43 #include <basegfx/polygon/b2dpolypolygontools.hxx>
44 #include <vclhelperbufferdevice.hxx>
45 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
46 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
47 #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
48 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
49 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
50 #include <drawinglayer/primitive2d/pointarrayprimitive2d.hxx>
51 #include <drawinglayer/primitive2d/wrongspellprimitive2d.hxx>
52 #include <svl/ctloptions.hxx>
53 #include <vcl/svapp.hxx>
54 #include <drawinglayer/primitive2d/pagepreviewprimitive2d.hxx>
55 #include <tools/diagnose_ex.h>
56 #include <vcl/metric.hxx>
57 #include <drawinglayer/primitive2d/textenumsprimitive2d.hxx>
58 #include <drawinglayer/primitive2d/epsprimitive2d.hxx>
59 #include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
60 #include <basegfx/color/bcolor.hxx>
61 #include <basegfx/matrix/b2dhommatrixtools.hxx>
62 #include <vcl/graph.hxx>
63 
64 //////////////////////////////////////////////////////////////////////////////
65 // control support
66 
67 #include <com/sun/star/awt/XWindow2.hpp>
68 #include <com/sun/star/awt/PosSize.hpp>
69 #include <com/sun/star/awt/XView.hpp>
70 #include <drawinglayer/primitive2d/controlprimitive2d.hxx>
71 #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
72 
73 //////////////////////////////////////////////////////////////////////////////
74 // for test, can be removed again
75 
76 #include <basegfx/polygon/b2dpolygonclipper.hxx>
77 #include <basegfx/polygon/b2dtrapezoid.hxx>
78 
79 //////////////////////////////////////////////////////////////////////////////
80 
81 using namespace com::sun::star;
82 
83 //////////////////////////////////////////////////////////////////////////////
84 
85 namespace
86 {
87     sal_uInt32 calculateStepsForSvgGradient(const basegfx::BColor& rColorA, const basegfx::BColor& rColorB, double fDelta, double fDiscreteUnit)
88     {
89         // use color distance, assume to do every color step
90         sal_uInt32 nSteps(basegfx::fround(rColorA.getDistance(rColorB) * 255.0));
91 
92         if(nSteps)
93         {
94             // calc discrete length to change color each disctete unit (pixel)
95             const sal_uInt32 nDistSteps(basegfx::fround(fDelta / fDiscreteUnit));
96 
97             nSteps = std::min(nSteps, nDistSteps);
98         }
99 
100         // reduce quality to 3 discrete units or every 3rd color step for rendering
101         nSteps /= 2;
102 
103         // roughly cut when too big or too small (not full quality, reduce complexity)
104         nSteps = std::min(nSteps, sal_uInt32(255));
105         nSteps = std::max(nSteps, sal_uInt32(1));
106 
107         return nSteps;
108     }
109 } // end of anonymous namespace
110 
111 //////////////////////////////////////////////////////////////////////////////
112 
113 namespace drawinglayer
114 {
115 	namespace processor2d
116 	{
117 		//////////////////////////////////////////////////////////////////////////////
118 		// UNO class usages
119 		using ::com::sun::star::uno::Reference;
120 		using ::com::sun::star::uno::UNO_QUERY;
121 	    using ::com::sun::star::uno::UNO_QUERY_THROW;
122         using ::com::sun::star::uno::Exception;
123 		using ::com::sun::star::awt::XView;
124 		using ::com::sun::star::awt::XGraphics;
125 	    using ::com::sun::star::awt::XWindow;
126 	    using ::com::sun::star::awt::PosSize::POSSIZE;
127 
128 		//////////////////////////////////////////////////////////////////////////////
129 		// rendering support
130 
131 		// directdraw of text simple portion or decorated portion primitive. When decorated, all the extra
132 		// information is translated to VCL parameters and set at the font.
133 		// Acceptance is restricted to no shearing and positive scaling in X and Y (no font mirroring
134 		// for VCL)
135 		void VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D(const primitive2d::TextSimplePortionPrimitive2D& rTextCandidate)
136 		{
137             // decompose matrix to have position and size of text
138 			basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rTextCandidate.getTextTransform());
139 			basegfx::B2DVector aFontScaling, aTranslate;
140 			double fRotate, fShearX;
141 			aLocalTransform.decompose(aFontScaling, aTranslate, fRotate, fShearX);
142 			bool bPrimitiveAccepted(false);
143 
144 			if(basegfx::fTools::equalZero(fShearX))
145 			{
146 				if(basegfx::fTools::less(aFontScaling.getX(), 0.0) && basegfx::fTools::less(aFontScaling.getY(), 0.0))
147 				{
148 					// handle special case: If scale is negative in (x,y) (3rd quadrant), it can
149 					// be expressed as rotation by PI. Use this since the Font rendering will not
150                     // apply the negative scales in any form
151 					aFontScaling = basegfx::absolute(aFontScaling);
152 					fRotate += F_PI;
153 				}
154 
155 				if(basegfx::fTools::more(aFontScaling.getX(), 0.0) && basegfx::fTools::more(aFontScaling.getY(), 0.0))
156 				{
157                     // Get the VCL font (use FontHeight as FontWidth)
158                     Font aFont(primitive2d::getVclFontFromFontAttribute(
159                         rTextCandidate.getFontAttribute(),
160                         aFontScaling.getX(),
161                         aFontScaling.getY(),
162                         fRotate,
163                         rTextCandidate.getLocale()));
164 
165 					// handle additional font attributes
166 					const primitive2d::TextDecoratedPortionPrimitive2D* pTCPP =
167 						dynamic_cast<const primitive2d::TextDecoratedPortionPrimitive2D*>( &rTextCandidate );
168 
169 					if( pTCPP != NULL )
170 					{
171 
172                         // set the color of text decorations
173                         const basegfx::BColor aTextlineColor = maBColorModifierStack.getModifiedColor(pTCPP->getTextlineColor());
174                         mpOutputDevice->SetTextLineColor( Color(aTextlineColor) );
175 
176                         // set Overline attribute
177                         const FontUnderline eFontOverline(primitive2d::mapTextLineToFontUnderline( pTCPP->getFontOverline() ));
178                         if( eFontOverline != UNDERLINE_NONE )
179                         {
180                             aFont.SetOverline( eFontOverline );
181                             const basegfx::BColor aOverlineColor = maBColorModifierStack.getModifiedColor(pTCPP->getOverlineColor());
182                             mpOutputDevice->SetOverlineColor( Color(aOverlineColor) );
183                             if( pTCPP->getWordLineMode() )
184                                 aFont.SetWordLineMode( true );
185                         }
186 
187                         // set Underline attribute
188                         const FontUnderline eFontUnderline(primitive2d::mapTextLineToFontUnderline( pTCPP->getFontUnderline() ));
189                         if( eFontUnderline != UNDERLINE_NONE )
190 						{
191 							aFont.SetUnderline( eFontUnderline );
192 							if( pTCPP->getWordLineMode() )
193 								aFont.SetWordLineMode( true );
194 //TODO: ???					if( pTCPP->getUnderlineAbove() )
195 //								aFont.SetUnderlineAbove( true );
196 						}
197 
198 						// set Strikeout attribute
199 						const FontStrikeout eFontStrikeout(primitive2d::mapTextStrikeoutToFontStrikeout(pTCPP->getTextStrikeout()));
200 
201 						if( eFontStrikeout != STRIKEOUT_NONE )
202 							aFont.SetStrikeout( eFontStrikeout );
203 
204 						// set EmphasisMark attribute
205 						FontEmphasisMark eFontEmphasisMark = EMPHASISMARK_NONE;
206 						switch( pTCPP->getTextEmphasisMark() )
207 						{
208 							default:
209 								DBG_WARNING1( "DrawingLayer: Unknown EmphasisMark style (%d)!", pTCPP->getTextEmphasisMark() );
210 								// fall through
211 							case primitive2d::TEXT_EMPHASISMARK_NONE:	eFontEmphasisMark = EMPHASISMARK_NONE; break;
212 							case primitive2d::TEXT_EMPHASISMARK_DOT:	eFontEmphasisMark = EMPHASISMARK_DOT; break;
213 							case primitive2d::TEXT_EMPHASISMARK_CIRCLE:	eFontEmphasisMark = EMPHASISMARK_CIRCLE; break;
214 							case primitive2d::TEXT_EMPHASISMARK_DISC:	eFontEmphasisMark = EMPHASISMARK_DISC; break;
215 							case primitive2d::TEXT_EMPHASISMARK_ACCENT:	eFontEmphasisMark = EMPHASISMARK_ACCENT; break;
216 						}
217 
218 						if( eFontEmphasisMark != EMPHASISMARK_NONE )
219 						{
220 							DBG_ASSERT( (pTCPP->getEmphasisMarkAbove() != pTCPP->getEmphasisMarkBelow()),
221 								"DrawingLayer: Bad EmphasisMark position!" );
222 							if( pTCPP->getEmphasisMarkAbove() )
223 								eFontEmphasisMark |= EMPHASISMARK_POS_ABOVE;
224 							else
225 								eFontEmphasisMark |= EMPHASISMARK_POS_BELOW;
226 							aFont.SetEmphasisMark( eFontEmphasisMark );
227 						}
228 
229 						// set Relief attribute
230 						FontRelief eFontRelief = RELIEF_NONE;
231 						switch( pTCPP->getTextRelief() )
232 						{
233 							default:
234 								DBG_WARNING1( "DrawingLayer: Unknown Relief style (%d)!", pTCPP->getTextRelief() );
235 								// fall through
236 							case primitive2d::TEXT_RELIEF_NONE:		eFontRelief = RELIEF_NONE; break;
237 							case primitive2d::TEXT_RELIEF_EMBOSSED:	eFontRelief = RELIEF_EMBOSSED; break;
238 							case primitive2d::TEXT_RELIEF_ENGRAVED:	eFontRelief = RELIEF_ENGRAVED; break;
239 						}
240 
241 						if( eFontRelief != RELIEF_NONE )
242 							aFont.SetRelief( eFontRelief );
243 
244 						// set Shadow attribute
245 						if( pTCPP->getShadow() )
246 							aFont.SetShadow( true );
247 					}
248 
249 					// create transformed integer DXArray in view coordinate system
250 					::std::vector< sal_Int32 > aTransformedDXArray;
251 
252 					if(rTextCandidate.getDXArray().size())
253 					{
254 						aTransformedDXArray.reserve(rTextCandidate.getDXArray().size());
255 						const basegfx::B2DVector aPixelVector(maCurrentTransformation * basegfx::B2DVector(1.0, 0.0));
256 						const double fPixelVectorFactor(aPixelVector.getLength());
257 
258 						for(::std::vector< double >::const_iterator aStart(rTextCandidate.getDXArray().begin());
259                             aStart != rTextCandidate.getDXArray().end(); aStart++)
260 						{
261 							aTransformedDXArray.push_back(basegfx::fround((*aStart) * fPixelVectorFactor));
262 						}
263 					}
264 
265 					// set parameters and paint text snippet
266 					const basegfx::BColor aRGBFontColor(maBColorModifierStack.getModifiedColor(rTextCandidate.getFontColor()));
267 					const basegfx::B2DPoint aPoint(aLocalTransform * basegfx::B2DPoint(0.0, 0.0));
268 					const Point aStartPoint(basegfx::fround(aPoint.getX()), basegfx::fround(aPoint.getY()));
269                     const sal_uInt32 nOldLayoutMode(mpOutputDevice->GetLayoutMode());
270 
271                     if(rTextCandidate.getFontAttribute().getRTL())
272                     {
273                         sal_uInt32 nRTLLayoutMode(nOldLayoutMode & ~(TEXT_LAYOUT_COMPLEX_DISABLED|TEXT_LAYOUT_BIDI_STRONG));
274                         nRTLLayoutMode |= TEXT_LAYOUT_BIDI_RTL|TEXT_LAYOUT_TEXTORIGIN_LEFT;
275                         mpOutputDevice->SetLayoutMode(nRTLLayoutMode);
276                     }
277 
278 					mpOutputDevice->SetFont(aFont);
279 					mpOutputDevice->SetTextColor(Color(aRGBFontColor));
280 
281 					if(aTransformedDXArray.size())
282 					{
283 						mpOutputDevice->DrawTextArray(
284 							aStartPoint,
285 							rTextCandidate.getText(),
286 							&(aTransformedDXArray[0]),
287 							rTextCandidate.getTextPosition(),
288 							rTextCandidate.getTextLength());
289 					}
290 					else
291 					{
292 						mpOutputDevice->DrawText(
293 							aStartPoint,
294 							rTextCandidate.getText(),
295 							rTextCandidate.getTextPosition(),
296 							rTextCandidate.getTextLength());
297 					}
298 
299                     if(rTextCandidate.getFontAttribute().getRTL())
300                     {
301                         mpOutputDevice->SetLayoutMode(nOldLayoutMode);
302                     }
303 
304 					bPrimitiveAccepted = true;
305 				}
306 			}
307 
308 			if(!bPrimitiveAccepted)
309 			{
310 				// let break down
311 				process(rTextCandidate.get2DDecomposition(getViewInformation2D()));
312 			}
313 		}
314 
315 		// direct draw of hairline
316 		void VclProcessor2D::RenderPolygonHairlinePrimitive2D(const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate, bool bPixelBased)
317 		{
318             const basegfx::BColor aHairlineColor(maBColorModifierStack.getModifiedColor(rPolygonCandidate.getBColor()));
319 			mpOutputDevice->SetLineColor(Color(aHairlineColor));
320 			mpOutputDevice->SetFillColor();
321 
322 			basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
323 			aLocalPolygon.transform(maCurrentTransformation);
324 
325             static bool bCheckTrapezoidDecomposition(false);
326             static bool bShowOutlinesThere(false);
327             if(bCheckTrapezoidDecomposition)
328             {
329                 // clip against discrete ViewPort
330                 const basegfx::B2DRange& rDiscreteViewport = getViewInformation2D().getDiscreteViewport();
331                 basegfx::B2DPolyPolygon aLocalPolyPolygon(basegfx::tools::clipPolygonOnRange(
332                     aLocalPolygon, rDiscreteViewport, true, false));
333 
334                 if(aLocalPolyPolygon.count())
335                 {
336                     // subdivide
337                     aLocalPolyPolygon = basegfx::tools::adaptiveSubdivideByDistance(
338                         aLocalPolyPolygon, 0.5);
339 
340                     // trapezoidize
341                     static double fLineWidth(2.0);
342                     basegfx::B2DTrapezoidVector aB2DTrapezoidVector;
343                     basegfx::tools::createLineTrapezoidFromB2DPolyPolygon(aB2DTrapezoidVector, aLocalPolyPolygon, fLineWidth);
344 
345                     const sal_uInt32 nCount(aB2DTrapezoidVector.size());
346 
347                     if(nCount)
348                     {
349                         basegfx::BColor aInvPolygonColor(aHairlineColor);
350                         aInvPolygonColor.invert();
351 
352                         for(sal_uInt32 a(0); a < nCount; a++)
353                         {
354                             const basegfx::B2DPolygon aTempPolygon(aB2DTrapezoidVector[a].getB2DPolygon());
355 
356                             if(bShowOutlinesThere)
357                             {
358                                 mpOutputDevice->SetFillColor(Color(aHairlineColor));
359 			                    mpOutputDevice->SetLineColor();
360                             }
361 
362                             mpOutputDevice->DrawPolygon(aTempPolygon);
363 
364                             if(bShowOutlinesThere)
365                             {
366                                 mpOutputDevice->SetFillColor();
367         		                mpOutputDevice->SetLineColor(Color(aInvPolygonColor));
368     	    		            mpOutputDevice->DrawPolyLine(aTempPolygon, 0.0);
369                             }
370                         }
371                     }
372                 }
373             }
374             else
375             {
376 			    if(bPixelBased && getOptionsDrawinglayer().IsAntiAliasing() && getOptionsDrawinglayer().IsSnapHorVerLinesToDiscrete())
377 			    {
378 				    // #i98289#
379 				    // when a Hairline is painted and AntiAliasing is on the option SnapHorVerLinesToDiscrete
380 				    // allows to suppress AntiAliasing for pure horizontal or vertical lines. This is done since
381 				    // not-AntiAliased such lines look more pleasing to the eye (e.g. 2D chart content). This
382 				    // NEEDS to be done in discrete coordinates, so only useful for pixel based rendering.
383 				    aLocalPolygon = basegfx::tools::snapPointsOfHorizontalOrVerticalEdges(aLocalPolygon);
384 			    }
385 
386 			    mpOutputDevice->DrawPolyLine(aLocalPolygon, 0.0);
387             }
388 		}
389 
390 		// direct draw of transformed BitmapEx primitive
391 		void VclProcessor2D::RenderBitmapPrimitive2D(const primitive2d::BitmapPrimitive2D& rBitmapCandidate)
392 		{
393             // create local transform
394 			basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rBitmapCandidate.getTransform());
395 			BitmapEx aBitmapEx(rBitmapCandidate.getBitmapEx());
396 			bool bPainted(false);
397 
398 			if(maBColorModifierStack.count())
399 			{
400 				aBitmapEx = impModifyBitmapEx(maBColorModifierStack, aBitmapEx);
401 
402 				if(aBitmapEx.IsEmpty())
403 				{
404 					// color gets completely replaced, get it
405 					const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(basegfx::BColor()));
406 					basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
407 					aPolygon.transform(aLocalTransform);
408 
409 					mpOutputDevice->SetFillColor(Color(aModifiedColor));
410 					mpOutputDevice->SetLineColor();
411 					mpOutputDevice->DrawPolygon(aPolygon);
412 
413 					bPainted = true;
414 				}
415 			}
416 
417 			if(!bPainted)
418 			{
419 				static bool bForceUseOfOwnTransformer(false);
420 				static bool bUseGraphicManager(true);
421 
422 				// decompose matrix to check for shear, rotate and mirroring
423 				basegfx::B2DVector aScale, aTranslate;
424 				double fRotate, fShearX;
425 				aLocalTransform.decompose(aScale, aTranslate, fRotate, fShearX);
426 
427 				if(!bForceUseOfOwnTransformer && basegfx::fTools::equalZero(fShearX))
428 				{
429 					if(!bUseGraphicManager && basegfx::fTools::equalZero(fRotate))
430 					{
431 						RenderBitmapPrimitive2D_BitmapEx(*mpOutputDevice, aBitmapEx, aLocalTransform);
432 					}
433 					else
434 					{
435 						RenderBitmapPrimitive2D_GraphicManager(*mpOutputDevice, aBitmapEx, aLocalTransform);
436 					}
437 				}
438 				else
439 				{
440 					if(!aBitmapEx.IsTransparent() && (!basegfx::fTools::equalZero(fShearX) || !basegfx::fTools::equalZero(fRotate)))
441 					{
442 						// parts will be uncovered, extend aBitmapEx with a mask bitmap
443 						const Bitmap aContent(aBitmapEx.GetBitmap());
444 						aBitmapEx = BitmapEx(aContent, Bitmap(aContent.GetSizePixel(), 1));
445 					}
446 
447 					RenderBitmapPrimitive2D_self(*mpOutputDevice, aBitmapEx, aLocalTransform);
448 				}
449 			}
450 		}
451 
452 		void VclProcessor2D::RenderFillGraphicPrimitive2D(const primitive2d::FillGraphicPrimitive2D& rFillBitmapCandidate)
453 		{
454 			const attribute::FillGraphicAttribute& rFillGraphicAttribute(rFillBitmapCandidate.getFillGraphic());
455 			bool bPrimitiveAccepted(false);
456             static bool bTryTilingDirect = true;
457 
458             // #121194# when tiling is used and content is bitmap-based, do direct tiling in the
459             // renderer on pixel base to ensure tight fitting. Do not do this when
460             // the fill is rotated or sheared.
461 
462             // ovveride static bool (for debug) and tiling is active
463 			if(bTryTilingDirect && rFillGraphicAttribute.getTiling())
464 			{
465                 // content is bitmap(ex)
466                 //
467                 // for SVG support, force decomposition when SVG is present. This will lead to use
468                 // the primitive representation of the svg directly.
469                 //
470                 // when graphic is animated, force decomposition to use the correct graphic, else
471                 // fill style will not be animated
472                 if(GRAPHIC_BITMAP == rFillGraphicAttribute.getGraphic().GetType()
473                     && !rFillGraphicAttribute.getGraphic().getSvgData().get()
474                     && !rFillGraphicAttribute.getGraphic().IsAnimated())
475                 {
476 				    // decompose matrix to check for shear, rotate and mirroring
477 				    basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rFillBitmapCandidate.getTransformation());
478 				    basegfx::B2DVector aScale, aTranslate;
479 				    double fRotate, fShearX;
480 				    aLocalTransform.decompose(aScale, aTranslate, fRotate, fShearX);
481 
482                     // when nopt rotated/sheared
483 				    if(basegfx::fTools::equalZero(fRotate) && basegfx::fTools::equalZero(fShearX))
484 				    {
485 					    // no shear or rotate, draw direct in pixel coordinates
486 					    bPrimitiveAccepted = true;
487 
488                         // transform object range to device coordinates (pixels). Use
489                         // the device transformation for better accuracy
490                         basegfx::B2DRange aObjectRange(aTranslate, aTranslate + aScale);
491                         aObjectRange.transform(mpOutputDevice->GetViewTransformation());
492 
493                         // extract discrete size of object
494                         const sal_Int32 nOWidth(basegfx::fround(aObjectRange.getWidth()));
495                         const sal_Int32 nOHeight(basegfx::fround(aObjectRange.getHeight()));
496 
497                         // only do something when object has a size in discrete units
498 						if(nOWidth > 0 && nOHeight > 0)
499 						{
500                             // transform graphic range to device coordinates (pixels). Use
501                             // the device transformation for better accuracy
502                             basegfx::B2DRange aGraphicRange(rFillGraphicAttribute.getGraphicRange());
503                             aGraphicRange.transform(mpOutputDevice->GetViewTransformation() * aLocalTransform);
504 
505                             // extract discrete size of graphic
506                             const sal_Int32 nBWidth(basegfx::fround(aGraphicRange.getWidth()));
507                             const sal_Int32 nBHeight(basegfx::fround(aGraphicRange.getHeight()));
508 
509                             // only do something when bitmap fill has a size in discrete units
510 						    if(nBWidth > 0 && nBHeight > 0)
511 						    {
512 						        // nBWidth, nBHeight is the pixel size of the neede bitmap. To not need to scale it
513 						        // in vcl many times, create a size-optimized version
514 						        const Size aNeededBitmapSizePixel(nBWidth, nBHeight);
515                                 BitmapEx aBitmapEx(rFillGraphicAttribute.getGraphic().GetBitmapEx());
516                                 static bool bEnablePreScaling(true);
517                                 const bool bPreScaled(bEnablePreScaling && nBWidth * nBHeight < (250 * 250));
518 
519                                 if(bPreScaled)
520                                 {
521                                     // ... but only up to a maximum size, else it gets too expensive
522                                     aBitmapEx.Scale(aNeededBitmapSizePixel, BMP_SCALE_INTERPOLATE);
523                                 }
524 
525 					            bool bPainted(false);
526 
527 					            if(maBColorModifierStack.count())
528 					            {
529                                     // when color modifier, apply to bitmap
530 						            aBitmapEx = impModifyBitmapEx(maBColorModifierStack, aBitmapEx);
531 
532                                     // impModifyBitmapEx uses empty bitmap as sign to return that
533                                     // the content will be completely replaced to mono color, use shortcut
534 						            if(aBitmapEx.IsEmpty())
535 						            {
536 							            // color gets completely replaced, get it
537 							            const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(basegfx::BColor()));
538 							            basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
539 							            aPolygon.transform(aLocalTransform);
540 
541 							            mpOutputDevice->SetFillColor(Color(aModifiedColor));
542 							            mpOutputDevice->SetLineColor();
543 							            mpOutputDevice->DrawPolygon(aPolygon);
544 
545 							            bPainted = true;
546 						            }
547 					            }
548 
549 					            if(!bPainted)
550 					            {
551                                     sal_Int32 nBLeft(basegfx::fround(aGraphicRange.getMinX()));
552                                     sal_Int32 nBTop(basegfx::fround(aGraphicRange.getMinY()));
553                                     const sal_Int32 nOLeft(basegfx::fround(aObjectRange.getMinX()));
554                                     const sal_Int32 nOTop(basegfx::fround(aObjectRange.getMinY()));
555                                     sal_Int32 nPosX(0);
556                                     sal_Int32 nPosY(0);
557 
558 						            if(nBLeft > nOLeft)
559 						            {
560                                         const sal_Int32 nDiff((nBLeft / nBWidth) + 1);
561 
562                                         nPosX -= nDiff;
563 							            nBLeft -= nDiff * nBWidth;
564 						            }
565 
566 						            if(nBLeft + nBWidth <= nOLeft)
567 						            {
568                                         const sal_Int32 nDiff(-nBLeft / nBWidth);
569 
570                                         nPosX += nDiff;
571 							            nBLeft += nDiff * nBWidth;
572 						            }
573 
574 						            if(nBTop > nOTop)
575 						            {
576                                         const sal_Int32 nDiff((nBTop / nBHeight) + 1);
577 
578                                         nPosY -= nDiff;
579 							            nBTop -= nDiff * nBHeight;
580 						            }
581 
582 						            if(nBTop + nBHeight <= nOTop)
583 						            {
584                                         const sal_Int32 nDiff(-nBTop / nBHeight);
585 
586                                         nPosY += nDiff;
587 							            nBTop += nDiff * nBHeight;
588 						            }
589 
590 						            // prepare OutDev
591 						            const Point aEmptyPoint(0, 0);
592 						            const Rectangle aVisiblePixel(aEmptyPoint, mpOutputDevice->GetOutputSizePixel());
593 						            const bool bWasEnabled(mpOutputDevice->IsMapModeEnabled());
594 						            mpOutputDevice->EnableMapMode(false);
595 
596                                     // check if offset is used
597                                     const sal_Int32 nOffsetX(basegfx::fround(rFillGraphicAttribute.getOffsetX() * nBWidth));
598 
599                                     if(nOffsetX)
600                                     {
601                                         // offset in X, so iterate over Y first and draw lines
602                                         for(sal_Int32 nYPos(nBTop); nYPos < nOTop + nOHeight; nYPos += nBHeight, nPosY++)
603                                         {
604                                             for(sal_Int32 nXPos(nPosY % 2 ? nBLeft - nBWidth + nOffsetX : nBLeft);
605                                                 nXPos < nOLeft + nOWidth; nXPos += nBWidth)
606                                             {
607                                                 const Rectangle aOutRectPixel(Point(nXPos, nYPos), aNeededBitmapSizePixel);
608 
609                                                 if(aOutRectPixel.IsOver(aVisiblePixel))
610                                                 {
611                                                     if(bPreScaled)
612                                                     {
613                                                         mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aBitmapEx);
614                                                     }
615                                                     else
616                                                     {
617                                                         mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aNeededBitmapSizePixel, aBitmapEx);
618                                                     }
619                                                 }
620                                             }
621                                         }
622                                     }
623                                     else
624                                     {
625                                         // check if offset is used
626                                         const sal_Int32 nOffsetY(basegfx::fround(rFillGraphicAttribute.getOffsetY() * nBHeight));
627 
628                                         // possible offset in Y, so iterate over X first and draw columns
629                                         for(sal_Int32 nXPos(nBLeft); nXPos < nOLeft + nOWidth; nXPos += nBWidth, nPosX++)
630                                         {
631                                             for(sal_Int32 nYPos(nPosX % 2 ? nBTop - nBHeight + nOffsetY : nBTop);
632                                                 nYPos < nOTop + nOHeight; nYPos += nBHeight)
633                                             {
634                                                 const Rectangle aOutRectPixel(Point(nXPos, nYPos), aNeededBitmapSizePixel);
635 
636                                                 if(aOutRectPixel.IsOver(aVisiblePixel))
637                                                 {
638                                                     if(bPreScaled)
639                                                     {
640                                                         mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aBitmapEx);
641                                                     }
642                                                     else
643                                                     {
644                                                         mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aNeededBitmapSizePixel, aBitmapEx);
645                                                     }
646                                                 }
647                                             }
648                                         }
649                                     }
650 
651 						            // restore OutDev
652 						            mpOutputDevice->EnableMapMode(bWasEnabled);
653                                 }
654                             }
655                         }
656 				    }
657 			    }
658             }
659 
660 			if(!bPrimitiveAccepted)
661 			{
662 				// do not accept, use decomposition
663 				process(rFillBitmapCandidate.get2DDecomposition(getViewInformation2D()));
664 			}
665 		}
666 
667 		// direct draw of gradient
668 		void VclProcessor2D::RenderPolyPolygonGradientPrimitive2D(const primitive2d::PolyPolygonGradientPrimitive2D& rPolygonCandidate)
669 		{
670 			const attribute::FillGradientAttribute& rGradient(rPolygonCandidate.getFillGradient());
671 			basegfx::BColor aStartColor(maBColorModifierStack.getModifiedColor(rGradient.getStartColor()));
672 			basegfx::BColor aEndColor(maBColorModifierStack.getModifiedColor(rGradient.getEndColor()));
673 			basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
674 
675 			if(aLocalPolyPolygon.count())
676 			{
677 				aLocalPolyPolygon.transform(maCurrentTransformation);
678 
679 				if(aStartColor == aEndColor)
680 				{
681 					// no gradient at all, draw as polygon in AA and non-AA case
682 					mpOutputDevice->SetLineColor();
683 					mpOutputDevice->SetFillColor(Color(aStartColor));
684 					mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon);
685 				}
686 				else if(getOptionsDrawinglayer().IsAntiAliasing())
687 				{
688 					// For AA, direct render has to be avoided since it uses XOR maskings which will not
689 					// work with AA. Instead, the decompose which uses MaskPrimitive2D with fillings is
690 					// used
691 					process(rPolygonCandidate.get2DDecomposition(getViewInformation2D()));
692 				}
693 				else
694 				{
695                     static bool bSimple = false; // allow testing simple paint in debugger
696 
697                     impDrawGradientToOutDev(
698 						*mpOutputDevice, aLocalPolyPolygon, rGradient.getStyle(), rGradient.getSteps(),
699 						aStartColor, aEndColor, rGradient.getBorder(),
700 						rGradient.getAngle(), rGradient.getOffsetX(), rGradient.getOffsetY(), bSimple);
701 				}
702 			}
703 		}
704 
705 		// direct draw of Graphic
706 		void VclProcessor2D::RenderPolyPolygonGraphicPrimitive2D(const primitive2d::PolyPolygonGraphicPrimitive2D& rPolygonCandidate)
707 		{
708             bool bDone(false);
709             const basegfx::B2DPolyPolygon& rPolyPolygon = rPolygonCandidate.getB2DPolyPolygon();
710 
711             // #121194# Todo: check if this works
712             if(!rPolyPolygon.count())
713             {
714                 // empty polyPolygon, done
715                 bDone = true;
716             }
717             else
718             {
719                 const attribute::FillGraphicAttribute& rFillGraphicAttribute = rPolygonCandidate.getFillGraphic();
720 
721                 // try to catch cases where the graphic will be color-modified to a single
722                 // color (e.g. shadow)
723                 switch(rFillGraphicAttribute.getGraphic().GetType())
724                 {
725                     case GRAPHIC_GDIMETAFILE:
726                     {
727                         // metafiles are potentially transparent, cannot optimize�, not done
728                         break;
729                     }
730                     case GRAPHIC_BITMAP:
731                     {
732                         if(!rFillGraphicAttribute.getGraphic().IsTransparent() && !rFillGraphicAttribute.getGraphic().IsAlpha())
733                         {
734                             // bitmap is not transparent and has no alpha
735                             const sal_uInt32 nBColorModifierStackCount(maBColorModifierStack.count());
736 
737                             if(nBColorModifierStackCount)
738                             {
739                                 const basegfx::BColorModifier& rTopmostModifier = maBColorModifierStack.getBColorModifier(nBColorModifierStackCount - 1);
740 
741                                 if(basegfx::BCOLORMODIFYMODE_REPLACE == rTopmostModifier.getMode())
742                                 {
743                                     // the bitmap fill is in unified color, so we can replace it with
744                                     // a single polygon fill. The form of the fill depends on tiling
745                                     if(rFillGraphicAttribute.getTiling())
746                                     {
747                                         // with tiling, fill the whole PolyPolygon with the modifier color
748                                         basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolyPolygon);
749 
750                                         aLocalPolyPolygon.transform(maCurrentTransformation);
751                                         mpOutputDevice->SetLineColor();
752                                         mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor()));
753                                         mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon);
754                                     }
755                                     else
756                                     {
757                                         // without tiling, only the area common to the bitmap tile and the
758                                         // PolyPolygon is filled. Create the bitmap tile area in object
759                                         // coordinates. For this, the object transformation needs to be created
760                                         // from the already scaled PolyPolygon. The tile area in object
761                                         // coordinates wil always be non-rotated, so it's not necessary to
762                                         // work with a polygon here
763                                         basegfx::B2DRange aTileRange(rFillGraphicAttribute.getGraphicRange());
764                                         const basegfx::B2DRange aPolyPolygonRange(rPolyPolygon.getB2DRange());
765                                         const basegfx::B2DHomMatrix aNewObjectTransform(
766                                             basegfx::tools::createScaleTranslateB2DHomMatrix(
767                                                 aPolyPolygonRange.getRange(),
768                                                 aPolyPolygonRange.getMinimum()));
769 
770                                         aTileRange.transform(aNewObjectTransform);
771 
772                                         // now clip the object polyPolygon against the tile range
773                                         // to get the common area
774                                         basegfx::B2DPolyPolygon aTarget = basegfx::tools::clipPolyPolygonOnRange(
775                                             rPolyPolygon,
776                                             aTileRange,
777                                             true,
778                                             false);
779 
780                                         if(aTarget.count())
781                                         {
782                                             aTarget.transform(maCurrentTransformation);
783                                             mpOutputDevice->SetLineColor();
784                                             mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor()));
785                                             mpOutputDevice->DrawPolyPolygon(aTarget);
786                                         }
787                                     }
788 
789                                     // simplified output executed, we are done
790                                     bDone = true;
791                                 }
792                             }
793                         }
794                         break;
795                     }
796                     default: //GRAPHIC_NONE, GRAPHIC_DEFAULT
797                     {
798                         // empty graphic, we are done
799                         bDone = true;
800                         break;
801                     }
802                 }
803             }
804 
805             if(!bDone)
806             {
807                 // use default decomposition
808                 process(rPolygonCandidate.get2DDecomposition(getViewInformation2D()));
809             }
810         }
811 
812 		// direct draw of PolyPolygon with color
813 		void VclProcessor2D::RenderPolyPolygonColorPrimitive2D(const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate)
814 		{
815 			const basegfx::BColor aPolygonColor(maBColorModifierStack.getModifiedColor(rPolygonCandidate.getBColor()));
816 			mpOutputDevice->SetFillColor(Color(aPolygonColor));
817 			mpOutputDevice->SetLineColor();
818 
819 			basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
820 			aLocalPolyPolygon.transform(maCurrentTransformation);
821 
822             static bool bCheckTrapezoidDecomposition(false);
823             static bool bShowOutlinesThere(false);
824             if(bCheckTrapezoidDecomposition)
825             {
826                 // clip against discrete ViewPort
827                 const basegfx::B2DRange& rDiscreteViewport = getViewInformation2D().getDiscreteViewport();
828                 aLocalPolyPolygon = basegfx::tools::clipPolyPolygonOnRange(
829                     aLocalPolyPolygon, rDiscreteViewport, true, false);
830 
831                 if(aLocalPolyPolygon.count())
832                 {
833                     // subdivide
834                     aLocalPolyPolygon = basegfx::tools::adaptiveSubdivideByDistance(
835                         aLocalPolyPolygon, 0.5);
836 
837                     // trapezoidize
838                     basegfx::B2DTrapezoidVector aB2DTrapezoidVector;
839                     basegfx::tools::trapezoidSubdivide(aB2DTrapezoidVector, aLocalPolyPolygon);
840 
841                     const sal_uInt32 nCount(aB2DTrapezoidVector.size());
842 
843                     if(nCount)
844                     {
845                         basegfx::BColor aInvPolygonColor(aPolygonColor);
846                         aInvPolygonColor.invert();
847 
848                         for(sal_uInt32 a(0); a < nCount; a++)
849                         {
850                             const basegfx::B2DPolygon aTempPolygon(aB2DTrapezoidVector[a].getB2DPolygon());
851 
852                             if(bShowOutlinesThere)
853                             {
854                                 mpOutputDevice->SetFillColor(Color(aPolygonColor));
855 			                    mpOutputDevice->SetLineColor();
856                             }
857 
858                             mpOutputDevice->DrawPolygon(aTempPolygon);
859 
860                             if(bShowOutlinesThere)
861                             {
862                                 mpOutputDevice->SetFillColor();
863         		                mpOutputDevice->SetLineColor(Color(aInvPolygonColor));
864     	    		            mpOutputDevice->DrawPolyLine(aTempPolygon, 0.0);
865                             }
866                         }
867                     }
868                 }
869             }
870             else
871             {
872 			    mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon);
873 
874                 if(mnPolygonStrokePrimitive2D
875                     && getOptionsDrawinglayer().IsAntiAliasing()
876                     && (mpOutputDevice->GetAntialiasing() & ANTIALIASING_ENABLE_B2DDRAW))
877                 {
878                     // when AA is on and this filled polygons are the result of stroked line geometry,
879                     // draw the geometry once extra as lines to avoid AA 'gaps' between partial polygons
880 			        mpOutputDevice->SetFillColor();
881 			        mpOutputDevice->SetLineColor(Color(aPolygonColor));
882                     const sal_uInt32 nCount(aLocalPolyPolygon.count());
883 
884                     for(sal_uInt32 a(0); a < nCount; a++)
885                     {
886                         mpOutputDevice->DrawPolyLine(aLocalPolyPolygon.getB2DPolygon(a), 0.0);
887                     }
888                 }
889             }
890 		}
891 
892 		// direct draw of MetaFile
893 		void VclProcessor2D::RenderMetafilePrimitive2D(const primitive2d::MetafilePrimitive2D& rMetaCandidate)
894 		{
895 			// decompose matrix to check for shear, rotate and mirroring
896 			basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rMetaCandidate.getTransform());
897 			basegfx::B2DVector aScale, aTranslate;
898 			double fRotate, fShearX;
899 			aLocalTransform.decompose(aScale, aTranslate, fRotate, fShearX);
900 
901 			if(basegfx::fTools::less(aScale.getX(), 0.0) && basegfx::fTools::less(aScale.getY(), 0.0))
902 			{
903 				// #i102175# handle special case: If scale is negative in (x,y) (3rd quadrant), it can
904 				// be expressed as rotation by PI. This needs to be done for Metafiles since
905                 // these can be rotated, but not really mirrored
906 				aScale = basegfx::absolute(aScale);
907 				fRotate += F_PI;
908 			}
909 
910             // get BoundRect
911 			basegfx::B2DRange aOutlineRange(rMetaCandidate.getB2DRange(getViewInformation2D()));
912 			aOutlineRange.transform(maCurrentTransformation);
913 
914 			// Due to the integer MapModes used from VCL aind inside MetaFiles errors of up to three
915 			// pixels in size may happen. As long as there is no better way (e.g. convert the MetaFile
916 			// to primitives) it is necessary to reduce maximum pixel size by 1 in X and Y and to use
917 			// the inner pixel bounds accordingly (ceil resp. floor). This will also be done for logic
918 			// units e.g. when creating a new MetaFile, but since much huger value ranges are used
919 			// there typically will be okay for this compromize.
920 			Rectangle aDestRectView(
921                 // !!CAUTION!! Here, ceil and floor are exchanged BY PURPOSE, do NOT copy when
922                 // looking for a standard conversion to rectangle (!)
923 				(sal_Int32)ceil(aOutlineRange.getMinX()), (sal_Int32)ceil(aOutlineRange.getMinY()),
924 				(sal_Int32)floor(aOutlineRange.getMaxX()), (sal_Int32)floor(aOutlineRange.getMaxY()));
925 
926 			// get metafile (copy it)
927 			GDIMetaFile aMetaFile;
928 
929 			if(maBColorModifierStack.count())
930 			{
931 				const basegfx::BColor aRGBBaseColor(0, 0, 0);
932 				const basegfx::BColor aRGBColor(maBColorModifierStack.getModifiedColor(aRGBBaseColor));
933 				aMetaFile = rMetaCandidate.getMetaFile().GetMonochromeMtf(Color(aRGBColor));
934 			}
935 			else
936 			{
937 				aMetaFile = rMetaCandidate.getMetaFile();
938 			}
939 
940 			// rotation
941 			if(!basegfx::fTools::equalZero(fRotate))
942 			{
943                 // #i103530#
944                 // MetaFile::Rotate has no input parameter check, so the parameter needs to be
945                 // well-aligned to the old range [0..3600] 10th degrees with inverse orientation
946 				sal_Int16 nRotation((sal_Int16)((fRotate / F_PI180) * -10.0));
947 
948                 while(nRotation < 0)
949                     nRotation += 3600;
950 
951                 while(nRotation >= 3600)
952                     nRotation -= 3600;
953 
954 				aMetaFile.Rotate(nRotation);
955 			}
956 
957 			// Prepare target output size
958 			Size aDestSize(aDestRectView.GetSize());
959 
960 			if(aDestSize.getWidth() && aDestSize.getHeight())
961 			{
962 				// Get preferred Metafile output size. When it's very equal to the output size, it's probably
963 				// a rounding error somewhere, so correct it to get a 1:1 output without single pixel scalings
964 				// of the Metafile (esp. for contaned Bitmaps, e.g 3D charts)
965 				const Size aPrefSize(mpOutputDevice->LogicToPixel(aMetaFile.GetPrefSize(), aMetaFile.GetPrefMapMode()));
966 
967 				if(aPrefSize.getWidth() && (aPrefSize.getWidth() - 1 == aDestSize.getWidth() || aPrefSize.getWidth() + 1 == aDestSize.getWidth()))
968 				{
969 					aDestSize.setWidth(aPrefSize.getWidth());
970 				}
971 
972 				if(aPrefSize.getHeight() && (aPrefSize.getHeight() - 1 == aDestSize.getHeight() || aPrefSize.getHeight() + 1 == aDestSize.getHeight()))
973 				{
974 					aDestSize.setHeight(aPrefSize.getHeight());
975 				}
976 
977 				// paint it
978 				aMetaFile.WindStart();
979 				aMetaFile.Play(mpOutputDevice, aDestRectView.TopLeft(), aDestSize);
980 			}
981 		}
982 
983 		// mask group. Force output to VDev and create mask from given mask
984 		void VclProcessor2D::RenderMaskPrimitive2DPixel(const primitive2d::MaskPrimitive2D& rMaskCandidate)
985 		{
986 			if(rMaskCandidate.getChildren().hasElements())
987 			{
988 				basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
989 
990 				if(aMask.count())
991 				{
992 					aMask.transform(maCurrentTransformation);
993 					const basegfx::B2DRange aRange(basegfx::tools::getRange(aMask));
994 					impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true);
995 
996 					if(aBufferDevice.isVisible())
997 					{
998 						// remember last OutDev and set to content
999 						OutputDevice* pLastOutputDevice = mpOutputDevice;
1000 						mpOutputDevice = &aBufferDevice.getContent();
1001 
1002 						// paint to it
1003 						process(rMaskCandidate.getChildren());
1004 
1005 						// back to old OutDev
1006 						mpOutputDevice = pLastOutputDevice;
1007 
1008 					    // draw mask
1009                         if(getOptionsDrawinglayer().IsAntiAliasing())
1010                         {
1011                             // with AA, use 8bit AlphaMask to get nice borders
1012 						    VirtualDevice& rTransparence = aBufferDevice.getTransparence();
1013 						    rTransparence.SetLineColor();
1014 						    rTransparence.SetFillColor(COL_BLACK);
1015 						    rTransparence.DrawPolyPolygon(aMask);
1016 
1017 						    // dump buffer to outdev
1018 						    aBufferDevice.paint();
1019                         }
1020                         else
1021                         {
1022                             // No AA, use 1bit mask
1023 						    VirtualDevice& rMask = aBufferDevice.getMask();
1024 						    rMask.SetLineColor();
1025 						    rMask.SetFillColor(COL_BLACK);
1026 						    rMask.DrawPolyPolygon(aMask);
1027 
1028 						    // dump buffer to outdev
1029 						    aBufferDevice.paint();
1030                         }
1031 					}
1032 				}
1033 			}
1034 		}
1035 
1036 		// modified color group. Force output to unified color.
1037 		void VclProcessor2D::RenderModifiedColorPrimitive2D(const primitive2d::ModifiedColorPrimitive2D& rModifiedCandidate)
1038 		{
1039 			if(rModifiedCandidate.getChildren().hasElements())
1040 			{
1041 				maBColorModifierStack.push(rModifiedCandidate.getColorModifier());
1042 				process(rModifiedCandidate.getChildren());
1043 				maBColorModifierStack.pop();
1044 			}
1045 		}
1046 
1047 		// unified sub-transparence. Draw to VDev first.
1048 		void VclProcessor2D::RenderUnifiedTransparencePrimitive2D(const primitive2d::UnifiedTransparencePrimitive2D& rTransCandidate)
1049 		{
1050             static bool bForceToDecomposition(false);
1051 
1052             if(rTransCandidate.getChildren().hasElements())
1053             {
1054                 if(bForceToDecomposition)
1055                 {
1056     			    // use decomposition
1057 	    		    process(rTransCandidate.get2DDecomposition(getViewInformation2D()));
1058                 }
1059                 else
1060                 {
1061 			        if(0.0 == rTransCandidate.getTransparence())
1062 			        {
1063 				        // no transparence used, so just use the content
1064     	    		    process(rTransCandidate.getChildren());
1065 			        }
1066 			        else if(rTransCandidate.getTransparence() > 0.0 && rTransCandidate.getTransparence() < 1.0)
1067 			        {
1068                         // transparence is in visible range
1069 				        basegfx::B2DRange aRange(primitive2d::getB2DRangeFromPrimitive2DSequence(rTransCandidate.getChildren(), getViewInformation2D()));
1070 				        aRange.transform(maCurrentTransformation);
1071 				        impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true);
1072 
1073 				        if(aBufferDevice.isVisible())
1074 				        {
1075 					        // remember last OutDev and set to content
1076 					        OutputDevice* pLastOutputDevice = mpOutputDevice;
1077 					        mpOutputDevice = &aBufferDevice.getContent();
1078 
1079 					        // paint content to it
1080 					        process(rTransCandidate.getChildren());
1081 
1082 					        // back to old OutDev
1083 					        mpOutputDevice = pLastOutputDevice;
1084 
1085 					        // dump buffer to outdev using given transparence
1086 					        aBufferDevice.paint(rTransCandidate.getTransparence());
1087 				        }
1088 			        }
1089                 }
1090             }
1091 		}
1092 
1093 		// sub-transparence group. Draw to VDev first.
1094 		void VclProcessor2D::RenderTransparencePrimitive2D(const primitive2d::TransparencePrimitive2D& rTransCandidate)
1095 		{
1096 			if(rTransCandidate.getChildren().hasElements())
1097 			{
1098 				basegfx::B2DRange aRange(primitive2d::getB2DRangeFromPrimitive2DSequence(rTransCandidate.getChildren(), getViewInformation2D()));
1099 				aRange.transform(maCurrentTransformation);
1100 				impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true);
1101 
1102 				if(aBufferDevice.isVisible())
1103 				{
1104 					// remember last OutDev and set to content
1105 					OutputDevice* pLastOutputDevice = mpOutputDevice;
1106 					mpOutputDevice = &aBufferDevice.getContent();
1107 
1108 					// paint content to it
1109 					process(rTransCandidate.getChildren());
1110 
1111 					// set to mask
1112 					mpOutputDevice = &aBufferDevice.getTransparence();
1113 
1114 					// when painting transparence masks, reset the color stack
1115 					basegfx::BColorModifierStack aLastBColorModifierStack(maBColorModifierStack);
1116 					maBColorModifierStack = basegfx::BColorModifierStack();
1117 
1118 					// paint mask to it (always with transparence intensities, evtl. with AA)
1119 					process(rTransCandidate.getTransparence());
1120 
1121 					// back to old color stack
1122 					maBColorModifierStack = aLastBColorModifierStack;
1123 
1124 					// back to old OutDev
1125 					mpOutputDevice = pLastOutputDevice;
1126 
1127 					// dump buffer to outdev
1128 					aBufferDevice.paint();
1129 				}
1130 			}
1131 		}
1132 
1133 		// transform group.
1134 		void VclProcessor2D::RenderTransformPrimitive2D(const primitive2d::TransformPrimitive2D& rTransformCandidate)
1135 		{
1136 			// remember current transformation and ViewInformation
1137 			const basegfx::B2DHomMatrix aLastCurrentTransformation(maCurrentTransformation);
1138             const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
1139 
1140 			// create new transformations for CurrentTransformation
1141             // and for local ViewInformation2D
1142 			maCurrentTransformation = maCurrentTransformation * rTransformCandidate.getTransformation();
1143             const geometry::ViewInformation2D aViewInformation2D(
1144                 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
1145                 getViewInformation2D().getViewTransformation(),
1146                 getViewInformation2D().getViewport(),
1147 				getViewInformation2D().getVisualizedPage(),
1148                 getViewInformation2D().getViewTime(),
1149 				getViewInformation2D().getExtendedInformationSequence());
1150 			updateViewInformation(aViewInformation2D);
1151 
1152 			// proccess content
1153 			process(rTransformCandidate.getChildren());
1154 
1155 			// restore transformations
1156 			maCurrentTransformation = aLastCurrentTransformation;
1157             updateViewInformation(aLastViewInformation2D);
1158 		}
1159 
1160 		// new XDrawPage for ViewInformation2D
1161 		void VclProcessor2D::RenderPagePreviewPrimitive2D(const primitive2d::PagePreviewPrimitive2D& rPagePreviewCandidate)
1162 		{
1163 			// remember current transformation and ViewInformation
1164             const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
1165 
1166 			// create new local ViewInformation2D
1167             const geometry::ViewInformation2D aViewInformation2D(
1168                 getViewInformation2D().getObjectTransformation(),
1169                 getViewInformation2D().getViewTransformation(),
1170                 getViewInformation2D().getViewport(),
1171 				rPagePreviewCandidate.getXDrawPage(),
1172                 getViewInformation2D().getViewTime(),
1173 				getViewInformation2D().getExtendedInformationSequence());
1174 			updateViewInformation(aViewInformation2D);
1175 
1176 			// proccess decomposed content
1177 			process(rPagePreviewCandidate.get2DDecomposition(getViewInformation2D()));
1178 
1179 			// restore transformations
1180             updateViewInformation(aLastViewInformation2D);
1181 		}
1182 
1183 		// marker
1184 		void VclProcessor2D::RenderMarkerArrayPrimitive2D(const primitive2d::MarkerArrayPrimitive2D& rMarkArrayCandidate)
1185 		{
1186             static bool bCheckCompleteMarkerDecompose(false);
1187             if(bCheckCompleteMarkerDecompose)
1188             {
1189 			    process(rMarkArrayCandidate.get2DDecomposition(getViewInformation2D()));
1190                 return;
1191             }
1192 
1193 			// get data
1194 	        const std::vector< basegfx::B2DPoint >& rPositions = rMarkArrayCandidate.getPositions();
1195 			const sal_uInt32 nCount(rPositions.size());
1196 
1197 			if(nCount && !rMarkArrayCandidate.getMarker().IsEmpty())
1198 			{
1199 				// get pixel size
1200 				const BitmapEx& rMarker(rMarkArrayCandidate.getMarker());
1201 				const Size aBitmapSize(rMarker.GetSizePixel());
1202 
1203 				if(aBitmapSize.Width() && aBitmapSize.Height())
1204 				{
1205 					// get discrete half size
1206 					const basegfx::B2DVector aDiscreteHalfSize(
1207                         (aBitmapSize.getWidth() - 1.0) * 0.5,
1208                         (aBitmapSize.getHeight() - 1.0) * 0.5);
1209 			        const bool bWasEnabled(mpOutputDevice->IsMapModeEnabled());
1210 
1211                     // do not forget evtl. moved origin in target device MapMode when
1212                     // switching it off; it would be missing and lead to wrong positions.
1213                     // All his could be done using logic sizes and coordinates, too, but
1214                     // we want a 1:1 bitmap rendering here, so it's more safe and faster
1215                     // to work with switching off MapMode usage completely.
1216                     const Point aOrigin(mpOutputDevice->GetMapMode().GetOrigin());
1217 
1218                     mpOutputDevice->EnableMapMode(false);
1219 
1220 					for(std::vector< basegfx::B2DPoint >::const_iterator aIter(rPositions.begin()); aIter != rPositions.end(); aIter++)
1221 				    {
1222 					    const basegfx::B2DPoint aDiscreteTopLeft((maCurrentTransformation * (*aIter)) - aDiscreteHalfSize);
1223                         const Point aDiscretePoint(basegfx::fround(aDiscreteTopLeft.getX()), basegfx::fround(aDiscreteTopLeft.getY()));
1224 
1225 						mpOutputDevice->DrawBitmapEx(aDiscretePoint + aOrigin, rMarker);
1226 					}
1227 
1228 			        mpOutputDevice->EnableMapMode(bWasEnabled);
1229 				}
1230 			}
1231 		}
1232 
1233 		// point
1234 		void VclProcessor2D::RenderPointArrayPrimitive2D(const primitive2d::PointArrayPrimitive2D& rPointArrayCandidate)
1235 		{
1236 			const std::vector< basegfx::B2DPoint >& rPositions = rPointArrayCandidate.getPositions();
1237 			const basegfx::BColor aRGBColor(maBColorModifierStack.getModifiedColor(rPointArrayCandidate.getRGBColor()));
1238 			const Color aVCLColor(aRGBColor);
1239 
1240 			for(std::vector< basegfx::B2DPoint >::const_iterator aIter(rPositions.begin()); aIter != rPositions.end(); aIter++)
1241 			{
1242 				const basegfx::B2DPoint aViewPosition(maCurrentTransformation * (*aIter));
1243 				const Point aPos(basegfx::fround(aViewPosition.getX()), basegfx::fround(aViewPosition.getY()));
1244 
1245 				mpOutputDevice->DrawPixel(aPos, aVCLColor);
1246 			}
1247 		}
1248 
1249 		void VclProcessor2D::RenderPolygonStrokePrimitive2D(const primitive2d::PolygonStrokePrimitive2D& rPolygonStrokeCandidate)
1250 		{
1251             // #i101491# method restructured to clearly use the DrawPolyLine
1252             // calls starting from a deined line width
1253 			const attribute::LineAttribute& rLineAttribute = rPolygonStrokeCandidate.getLineAttribute();
1254 			const double fLineWidth(rLineAttribute.getWidth());
1255 			bool bDone(false);
1256 
1257 			if(basegfx::fTools::more(fLineWidth, 0.0))
1258 			{
1259 				const basegfx::B2DVector aDiscreteUnit(maCurrentTransformation * basegfx::B2DVector(fLineWidth, 0.0));
1260 				const double fDiscreteLineWidth(aDiscreteUnit.getLength());
1261 				const attribute::StrokeAttribute& rStrokeAttribute = rPolygonStrokeCandidate.getStrokeAttribute();
1262 				const basegfx::BColor aHairlineColor(maBColorModifierStack.getModifiedColor(rLineAttribute.getColor()));
1263 				basegfx::B2DPolyPolygon aHairlinePolyPolygon;
1264 
1265 				mpOutputDevice->SetLineColor(Color(aHairlineColor));
1266 				mpOutputDevice->SetFillColor();
1267 
1268 				if(0.0 == rStrokeAttribute.getFullDotDashLen())
1269 				{
1270 					// no line dashing, just copy
1271 					aHairlinePolyPolygon.append(rPolygonStrokeCandidate.getB2DPolygon());
1272 				}
1273 				else
1274 				{
1275 					// else apply LineStyle
1276 					basegfx::tools::applyLineDashing(rPolygonStrokeCandidate.getB2DPolygon(),
1277 						rStrokeAttribute.getDotDashArray(),
1278 						&aHairlinePolyPolygon, 0, rStrokeAttribute.getFullDotDashLen());
1279 				}
1280 
1281 				const sal_uInt32 nCount(aHairlinePolyPolygon.count());
1282 
1283 				if(nCount)
1284 				{
1285                     const bool bAntiAliased(getOptionsDrawinglayer().IsAntiAliasing());
1286                     aHairlinePolyPolygon.transform(maCurrentTransformation);
1287 
1288                     if(bAntiAliased)
1289                     {
1290                         if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 1.0))
1291                         {
1292                             // line in range ]0.0 .. 1.0[
1293                             // paint as simple hairline
1294                             for(sal_uInt32 a(0); a < nCount; a++)
1295                             {
1296                                 mpOutputDevice->DrawPolyLine(aHairlinePolyPolygon.getB2DPolygon(a), 0.0);
1297                             }
1298 
1299                             bDone = true;
1300                         }
1301                         else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 2.0))
1302                         {
1303                             // line in range [1.0 .. 2.0[
1304                             // paint as 2x2 with dynamic line distance
1305                             basegfx::B2DHomMatrix aMat;
1306                             const double fDistance(fDiscreteLineWidth - 1.0);
1307                             const double fHalfDistance(fDistance * 0.5);
1308 
1309                             for(sal_uInt32 a(0); a < nCount; a++)
1310                             {
1311                                 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a));
1312 
1313                                 aMat.set(0, 2, -fHalfDistance);
1314                                 aMat.set(1, 2, -fHalfDistance);
1315                                 aCandidate.transform(aMat);
1316                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1317 
1318                                 aMat.set(0, 2, fDistance);
1319                                 aMat.set(1, 2, 0.0);
1320                                 aCandidate.transform(aMat);
1321                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1322 
1323                                 aMat.set(0, 2, 0.0);
1324                                 aMat.set(1, 2, fDistance);
1325                                 aCandidate.transform(aMat);
1326                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1327 
1328                                 aMat.set(0, 2, -fDistance);
1329                                 aMat.set(1, 2, 0.0);
1330                                 aCandidate.transform(aMat);
1331                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1332                             }
1333 
1334                             bDone = true;
1335                         }
1336                         else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 3.0))
1337                         {
1338                             // line in range [2.0 .. 3.0]
1339                             // paint as cross in a 3x3  with dynamic line distance
1340                             basegfx::B2DHomMatrix aMat;
1341                             const double fDistance((fDiscreteLineWidth - 1.0) * 0.5);
1342 
1343                             for(sal_uInt32 a(0); a < nCount; a++)
1344                             {
1345                                 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a));
1346 
1347                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1348 
1349                                 aMat.set(0, 2, -fDistance);
1350                                 aMat.set(1, 2, 0.0);
1351                                 aCandidate.transform(aMat);
1352                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1353 
1354                                 aMat.set(0, 2, fDistance);
1355                                 aMat.set(1, 2, -fDistance);
1356                                 aCandidate.transform(aMat);
1357                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1358 
1359                                 aMat.set(0, 2, fDistance);
1360                                 aMat.set(1, 2, fDistance);
1361                                 aCandidate.transform(aMat);
1362                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1363 
1364                                 aMat.set(0, 2, -fDistance);
1365                                 aMat.set(1, 2, fDistance);
1366                                 aCandidate.transform(aMat);
1367                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1368                             }
1369 
1370                             bDone = true;
1371                         }
1372                         else
1373                         {
1374                             // #i101491# line width above 3.0
1375                         }
1376                     }
1377                     else
1378                     {
1379                         if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 1.5))
1380                         {
1381                             // line width below 1.5, draw the basic hairline polygon
1382                             for(sal_uInt32 a(0); a < nCount; a++)
1383                             {
1384                                 mpOutputDevice->DrawPolyLine(aHairlinePolyPolygon.getB2DPolygon(a), 0.0);
1385                             }
1386 
1387                             bDone = true;
1388                         }
1389                         else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 2.5))
1390                         {
1391                             // line width is in range ]1.5 .. 2.5], use four hairlines
1392                             // drawn in a square
1393                             for(sal_uInt32 a(0); a < nCount; a++)
1394                             {
1395                                 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a));
1396                                 basegfx::B2DHomMatrix aMat;
1397 
1398                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1399 
1400                                 aMat.set(0, 2, 1.0);
1401                                 aMat.set(1, 2, 0.0);
1402                                 aCandidate.transform(aMat);
1403 
1404                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1405 
1406                                 aMat.set(0, 2, 0.0);
1407                                 aMat.set(1, 2, 1.0);
1408                                 aCandidate.transform(aMat);
1409 
1410                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1411 
1412                                 aMat.set(0, 2, -1.0);
1413                                 aMat.set(1, 2, 0.0);
1414                                 aCandidate.transform(aMat);
1415 
1416                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1417                             }
1418 
1419                             bDone = true;
1420                         }
1421                         else
1422                         {
1423                             // #i101491# line width is above 2.5
1424                         }
1425                     }
1426 
1427                     if(!bDone && rPolygonStrokeCandidate.getB2DPolygon().count() > 1000)
1428                     {
1429                         // #i101491# If the polygon complexity uses more than a given amount, do
1430                         // use OuputDevice::DrawPolyLine directly; this will avoid buffering all
1431                         // decompositions in primtives (memory) and fallback to old line painting
1432                         // for very complex polygons, too
1433                         for(sal_uInt32 a(0); a < nCount; a++)
1434                         {
1435                             mpOutputDevice->DrawPolyLine(
1436                                 aHairlinePolyPolygon.getB2DPolygon(a),
1437                                 fDiscreteLineWidth,
1438                                 rLineAttribute.getLineJoin(),
1439                                 rLineAttribute.getLineCap());
1440                         }
1441 
1442                         bDone = true;
1443                     }
1444                 }
1445             }
1446 
1447 			if(!bDone)
1448             {
1449                 // remeber that we enter a PolygonStrokePrimitive2D decomposition,
1450                 // used for AA thick line drawing
1451                 mnPolygonStrokePrimitive2D++;
1452 
1453                 // line width is big enough for standard filled polygon visualisation or zero
1454 				process(rPolygonStrokeCandidate.get2DDecomposition(getViewInformation2D()));
1455 
1456                 // leave PolygonStrokePrimitive2D
1457                 mnPolygonStrokePrimitive2D--;
1458             }
1459 		}
1460 
1461         void VclProcessor2D::RenderEpsPrimitive2D(const primitive2d::EpsPrimitive2D& rEpsPrimitive2D)
1462         {
1463             // The new decomposition of Metafiles made it necessary to add an Eps
1464             // primitive to handle embedded Eps data. On some devices, this can be
1465             // painted directly (mac, printer).
1466             // To be able to handle the replacement correctly, i need to handle it myself
1467             // since DrawEPS will not be able e.g. to rotate the replacement. To be able
1468             // to do that, i added a boolean return to OutputDevice::DrawEPS(..)
1469             // to know when EPS was handled directly already.
1470 			basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
1471             aRange.transform(maCurrentTransformation * rEpsPrimitive2D.getEpsTransform());
1472 
1473             if(!aRange.isEmpty())
1474             {
1475                 const Rectangle aRectangle(
1476 				    (sal_Int32)floor(aRange.getMinX()), (sal_Int32)floor(aRange.getMinY()),
1477 				    (sal_Int32)ceil(aRange.getMaxX()), (sal_Int32)ceil(aRange.getMaxY()));
1478 
1479                 if(!aRectangle.IsEmpty())
1480                 {
1481                     // try to paint EPS directly without fallback visualisation
1482                     const bool bEPSPaintedDirectly(mpOutputDevice->DrawEPS(
1483                         aRectangle.TopLeft(),
1484                         aRectangle.GetSize(),
1485                         rEpsPrimitive2D.getGfxLink(),
1486                         0));
1487 
1488                     if(!bEPSPaintedDirectly)
1489                     {
1490                         // use the decomposition which will correctly handle the
1491                         // fallback visualisation using full transformation (e.g. rotation)
1492         				process(rEpsPrimitive2D.get2DDecomposition(getViewInformation2D()));
1493                     }
1494                 }
1495             }
1496         }
1497 
1498         void VclProcessor2D::RenderSvgLinearAtomPrimitive2D(const primitive2d::SvgLinearAtomPrimitive2D& rCandidate)
1499         {
1500             const double fDelta(rCandidate.getOffsetB() - rCandidate.getOffsetA());
1501 
1502             if(basegfx::fTools::more(fDelta, 0.0))
1503             {
1504                 const basegfx::BColor aColorA(maBColorModifierStack.getModifiedColor(rCandidate.getColorA()));
1505                 const basegfx::BColor aColorB(maBColorModifierStack.getModifiedColor(rCandidate.getColorB()));
1506                 const double fDiscreteUnit((getViewInformation2D().getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0)).getLength());
1507 
1508                 // use color distance and discrete lengths to calculate step count
1509                 const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, fDelta, fDiscreteUnit));
1510 
1511                 // switch off line painting
1512                 mpOutputDevice->SetLineColor();
1513 
1514                 // prepare polygon in needed width at start position (with discrete overlap)
1515                 const basegfx::B2DPolygon aPolygon(
1516                     basegfx::tools::createPolygonFromRect(
1517                         basegfx::B2DRange(
1518                             rCandidate.getOffsetA() - fDiscreteUnit,
1519                             0.0,
1520                             rCandidate.getOffsetA() + (fDelta / nSteps) + fDiscreteUnit,
1521                             1.0)));
1522 
1523 
1524                 // prepare loop ([0.0 .. 1.0[)
1525                 double fUnitScale(0.0);
1526                 const double fUnitStep(1.0 / nSteps);
1527 
1528                 // loop and paint
1529                 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep)
1530                 {
1531                     basegfx::B2DPolygon aNew(aPolygon);
1532 
1533                     aNew.transform(maCurrentTransformation * basegfx::tools::createTranslateB2DHomMatrix(fDelta * fUnitScale, 0.0));
1534                     mpOutputDevice->SetFillColor(Color(basegfx::interpolate(aColorA, aColorB, fUnitScale)));
1535                     mpOutputDevice->DrawPolyPolygon(basegfx::B2DPolyPolygon(aNew));
1536                 }
1537             }
1538         }
1539 
1540         void VclProcessor2D::RenderSvgRadialAtomPrimitive2D(const primitive2d::SvgRadialAtomPrimitive2D& rCandidate)
1541         {
1542             const double fDeltaScale(rCandidate.getScaleB() - rCandidate.getScaleA());
1543 
1544             if(basegfx::fTools::more(fDeltaScale, 0.0))
1545             {
1546                 const basegfx::BColor aColorA(maBColorModifierStack.getModifiedColor(rCandidate.getColorA()));
1547                 const basegfx::BColor aColorB(maBColorModifierStack.getModifiedColor(rCandidate.getColorB()));
1548                 const double fDiscreteUnit((getViewInformation2D().getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0)).getLength());
1549 
1550                 // use color distance and discrete lengths to calculate step count
1551                 const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, fDeltaScale, fDiscreteUnit));
1552 
1553                 // switch off line painting
1554                 mpOutputDevice->SetLineColor();
1555 
1556                 // prepare loop ([0.0 .. 1.0[, full polygons, no polypolygons with holes)
1557                 double fUnitScale(0.0);
1558                 const double fUnitStep(1.0 / nSteps);
1559 
1560                 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep)
1561                 {
1562                     basegfx::B2DHomMatrix aTransform;
1563                     const double fEndScale(rCandidate.getScaleB() - (fDeltaScale * fUnitScale));
1564 
1565                     if(rCandidate.isTranslateSet())
1566                     {
1567                         const basegfx::B2DVector aTranslate(
1568                             basegfx::interpolate(
1569                                 rCandidate.getTranslateB(),
1570                                 rCandidate.getTranslateA(),
1571                                 fUnitScale));
1572 
1573                         aTransform = basegfx::tools::createScaleTranslateB2DHomMatrix(
1574                             fEndScale,
1575                             fEndScale,
1576                             aTranslate.getX(),
1577                             aTranslate.getY());
1578                     }
1579                     else
1580                     {
1581                         aTransform = basegfx::tools::createScaleB2DHomMatrix(
1582                             fEndScale,
1583                             fEndScale);
1584                     }
1585 
1586                     basegfx::B2DPolygon aNew(basegfx::tools::createPolygonFromUnitCircle());
1587 
1588                     aNew.transform(maCurrentTransformation * aTransform);
1589                     mpOutputDevice->SetFillColor(Color(basegfx::interpolate(aColorB, aColorA, fUnitScale)));
1590                     mpOutputDevice->DrawPolyPolygon(basegfx::B2DPolyPolygon(aNew));
1591                 }
1592             }
1593         }
1594 
1595 		void VclProcessor2D::adaptLineToFillDrawMode() const
1596 		{
1597 			const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode());
1598 
1599 			if(nOriginalDrawMode & (DRAWMODE_BLACKLINE|DRAWMODE_GRAYLINE|DRAWMODE_GHOSTEDLINE|DRAWMODE_WHITELINE|DRAWMODE_SETTINGSLINE))
1600 			{
1601 				sal_uInt32 nAdaptedDrawMode(nOriginalDrawMode);
1602 
1603 				if(nOriginalDrawMode & DRAWMODE_BLACKLINE)
1604 				{
1605 					nAdaptedDrawMode |= DRAWMODE_BLACKFILL;
1606 				}
1607 				else
1608 				{
1609 					nAdaptedDrawMode &= ~DRAWMODE_BLACKFILL;
1610 				}
1611 
1612 				if(nOriginalDrawMode & DRAWMODE_GRAYLINE)
1613 				{
1614 					nAdaptedDrawMode |= DRAWMODE_GRAYFILL;
1615 				}
1616 				else
1617 				{
1618 					nAdaptedDrawMode &= ~DRAWMODE_GRAYFILL;
1619 				}
1620 
1621 				if(nOriginalDrawMode & DRAWMODE_GHOSTEDLINE)
1622 				{
1623 					nAdaptedDrawMode |= DRAWMODE_GHOSTEDFILL;
1624 				}
1625 				else
1626 				{
1627 					nAdaptedDrawMode &= ~DRAWMODE_GHOSTEDFILL;
1628 				}
1629 
1630 				if(nOriginalDrawMode & DRAWMODE_WHITELINE)
1631 				{
1632 					nAdaptedDrawMode |= DRAWMODE_WHITEFILL;
1633 				}
1634 				else
1635 				{
1636 					nAdaptedDrawMode &= ~DRAWMODE_WHITEFILL;
1637 				}
1638 
1639 				if(nOriginalDrawMode & DRAWMODE_SETTINGSLINE)
1640 				{
1641 					nAdaptedDrawMode |= DRAWMODE_SETTINGSFILL;
1642 				}
1643 				else
1644 				{
1645 					nAdaptedDrawMode &= ~DRAWMODE_SETTINGSFILL;
1646 				}
1647 
1648 				mpOutputDevice->SetDrawMode(nAdaptedDrawMode);
1649 			}
1650 		}
1651 
1652 		void VclProcessor2D::adaptTextToFillDrawMode() const
1653 		{
1654 			const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode());
1655 			if(nOriginalDrawMode & (DRAWMODE_BLACKTEXT|DRAWMODE_GRAYTEXT|DRAWMODE_GHOSTEDTEXT|DRAWMODE_WHITETEXT|DRAWMODE_SETTINGSTEXT))
1656 			{
1657 				sal_uInt32 nAdaptedDrawMode(nOriginalDrawMode);
1658 
1659 				if(nOriginalDrawMode & DRAWMODE_BLACKTEXT)
1660 				{
1661 					nAdaptedDrawMode |= DRAWMODE_BLACKFILL;
1662 				}
1663 				else
1664 				{
1665 					nAdaptedDrawMode &= ~DRAWMODE_BLACKFILL;
1666 				}
1667 
1668 				if(nOriginalDrawMode & DRAWMODE_GRAYTEXT)
1669 				{
1670 					nAdaptedDrawMode |= DRAWMODE_GRAYFILL;
1671 				}
1672 				else
1673 				{
1674 					nAdaptedDrawMode &= ~DRAWMODE_GRAYFILL;
1675 				}
1676 
1677 				if(nOriginalDrawMode & DRAWMODE_GHOSTEDTEXT)
1678 				{
1679 					nAdaptedDrawMode |= DRAWMODE_GHOSTEDFILL;
1680 				}
1681 				else
1682 				{
1683 					nAdaptedDrawMode &= ~DRAWMODE_GHOSTEDFILL;
1684 				}
1685 
1686 				if(nOriginalDrawMode & DRAWMODE_WHITETEXT)
1687 				{
1688 					nAdaptedDrawMode |= DRAWMODE_WHITEFILL;
1689 				}
1690 				else
1691 				{
1692 					nAdaptedDrawMode &= ~DRAWMODE_WHITEFILL;
1693 				}
1694 
1695 				if(nOriginalDrawMode & DRAWMODE_SETTINGSTEXT)
1696 				{
1697 					nAdaptedDrawMode |= DRAWMODE_SETTINGSFILL;
1698 				}
1699 				else
1700 				{
1701 					nAdaptedDrawMode &= ~DRAWMODE_SETTINGSFILL;
1702 				}
1703 
1704 				mpOutputDevice->SetDrawMode(nAdaptedDrawMode);
1705 			}
1706 		}
1707 
1708 		//////////////////////////////////////////////////////////////////////////////
1709 		// process support
1710 
1711 		VclProcessor2D::VclProcessor2D(
1712 			const geometry::ViewInformation2D& rViewInformation,
1713 			OutputDevice& rOutDev)
1714 		:	BaseProcessor2D(rViewInformation),
1715 			mpOutputDevice(&rOutDev),
1716 			maBColorModifierStack(),
1717 			maCurrentTransformation(),
1718 			maDrawinglayerOpt(),
1719             mnPolygonStrokePrimitive2D(0)
1720 		{
1721             // set digit language, derived from SvtCTLOptions to have the correct
1722             // number display for arabic/hindi numerals
1723             const SvtCTLOptions aSvtCTLOptions;
1724             LanguageType eLang(LANGUAGE_SYSTEM);
1725 
1726             if(SvtCTLOptions::NUMERALS_HINDI == aSvtCTLOptions.GetCTLTextNumerals())
1727             {
1728                 eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
1729             }
1730             else if(SvtCTLOptions::NUMERALS_ARABIC == aSvtCTLOptions.GetCTLTextNumerals())
1731             {
1732                 eLang = LANGUAGE_ENGLISH;
1733             }
1734             else
1735             {
1736                 eLang = (LanguageType)Application::GetSettings().GetLanguage();
1737             }
1738 
1739             rOutDev.SetDigitLanguage(eLang);
1740 		}
1741 
1742 		VclProcessor2D::~VclProcessor2D()
1743 		{
1744 		}
1745 	} // end of namespace processor2d
1746 } // end of namespace drawinglayer
1747 
1748 //////////////////////////////////////////////////////////////////////////////
1749 // eof
1750