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