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