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                 // #121387# when mirrored and rotated, avoid the GraphicManager output which has low quality
428                 const bool bRotated(basegfx::fTools::equalZero(fRotate));
429                 const bool bSheared(basegfx::fTools::equalZero(fShearX));
430                 const bool bMirroredAndRotated(bRotated && (aScale.getX() < 0.0 || aScale.getY() < 0.0));
431 
432 				if(!bForceUseOfOwnTransformer && !bSheared && !bMirroredAndRotated)
433 				{
434 					if(!bUseGraphicManager && !bRotated)
435 					{
436 						RenderBitmapPrimitive2D_BitmapEx(*mpOutputDevice, aBitmapEx, aLocalTransform);
437 					}
438 					else
439 					{
440 						RenderBitmapPrimitive2D_GraphicManager(*mpOutputDevice, aBitmapEx, aLocalTransform);
441 					}
442 				}
443 				else
444 				{
445 					if(!aBitmapEx.IsTransparent() && (bSheared || bRotated))
446 					{
447 						// parts will be uncovered, extend aBitmapEx with a mask bitmap
448 						const Bitmap aContent(aBitmapEx.GetBitmap());
449 						aBitmapEx = BitmapEx(aContent, Bitmap(aContent.GetSizePixel(), 1));
450 					}
451 
452 					RenderBitmapPrimitive2D_self(*mpOutputDevice, aBitmapEx, aLocalTransform);
453 				}
454 			}
455 		}
456 
457 		void VclProcessor2D::RenderFillGraphicPrimitive2D(const primitive2d::FillGraphicPrimitive2D& rFillBitmapCandidate)
458 		{
459 			const attribute::FillGraphicAttribute& rFillGraphicAttribute(rFillBitmapCandidate.getFillGraphic());
460 			bool bPrimitiveAccepted(false);
461             static bool bTryTilingDirect = true;
462 
463             // #121194# when tiling is used and content is bitmap-based, do direct tiling in the
464             // renderer on pixel base to ensure tight fitting. Do not do this when
465             // the fill is rotated or sheared.
466 
467             // ovveride static bool (for debug) and tiling is active
468 			if(bTryTilingDirect && rFillGraphicAttribute.getTiling())
469 			{
470                 // content is bitmap(ex)
471                 //
472                 // for SVG support, force decomposition when SVG is present. This will lead to use
473                 // the primitive representation of the svg directly.
474                 //
475                 // when graphic is animated, force decomposition to use the correct graphic, else
476                 // fill style will not be animated
477                 if(GRAPHIC_BITMAP == rFillGraphicAttribute.getGraphic().GetType()
478                     && !rFillGraphicAttribute.getGraphic().getSvgData().get()
479                     && !rFillGraphicAttribute.getGraphic().IsAnimated())
480                 {
481 				    // decompose matrix to check for shear, rotate and mirroring
482 				    basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rFillBitmapCandidate.getTransformation());
483 				    basegfx::B2DVector aScale, aTranslate;
484 				    double fRotate, fShearX;
485 				    aLocalTransform.decompose(aScale, aTranslate, fRotate, fShearX);
486 
487                     // when nopt rotated/sheared
488 				    if(basegfx::fTools::equalZero(fRotate) && basegfx::fTools::equalZero(fShearX))
489 				    {
490 					    // no shear or rotate, draw direct in pixel coordinates
491 					    bPrimitiveAccepted = true;
492 
493                         // transform object range to device coordinates (pixels). Use
494                         // the device transformation for better accuracy
495                         basegfx::B2DRange aObjectRange(aTranslate, aTranslate + aScale);
496                         aObjectRange.transform(mpOutputDevice->GetViewTransformation());
497 
498                         // extract discrete size of object
499                         const sal_Int32 nOWidth(basegfx::fround(aObjectRange.getWidth()));
500                         const sal_Int32 nOHeight(basegfx::fround(aObjectRange.getHeight()));
501 
502                         // only do something when object has a size in discrete units
503 						if(nOWidth > 0 && nOHeight > 0)
504 						{
505                             // transform graphic range to device coordinates (pixels). Use
506                             // the device transformation for better accuracy
507                             basegfx::B2DRange aGraphicRange(rFillGraphicAttribute.getGraphicRange());
508                             aGraphicRange.transform(mpOutputDevice->GetViewTransformation() * aLocalTransform);
509 
510                             // extract discrete size of graphic
511                             const sal_Int32 nBWidth(basegfx::fround(aGraphicRange.getWidth()));
512                             const sal_Int32 nBHeight(basegfx::fround(aGraphicRange.getHeight()));
513 
514                             // only do something when bitmap fill has a size in discrete units
515 						    if(nBWidth > 0 && nBHeight > 0)
516 						    {
517 						        // nBWidth, nBHeight is the pixel size of the neede bitmap. To not need to scale it
518 						        // in vcl many times, create a size-optimized version
519 						        const Size aNeededBitmapSizePixel(nBWidth, nBHeight);
520                                 BitmapEx aBitmapEx(rFillGraphicAttribute.getGraphic().GetBitmapEx());
521                                 static bool bEnablePreScaling(true);
522                                 const bool bPreScaled(bEnablePreScaling && nBWidth * nBHeight < (250 * 250));
523 
524                                 if(bPreScaled)
525                                 {
526                                     // ... but only up to a maximum size, else it gets too expensive
527                                     aBitmapEx.Scale(aNeededBitmapSizePixel, BMP_SCALE_INTERPOLATE);
528                                 }
529 
530 					            bool bPainted(false);
531 
532 					            if(maBColorModifierStack.count())
533 					            {
534                                     // when color modifier, apply to bitmap
535 						            aBitmapEx = impModifyBitmapEx(maBColorModifierStack, aBitmapEx);
536 
537                                     // impModifyBitmapEx uses empty bitmap as sign to return that
538                                     // the content will be completely replaced to mono color, use shortcut
539 						            if(aBitmapEx.IsEmpty())
540 						            {
541 							            // color gets completely replaced, get it
542 							            const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(basegfx::BColor()));
543 							            basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
544 							            aPolygon.transform(aLocalTransform);
545 
546 							            mpOutputDevice->SetFillColor(Color(aModifiedColor));
547 							            mpOutputDevice->SetLineColor();
548 							            mpOutputDevice->DrawPolygon(aPolygon);
549 
550 							            bPainted = true;
551 						            }
552 					            }
553 
554 					            if(!bPainted)
555 					            {
556                                     sal_Int32 nBLeft(basegfx::fround(aGraphicRange.getMinX()));
557                                     sal_Int32 nBTop(basegfx::fround(aGraphicRange.getMinY()));
558                                     const sal_Int32 nOLeft(basegfx::fround(aObjectRange.getMinX()));
559                                     const sal_Int32 nOTop(basegfx::fround(aObjectRange.getMinY()));
560                                     sal_Int32 nPosX(0);
561                                     sal_Int32 nPosY(0);
562 
563 						            if(nBLeft > nOLeft)
564 						            {
565                                         const sal_Int32 nDiff((nBLeft / nBWidth) + 1);
566 
567                                         nPosX -= nDiff;
568 							            nBLeft -= nDiff * nBWidth;
569 						            }
570 
571 						            if(nBLeft + nBWidth <= nOLeft)
572 						            {
573                                         const sal_Int32 nDiff(-nBLeft / nBWidth);
574 
575                                         nPosX += nDiff;
576 							            nBLeft += nDiff * nBWidth;
577 						            }
578 
579 						            if(nBTop > nOTop)
580 						            {
581                                         const sal_Int32 nDiff((nBTop / nBHeight) + 1);
582 
583                                         nPosY -= nDiff;
584 							            nBTop -= nDiff * nBHeight;
585 						            }
586 
587 						            if(nBTop + nBHeight <= nOTop)
588 						            {
589                                         const sal_Int32 nDiff(-nBTop / nBHeight);
590 
591                                         nPosY += nDiff;
592 							            nBTop += nDiff * nBHeight;
593 						            }
594 
595 						            // prepare OutDev
596 						            const Point aEmptyPoint(0, 0);
597 						            const Rectangle aVisiblePixel(aEmptyPoint, mpOutputDevice->GetOutputSizePixel());
598 						            const bool bWasEnabled(mpOutputDevice->IsMapModeEnabled());
599 						            mpOutputDevice->EnableMapMode(false);
600 
601                                     // check if offset is used
602                                     const sal_Int32 nOffsetX(basegfx::fround(rFillGraphicAttribute.getOffsetX() * nBWidth));
603 
604                                     if(nOffsetX)
605                                     {
606                                         // offset in X, so iterate over Y first and draw lines
607                                         for(sal_Int32 nYPos(nBTop); nYPos < nOTop + nOHeight; nYPos += nBHeight, nPosY++)
608                                         {
609                                             for(sal_Int32 nXPos(nPosY % 2 ? nBLeft - nBWidth + nOffsetX : nBLeft);
610                                                 nXPos < nOLeft + nOWidth; nXPos += nBWidth)
611                                             {
612                                                 const Rectangle aOutRectPixel(Point(nXPos, nYPos), aNeededBitmapSizePixel);
613 
614                                                 if(aOutRectPixel.IsOver(aVisiblePixel))
615                                                 {
616                                                     if(bPreScaled)
617                                                     {
618                                                         mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aBitmapEx);
619                                                     }
620                                                     else
621                                                     {
622                                                         mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aNeededBitmapSizePixel, aBitmapEx);
623                                                     }
624                                                 }
625                                             }
626                                         }
627                                     }
628                                     else
629                                     {
630                                         // check if offset is used
631                                         const sal_Int32 nOffsetY(basegfx::fround(rFillGraphicAttribute.getOffsetY() * nBHeight));
632 
633                                         // possible offset in Y, so iterate over X first and draw columns
634                                         for(sal_Int32 nXPos(nBLeft); nXPos < nOLeft + nOWidth; nXPos += nBWidth, nPosX++)
635                                         {
636                                             for(sal_Int32 nYPos(nPosX % 2 ? nBTop - nBHeight + nOffsetY : nBTop);
637                                                 nYPos < nOTop + nOHeight; nYPos += nBHeight)
638                                             {
639                                                 const Rectangle aOutRectPixel(Point(nXPos, nYPos), aNeededBitmapSizePixel);
640 
641                                                 if(aOutRectPixel.IsOver(aVisiblePixel))
642                                                 {
643                                                     if(bPreScaled)
644                                                     {
645                                                         mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aBitmapEx);
646                                                     }
647                                                     else
648                                                     {
649                                                         mpOutputDevice->DrawBitmapEx(aOutRectPixel.TopLeft(), aNeededBitmapSizePixel, aBitmapEx);
650                                                     }
651                                                 }
652                                             }
653                                         }
654                                     }
655 
656 						            // restore OutDev
657 						            mpOutputDevice->EnableMapMode(bWasEnabled);
658                                 }
659                             }
660                         }
661 				    }
662 			    }
663             }
664 
665 			if(!bPrimitiveAccepted)
666 			{
667 				// do not accept, use decomposition
668 				process(rFillBitmapCandidate.get2DDecomposition(getViewInformation2D()));
669 			}
670 		}
671 
672 		// direct draw of gradient
673 		void VclProcessor2D::RenderPolyPolygonGradientPrimitive2D(const primitive2d::PolyPolygonGradientPrimitive2D& rPolygonCandidate)
674 		{
675 			const attribute::FillGradientAttribute& rGradient(rPolygonCandidate.getFillGradient());
676 			basegfx::BColor aStartColor(maBColorModifierStack.getModifiedColor(rGradient.getStartColor()));
677 			basegfx::BColor aEndColor(maBColorModifierStack.getModifiedColor(rGradient.getEndColor()));
678 			basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
679 
680 			if(aLocalPolyPolygon.count())
681 			{
682 				aLocalPolyPolygon.transform(maCurrentTransformation);
683 
684 				if(aStartColor == aEndColor)
685 				{
686 					// no gradient at all, draw as polygon in AA and non-AA case
687 					mpOutputDevice->SetLineColor();
688 					mpOutputDevice->SetFillColor(Color(aStartColor));
689 					mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon);
690 				}
691 				else if(getOptionsDrawinglayer().IsAntiAliasing())
692 				{
693 					// For AA, direct render has to be avoided since it uses XOR maskings which will not
694 					// work with AA. Instead, the decompose which uses MaskPrimitive2D with fillings is
695 					// used
696 					process(rPolygonCandidate.get2DDecomposition(getViewInformation2D()));
697 				}
698 				else
699 				{
700                     static bool bSimple = false; // allow testing simple paint in debugger
701 
702                     impDrawGradientToOutDev(
703 						*mpOutputDevice, aLocalPolyPolygon, rGradient.getStyle(), rGradient.getSteps(),
704 						aStartColor, aEndColor, rGradient.getBorder(),
705 						rGradient.getAngle(), rGradient.getOffsetX(), rGradient.getOffsetY(), bSimple);
706 				}
707 			}
708 		}
709 
710 		// direct draw of Graphic
711 		void VclProcessor2D::RenderPolyPolygonGraphicPrimitive2D(const primitive2d::PolyPolygonGraphicPrimitive2D& rPolygonCandidate)
712 		{
713             bool bDone(false);
714             const basegfx::B2DPolyPolygon& rPolyPolygon = rPolygonCandidate.getB2DPolyPolygon();
715 
716             // #121194# Todo: check if this works
717             if(!rPolyPolygon.count())
718             {
719                 // empty polyPolygon, done
720                 bDone = true;
721             }
722             else
723             {
724                 const attribute::FillGraphicAttribute& rFillGraphicAttribute = rPolygonCandidate.getFillGraphic();
725 
726                 // try to catch cases where the graphic will be color-modified to a single
727                 // color (e.g. shadow)
728                 switch(rFillGraphicAttribute.getGraphic().GetType())
729                 {
730                     case GRAPHIC_GDIMETAFILE:
731                     {
732                         // metafiles are potentially transparent, cannot optimize�, not done
733                         break;
734                     }
735                     case GRAPHIC_BITMAP:
736                     {
737                         if(!rFillGraphicAttribute.getGraphic().IsTransparent() && !rFillGraphicAttribute.getGraphic().IsAlpha())
738                         {
739                             // bitmap is not transparent and has no alpha
740                             const sal_uInt32 nBColorModifierStackCount(maBColorModifierStack.count());
741 
742                             if(nBColorModifierStackCount)
743                             {
744                                 const basegfx::BColorModifier& rTopmostModifier = maBColorModifierStack.getBColorModifier(nBColorModifierStackCount - 1);
745 
746                                 if(basegfx::BCOLORMODIFYMODE_REPLACE == rTopmostModifier.getMode())
747                                 {
748                                     // the bitmap fill is in unified color, so we can replace it with
749                                     // a single polygon fill. The form of the fill depends on tiling
750                                     if(rFillGraphicAttribute.getTiling())
751                                     {
752                                         // with tiling, fill the whole PolyPolygon with the modifier color
753                                         basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolyPolygon);
754 
755                                         aLocalPolyPolygon.transform(maCurrentTransformation);
756                                         mpOutputDevice->SetLineColor();
757                                         mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor()));
758                                         mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon);
759                                     }
760                                     else
761                                     {
762                                         // without tiling, only the area common to the bitmap tile and the
763                                         // PolyPolygon is filled. Create the bitmap tile area in object
764                                         // coordinates. For this, the object transformation needs to be created
765                                         // from the already scaled PolyPolygon. The tile area in object
766                                         // coordinates wil always be non-rotated, so it's not necessary to
767                                         // work with a polygon here
768                                         basegfx::B2DRange aTileRange(rFillGraphicAttribute.getGraphicRange());
769                                         const basegfx::B2DRange aPolyPolygonRange(rPolyPolygon.getB2DRange());
770                                         const basegfx::B2DHomMatrix aNewObjectTransform(
771                                             basegfx::tools::createScaleTranslateB2DHomMatrix(
772                                                 aPolyPolygonRange.getRange(),
773                                                 aPolyPolygonRange.getMinimum()));
774 
775                                         aTileRange.transform(aNewObjectTransform);
776 
777                                         // now clip the object polyPolygon against the tile range
778                                         // to get the common area
779                                         basegfx::B2DPolyPolygon aTarget = basegfx::tools::clipPolyPolygonOnRange(
780                                             rPolyPolygon,
781                                             aTileRange,
782                                             true,
783                                             false);
784 
785                                         if(aTarget.count())
786                                         {
787                                             aTarget.transform(maCurrentTransformation);
788                                             mpOutputDevice->SetLineColor();
789                                             mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor()));
790                                             mpOutputDevice->DrawPolyPolygon(aTarget);
791                                         }
792                                     }
793 
794                                     // simplified output executed, we are done
795                                     bDone = true;
796                                 }
797                             }
798                         }
799                         break;
800                     }
801                     default: //GRAPHIC_NONE, GRAPHIC_DEFAULT
802                     {
803                         // empty graphic, we are done
804                         bDone = true;
805                         break;
806                     }
807                 }
808             }
809 
810             if(!bDone)
811             {
812                 // use default decomposition
813                 process(rPolygonCandidate.get2DDecomposition(getViewInformation2D()));
814             }
815         }
816 
817 		// direct draw of PolyPolygon with color
818 		void VclProcessor2D::RenderPolyPolygonColorPrimitive2D(const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate)
819 		{
820 			const basegfx::BColor aPolygonColor(maBColorModifierStack.getModifiedColor(rPolygonCandidate.getBColor()));
821 			mpOutputDevice->SetFillColor(Color(aPolygonColor));
822 			mpOutputDevice->SetLineColor();
823 
824 			basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
825 			aLocalPolyPolygon.transform(maCurrentTransformation);
826 
827             static bool bCheckTrapezoidDecomposition(false);
828             static bool bShowOutlinesThere(false);
829             if(bCheckTrapezoidDecomposition)
830             {
831                 // clip against discrete ViewPort
832                 const basegfx::B2DRange& rDiscreteViewport = getViewInformation2D().getDiscreteViewport();
833                 aLocalPolyPolygon = basegfx::tools::clipPolyPolygonOnRange(
834                     aLocalPolyPolygon, rDiscreteViewport, true, false);
835 
836                 if(aLocalPolyPolygon.count())
837                 {
838                     // subdivide
839                     aLocalPolyPolygon = basegfx::tools::adaptiveSubdivideByDistance(
840                         aLocalPolyPolygon, 0.5);
841 
842                     // trapezoidize
843                     basegfx::B2DTrapezoidVector aB2DTrapezoidVector;
844                     basegfx::tools::trapezoidSubdivide(aB2DTrapezoidVector, aLocalPolyPolygon);
845 
846                     const sal_uInt32 nCount(aB2DTrapezoidVector.size());
847 
848                     if(nCount)
849                     {
850                         basegfx::BColor aInvPolygonColor(aPolygonColor);
851                         aInvPolygonColor.invert();
852 
853                         for(sal_uInt32 a(0); a < nCount; a++)
854                         {
855                             const basegfx::B2DPolygon aTempPolygon(aB2DTrapezoidVector[a].getB2DPolygon());
856 
857                             if(bShowOutlinesThere)
858                             {
859                                 mpOutputDevice->SetFillColor(Color(aPolygonColor));
860 			                    mpOutputDevice->SetLineColor();
861                             }
862 
863                             mpOutputDevice->DrawPolygon(aTempPolygon);
864 
865                             if(bShowOutlinesThere)
866                             {
867                                 mpOutputDevice->SetFillColor();
868         		                mpOutputDevice->SetLineColor(Color(aInvPolygonColor));
869     	    		            mpOutputDevice->DrawPolyLine(aTempPolygon, 0.0);
870                             }
871                         }
872                     }
873                 }
874             }
875             else
876             {
877 			    mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon);
878 
879                 if(mnPolygonStrokePrimitive2D
880                     && getOptionsDrawinglayer().IsAntiAliasing()
881                     && (mpOutputDevice->GetAntialiasing() & ANTIALIASING_ENABLE_B2DDRAW))
882                 {
883                     // when AA is on and this filled polygons are the result of stroked line geometry,
884                     // draw the geometry once extra as lines to avoid AA 'gaps' between partial polygons
885 			        mpOutputDevice->SetFillColor();
886 			        mpOutputDevice->SetLineColor(Color(aPolygonColor));
887                     const sal_uInt32 nCount(aLocalPolyPolygon.count());
888 
889                     for(sal_uInt32 a(0); a < nCount; a++)
890                     {
891                         mpOutputDevice->DrawPolyLine(aLocalPolyPolygon.getB2DPolygon(a), 0.0);
892                     }
893                 }
894             }
895 		}
896 
897 		// direct draw of MetaFile
898 		void VclProcessor2D::RenderMetafilePrimitive2D(const primitive2d::MetafilePrimitive2D& rMetaCandidate)
899 		{
900 			// decompose matrix to check for shear, rotate and mirroring
901 			basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rMetaCandidate.getTransform());
902 			basegfx::B2DVector aScale, aTranslate;
903 			double fRotate, fShearX;
904 			aLocalTransform.decompose(aScale, aTranslate, fRotate, fShearX);
905 
906 			if(basegfx::fTools::less(aScale.getX(), 0.0) && basegfx::fTools::less(aScale.getY(), 0.0))
907 			{
908 				// #i102175# handle special case: If scale is negative in (x,y) (3rd quadrant), it can
909 				// be expressed as rotation by PI. This needs to be done for Metafiles since
910                 // these can be rotated, but not really mirrored
911 				aScale = basegfx::absolute(aScale);
912 				fRotate += F_PI;
913 			}
914 
915             // get BoundRect
916 			basegfx::B2DRange aOutlineRange(rMetaCandidate.getB2DRange(getViewInformation2D()));
917 			aOutlineRange.transform(maCurrentTransformation);
918 
919 			// Due to the integer MapModes used from VCL aind inside MetaFiles errors of up to three
920 			// pixels in size may happen. As long as there is no better way (e.g. convert the MetaFile
921 			// to primitives) it is necessary to reduce maximum pixel size by 1 in X and Y and to use
922 			// the inner pixel bounds accordingly (ceil resp. floor). This will also be done for logic
923 			// units e.g. when creating a new MetaFile, but since much huger value ranges are used
924 			// there typically will be okay for this compromize.
925 			Rectangle aDestRectView(
926                 // !!CAUTION!! Here, ceil and floor are exchanged BY PURPOSE, do NOT copy when
927                 // looking for a standard conversion to rectangle (!)
928 				(sal_Int32)ceil(aOutlineRange.getMinX()), (sal_Int32)ceil(aOutlineRange.getMinY()),
929 				(sal_Int32)floor(aOutlineRange.getMaxX()), (sal_Int32)floor(aOutlineRange.getMaxY()));
930 
931 			// get metafile (copy it)
932 			GDIMetaFile aMetaFile;
933 
934 			if(maBColorModifierStack.count())
935 			{
936 				const basegfx::BColor aRGBBaseColor(0, 0, 0);
937 				const basegfx::BColor aRGBColor(maBColorModifierStack.getModifiedColor(aRGBBaseColor));
938 				aMetaFile = rMetaCandidate.getMetaFile().GetMonochromeMtf(Color(aRGBColor));
939 			}
940 			else
941 			{
942 				aMetaFile = rMetaCandidate.getMetaFile();
943 			}
944 
945 			// rotation
946 			if(!basegfx::fTools::equalZero(fRotate))
947 			{
948                 // #i103530#
949                 // MetaFile::Rotate has no input parameter check, so the parameter needs to be
950                 // well-aligned to the old range [0..3600] 10th degrees with inverse orientation
951 				sal_Int16 nRotation((sal_Int16)((fRotate / F_PI180) * -10.0));
952 
953                 while(nRotation < 0)
954                     nRotation += 3600;
955 
956                 while(nRotation >= 3600)
957                     nRotation -= 3600;
958 
959 				aMetaFile.Rotate(nRotation);
960 			}
961 
962 			// Prepare target output size
963 			Size aDestSize(aDestRectView.GetSize());
964 
965 			if(aDestSize.getWidth() && aDestSize.getHeight())
966 			{
967 				// Get preferred Metafile output size. When it's very equal to the output size, it's probably
968 				// a rounding error somewhere, so correct it to get a 1:1 output without single pixel scalings
969 				// of the Metafile (esp. for contaned Bitmaps, e.g 3D charts)
970 				const Size aPrefSize(mpOutputDevice->LogicToPixel(aMetaFile.GetPrefSize(), aMetaFile.GetPrefMapMode()));
971 
972 				if(aPrefSize.getWidth() && (aPrefSize.getWidth() - 1 == aDestSize.getWidth() || aPrefSize.getWidth() + 1 == aDestSize.getWidth()))
973 				{
974 					aDestSize.setWidth(aPrefSize.getWidth());
975 				}
976 
977 				if(aPrefSize.getHeight() && (aPrefSize.getHeight() - 1 == aDestSize.getHeight() || aPrefSize.getHeight() + 1 == aDestSize.getHeight()))
978 				{
979 					aDestSize.setHeight(aPrefSize.getHeight());
980 				}
981 
982 				// paint it
983 				aMetaFile.WindStart();
984 				aMetaFile.Play(mpOutputDevice, aDestRectView.TopLeft(), aDestSize);
985 			}
986 		}
987 
988 		// mask group. Force output to VDev and create mask from given mask
989 		void VclProcessor2D::RenderMaskPrimitive2DPixel(const primitive2d::MaskPrimitive2D& rMaskCandidate)
990 		{
991 			if(rMaskCandidate.getChildren().hasElements())
992 			{
993 				basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
994 
995 				if(aMask.count())
996 				{
997 					aMask.transform(maCurrentTransformation);
998 					const basegfx::B2DRange aRange(basegfx::tools::getRange(aMask));
999 					impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true);
1000 
1001 					if(aBufferDevice.isVisible())
1002 					{
1003 						// remember last OutDev and set to content
1004 						OutputDevice* pLastOutputDevice = mpOutputDevice;
1005 						mpOutputDevice = &aBufferDevice.getContent();
1006 
1007 						// paint to it
1008 						process(rMaskCandidate.getChildren());
1009 
1010 						// back to old OutDev
1011 						mpOutputDevice = pLastOutputDevice;
1012 
1013 					    // draw mask
1014                         if(getOptionsDrawinglayer().IsAntiAliasing())
1015                         {
1016                             // with AA, use 8bit AlphaMask to get nice borders
1017 						    VirtualDevice& rTransparence = aBufferDevice.getTransparence();
1018 						    rTransparence.SetLineColor();
1019 						    rTransparence.SetFillColor(COL_BLACK);
1020 						    rTransparence.DrawPolyPolygon(aMask);
1021 
1022 						    // dump buffer to outdev
1023 						    aBufferDevice.paint();
1024                         }
1025                         else
1026                         {
1027                             // No AA, use 1bit mask
1028 						    VirtualDevice& rMask = aBufferDevice.getMask();
1029 						    rMask.SetLineColor();
1030 						    rMask.SetFillColor(COL_BLACK);
1031 						    rMask.DrawPolyPolygon(aMask);
1032 
1033 						    // dump buffer to outdev
1034 						    aBufferDevice.paint();
1035                         }
1036 					}
1037 				}
1038 			}
1039 		}
1040 
1041 		// modified color group. Force output to unified color.
1042 		void VclProcessor2D::RenderModifiedColorPrimitive2D(const primitive2d::ModifiedColorPrimitive2D& rModifiedCandidate)
1043 		{
1044 			if(rModifiedCandidate.getChildren().hasElements())
1045 			{
1046 				maBColorModifierStack.push(rModifiedCandidate.getColorModifier());
1047 				process(rModifiedCandidate.getChildren());
1048 				maBColorModifierStack.pop();
1049 			}
1050 		}
1051 
1052 		// unified sub-transparence. Draw to VDev first.
1053 		void VclProcessor2D::RenderUnifiedTransparencePrimitive2D(const primitive2d::UnifiedTransparencePrimitive2D& rTransCandidate)
1054 		{
1055             static bool bForceToDecomposition(false);
1056 
1057             if(rTransCandidate.getChildren().hasElements())
1058             {
1059                 if(bForceToDecomposition)
1060                 {
1061     			    // use decomposition
1062 	    		    process(rTransCandidate.get2DDecomposition(getViewInformation2D()));
1063                 }
1064                 else
1065                 {
1066 			        if(0.0 == rTransCandidate.getTransparence())
1067 			        {
1068 				        // no transparence used, so just use the content
1069     	    		    process(rTransCandidate.getChildren());
1070 			        }
1071 			        else if(rTransCandidate.getTransparence() > 0.0 && rTransCandidate.getTransparence() < 1.0)
1072 			        {
1073                         // transparence is in visible range
1074 				        basegfx::B2DRange aRange(primitive2d::getB2DRangeFromPrimitive2DSequence(rTransCandidate.getChildren(), getViewInformation2D()));
1075 				        aRange.transform(maCurrentTransformation);
1076 				        impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true);
1077 
1078 				        if(aBufferDevice.isVisible())
1079 				        {
1080 					        // remember last OutDev and set to content
1081 					        OutputDevice* pLastOutputDevice = mpOutputDevice;
1082 					        mpOutputDevice = &aBufferDevice.getContent();
1083 
1084 					        // paint content to it
1085 					        process(rTransCandidate.getChildren());
1086 
1087 					        // back to old OutDev
1088 					        mpOutputDevice = pLastOutputDevice;
1089 
1090 					        // dump buffer to outdev using given transparence
1091 					        aBufferDevice.paint(rTransCandidate.getTransparence());
1092 				        }
1093 			        }
1094                 }
1095             }
1096 		}
1097 
1098 		// sub-transparence group. Draw to VDev first.
1099 		void VclProcessor2D::RenderTransparencePrimitive2D(const primitive2d::TransparencePrimitive2D& rTransCandidate)
1100 		{
1101 			if(rTransCandidate.getChildren().hasElements())
1102 			{
1103 				basegfx::B2DRange aRange(primitive2d::getB2DRangeFromPrimitive2DSequence(rTransCandidate.getChildren(), getViewInformation2D()));
1104 				aRange.transform(maCurrentTransformation);
1105 				impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true);
1106 
1107 				if(aBufferDevice.isVisible())
1108 				{
1109 					// remember last OutDev and set to content
1110 					OutputDevice* pLastOutputDevice = mpOutputDevice;
1111 					mpOutputDevice = &aBufferDevice.getContent();
1112 
1113 					// paint content to it
1114 					process(rTransCandidate.getChildren());
1115 
1116 					// set to mask
1117 					mpOutputDevice = &aBufferDevice.getTransparence();
1118 
1119 					// when painting transparence masks, reset the color stack
1120 					basegfx::BColorModifierStack aLastBColorModifierStack(maBColorModifierStack);
1121 					maBColorModifierStack = basegfx::BColorModifierStack();
1122 
1123 					// paint mask to it (always with transparence intensities, evtl. with AA)
1124 					process(rTransCandidate.getTransparence());
1125 
1126 					// back to old color stack
1127 					maBColorModifierStack = aLastBColorModifierStack;
1128 
1129 					// back to old OutDev
1130 					mpOutputDevice = pLastOutputDevice;
1131 
1132 					// dump buffer to outdev
1133 					aBufferDevice.paint();
1134 				}
1135 			}
1136 		}
1137 
1138 		// transform group.
1139 		void VclProcessor2D::RenderTransformPrimitive2D(const primitive2d::TransformPrimitive2D& rTransformCandidate)
1140 		{
1141 			// remember current transformation and ViewInformation
1142 			const basegfx::B2DHomMatrix aLastCurrentTransformation(maCurrentTransformation);
1143             const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
1144 
1145 			// create new transformations for CurrentTransformation
1146             // and for local ViewInformation2D
1147 			maCurrentTransformation = maCurrentTransformation * rTransformCandidate.getTransformation();
1148             const geometry::ViewInformation2D aViewInformation2D(
1149                 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
1150                 getViewInformation2D().getViewTransformation(),
1151                 getViewInformation2D().getViewport(),
1152 				getViewInformation2D().getVisualizedPage(),
1153                 getViewInformation2D().getViewTime(),
1154 				getViewInformation2D().getExtendedInformationSequence());
1155 			updateViewInformation(aViewInformation2D);
1156 
1157 			// proccess content
1158 			process(rTransformCandidate.getChildren());
1159 
1160 			// restore transformations
1161 			maCurrentTransformation = aLastCurrentTransformation;
1162             updateViewInformation(aLastViewInformation2D);
1163 		}
1164 
1165 		// new XDrawPage for ViewInformation2D
1166 		void VclProcessor2D::RenderPagePreviewPrimitive2D(const primitive2d::PagePreviewPrimitive2D& rPagePreviewCandidate)
1167 		{
1168 			// remember current transformation and ViewInformation
1169             const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
1170 
1171 			// create new local ViewInformation2D
1172             const geometry::ViewInformation2D aViewInformation2D(
1173                 getViewInformation2D().getObjectTransformation(),
1174                 getViewInformation2D().getViewTransformation(),
1175                 getViewInformation2D().getViewport(),
1176 				rPagePreviewCandidate.getXDrawPage(),
1177                 getViewInformation2D().getViewTime(),
1178 				getViewInformation2D().getExtendedInformationSequence());
1179 			updateViewInformation(aViewInformation2D);
1180 
1181 			// proccess decomposed content
1182 			process(rPagePreviewCandidate.get2DDecomposition(getViewInformation2D()));
1183 
1184 			// restore transformations
1185             updateViewInformation(aLastViewInformation2D);
1186 		}
1187 
1188 		// marker
1189 		void VclProcessor2D::RenderMarkerArrayPrimitive2D(const primitive2d::MarkerArrayPrimitive2D& rMarkArrayCandidate)
1190 		{
1191             static bool bCheckCompleteMarkerDecompose(false);
1192             if(bCheckCompleteMarkerDecompose)
1193             {
1194 			    process(rMarkArrayCandidate.get2DDecomposition(getViewInformation2D()));
1195                 return;
1196             }
1197 
1198 			// get data
1199 	        const std::vector< basegfx::B2DPoint >& rPositions = rMarkArrayCandidate.getPositions();
1200 			const sal_uInt32 nCount(rPositions.size());
1201 
1202 			if(nCount && !rMarkArrayCandidate.getMarker().IsEmpty())
1203 			{
1204 				// get pixel size
1205 				const BitmapEx& rMarker(rMarkArrayCandidate.getMarker());
1206 				const Size aBitmapSize(rMarker.GetSizePixel());
1207 
1208 				if(aBitmapSize.Width() && aBitmapSize.Height())
1209 				{
1210 					// get discrete half size
1211 					const basegfx::B2DVector aDiscreteHalfSize(
1212                         (aBitmapSize.getWidth() - 1.0) * 0.5,
1213                         (aBitmapSize.getHeight() - 1.0) * 0.5);
1214 			        const bool bWasEnabled(mpOutputDevice->IsMapModeEnabled());
1215 
1216                     // do not forget evtl. moved origin in target device MapMode when
1217                     // switching it off; it would be missing and lead to wrong positions.
1218                     // All his could be done using logic sizes and coordinates, too, but
1219                     // we want a 1:1 bitmap rendering here, so it's more safe and faster
1220                     // to work with switching off MapMode usage completely.
1221                     const Point aOrigin(mpOutputDevice->GetMapMode().GetOrigin());
1222 
1223                     mpOutputDevice->EnableMapMode(false);
1224 
1225 					for(std::vector< basegfx::B2DPoint >::const_iterator aIter(rPositions.begin()); aIter != rPositions.end(); aIter++)
1226 				    {
1227 					    const basegfx::B2DPoint aDiscreteTopLeft((maCurrentTransformation * (*aIter)) - aDiscreteHalfSize);
1228                         const Point aDiscretePoint(basegfx::fround(aDiscreteTopLeft.getX()), basegfx::fround(aDiscreteTopLeft.getY()));
1229 
1230 						mpOutputDevice->DrawBitmapEx(aDiscretePoint + aOrigin, rMarker);
1231 					}
1232 
1233 			        mpOutputDevice->EnableMapMode(bWasEnabled);
1234 				}
1235 			}
1236 		}
1237 
1238 		// point
1239 		void VclProcessor2D::RenderPointArrayPrimitive2D(const primitive2d::PointArrayPrimitive2D& rPointArrayCandidate)
1240 		{
1241 			const std::vector< basegfx::B2DPoint >& rPositions = rPointArrayCandidate.getPositions();
1242 			const basegfx::BColor aRGBColor(maBColorModifierStack.getModifiedColor(rPointArrayCandidate.getRGBColor()));
1243 			const Color aVCLColor(aRGBColor);
1244 
1245 			for(std::vector< basegfx::B2DPoint >::const_iterator aIter(rPositions.begin()); aIter != rPositions.end(); aIter++)
1246 			{
1247 				const basegfx::B2DPoint aViewPosition(maCurrentTransformation * (*aIter));
1248 				const Point aPos(basegfx::fround(aViewPosition.getX()), basegfx::fround(aViewPosition.getY()));
1249 
1250 				mpOutputDevice->DrawPixel(aPos, aVCLColor);
1251 			}
1252 		}
1253 
1254 		void VclProcessor2D::RenderPolygonStrokePrimitive2D(const primitive2d::PolygonStrokePrimitive2D& rPolygonStrokeCandidate)
1255 		{
1256             // #i101491# method restructured to clearly use the DrawPolyLine
1257             // calls starting from a deined line width
1258 			const attribute::LineAttribute& rLineAttribute = rPolygonStrokeCandidate.getLineAttribute();
1259 			const double fLineWidth(rLineAttribute.getWidth());
1260 			bool bDone(false);
1261 
1262 			if(basegfx::fTools::more(fLineWidth, 0.0))
1263 			{
1264 				const basegfx::B2DVector aDiscreteUnit(maCurrentTransformation * basegfx::B2DVector(fLineWidth, 0.0));
1265 				const double fDiscreteLineWidth(aDiscreteUnit.getLength());
1266 				const attribute::StrokeAttribute& rStrokeAttribute = rPolygonStrokeCandidate.getStrokeAttribute();
1267 				const basegfx::BColor aHairlineColor(maBColorModifierStack.getModifiedColor(rLineAttribute.getColor()));
1268 				basegfx::B2DPolyPolygon aHairlinePolyPolygon;
1269 
1270 				mpOutputDevice->SetLineColor(Color(aHairlineColor));
1271 				mpOutputDevice->SetFillColor();
1272 
1273 				if(0.0 == rStrokeAttribute.getFullDotDashLen())
1274 				{
1275 					// no line dashing, just copy
1276 					aHairlinePolyPolygon.append(rPolygonStrokeCandidate.getB2DPolygon());
1277 				}
1278 				else
1279 				{
1280 					// else apply LineStyle
1281 					basegfx::tools::applyLineDashing(rPolygonStrokeCandidate.getB2DPolygon(),
1282 						rStrokeAttribute.getDotDashArray(),
1283 						&aHairlinePolyPolygon, 0, rStrokeAttribute.getFullDotDashLen());
1284 				}
1285 
1286 				const sal_uInt32 nCount(aHairlinePolyPolygon.count());
1287 
1288 				if(nCount)
1289 				{
1290                     const bool bAntiAliased(getOptionsDrawinglayer().IsAntiAliasing());
1291                     aHairlinePolyPolygon.transform(maCurrentTransformation);
1292 
1293                     if(bAntiAliased)
1294                     {
1295                         if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 1.0))
1296                         {
1297                             // line in range ]0.0 .. 1.0[
1298                             // paint as simple hairline
1299                             for(sal_uInt32 a(0); a < nCount; a++)
1300                             {
1301                                 mpOutputDevice->DrawPolyLine(aHairlinePolyPolygon.getB2DPolygon(a), 0.0);
1302                             }
1303 
1304                             bDone = true;
1305                         }
1306                         else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 2.0))
1307                         {
1308                             // line in range [1.0 .. 2.0[
1309                             // paint as 2x2 with dynamic line distance
1310                             basegfx::B2DHomMatrix aMat;
1311                             const double fDistance(fDiscreteLineWidth - 1.0);
1312                             const double fHalfDistance(fDistance * 0.5);
1313 
1314                             for(sal_uInt32 a(0); a < nCount; a++)
1315                             {
1316                                 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a));
1317 
1318                                 aMat.set(0, 2, -fHalfDistance);
1319                                 aMat.set(1, 2, -fHalfDistance);
1320                                 aCandidate.transform(aMat);
1321                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1322 
1323                                 aMat.set(0, 2, fDistance);
1324                                 aMat.set(1, 2, 0.0);
1325                                 aCandidate.transform(aMat);
1326                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1327 
1328                                 aMat.set(0, 2, 0.0);
1329                                 aMat.set(1, 2, fDistance);
1330                                 aCandidate.transform(aMat);
1331                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1332 
1333                                 aMat.set(0, 2, -fDistance);
1334                                 aMat.set(1, 2, 0.0);
1335                                 aCandidate.transform(aMat);
1336                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1337                             }
1338 
1339                             bDone = true;
1340                         }
1341                         else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 3.0))
1342                         {
1343                             // line in range [2.0 .. 3.0]
1344                             // paint as cross in a 3x3  with dynamic line distance
1345                             basegfx::B2DHomMatrix aMat;
1346                             const double fDistance((fDiscreteLineWidth - 1.0) * 0.5);
1347 
1348                             for(sal_uInt32 a(0); a < nCount; a++)
1349                             {
1350                                 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a));
1351 
1352                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1353 
1354                                 aMat.set(0, 2, -fDistance);
1355                                 aMat.set(1, 2, 0.0);
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                                 aMat.set(0, 2, -fDistance);
1370                                 aMat.set(1, 2, fDistance);
1371                                 aCandidate.transform(aMat);
1372                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1373                             }
1374 
1375                             bDone = true;
1376                         }
1377                         else
1378                         {
1379                             // #i101491# line width above 3.0
1380                         }
1381                     }
1382                     else
1383                     {
1384                         if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 1.5))
1385                         {
1386                             // line width below 1.5, draw the basic hairline polygon
1387                             for(sal_uInt32 a(0); a < nCount; a++)
1388                             {
1389                                 mpOutputDevice->DrawPolyLine(aHairlinePolyPolygon.getB2DPolygon(a), 0.0);
1390                             }
1391 
1392                             bDone = true;
1393                         }
1394                         else if(basegfx::fTools::lessOrEqual(fDiscreteLineWidth, 2.5))
1395                         {
1396                             // line width is in range ]1.5 .. 2.5], use four hairlines
1397                             // drawn in a square
1398                             for(sal_uInt32 a(0); a < nCount; a++)
1399                             {
1400                                 basegfx::B2DPolygon aCandidate(aHairlinePolyPolygon.getB2DPolygon(a));
1401                                 basegfx::B2DHomMatrix aMat;
1402 
1403                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1404 
1405                                 aMat.set(0, 2, 1.0);
1406                                 aMat.set(1, 2, 0.0);
1407                                 aCandidate.transform(aMat);
1408 
1409                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1410 
1411                                 aMat.set(0, 2, 0.0);
1412                                 aMat.set(1, 2, 1.0);
1413                                 aCandidate.transform(aMat);
1414 
1415                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1416 
1417                                 aMat.set(0, 2, -1.0);
1418                                 aMat.set(1, 2, 0.0);
1419                                 aCandidate.transform(aMat);
1420 
1421                                 mpOutputDevice->DrawPolyLine(aCandidate, 0.0);
1422                             }
1423 
1424                             bDone = true;
1425                         }
1426                         else
1427                         {
1428                             // #i101491# line width is above 2.5
1429                         }
1430                     }
1431 
1432                     if(!bDone && rPolygonStrokeCandidate.getB2DPolygon().count() > 1000)
1433                     {
1434                         // #i101491# If the polygon complexity uses more than a given amount, do
1435                         // use OuputDevice::DrawPolyLine directly; this will avoid buffering all
1436                         // decompositions in primtives (memory) and fallback to old line painting
1437                         // for very complex polygons, too
1438                         for(sal_uInt32 a(0); a < nCount; a++)
1439                         {
1440                             mpOutputDevice->DrawPolyLine(
1441                                 aHairlinePolyPolygon.getB2DPolygon(a),
1442                                 fDiscreteLineWidth,
1443                                 rLineAttribute.getLineJoin(),
1444                                 rLineAttribute.getLineCap());
1445                         }
1446 
1447                         bDone = true;
1448                     }
1449                 }
1450             }
1451 
1452 			if(!bDone)
1453             {
1454                 // remeber that we enter a PolygonStrokePrimitive2D decomposition,
1455                 // used for AA thick line drawing
1456                 mnPolygonStrokePrimitive2D++;
1457 
1458                 // line width is big enough for standard filled polygon visualisation or zero
1459 				process(rPolygonStrokeCandidate.get2DDecomposition(getViewInformation2D()));
1460 
1461                 // leave PolygonStrokePrimitive2D
1462                 mnPolygonStrokePrimitive2D--;
1463             }
1464 		}
1465 
1466         void VclProcessor2D::RenderEpsPrimitive2D(const primitive2d::EpsPrimitive2D& rEpsPrimitive2D)
1467         {
1468             // The new decomposition of Metafiles made it necessary to add an Eps
1469             // primitive to handle embedded Eps data. On some devices, this can be
1470             // painted directly (mac, printer).
1471             // To be able to handle the replacement correctly, i need to handle it myself
1472             // since DrawEPS will not be able e.g. to rotate the replacement. To be able
1473             // to do that, i added a boolean return to OutputDevice::DrawEPS(..)
1474             // to know when EPS was handled directly already.
1475 			basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
1476             aRange.transform(maCurrentTransformation * rEpsPrimitive2D.getEpsTransform());
1477 
1478             if(!aRange.isEmpty())
1479             {
1480                 const Rectangle aRectangle(
1481 				    (sal_Int32)floor(aRange.getMinX()), (sal_Int32)floor(aRange.getMinY()),
1482 				    (sal_Int32)ceil(aRange.getMaxX()), (sal_Int32)ceil(aRange.getMaxY()));
1483 
1484                 if(!aRectangle.IsEmpty())
1485                 {
1486                     // try to paint EPS directly without fallback visualisation
1487                     const bool bEPSPaintedDirectly(mpOutputDevice->DrawEPS(
1488                         aRectangle.TopLeft(),
1489                         aRectangle.GetSize(),
1490                         rEpsPrimitive2D.getGfxLink(),
1491                         0));
1492 
1493                     if(!bEPSPaintedDirectly)
1494                     {
1495                         // use the decomposition which will correctly handle the
1496                         // fallback visualisation using full transformation (e.g. rotation)
1497         				process(rEpsPrimitive2D.get2DDecomposition(getViewInformation2D()));
1498                     }
1499                 }
1500             }
1501         }
1502 
1503         void VclProcessor2D::RenderSvgLinearAtomPrimitive2D(const primitive2d::SvgLinearAtomPrimitive2D& rCandidate)
1504         {
1505             const double fDelta(rCandidate.getOffsetB() - rCandidate.getOffsetA());
1506 
1507             if(basegfx::fTools::more(fDelta, 0.0))
1508             {
1509                 const basegfx::BColor aColorA(maBColorModifierStack.getModifiedColor(rCandidate.getColorA()));
1510                 const basegfx::BColor aColorB(maBColorModifierStack.getModifiedColor(rCandidate.getColorB()));
1511                 const double fDiscreteUnit((getViewInformation2D().getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0)).getLength());
1512 
1513                 // use color distance and discrete lengths to calculate step count
1514                 const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, fDelta, fDiscreteUnit));
1515 
1516                 // switch off line painting
1517                 mpOutputDevice->SetLineColor();
1518 
1519                 // prepare polygon in needed width at start position (with discrete overlap)
1520                 const basegfx::B2DPolygon aPolygon(
1521                     basegfx::tools::createPolygonFromRect(
1522                         basegfx::B2DRange(
1523                             rCandidate.getOffsetA() - fDiscreteUnit,
1524                             0.0,
1525                             rCandidate.getOffsetA() + (fDelta / nSteps) + fDiscreteUnit,
1526                             1.0)));
1527 
1528 
1529                 // prepare loop ([0.0 .. 1.0[)
1530                 double fUnitScale(0.0);
1531                 const double fUnitStep(1.0 / nSteps);
1532 
1533                 // loop and paint
1534                 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep)
1535                 {
1536                     basegfx::B2DPolygon aNew(aPolygon);
1537 
1538                     aNew.transform(maCurrentTransformation * basegfx::tools::createTranslateB2DHomMatrix(fDelta * fUnitScale, 0.0));
1539                     mpOutputDevice->SetFillColor(Color(basegfx::interpolate(aColorA, aColorB, fUnitScale)));
1540                     mpOutputDevice->DrawPolyPolygon(basegfx::B2DPolyPolygon(aNew));
1541                 }
1542             }
1543         }
1544 
1545         void VclProcessor2D::RenderSvgRadialAtomPrimitive2D(const primitive2d::SvgRadialAtomPrimitive2D& rCandidate)
1546         {
1547             const double fDeltaScale(rCandidate.getScaleB() - rCandidate.getScaleA());
1548 
1549             if(basegfx::fTools::more(fDeltaScale, 0.0))
1550             {
1551                 const basegfx::BColor aColorA(maBColorModifierStack.getModifiedColor(rCandidate.getColorA()));
1552                 const basegfx::BColor aColorB(maBColorModifierStack.getModifiedColor(rCandidate.getColorB()));
1553                 const double fDiscreteUnit((getViewInformation2D().getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0)).getLength());
1554 
1555                 // use color distance and discrete lengths to calculate step count
1556                 const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, fDeltaScale, fDiscreteUnit));
1557 
1558                 // switch off line painting
1559                 mpOutputDevice->SetLineColor();
1560 
1561                 // prepare loop ([0.0 .. 1.0[, full polygons, no polypolygons with holes)
1562                 double fUnitScale(0.0);
1563                 const double fUnitStep(1.0 / nSteps);
1564 
1565                 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep)
1566                 {
1567                     basegfx::B2DHomMatrix aTransform;
1568                     const double fEndScale(rCandidate.getScaleB() - (fDeltaScale * fUnitScale));
1569 
1570                     if(rCandidate.isTranslateSet())
1571                     {
1572                         const basegfx::B2DVector aTranslate(
1573                             basegfx::interpolate(
1574                                 rCandidate.getTranslateB(),
1575                                 rCandidate.getTranslateA(),
1576                                 fUnitScale));
1577 
1578                         aTransform = basegfx::tools::createScaleTranslateB2DHomMatrix(
1579                             fEndScale,
1580                             fEndScale,
1581                             aTranslate.getX(),
1582                             aTranslate.getY());
1583                     }
1584                     else
1585                     {
1586                         aTransform = basegfx::tools::createScaleB2DHomMatrix(
1587                             fEndScale,
1588                             fEndScale);
1589                     }
1590 
1591                     basegfx::B2DPolygon aNew(basegfx::tools::createPolygonFromUnitCircle());
1592 
1593                     aNew.transform(maCurrentTransformation * aTransform);
1594                     mpOutputDevice->SetFillColor(Color(basegfx::interpolate(aColorB, aColorA, fUnitScale)));
1595                     mpOutputDevice->DrawPolyPolygon(basegfx::B2DPolyPolygon(aNew));
1596                 }
1597             }
1598         }
1599 
1600 		void VclProcessor2D::adaptLineToFillDrawMode() const
1601 		{
1602 			const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode());
1603 
1604 			if(nOriginalDrawMode & (DRAWMODE_BLACKLINE|DRAWMODE_GRAYLINE|DRAWMODE_GHOSTEDLINE|DRAWMODE_WHITELINE|DRAWMODE_SETTINGSLINE))
1605 			{
1606 				sal_uInt32 nAdaptedDrawMode(nOriginalDrawMode);
1607 
1608 				if(nOriginalDrawMode & DRAWMODE_BLACKLINE)
1609 				{
1610 					nAdaptedDrawMode |= DRAWMODE_BLACKFILL;
1611 				}
1612 				else
1613 				{
1614 					nAdaptedDrawMode &= ~DRAWMODE_BLACKFILL;
1615 				}
1616 
1617 				if(nOriginalDrawMode & DRAWMODE_GRAYLINE)
1618 				{
1619 					nAdaptedDrawMode |= DRAWMODE_GRAYFILL;
1620 				}
1621 				else
1622 				{
1623 					nAdaptedDrawMode &= ~DRAWMODE_GRAYFILL;
1624 				}
1625 
1626 				if(nOriginalDrawMode & DRAWMODE_GHOSTEDLINE)
1627 				{
1628 					nAdaptedDrawMode |= DRAWMODE_GHOSTEDFILL;
1629 				}
1630 				else
1631 				{
1632 					nAdaptedDrawMode &= ~DRAWMODE_GHOSTEDFILL;
1633 				}
1634 
1635 				if(nOriginalDrawMode & DRAWMODE_WHITELINE)
1636 				{
1637 					nAdaptedDrawMode |= DRAWMODE_WHITEFILL;
1638 				}
1639 				else
1640 				{
1641 					nAdaptedDrawMode &= ~DRAWMODE_WHITEFILL;
1642 				}
1643 
1644 				if(nOriginalDrawMode & DRAWMODE_SETTINGSLINE)
1645 				{
1646 					nAdaptedDrawMode |= DRAWMODE_SETTINGSFILL;
1647 				}
1648 				else
1649 				{
1650 					nAdaptedDrawMode &= ~DRAWMODE_SETTINGSFILL;
1651 				}
1652 
1653 				mpOutputDevice->SetDrawMode(nAdaptedDrawMode);
1654 			}
1655 		}
1656 
1657 		void VclProcessor2D::adaptTextToFillDrawMode() const
1658 		{
1659 			const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode());
1660 			if(nOriginalDrawMode & (DRAWMODE_BLACKTEXT|DRAWMODE_GRAYTEXT|DRAWMODE_GHOSTEDTEXT|DRAWMODE_WHITETEXT|DRAWMODE_SETTINGSTEXT))
1661 			{
1662 				sal_uInt32 nAdaptedDrawMode(nOriginalDrawMode);
1663 
1664 				if(nOriginalDrawMode & DRAWMODE_BLACKTEXT)
1665 				{
1666 					nAdaptedDrawMode |= DRAWMODE_BLACKFILL;
1667 				}
1668 				else
1669 				{
1670 					nAdaptedDrawMode &= ~DRAWMODE_BLACKFILL;
1671 				}
1672 
1673 				if(nOriginalDrawMode & DRAWMODE_GRAYTEXT)
1674 				{
1675 					nAdaptedDrawMode |= DRAWMODE_GRAYFILL;
1676 				}
1677 				else
1678 				{
1679 					nAdaptedDrawMode &= ~DRAWMODE_GRAYFILL;
1680 				}
1681 
1682 				if(nOriginalDrawMode & DRAWMODE_GHOSTEDTEXT)
1683 				{
1684 					nAdaptedDrawMode |= DRAWMODE_GHOSTEDFILL;
1685 				}
1686 				else
1687 				{
1688 					nAdaptedDrawMode &= ~DRAWMODE_GHOSTEDFILL;
1689 				}
1690 
1691 				if(nOriginalDrawMode & DRAWMODE_WHITETEXT)
1692 				{
1693 					nAdaptedDrawMode |= DRAWMODE_WHITEFILL;
1694 				}
1695 				else
1696 				{
1697 					nAdaptedDrawMode &= ~DRAWMODE_WHITEFILL;
1698 				}
1699 
1700 				if(nOriginalDrawMode & DRAWMODE_SETTINGSTEXT)
1701 				{
1702 					nAdaptedDrawMode |= DRAWMODE_SETTINGSFILL;
1703 				}
1704 				else
1705 				{
1706 					nAdaptedDrawMode &= ~DRAWMODE_SETTINGSFILL;
1707 				}
1708 
1709 				mpOutputDevice->SetDrawMode(nAdaptedDrawMode);
1710 			}
1711 		}
1712 
1713 		//////////////////////////////////////////////////////////////////////////////
1714 		// process support
1715 
1716 		VclProcessor2D::VclProcessor2D(
1717 			const geometry::ViewInformation2D& rViewInformation,
1718 			OutputDevice& rOutDev)
1719 		:	BaseProcessor2D(rViewInformation),
1720 			mpOutputDevice(&rOutDev),
1721 			maBColorModifierStack(),
1722 			maCurrentTransformation(),
1723 			maDrawinglayerOpt(),
1724             mnPolygonStrokePrimitive2D(0)
1725 		{
1726             // set digit language, derived from SvtCTLOptions to have the correct
1727             // number display for arabic/hindi numerals
1728             const SvtCTLOptions aSvtCTLOptions;
1729             LanguageType eLang(LANGUAGE_SYSTEM);
1730 
1731             if(SvtCTLOptions::NUMERALS_HINDI == aSvtCTLOptions.GetCTLTextNumerals())
1732             {
1733                 eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
1734             }
1735             else if(SvtCTLOptions::NUMERALS_ARABIC == aSvtCTLOptions.GetCTLTextNumerals())
1736             {
1737                 eLang = LANGUAGE_ENGLISH;
1738             }
1739             else
1740             {
1741                 eLang = (LanguageType)Application::GetSettings().GetLanguage();
1742             }
1743 
1744             rOutDev.SetDigitLanguage(eLang);
1745 		}
1746 
1747 		VclProcessor2D::~VclProcessor2D()
1748 		{
1749 		}
1750 	} // end of namespace processor2d
1751 } // end of namespace drawinglayer
1752 
1753 //////////////////////////////////////////////////////////////////////////////
1754 // eof
1755