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/vclpixelprocessor2d.hxx>
28 #include <vcl/outdev.hxx>
29 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
30 #include <drawinglayer/primitive2d/textprimitive2d.hxx>
31 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
32 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
33 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
34 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
35 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
36 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
37 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
38 #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
39 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
40 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
41 #include <drawinglayer/primitive2d/pointarrayprimitive2d.hxx>
42 #include <drawinglayer/primitive2d/wrongspellprimitive2d.hxx>
43 #include <drawinglayer/primitive2d/controlprimitive2d.hxx>
44 #include <com/sun/star/awt/XWindow2.hpp>
45 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
46 #include <drawinglayer/primitive2d/pagepreviewprimitive2d.hxx>
47 #include <helperwrongspellrenderer.hxx>
48 #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx>
49 #include <basegfx/polygon/b2dpolygontools.hxx>
50 #include <vcl/hatch.hxx>
51 #include <tools/diagnose_ex.h>
52 #include <com/sun/star/awt/PosSize.hpp>
53 #include <drawinglayer/primitive2d/invertprimitive2d.hxx>
54 #include <cstdio>
55 #include <drawinglayer/primitive2d/backgroundcolorprimitive2d.hxx>
56 #include <basegfx/matrix/b2dhommatrixtools.hxx>
57 #include <drawinglayer/primitive2d/epsprimitive2d.hxx>
58 #include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
59 #include <toolkit/helper/vclunohelper.hxx>
60 #include <vcl/window.hxx>
61 
62 //////////////////////////////////////////////////////////////////////////////
63 
64 using namespace com::sun::star;
65 
66 //////////////////////////////////////////////////////////////////////////////
67 
68 namespace drawinglayer
69 {
70 	namespace processor2d
71 	{
72 		VclPixelProcessor2D::VclPixelProcessor2D(const geometry::ViewInformation2D& rViewInformation, OutputDevice& rOutDev)
73 		:	VclProcessor2D(rViewInformation, rOutDev)
74 		{
75 			// prepare maCurrentTransformation matrix with viewTransformation to target directly to pixels
76 			maCurrentTransformation = rViewInformation.getObjectToViewTransformation();
77 
78             // prepare output directly to pixels
79    			mpOutputDevice->Push(PUSH_MAPMODE);
80     		mpOutputDevice->SetMapMode();
81 
82             // react on AntiAliasing settings
83             if(getOptionsDrawinglayer().IsAntiAliasing())
84             {
85                 mpOutputDevice->SetAntialiasing(mpOutputDevice->GetAntialiasing() | ANTIALIASING_ENABLE_B2DDRAW);
86             }
87             else
88             {
89                 mpOutputDevice->SetAntialiasing(mpOutputDevice->GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
90             }
91         }
92 
93 		VclPixelProcessor2D::~VclPixelProcessor2D()
94 		{
95             // restore MapMode
96    			mpOutputDevice->Pop();
97 
98             // restore AntiAliasing
99             mpOutputDevice->SetAntialiasing(mpOutputDevice->GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
100 		}
101 
102 		void VclPixelProcessor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
103 		{
104 			switch(rCandidate.getPrimitive2DID())
105 			{
106                 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
107                 {
108 					// directdraw of wrong spell primitive; added test possibility to check wrong spell decompose
109                     static bool bHandleWrongSpellDirectly(true);
110 
111                     if(bHandleWrongSpellDirectly)
112                     {
113 						const primitive2d::WrongSpellPrimitive2D& rWrongSpellPrimitive = static_cast< const primitive2d::WrongSpellPrimitive2D& >(rCandidate);
114 
115 						if(!renderWrongSpellPrimitive2D(
116 							rWrongSpellPrimitive,
117 							*mpOutputDevice,
118 							maCurrentTransformation,
119 							maBColorModifierStack))
120 						{
121 							// fallback to decomposition (MetaFile)
122 							process(rWrongSpellPrimitive.get2DDecomposition(getViewInformation2D()));
123 						}
124                     }
125                     else
126                     {
127     					process(rCandidate.get2DDecomposition(getViewInformation2D()));
128                     }
129                     break;
130                 }
131 				case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
132 				{
133 					// directdraw of text simple portion; added test possibility to check text decompose
134                     static bool bForceSimpleTextDecomposition(false);
135 
136 					// Adapt evtl. used special DrawMode
137 					const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode());
138 					adaptTextToFillDrawMode();
139 
140 					if(!bForceSimpleTextDecomposition && getOptionsDrawinglayer().IsRenderSimpleTextDirect())
141                     {
142     					RenderTextSimpleOrDecoratedPortionPrimitive2D(static_cast< const primitive2d::TextSimplePortionPrimitive2D& >(rCandidate));
143                     }
144                     else
145                     {
146     					process(rCandidate.get2DDecomposition(getViewInformation2D()));
147                     }
148 
149 					// restore DrawMode
150 					mpOutputDevice->SetDrawMode(nOriginalDrawMode);
151 
152 					break;
153 				}
154 				case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
155 				{
156 					// directdraw of text simple portion; added test possibility to check text decompose
157                     static bool bForceComplexTextDecomposition(false);
158 
159 					// Adapt evtl. used special DrawMode
160 					const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode());
161 					adaptTextToFillDrawMode();
162 
163 					if(!bForceComplexTextDecomposition && getOptionsDrawinglayer().IsRenderDecoratedTextDirect())
164                     {
165     					RenderTextSimpleOrDecoratedPortionPrimitive2D(static_cast< const primitive2d::TextSimplePortionPrimitive2D& >(rCandidate));
166                     }
167                     else
168                     {
169     					process(rCandidate.get2DDecomposition(getViewInformation2D()));
170                     }
171 
172 					// restore DrawMode
173 					mpOutputDevice->SetDrawMode(nOriginalDrawMode);
174 
175 					break;
176 				}
177 				case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
178 				{
179 					// direct draw of hairline
180 					RenderPolygonHairlinePrimitive2D(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate), true);
181 					break;
182 				}
183 				case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
184 				{
185                     // direct draw of transformed BitmapEx primitive
186                     const primitive2d::BitmapPrimitive2D& rBitmapCandidate = static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate);
187 
188                     // check if graphic content is inside discrete local ViewPort
189                     const basegfx::B2DRange& rDiscreteViewPort(getViewInformation2D().getDiscreteViewport());
190                     const basegfx::B2DHomMatrix aLocalTransform(maCurrentTransformation * rBitmapCandidate.getTransform());
191 
192                     if(!rDiscreteViewPort.isEmpty())
193                     {
194                         basegfx::B2DRange aUnitRange(0.0, 0.0, 1.0, 1.0);
195 
196                         aUnitRange.transform(aLocalTransform);
197 
198                         if(!aUnitRange.overlaps(rDiscreteViewPort))
199                         {
200                             // content is outside discrete local ViewPort
201                             break;
202                         }
203                     }
204 
205 					RenderBitmapPrimitive2D(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate));
206 					break;
207 				}
208 				case PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D :
209 				{
210 					// direct draw of fillBitmapPrimitive
211 					RenderFillGraphicPrimitive2D(static_cast< const primitive2d::FillGraphicPrimitive2D& >(rCandidate));
212 					break;
213 				}
214 				case PRIMITIVE2D_ID_POLYPOLYGONGRADIENTPRIMITIVE2D :
215 				{
216 				    // direct draw of gradient
217 					const primitive2d::PolyPolygonGradientPrimitive2D& rPolygonCandidate = static_cast< const primitive2d::PolyPolygonGradientPrimitive2D& >(rCandidate);
218 			        const attribute::FillGradientAttribute& rGradient(rPolygonCandidate.getFillGradient());
219 			        basegfx::BColor aStartColor(maBColorModifierStack.getModifiedColor(rGradient.getStartColor()));
220 			        basegfx::BColor aEndColor(maBColorModifierStack.getModifiedColor(rGradient.getEndColor()));
221 			        basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
222 
223 			        if(aLocalPolyPolygon.count())
224 			        {
225 				        aLocalPolyPolygon.transform(maCurrentTransformation);
226 
227 				        if(aStartColor == aEndColor)
228 				        {
229 					        // no gradient at all, draw as polygon in AA and non-AA case
230 					        mpOutputDevice->SetLineColor();
231 					        mpOutputDevice->SetFillColor(Color(aStartColor));
232 					        mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon);
233 				        }
234 				        else
235 				        {
236                             // use the primitive decomposition of the metafile
237 					        process(rPolygonCandidate.get2DDecomposition(getViewInformation2D()));
238 				        }
239 			        }
240 					break;
241 				}
242 				case PRIMITIVE2D_ID_POLYPOLYGONGRAPHICPRIMITIVE2D :
243 				{
244 				    // direct draw of bitmap
245 				    RenderPolyPolygonGraphicPrimitive2D(static_cast< const primitive2d::PolyPolygonGraphicPrimitive2D& >(rCandidate));
246 					break;
247 				}
248 				case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
249 				{
250 					// direct draw of PolyPolygon with color
251 					RenderPolyPolygonColorPrimitive2D(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
252 					break;
253 				}
254 				case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
255 				{
256        				// #i98289#
257                     const bool bForceLineSnap(getOptionsDrawinglayer().IsAntiAliasing() && getOptionsDrawinglayer().IsSnapHorVerLinesToDiscrete());
258                     const sal_uInt16 nOldAntiAliase(mpOutputDevice->GetAntialiasing());
259 
260                     if(bForceLineSnap)
261                     {
262                         mpOutputDevice->SetAntialiasing(nOldAntiAliase | ANTIALIASING_PIXELSNAPHAIRLINE);
263                     }
264 
265                     // use new Metafile decomposition
266     				process(rCandidate.get2DDecomposition(getViewInformation2D()));
267 
268                     if(bForceLineSnap)
269                     {
270                         mpOutputDevice->SetAntialiasing(nOldAntiAliase);
271                     }
272 
273                     break;
274 				}
275 				case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
276 				{
277 					// mask group.
278 					RenderMaskPrimitive2DPixel(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate));
279 					break;
280 				}
281 				case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D :
282 				{
283 					// modified color group. Force output to unified color.
284 					RenderModifiedColorPrimitive2D(static_cast< const primitive2d::ModifiedColorPrimitive2D& >(rCandidate));
285 					break;
286 				}
287 				case PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D :
288 				{
289 					// Detect if a single PolyPolygonColorPrimitive2D is contained; in that case,
290 					// use the faster OutputDevice::DrawTransparent method
291 					const primitive2d::UnifiedTransparencePrimitive2D& rUniTransparenceCandidate = static_cast< const primitive2d::UnifiedTransparencePrimitive2D& >(rCandidate);
292 					const primitive2d::Primitive2DSequence rContent = rUniTransparenceCandidate.getChildren();
293 
294 					if(rContent.hasElements())
295 					{
296                         if(0.0 == rUniTransparenceCandidate.getTransparence())
297                         {
298                             // not transparent at all, use content
299 	                        process(rUniTransparenceCandidate.getChildren());
300                         }
301 			            else if(rUniTransparenceCandidate.getTransparence() > 0.0 && rUniTransparenceCandidate.getTransparence() < 1.0)
302 			            {
303 					        bool bDrawTransparentUsed(false);
304 
305 					        // since DEV300 m33 DrawTransparent is supported in VCL (for some targets
306                             // natively), so i am now enabling this shortcut
307 					        static bool bAllowUsingDrawTransparent(true);
308 
309 					        if(bAllowUsingDrawTransparent && 1 == rContent.getLength())
310 					        {
311 						        const primitive2d::Primitive2DReference xReference(rContent[0]);
312 								const primitive2d::BasePrimitive2D* pBasePrimitive = dynamic_cast< const primitive2d::BasePrimitive2D* >(xReference.get());
313 
314 								if(pBasePrimitive)
315 								{
316 									switch(pBasePrimitive->getPrimitive2DID())
317 									{
318 										case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D:
319 										{
320 											// single transparent PolyPolygon identified, use directly
321 											const primitive2d::PolyPolygonColorPrimitive2D* pPoPoColor = static_cast< const primitive2d::PolyPolygonColorPrimitive2D* >(pBasePrimitive);
322 											OSL_ENSURE(pPoPoColor, "OOps, PrimitiveID and PrimitiveType do not match (!)");
323 											const basegfx::BColor aPolygonColor(maBColorModifierStack.getModifiedColor(pPoPoColor->getBColor()));
324 											mpOutputDevice->SetFillColor(Color(aPolygonColor));
325 											mpOutputDevice->SetLineColor();
326 
327 											basegfx::B2DPolyPolygon aLocalPolyPolygon(pPoPoColor->getB2DPolyPolygon());
328 											aLocalPolyPolygon.transform(maCurrentTransformation);
329 
330 											mpOutputDevice->DrawTransparent(aLocalPolyPolygon, rUniTransparenceCandidate.getTransparence());
331 											bDrawTransparentUsed = true;
332 											break;
333 										}
334 										// #i# need to wait for #i101378# which is in CWS vcl112 to directly paint transparent hairlines
335 										//case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D:
336 										//{
337 										//	// single transparent PolygonHairlinePrimitive2D identified, use directly
338 										//	const primitive2d::PolygonHairlinePrimitive2D* pPoHair = static_cast< const primitive2d::PolygonHairlinePrimitive2D* >(pBasePrimitive);
339 										//	OSL_ENSURE(pPoHair, "OOps, PrimitiveID and PrimitiveType do not match (!)");
340 										//	break;
341 										//}
342 									}
343 								}
344 					        }
345 
346 					        if(!bDrawTransparentUsed)
347 					        {
348 					            // unified sub-transparence. Draw to VDev first.
349 					            RenderUnifiedTransparencePrimitive2D(rUniTransparenceCandidate);
350 					        }
351                         }
352                     }
353 
354 					break;
355 				}
356 				case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D :
357 				{
358 					// sub-transparence group. Draw to VDev first.
359 					RenderTransparencePrimitive2D(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate));
360 					break;
361 				}
362 				case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
363 				{
364 					// transform group.
365 					RenderTransformPrimitive2D(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
366 					break;
367 				}
368                 case PRIMITIVE2D_ID_PAGEPREVIEWPRIMITIVE2D :
369 				{
370 					// new XDrawPage for ViewInformation2D
371 					RenderPagePreviewPrimitive2D(static_cast< const primitive2d::PagePreviewPrimitive2D& >(rCandidate));
372 					break;
373 				}
374 				case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
375 				{
376 					// marker array
377 					RenderMarkerArrayPrimitive2D(static_cast< const primitive2d::MarkerArrayPrimitive2D& >(rCandidate));
378 					break;
379 				}
380 				case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
381 				{
382 					// point array
383 					RenderPointArrayPrimitive2D(static_cast< const primitive2d::PointArrayPrimitive2D& >(rCandidate));
384 					break;
385 				}
386 				case PRIMITIVE2D_ID_CONTROLPRIMITIVE2D :
387 				{
388 					// control primitive
389 					const primitive2d::ControlPrimitive2D& rControlPrimitive = static_cast< const primitive2d::ControlPrimitive2D& >(rCandidate);
390         			const uno::Reference< awt::XControl >& rXControl(rControlPrimitive.getXControl());
391 
392                     try
393                     {
394                         // remember old graphics and create new
395 					    uno::Reference< awt::XView > xControlView(rXControl, uno::UNO_QUERY_THROW);
396                         const uno::Reference< awt::XGraphics > xOriginalGraphics(xControlView->getGraphics());
397 					    const uno::Reference< awt::XGraphics > xNewGraphics(mpOutputDevice->CreateUnoGraphics());
398 
399                         if(xNewGraphics.is())
400                         {
401 				            // link graphics and view
402 				            xControlView->setGraphics(xNewGraphics);
403 
404                             // get position
405                             const basegfx::B2DHomMatrix aObjectToPixel(maCurrentTransformation * rControlPrimitive.getTransform());
406                             const basegfx::B2DPoint aTopLeftPixel(aObjectToPixel * basegfx::B2DPoint(0.0, 0.0));
407 
408                             // find out if the control is already visualized as a VCL-ChildWindow. If yes,
409                             // it does not need to be painted at all.
410                             uno::Reference< awt::XWindow2 > xControlWindow(rXControl, uno::UNO_QUERY_THROW);
411 	                        const bool bControlIsVisibleAsChildWindow(rXControl->getPeer().is() && xControlWindow->isVisible());
412 
413     					    if(!bControlIsVisibleAsChildWindow)
414                             {
415                                 // draw it. Do not forget to use the evtl. offsetted origin of the target device,
416                                 // e.g. when used with mask/transparence buffer device
417                                 const Point aOrigin(mpOutputDevice->GetMapMode().GetOrigin());
418                                 xControlView->draw(
419                                     aOrigin.X() + basegfx::fround(aTopLeftPixel.getX()),
420                                     aOrigin.Y() + basegfx::fround(aTopLeftPixel.getY()));
421                             }
422 
423                             // restore original graphics
424 				            xControlView->setGraphics(xOriginalGraphics);
425                         }
426                     }
427                     catch(const uno::Exception&)
428                     {
429 						// #i116763# removing since there is a good alternative when the xControlView
430 						// is not found and it is allowed to happen
431                         // DBG_UNHANDLED_EXCEPTION();
432 
433                         // process recursively and use the decomposition as Bitmap
434 				        process(rCandidate.get2DDecomposition(getViewInformation2D()));
435                     }
436 
437                     break;
438 				}
439 				case PRIMITIVE2D_ID_POLYGONSTROKEPRIMITIVE2D:
440 				{
441 					// the stroke primitive may be decomposed to filled polygons. To keep
442 					// evtl. set DrawModes aka DRAWMODE_BLACKLINE, DRAWMODE_GRAYLINE,
443 					// DRAWMODE_GHOSTEDLINE, DRAWMODE_WHITELINE or DRAWMODE_SETTINGSLINE
444 					// working, these need to be copied to the corresponding fill modes
445 					const sal_uInt32 nOriginalDrawMode(mpOutputDevice->GetDrawMode());
446 					adaptLineToFillDrawMode();
447 
448 					// polygon stroke primitive
449 					static bool bSuppressFatToHairlineCorrection(false);
450 
451 					if(bSuppressFatToHairlineCorrection)
452 					{
453                         // remeber that we enter a PolygonStrokePrimitive2D decomposition,
454                         // used for AA thick line drawing
455                         mnPolygonStrokePrimitive2D++;
456 
457                         // with AA there is no need to handle thin lines special
458 						process(rCandidate.get2DDecomposition(getViewInformation2D()));
459 
460                         // leave PolygonStrokePrimitive2D
461                         mnPolygonStrokePrimitive2D--;
462 					}
463 					else
464 					{
465 						// Lines with 1 and 2 pixel width without AA need special treatment since their vsiualisation
466 						// as filled polygons is geometrically corret but looks wrong since polygon filling avoids
467 						// the right and bottom pixels. The used method evaluates that and takes the correct action,
468 						// including calling recursively with decomposition if line is wide enough
469 						const primitive2d::PolygonStrokePrimitive2D& rPolygonStrokePrimitive = static_cast< const primitive2d::PolygonStrokePrimitive2D& >(rCandidate);
470 
471 						RenderPolygonStrokePrimitive2D(rPolygonStrokePrimitive);
472 					}
473 
474 					// restore DrawMode
475 					mpOutputDevice->SetDrawMode(nOriginalDrawMode);
476 
477 					break;
478 				}
479 				case PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D :
480 				{
481 					static bool bForceIgnoreHatchSmoothing(false);
482 
483                     if(bForceIgnoreHatchSmoothing || getOptionsDrawinglayer().IsAntiAliasing())
484                     {
485 						// if AA is used (or ignore smoothing is on), there is no need to smooth
486 						// hatch painting, use decomposition
487 						process(rCandidate.get2DDecomposition(getViewInformation2D()));
488 					}
489 					else
490 					{
491 						// without AA, use VCL to draw the hatch. It snaps hatch distances to the next pixel
492 						// and forces hatch distance to be >= 3 pixels to make the hatch display look smoother.
493 						// This is wrong in principle, but looks nicer. This could also be done here directly
494 						// without VCL usage if needed
495 						const primitive2d::FillHatchPrimitive2D& rFillHatchPrimitive = static_cast< const primitive2d::FillHatchPrimitive2D& >(rCandidate);
496 						const attribute::FillHatchAttribute& rFillHatchAttributes = rFillHatchPrimitive.getFillHatch();
497 
498 						// create hatch polygon in range size and discrete coordinates
499 						basegfx::B2DRange aHatchRange(rFillHatchPrimitive.getObjectRange());
500 						aHatchRange.transform(maCurrentTransformation);
501 						const basegfx::B2DPolygon aHatchPolygon(basegfx::tools::createPolygonFromRect(aHatchRange));
502 
503                         if(rFillHatchAttributes.isFillBackground())
504                         {
505                             // #i111846# background fill is active; draw fill polygon
506 			                const basegfx::BColor aPolygonColor(maBColorModifierStack.getModifiedColor(rFillHatchPrimitive.getBColor()));
507 
508                             mpOutputDevice->SetFillColor(Color(aPolygonColor));
509 			                mpOutputDevice->SetLineColor();
510             			    mpOutputDevice->DrawPolygon(aHatchPolygon);
511                         }
512 
513 						// set hatch line color
514 						const basegfx::BColor aHatchColor(maBColorModifierStack.getModifiedColor(rFillHatchPrimitive.getBColor()));
515 						mpOutputDevice->SetFillColor();
516 						mpOutputDevice->SetLineColor(Color(aHatchColor));
517 
518 						// get hatch style
519 						HatchStyle eHatchStyle(HATCH_SINGLE);
520 
521 						switch(rFillHatchAttributes.getStyle())
522 						{
523 							default : // HATCHSTYLE_SINGLE
524 							{
525 								break;
526 							}
527 							case attribute::HATCHSTYLE_DOUBLE :
528 							{
529 								eHatchStyle = HATCH_DOUBLE;
530 								break;
531 							}
532 							case attribute::HATCHSTYLE_TRIPLE :
533 							{
534 								eHatchStyle = HATCH_TRIPLE;
535 								break;
536 							}
537 						}
538 
539 						// create hatch
540 						const basegfx::B2DVector aDiscreteDistance(maCurrentTransformation * basegfx::B2DVector(rFillHatchAttributes.getDistance(), 0.0));
541 						const sal_uInt32 nDistance(basegfx::fround(aDiscreteDistance.getLength()));
542 						const sal_uInt16 nAngle10((sal_uInt16)basegfx::fround(rFillHatchAttributes.getAngle() / F_PI1800));
543 						::Hatch aVCLHatch(eHatchStyle, Color(rFillHatchAttributes.getColor()), nDistance, nAngle10);
544 
545 						// draw hatch using VCL
546 						mpOutputDevice->DrawHatch(PolyPolygon(Polygon(aHatchPolygon)), aVCLHatch);
547 					}
548 					break;
549 				}
550 				case PRIMITIVE2D_ID_BACKGROUNDCOLORPRIMITIVE2D :
551 				{
552 					// #i98404# Handle directly, especially when AA is active
553 					const primitive2d::BackgroundColorPrimitive2D& rPrimitive = static_cast< const primitive2d::BackgroundColorPrimitive2D& >(rCandidate);
554 					const sal_uInt16 nOriginalAA(mpOutputDevice->GetAntialiasing());
555 
556 					// switch AA off in all cases
557 	                mpOutputDevice->SetAntialiasing(mpOutputDevice->GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
558 
559 					// create color for fill
560 					const basegfx::BColor aPolygonColor(maBColorModifierStack.getModifiedColor(rPrimitive.getBColor()));
561 					mpOutputDevice->SetFillColor(Color(aPolygonColor));
562 					mpOutputDevice->SetLineColor();
563 
564 					// create rectangle for fill
565 					const basegfx::B2DRange& aViewport(getViewInformation2D().getDiscreteViewport());
566 					const Rectangle aRectangle(
567 						(sal_Int32)floor(aViewport.getMinX()), (sal_Int32)floor(aViewport.getMinY()),
568 						(sal_Int32)ceil(aViewport.getMaxX()), (sal_Int32)ceil(aViewport.getMaxY()));
569 					mpOutputDevice->DrawRect(aRectangle);
570 
571 					// restore AA setting
572 					mpOutputDevice->SetAntialiasing(nOriginalAA);
573 					break;
574 				}
575                 case PRIMITIVE2D_ID_TEXTHIERARCHYEDITPRIMITIVE2D :
576                 {
577                     // #i97628#
578                     // This primitive means that the content is derived from an active text edit,
579                     // not from model data itself. Some renderers need to suppress this content, e.g.
580                     // the pixel renderer used for displaying the edit view (like this one). It's
581                     // not to be suppressed by the MetaFile renderers, so that the edited text is
582                     // part of the MetaFile, e.g. needed for presentation previews.
583                     // Action: Ignore here, do nothing.
584                     break;
585                 }
586 				case PRIMITIVE2D_ID_INVERTPRIMITIVE2D :
587 				{
588 					// invert primitive (currently only used for HighContrast fallback for selection in SW and SC).
589 					// Set OutDev to XOR and switch AA off (XOR does not work with AA)
590                     mpOutputDevice->Push();
591                     mpOutputDevice->SetRasterOp( ROP_XOR );
592                     const sal_uInt16 nAntiAliasing(mpOutputDevice->GetAntialiasing());
593                     mpOutputDevice->SetAntialiasing(nAntiAliasing & ~ANTIALIASING_ENABLE_B2DDRAW);
594 
595 					// process content recursively
596 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
597 
598 					// restore OutDev
599 					mpOutputDevice->Pop();
600                     mpOutputDevice->SetAntialiasing(nAntiAliasing);
601 					break;
602 				}
603                 case PRIMITIVE2D_ID_EPSPRIMITIVE2D :
604                 {
605 					RenderEpsPrimitive2D(static_cast< const primitive2d::EpsPrimitive2D& >(rCandidate));
606                     break;
607                 }
608                 case PRIMITIVE2D_ID_SVGLINEARATOMPRIMITIVE2D:
609                 {
610                     RenderSvgLinearAtomPrimitive2D(static_cast< const primitive2d::SvgLinearAtomPrimitive2D& >(rCandidate));
611                     break;
612                 }
613                 case PRIMITIVE2D_ID_SVGRADIALATOMPRIMITIVE2D:
614                 {
615                     RenderSvgRadialAtomPrimitive2D(static_cast< const primitive2d::SvgRadialAtomPrimitive2D& >(rCandidate));
616                     break;
617                 }
618 				default :
619 				{
620 					// process recursively
621 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
622 					break;
623 				}
624 			}
625 		}
626 	} // end of namespace processor2d
627 } // end of namespace drawinglayer
628 
629 //////////////////////////////////////////////////////////////////////////////
630 // eof
631