xref: /AOO41X/main/vcl/source/gdi/print2.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <functional>
32*cdf0e10cSrcweir #include <algorithm>
33*cdf0e10cSrcweir #include <utility>
34*cdf0e10cSrcweir #include <list>
35*cdf0e10cSrcweir #include <vector>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
38*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <tools/debug.hxx>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <vcl/virdev.hxx>
43*cdf0e10cSrcweir #include <vcl/metaact.hxx>
44*cdf0e10cSrcweir #include <vcl/gdimtf.hxx>
45*cdf0e10cSrcweir #include <vcl/salbtype.hxx>
46*cdf0e10cSrcweir #include <vcl/print.hxx>
47*cdf0e10cSrcweir #include <vcl/svapp.hxx>
48*cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
49*cdf0e10cSrcweir #include <vcl/rendergraphicrasterizer.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <print.h>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #include "pdfwriter_impl.hxx"
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir // -----------
56*cdf0e10cSrcweir // - Defines -
57*cdf0e10cSrcweir // -----------
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #define MAX_TILE_WIDTH  1024
60*cdf0e10cSrcweir #define MAX_TILE_HEIGHT 1024
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir // ---------
63*cdf0e10cSrcweir // - Types -
64*cdf0e10cSrcweir // ---------
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir typedef ::std::pair< MetaAction*, int > Component; // MetaAction plus index in metafile
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir typedef ::std::list< Component > ComponentList;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir // List of (intersecting) actions, plus overall bounds
71*cdf0e10cSrcweir struct ConnectedComponents
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir     ConnectedComponents() :
74*cdf0e10cSrcweir         aComponentList(),
75*cdf0e10cSrcweir         aBounds(),
76*cdf0e10cSrcweir         aBgColor(COL_WHITE),
77*cdf0e10cSrcweir         bIsSpecial(false),
78*cdf0e10cSrcweir         bIsFullyTransparent(false)
79*cdf0e10cSrcweir     {}
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     ComponentList	aComponentList;
82*cdf0e10cSrcweir     Rectangle		aBounds;
83*cdf0e10cSrcweir     Color           aBgColor;
84*cdf0e10cSrcweir     bool			bIsSpecial;
85*cdf0e10cSrcweir     bool			bIsFullyTransparent;
86*cdf0e10cSrcweir };
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir typedef ::std::list< ConnectedComponents > ConnectedComponentsList;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir // -----------
92*cdf0e10cSrcweir // - Printer -
93*cdf0e10cSrcweir // -----------
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir /** #i10613# Extracted from Printer::GetPreparedMetaFile. Returns true
96*cdf0e10cSrcweir     if given action requires special handling (usually because of
97*cdf0e10cSrcweir     transparency)
98*cdf0e10cSrcweir */
99*cdf0e10cSrcweir static bool ImplIsActionSpecial( const MetaAction& rAct )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     switch( rAct.GetType() )
102*cdf0e10cSrcweir     {
103*cdf0e10cSrcweir         case META_TRANSPARENT_ACTION:
104*cdf0e10cSrcweir             return true;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         case META_FLOATTRANSPARENT_ACTION:
107*cdf0e10cSrcweir             return true;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir         case META_BMPEX_ACTION:
110*cdf0e10cSrcweir             return static_cast<const MetaBmpExAction&>(rAct).GetBitmapEx().IsTransparent();
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir         case META_BMPEXSCALE_ACTION:
113*cdf0e10cSrcweir             return static_cast<const MetaBmpExScaleAction&>(rAct).GetBitmapEx().IsTransparent();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         case META_BMPEXSCALEPART_ACTION:
116*cdf0e10cSrcweir             return static_cast<const MetaBmpExScalePartAction&>(rAct).GetBitmapEx().IsTransparent();
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir         case META_RENDERGRAPHIC_ACTION:
119*cdf0e10cSrcweir             return true;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir         default:
122*cdf0e10cSrcweir             return false;
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir /** Check whether rCurrRect rectangle fully covers io_rPrevRect - if
127*cdf0e10cSrcweir     yes, return true and update o_rBgColor
128*cdf0e10cSrcweir  */
129*cdf0e10cSrcweir static bool checkRect( Rectangle&       io_rPrevRect,
130*cdf0e10cSrcweir                        Color&           o_rBgColor,
131*cdf0e10cSrcweir                        const Rectangle& rCurrRect,
132*cdf0e10cSrcweir                        OutputDevice&    rMapModeVDev )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     // shape needs to fully cover previous content, and have uniform
135*cdf0e10cSrcweir     // color
136*cdf0e10cSrcweir     const bool bRet(
137*cdf0e10cSrcweir         rMapModeVDev.LogicToPixel(rCurrRect).IsInside(io_rPrevRect) &&
138*cdf0e10cSrcweir         rMapModeVDev.IsFillColor() );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     if( bRet )
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir         io_rPrevRect = rCurrRect;
143*cdf0e10cSrcweir         o_rBgColor = rMapModeVDev.GetFillColor();
144*cdf0e10cSrcweir     }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     return bRet;
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir /** #107169# Convert BitmapEx to Bitmap with appropriately blended
150*cdf0e10cSrcweir     color. Convert MetaTransparentAction to plain polygon,
151*cdf0e10cSrcweir     appropriately colored
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     @param o_rMtf
154*cdf0e10cSrcweir     Add converted actions to this metafile
155*cdf0e10cSrcweir */
156*cdf0e10cSrcweir static void ImplConvertTransparentAction( GDIMetaFile&        o_rMtf,
157*cdf0e10cSrcweir                                           const MetaAction&   rAct,
158*cdf0e10cSrcweir                                           const OutputDevice& rStateOutDev,
159*cdf0e10cSrcweir                                           Color               aBgColor )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     if( rAct.GetType() == META_TRANSPARENT_ACTION )
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         const MetaTransparentAction* pTransAct = static_cast<const MetaTransparentAction*>(&rAct);
164*cdf0e10cSrcweir         sal_uInt16				         nTransparency( pTransAct->GetTransparence() );
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir         // #i10613# Respect transparency for draw color
167*cdf0e10cSrcweir         if( nTransparency )
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             o_rMtf.AddAction( new MetaPushAction( PUSH_LINECOLOR|PUSH_FILLCOLOR ) );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir             // assume white background for alpha blending
172*cdf0e10cSrcweir             Color aLineColor( rStateOutDev.GetLineColor() );
173*cdf0e10cSrcweir             aLineColor.SetRed( static_cast<sal_uInt8>( (255L*nTransparency + (100L - nTransparency)*aLineColor.GetRed()) / 100L ) );
174*cdf0e10cSrcweir             aLineColor.SetGreen( static_cast<sal_uInt8>( (255L*nTransparency + (100L - nTransparency)*aLineColor.GetGreen()) / 100L ) );
175*cdf0e10cSrcweir             aLineColor.SetBlue( static_cast<sal_uInt8>( (255L*nTransparency + (100L - nTransparency)*aLineColor.GetBlue()) / 100L ) );
176*cdf0e10cSrcweir             o_rMtf.AddAction( new MetaLineColorAction(aLineColor, sal_True) );
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir             Color aFillColor( rStateOutDev.GetFillColor() );
179*cdf0e10cSrcweir             aFillColor.SetRed( static_cast<sal_uInt8>( (255L*nTransparency + (100L - nTransparency)*aFillColor.GetRed()) / 100L ) );
180*cdf0e10cSrcweir             aFillColor.SetGreen( static_cast<sal_uInt8>( (255L*nTransparency + (100L - nTransparency)*aFillColor.GetGreen()) / 100L ) );
181*cdf0e10cSrcweir             aFillColor.SetBlue( static_cast<sal_uInt8>( (255L*nTransparency + (100L - nTransparency)*aFillColor.GetBlue()) / 100L ) );
182*cdf0e10cSrcweir             o_rMtf.AddAction( new MetaFillColorAction(aFillColor, sal_True) );
183*cdf0e10cSrcweir         }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         o_rMtf.AddAction( new MetaPolyPolygonAction(pTransAct->GetPolyPolygon()) );
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         if( nTransparency )
188*cdf0e10cSrcweir             o_rMtf.AddAction( new MetaPopAction() );
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir     else
191*cdf0e10cSrcweir     {
192*cdf0e10cSrcweir         BitmapEx aBmpEx;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         switch( rAct.GetType() )
195*cdf0e10cSrcweir         {
196*cdf0e10cSrcweir             case META_BMPEX_ACTION:
197*cdf0e10cSrcweir                 aBmpEx = static_cast<const MetaBmpExAction&>(rAct).GetBitmapEx();
198*cdf0e10cSrcweir                 break;
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir             case META_BMPEXSCALE_ACTION:
201*cdf0e10cSrcweir                 aBmpEx = static_cast<const MetaBmpExScaleAction&>(rAct).GetBitmapEx();
202*cdf0e10cSrcweir                 break;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir             case META_BMPEXSCALEPART_ACTION:
205*cdf0e10cSrcweir                 aBmpEx = static_cast<const MetaBmpExScaleAction&>(rAct).GetBitmapEx();
206*cdf0e10cSrcweir                 break;
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir             case META_RENDERGRAPHIC_ACTION:
209*cdf0e10cSrcweir             {
210*cdf0e10cSrcweir                 const ::vcl::RenderGraphicRasterizer aRasterizer( static_cast<const MetaRenderGraphicAction&>(rAct).
211*cdf0e10cSrcweir                                                                       GetRenderGraphic() );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir                 aBmpEx = aRasterizer.Rasterize( rStateOutDev.LogicToPixel(
214*cdf0e10cSrcweir                              static_cast<const MetaRenderGraphicAction&>(rAct).GetSize() ) );
215*cdf0e10cSrcweir                 break;
216*cdf0e10cSrcweir             }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir             case META_TRANSPARENT_ACTION:
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir             default:
221*cdf0e10cSrcweir                 DBG_ERROR("Printer::GetPreparedMetafile impossible state reached");
222*cdf0e10cSrcweir                 break;
223*cdf0e10cSrcweir         }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         Bitmap aBmp( aBmpEx.GetBitmap() );
226*cdf0e10cSrcweir         if( !aBmpEx.IsAlpha() )
227*cdf0e10cSrcweir         {
228*cdf0e10cSrcweir             // blend with mask
229*cdf0e10cSrcweir             BitmapReadAccess* pRA = aBmp.AcquireReadAccess();
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir             if( !pRA )
232*cdf0e10cSrcweir                 return; // what else should I do?
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir             Color aActualColor( aBgColor );
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir             if( pRA->HasPalette() )
237*cdf0e10cSrcweir                 aActualColor = pRA->GetBestPaletteColor( aBgColor ).operator Color();
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir             aBmp.ReleaseAccess(pRA);
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir             // did we get true white?
242*cdf0e10cSrcweir             if( aActualColor.GetColorError( aBgColor ) )
243*cdf0e10cSrcweir             {
244*cdf0e10cSrcweir                 // no, create truecolor bitmap, then
245*cdf0e10cSrcweir                 aBmp.Convert( BMP_CONVERSION_24BIT );
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir                 // fill masked out areas white
248*cdf0e10cSrcweir                 aBmp.Replace( aBmpEx.GetMask(), aBgColor );
249*cdf0e10cSrcweir             }
250*cdf0e10cSrcweir             else
251*cdf0e10cSrcweir             {
252*cdf0e10cSrcweir                 // fill masked out areas white
253*cdf0e10cSrcweir                 aBmp.Replace( aBmpEx.GetMask(), aActualColor );
254*cdf0e10cSrcweir             }
255*cdf0e10cSrcweir         }
256*cdf0e10cSrcweir         else
257*cdf0e10cSrcweir         {
258*cdf0e10cSrcweir             // blend with alpha channel
259*cdf0e10cSrcweir             aBmp.Convert( BMP_CONVERSION_24BIT );
260*cdf0e10cSrcweir             aBmp.Blend(aBmpEx.GetAlpha(),aBgColor);
261*cdf0e10cSrcweir         }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir         // add corresponding action
264*cdf0e10cSrcweir         switch( rAct.GetType() )
265*cdf0e10cSrcweir         {
266*cdf0e10cSrcweir             case META_BMPEX_ACTION:
267*cdf0e10cSrcweir                 o_rMtf.AddAction( new MetaBmpAction(
268*cdf0e10cSrcweir                                        static_cast<const MetaBmpExAction&>(rAct).GetPoint(),
269*cdf0e10cSrcweir                                        aBmp ));
270*cdf0e10cSrcweir                 break;
271*cdf0e10cSrcweir             case META_BMPEXSCALE_ACTION:
272*cdf0e10cSrcweir                 o_rMtf.AddAction( new MetaBmpScaleAction(
273*cdf0e10cSrcweir                                        static_cast<const MetaBmpExScaleAction&>(rAct).GetPoint(),
274*cdf0e10cSrcweir                                        static_cast<const MetaBmpExScaleAction&>(rAct).GetSize(),
275*cdf0e10cSrcweir                                        aBmp ));
276*cdf0e10cSrcweir                 break;
277*cdf0e10cSrcweir             case META_BMPEXSCALEPART_ACTION:
278*cdf0e10cSrcweir                 o_rMtf.AddAction( new MetaBmpScalePartAction(
279*cdf0e10cSrcweir                                        static_cast<const MetaBmpExScalePartAction&>(rAct).GetDestPoint(),
280*cdf0e10cSrcweir                                        static_cast<const MetaBmpExScalePartAction&>(rAct).GetDestSize(),
281*cdf0e10cSrcweir                                        static_cast<const MetaBmpExScalePartAction&>(rAct).GetSrcPoint(),
282*cdf0e10cSrcweir                                        static_cast<const MetaBmpExScalePartAction&>(rAct).GetSrcSize(),
283*cdf0e10cSrcweir                                        aBmp ));
284*cdf0e10cSrcweir                 break;
285*cdf0e10cSrcweir             case META_RENDERGRAPHIC_ACTION:
286*cdf0e10cSrcweir                 o_rMtf.AddAction( new MetaBmpScaleAction(
287*cdf0e10cSrcweir                                        static_cast<const MetaRenderGraphicAction&>(rAct).GetPoint(),
288*cdf0e10cSrcweir                                        static_cast<const MetaRenderGraphicAction&>(rAct).GetSize(),
289*cdf0e10cSrcweir                                        aBmp ));
290*cdf0e10cSrcweir             default:
291*cdf0e10cSrcweir                 DBG_ERROR("Unexpected case");
292*cdf0e10cSrcweir                 break;
293*cdf0e10cSrcweir         }
294*cdf0e10cSrcweir     }
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir // #i10613# Extracted from ImplCheckRect::ImplCreate
298*cdf0e10cSrcweir // Returns true, if given action creates visible (i.e. non-transparent) output
299*cdf0e10cSrcweir static bool ImplIsNotTransparent( const MetaAction& rAct, const OutputDevice& rOut )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir     const bool	bLineTransparency( rOut.IsLineColor() ? rOut.GetLineColor().GetTransparency() == 255 : true );
302*cdf0e10cSrcweir     const bool 	bFillTransparency( rOut.IsFillColor() ? rOut.GetFillColor().GetTransparency() == 255 : true );
303*cdf0e10cSrcweir     bool		bRet( false );
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	switch( rAct.GetType() )
306*cdf0e10cSrcweir 	{
307*cdf0e10cSrcweir 		case META_POINT_ACTION:
308*cdf0e10cSrcweir             if( !bLineTransparency )
309*cdf0e10cSrcweir                 bRet = true;
310*cdf0e10cSrcweir             break;
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 		case META_LINE_ACTION:
313*cdf0e10cSrcweir             if( !bLineTransparency )
314*cdf0e10cSrcweir                 bRet = true;
315*cdf0e10cSrcweir             break;
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 		case META_RECT_ACTION:
318*cdf0e10cSrcweir             if( !bLineTransparency || !bFillTransparency )
319*cdf0e10cSrcweir                 bRet = true;
320*cdf0e10cSrcweir             break;
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 		case META_ROUNDRECT_ACTION:
323*cdf0e10cSrcweir             if( !bLineTransparency || !bFillTransparency )
324*cdf0e10cSrcweir                 bRet = true;
325*cdf0e10cSrcweir             break;
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 		case META_ELLIPSE_ACTION:
328*cdf0e10cSrcweir             if( !bLineTransparency || !bFillTransparency )
329*cdf0e10cSrcweir                 bRet = true;
330*cdf0e10cSrcweir             break;
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 		case META_ARC_ACTION:
333*cdf0e10cSrcweir             if( !bLineTransparency || !bFillTransparency )
334*cdf0e10cSrcweir                 bRet = true;
335*cdf0e10cSrcweir             break;
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 		case META_PIE_ACTION:
338*cdf0e10cSrcweir             if( !bLineTransparency || !bFillTransparency )
339*cdf0e10cSrcweir                 bRet = true;
340*cdf0e10cSrcweir             break;
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		case META_CHORD_ACTION:
343*cdf0e10cSrcweir             if( !bLineTransparency || !bFillTransparency )
344*cdf0e10cSrcweir                 bRet = true;
345*cdf0e10cSrcweir             break;
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 		case META_POLYLINE_ACTION:
348*cdf0e10cSrcweir             if( !bLineTransparency )
349*cdf0e10cSrcweir                 bRet = true;
350*cdf0e10cSrcweir             break;
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 		case META_POLYGON_ACTION:
353*cdf0e10cSrcweir             if( !bLineTransparency || !bFillTransparency )
354*cdf0e10cSrcweir                 bRet = true;
355*cdf0e10cSrcweir             break;
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 		case META_POLYPOLYGON_ACTION:
358*cdf0e10cSrcweir             if( !bLineTransparency || !bFillTransparency )
359*cdf0e10cSrcweir                 bRet = true;
360*cdf0e10cSrcweir             break;
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir         case META_TEXT_ACTION:
363*cdf0e10cSrcweir         {
364*cdf0e10cSrcweir             const MetaTextAction& rTextAct = static_cast<const MetaTextAction&>(rAct);
365*cdf0e10cSrcweir             const XubString aString( rTextAct.GetText(), rTextAct.GetIndex(), rTextAct.GetLen() );
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir             if( aString.Len() )
368*cdf0e10cSrcweir                 bRet = true;
369*cdf0e10cSrcweir         }
370*cdf0e10cSrcweir         break;
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 		case META_TEXTARRAY_ACTION:
373*cdf0e10cSrcweir 		{
374*cdf0e10cSrcweir             const MetaTextArrayAction& rTextAct = static_cast<const MetaTextArrayAction&>(rAct);
375*cdf0e10cSrcweir             const XubString aString( rTextAct.GetText(), rTextAct.GetIndex(), rTextAct.GetLen() );
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir             if( aString.Len() )
378*cdf0e10cSrcweir                 bRet = true;
379*cdf0e10cSrcweir 		}
380*cdf0e10cSrcweir 		break;
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 		case META_PIXEL_ACTION:
383*cdf0e10cSrcweir 		case META_BMP_ACTION:
384*cdf0e10cSrcweir 		case META_BMPSCALE_ACTION:
385*cdf0e10cSrcweir 		case META_BMPSCALEPART_ACTION:
386*cdf0e10cSrcweir 		case META_BMPEX_ACTION:
387*cdf0e10cSrcweir 		case META_BMPEXSCALE_ACTION:
388*cdf0e10cSrcweir 		case META_BMPEXSCALEPART_ACTION:
389*cdf0e10cSrcweir 		case META_MASK_ACTION:
390*cdf0e10cSrcweir 		case META_MASKSCALE_ACTION:
391*cdf0e10cSrcweir 		case META_MASKSCALEPART_ACTION:
392*cdf0e10cSrcweir 		case META_GRADIENT_ACTION:
393*cdf0e10cSrcweir 		case META_GRADIENTEX_ACTION:
394*cdf0e10cSrcweir 		case META_HATCH_ACTION:
395*cdf0e10cSrcweir 		case META_WALLPAPER_ACTION:
396*cdf0e10cSrcweir 		case META_TRANSPARENT_ACTION:
397*cdf0e10cSrcweir 		case META_FLOATTRANSPARENT_ACTION:
398*cdf0e10cSrcweir 		case META_EPS_ACTION:
399*cdf0e10cSrcweir 		case META_TEXTRECT_ACTION:
400*cdf0e10cSrcweir 		case META_STRETCHTEXT_ACTION:
401*cdf0e10cSrcweir 		case META_TEXTLINE_ACTION:
402*cdf0e10cSrcweir 		case META_RENDERGRAPHIC_ACTION:
403*cdf0e10cSrcweir             // all other actions: generate non-transparent output
404*cdf0e10cSrcweir             bRet = true;
405*cdf0e10cSrcweir             break;
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 		default:
408*cdf0e10cSrcweir             break;
409*cdf0e10cSrcweir 	}
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir     return bRet;
412*cdf0e10cSrcweir }
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir // #i10613# Extracted from ImplCheckRect::ImplCreate
415*cdf0e10cSrcweir static Rectangle ImplCalcActionBounds( const MetaAction& rAct, const OutputDevice& rOut )
416*cdf0e10cSrcweir {
417*cdf0e10cSrcweir     Rectangle aActionBounds;
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 	switch( rAct.GetType() )
420*cdf0e10cSrcweir 	{
421*cdf0e10cSrcweir 		case META_PIXEL_ACTION:
422*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaPixelAction&>(rAct).GetPoint(), Size( 1, 1 ) );
423*cdf0e10cSrcweir             break;
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 		case META_POINT_ACTION:
426*cdf0e10cSrcweir             aActionBounds = Rectangle( static_cast<const MetaPointAction&>(rAct).GetPoint(), Size( 1, 1 ) );
427*cdf0e10cSrcweir             break;
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir 		case META_LINE_ACTION:
430*cdf0e10cSrcweir 		{
431*cdf0e10cSrcweir 			const MetaLineAction& rMetaLineAction = static_cast<const MetaLineAction&>(rAct);
432*cdf0e10cSrcweir             aActionBounds = Rectangle( rMetaLineAction.GetStartPoint(),  rMetaLineAction.GetEndPoint() );
433*cdf0e10cSrcweir             aActionBounds.Justify();
434*cdf0e10cSrcweir 			const long nLineWidth(rMetaLineAction.GetLineInfo().GetWidth());
435*cdf0e10cSrcweir 			if(nLineWidth)
436*cdf0e10cSrcweir 			{
437*cdf0e10cSrcweir 				const long nHalfLineWidth((nLineWidth + 1) / 2);
438*cdf0e10cSrcweir 				aActionBounds.Left() -= nHalfLineWidth;
439*cdf0e10cSrcweir 				aActionBounds.Top() -= nHalfLineWidth;
440*cdf0e10cSrcweir 				aActionBounds.Right() += nHalfLineWidth;
441*cdf0e10cSrcweir 				aActionBounds.Bottom() += nHalfLineWidth;
442*cdf0e10cSrcweir 			}
443*cdf0e10cSrcweir             break;
444*cdf0e10cSrcweir 		}
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 		case META_RECT_ACTION:
447*cdf0e10cSrcweir             aActionBounds = static_cast<const MetaRectAction&>(rAct).GetRect();
448*cdf0e10cSrcweir             break;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 		case META_ROUNDRECT_ACTION:
451*cdf0e10cSrcweir             aActionBounds = Polygon( static_cast<const MetaRoundRectAction&>(rAct).GetRect(),
452*cdf0e10cSrcweir                                      static_cast<const MetaRoundRectAction&>(rAct).GetHorzRound(),
453*cdf0e10cSrcweir                                      static_cast<const MetaRoundRectAction&>(rAct).GetVertRound() ).GetBoundRect();
454*cdf0e10cSrcweir             break;
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir 		case META_ELLIPSE_ACTION:
457*cdf0e10cSrcweir         {
458*cdf0e10cSrcweir             const Rectangle& rRect = static_cast<const MetaEllipseAction&>(rAct).GetRect();
459*cdf0e10cSrcweir             aActionBounds = Polygon( rRect.Center(),
460*cdf0e10cSrcweir                                      rRect.GetWidth() >> 1,
461*cdf0e10cSrcweir                                      rRect.GetHeight() >> 1 ).GetBoundRect();
462*cdf0e10cSrcweir             break;
463*cdf0e10cSrcweir         }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 		case META_ARC_ACTION:
466*cdf0e10cSrcweir             aActionBounds = Polygon( static_cast<const MetaArcAction&>(rAct).GetRect(),
467*cdf0e10cSrcweir                                      static_cast<const MetaArcAction&>(rAct).GetStartPoint(),
468*cdf0e10cSrcweir                                      static_cast<const MetaArcAction&>(rAct).GetEndPoint(), POLY_ARC ).GetBoundRect();
469*cdf0e10cSrcweir             break;
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 		case META_PIE_ACTION:
472*cdf0e10cSrcweir             aActionBounds = Polygon( static_cast<const MetaPieAction&>(rAct).GetRect(),
473*cdf0e10cSrcweir                                      static_cast<const MetaPieAction&>(rAct).GetStartPoint(),
474*cdf0e10cSrcweir                                      static_cast<const MetaPieAction&>(rAct).GetEndPoint(), POLY_PIE ).GetBoundRect();
475*cdf0e10cSrcweir             break;
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 		case META_CHORD_ACTION:
478*cdf0e10cSrcweir             aActionBounds = Polygon( static_cast<const MetaChordAction&>(rAct).GetRect(),
479*cdf0e10cSrcweir                                      static_cast<const MetaChordAction&>(rAct).GetStartPoint(),
480*cdf0e10cSrcweir                                      static_cast<const MetaChordAction&>(rAct).GetEndPoint(), POLY_CHORD ).GetBoundRect();
481*cdf0e10cSrcweir             break;
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir 		case META_POLYLINE_ACTION:
484*cdf0e10cSrcweir 		{
485*cdf0e10cSrcweir 			const MetaPolyLineAction& rMetaPolyLineAction = static_cast<const MetaPolyLineAction&>(rAct);
486*cdf0e10cSrcweir             aActionBounds = rMetaPolyLineAction.GetPolygon().GetBoundRect();
487*cdf0e10cSrcweir 			const long nLineWidth(rMetaPolyLineAction.GetLineInfo().GetWidth());
488*cdf0e10cSrcweir 			if(nLineWidth)
489*cdf0e10cSrcweir 			{
490*cdf0e10cSrcweir 				const long nHalfLineWidth((nLineWidth + 1) / 2);
491*cdf0e10cSrcweir 				aActionBounds.Left() -= nHalfLineWidth;
492*cdf0e10cSrcweir 				aActionBounds.Top() -= nHalfLineWidth;
493*cdf0e10cSrcweir 				aActionBounds.Right() += nHalfLineWidth;
494*cdf0e10cSrcweir 				aActionBounds.Bottom() += nHalfLineWidth;
495*cdf0e10cSrcweir 			}
496*cdf0e10cSrcweir             break;
497*cdf0e10cSrcweir 		}
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir 		case META_POLYGON_ACTION:
500*cdf0e10cSrcweir             aActionBounds = static_cast<const MetaPolygonAction&>(rAct).GetPolygon().GetBoundRect();
501*cdf0e10cSrcweir             break;
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir 		case META_POLYPOLYGON_ACTION:
504*cdf0e10cSrcweir             aActionBounds = static_cast<const MetaPolyPolygonAction&>(rAct).GetPolyPolygon().GetBoundRect();
505*cdf0e10cSrcweir             break;
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 		case META_BMP_ACTION:
508*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaBmpAction&>(rAct).GetPoint(),
509*cdf0e10cSrcweir                                        rOut.PixelToLogic( static_cast<const MetaBmpAction&>(rAct).GetBitmap().GetSizePixel() ) );
510*cdf0e10cSrcweir             break;
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 		case META_BMPSCALE_ACTION:
513*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaBmpScaleAction&>(rAct).GetPoint(),
514*cdf0e10cSrcweir                                        static_cast<const MetaBmpScaleAction&>(rAct).GetSize() );
515*cdf0e10cSrcweir             break;
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir 		case META_BMPSCALEPART_ACTION:
518*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaBmpScalePartAction&>(rAct).GetDestPoint(),
519*cdf0e10cSrcweir                                        static_cast<const MetaBmpScalePartAction&>(rAct).GetDestSize() );
520*cdf0e10cSrcweir             break;
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 		case META_BMPEX_ACTION:
523*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaBmpExAction&>(rAct).GetPoint(),
524*cdf0e10cSrcweir                                        rOut.PixelToLogic( static_cast<const MetaBmpExAction&>(rAct).GetBitmapEx().GetSizePixel() ) );
525*cdf0e10cSrcweir             break;
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 		case META_BMPEXSCALE_ACTION:
528*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaBmpExScaleAction&>(rAct).GetPoint(),
529*cdf0e10cSrcweir                                        static_cast<const MetaBmpExScaleAction&>(rAct).GetSize() );
530*cdf0e10cSrcweir             break;
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 		case META_BMPEXSCALEPART_ACTION:
533*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaBmpExScalePartAction&>(rAct).GetDestPoint(),
534*cdf0e10cSrcweir                                        static_cast<const MetaBmpExScalePartAction&>(rAct).GetDestSize() );
535*cdf0e10cSrcweir             break;
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 		case META_MASK_ACTION:
538*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaMaskAction&>(rAct).GetPoint(),
539*cdf0e10cSrcweir                                        rOut.PixelToLogic( static_cast<const MetaMaskAction&>(rAct).GetBitmap().GetSizePixel() ) );
540*cdf0e10cSrcweir             break;
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 		case META_MASKSCALE_ACTION:
543*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaMaskScaleAction&>(rAct).GetPoint(),
544*cdf0e10cSrcweir                                        static_cast<const MetaMaskScaleAction&>(rAct).GetSize() );
545*cdf0e10cSrcweir             break;
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 		case META_MASKSCALEPART_ACTION:
548*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaMaskScalePartAction&>(rAct).GetDestPoint(),
549*cdf0e10cSrcweir                                        static_cast<const MetaMaskScalePartAction&>(rAct).GetDestSize() );
550*cdf0e10cSrcweir             break;
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir 		case META_GRADIENT_ACTION:
553*cdf0e10cSrcweir 			aActionBounds = static_cast<const MetaGradientAction&>(rAct).GetRect();
554*cdf0e10cSrcweir             break;
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 		case META_GRADIENTEX_ACTION:
557*cdf0e10cSrcweir 			aActionBounds = static_cast<const MetaGradientExAction&>(rAct).GetPolyPolygon().GetBoundRect();
558*cdf0e10cSrcweir             break;
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 		case META_HATCH_ACTION:
561*cdf0e10cSrcweir 			aActionBounds = static_cast<const MetaHatchAction&>(rAct).GetPolyPolygon().GetBoundRect();
562*cdf0e10cSrcweir             break;
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 		case META_WALLPAPER_ACTION:
565*cdf0e10cSrcweir 			aActionBounds = static_cast<const MetaWallpaperAction&>(rAct).GetRect();
566*cdf0e10cSrcweir             break;
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 		case META_TRANSPARENT_ACTION:
569*cdf0e10cSrcweir 			aActionBounds = static_cast<const MetaTransparentAction&>(rAct).GetPolyPolygon().GetBoundRect();
570*cdf0e10cSrcweir             break;
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 		case META_FLOATTRANSPARENT_ACTION:
573*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaFloatTransparentAction&>(rAct).GetPoint(),
574*cdf0e10cSrcweir                                        static_cast<const MetaFloatTransparentAction&>(rAct).GetSize() );
575*cdf0e10cSrcweir             break;
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir 		case META_EPS_ACTION:
578*cdf0e10cSrcweir 			aActionBounds = Rectangle( static_cast<const MetaEPSAction&>(rAct).GetPoint(),
579*cdf0e10cSrcweir                                        static_cast<const MetaEPSAction&>(rAct).GetSize() );
580*cdf0e10cSrcweir             break;
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir         case META_TEXT_ACTION:
583*cdf0e10cSrcweir         {
584*cdf0e10cSrcweir             const MetaTextAction& rTextAct = static_cast<const MetaTextAction&>(rAct);
585*cdf0e10cSrcweir             const XubString aString( rTextAct.GetText(), rTextAct.GetIndex(), rTextAct.GetLen() );
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir             if( aString.Len() )
588*cdf0e10cSrcweir             {
589*cdf0e10cSrcweir     			const Point aPtLog( rTextAct.GetPoint() );
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir                 // #105987# Use API method instead of Impl* methods
592*cdf0e10cSrcweir                 // #107490# Set base parameter equal to index parameter
593*cdf0e10cSrcweir                 rOut.GetTextBoundRect( aActionBounds, rTextAct.GetText(), rTextAct.GetIndex(),
594*cdf0e10cSrcweir                                        rTextAct.GetIndex(), rTextAct.GetLen() );
595*cdf0e10cSrcweir                 aActionBounds.Move( aPtLog.X(), aPtLog.Y() );
596*cdf0e10cSrcweir             }
597*cdf0e10cSrcweir         }
598*cdf0e10cSrcweir         break;
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 		case META_TEXTARRAY_ACTION:
601*cdf0e10cSrcweir 		{
602*cdf0e10cSrcweir 			const MetaTextArrayAction&	rTextAct = static_cast<const MetaTextArrayAction&>(rAct);
603*cdf0e10cSrcweir 			const XubString 			aString( rTextAct.GetText(), rTextAct.GetIndex(), rTextAct.GetLen() );
604*cdf0e10cSrcweir             const long              	nLen = aString.Len();
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir             if( nLen )
607*cdf0e10cSrcweir             {
608*cdf0e10cSrcweir                 // #105987# ImplLayout takes everything in logical coordinates
609*cdf0e10cSrcweir                 SalLayout* pSalLayout = rOut.ImplLayout( rTextAct.GetText(), rTextAct.GetIndex(),
610*cdf0e10cSrcweir                                                          rTextAct.GetLen(), rTextAct.GetPoint(),
611*cdf0e10cSrcweir                                                          0, rTextAct.GetDXArray() );
612*cdf0e10cSrcweir                 if( pSalLayout )
613*cdf0e10cSrcweir                 {
614*cdf0e10cSrcweir                     Rectangle aBoundRect( const_cast<OutputDevice&>(rOut).ImplGetTextBoundRect( *pSalLayout ) );
615*cdf0e10cSrcweir                     aActionBounds = rOut.PixelToLogic( aBoundRect );
616*cdf0e10cSrcweir                     pSalLayout->Release();
617*cdf0e10cSrcweir                 }
618*cdf0e10cSrcweir             }
619*cdf0e10cSrcweir 		}
620*cdf0e10cSrcweir 		break;
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 		case META_TEXTRECT_ACTION:
623*cdf0e10cSrcweir 			aActionBounds = static_cast<const MetaTextRectAction&>(rAct).GetRect();
624*cdf0e10cSrcweir             break;
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir 		case META_STRETCHTEXT_ACTION:
627*cdf0e10cSrcweir         {
628*cdf0e10cSrcweir             const MetaStretchTextAction& rTextAct = static_cast<const MetaStretchTextAction&>(rAct);
629*cdf0e10cSrcweir             const XubString 			 aString( rTextAct.GetText(), rTextAct.GetIndex(), rTextAct.GetLen() );
630*cdf0e10cSrcweir             const long              	 nLen = aString.Len();
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir             // #i16195# Literate copy from TextArray action, the
633*cdf0e10cSrcweir             // semantics for the ImplLayout call are copied from the
634*cdf0e10cSrcweir             // OutDev::DrawStretchText() code. Unfortunately, also in
635*cdf0e10cSrcweir             // this case, public outdev methods such as GetTextWidth()
636*cdf0e10cSrcweir             // don't provide enough info.
637*cdf0e10cSrcweir             if( nLen )
638*cdf0e10cSrcweir             {
639*cdf0e10cSrcweir                 // #105987# ImplLayout takes everything in logical coordinates
640*cdf0e10cSrcweir                 SalLayout* pSalLayout = rOut.ImplLayout( rTextAct.GetText(), rTextAct.GetIndex(),
641*cdf0e10cSrcweir                                                          rTextAct.GetLen(), rTextAct.GetPoint(),
642*cdf0e10cSrcweir                                                          rTextAct.GetWidth() );
643*cdf0e10cSrcweir                 if( pSalLayout )
644*cdf0e10cSrcweir                 {
645*cdf0e10cSrcweir                     Rectangle aBoundRect( const_cast<OutputDevice&>(rOut).ImplGetTextBoundRect( *pSalLayout ) );
646*cdf0e10cSrcweir                     aActionBounds = rOut.PixelToLogic( aBoundRect );
647*cdf0e10cSrcweir                     pSalLayout->Release();
648*cdf0e10cSrcweir                 }
649*cdf0e10cSrcweir             }
650*cdf0e10cSrcweir         }
651*cdf0e10cSrcweir         break;
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 		case META_TEXTLINE_ACTION:
654*cdf0e10cSrcweir 			DBG_ERROR("META_TEXTLINE_ACTION not supported");
655*cdf0e10cSrcweir         break;
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir         case( META_RENDERGRAPHIC_ACTION ):
658*cdf0e10cSrcweir         {
659*cdf0e10cSrcweir             const MetaRenderGraphicAction& rRenderAct = static_cast<const MetaRenderGraphicAction&>(rAct);
660*cdf0e10cSrcweir 			aActionBounds = Rectangle( rRenderAct.GetPoint(), rRenderAct.GetSize() );
661*cdf0e10cSrcweir         }
662*cdf0e10cSrcweir         break;
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir 		default:
665*cdf0e10cSrcweir             break;
666*cdf0e10cSrcweir 	}
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir 	if( !aActionBounds.IsEmpty() )
669*cdf0e10cSrcweir 		return rOut.LogicToPixel( aActionBounds );
670*cdf0e10cSrcweir     else
671*cdf0e10cSrcweir         return Rectangle();
672*cdf0e10cSrcweir }
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir static bool ImplIsActionHandlingTransparency( const MetaAction& rAct )
675*cdf0e10cSrcweir {
676*cdf0e10cSrcweir     // META_FLOATTRANSPARENT_ACTION can contain a whole metafile,
677*cdf0e10cSrcweir     // which is to be rendered with the given transparent gradient. We
678*cdf0e10cSrcweir     // currently cannot emulate transparent painting on a white
679*cdf0e10cSrcweir     // background reliably.
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir     // the remainder can handle printing itself correctly on a uniform
682*cdf0e10cSrcweir     // white background.
683*cdf0e10cSrcweir     switch( rAct.GetType() )
684*cdf0e10cSrcweir     {
685*cdf0e10cSrcweir         case META_TRANSPARENT_ACTION:
686*cdf0e10cSrcweir         case META_BMPEX_ACTION:
687*cdf0e10cSrcweir         case META_BMPEXSCALE_ACTION:
688*cdf0e10cSrcweir         case META_BMPEXSCALEPART_ACTION:
689*cdf0e10cSrcweir         case META_RENDERGRAPHIC_ACTION:
690*cdf0e10cSrcweir             return true;
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir         default:
693*cdf0e10cSrcweir             return false;
694*cdf0e10cSrcweir     }
695*cdf0e10cSrcweir }
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir // remove comment to enable highlighting of generated output
698*cdf0e10cSrcweir bool OutputDevice::RemoveTransparenciesFromMetaFile( const GDIMetaFile& rInMtf, GDIMetaFile& rOutMtf,
699*cdf0e10cSrcweir                                                      long nMaxBmpDPIX, long nMaxBmpDPIY,
700*cdf0e10cSrcweir                                                      bool bReduceTransparency, bool bTransparencyAutoMode,
701*cdf0e10cSrcweir                                                      bool bDownsampleBitmaps,
702*cdf0e10cSrcweir                                                      const Color& rBackground
703*cdf0e10cSrcweir                                                      )
704*cdf0e10cSrcweir {
705*cdf0e10cSrcweir 	MetaAction*             pCurrAct;
706*cdf0e10cSrcweir 	bool		            bTransparent( false );
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir 	rOutMtf.Clear();
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir     if( ! bReduceTransparency || bTransparencyAutoMode )
711*cdf0e10cSrcweir     {
712*cdf0e10cSrcweir         // watch for transparent drawing actions
713*cdf0e10cSrcweir 	    for( pCurrAct = ( (GDIMetaFile&) rInMtf ).FirstAction();
714*cdf0e10cSrcweir              pCurrAct && !bTransparent;
715*cdf0e10cSrcweir              pCurrAct = ( (GDIMetaFile&) rInMtf ).NextAction() )
716*cdf0e10cSrcweir         {
717*cdf0e10cSrcweir             // #i10613# Extracted "specialness" predicate into extra method
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir             // #107169# Also examine metafiles with masked bitmaps in
720*cdf0e10cSrcweir             // detail. Further down, this is optimized in such a way
721*cdf0e10cSrcweir             // that there's no unnecessary painting of masked bitmaps
722*cdf0e10cSrcweir             // (which are _always_ subdivided into rectangular regions
723*cdf0e10cSrcweir             // of uniform opacity): if a masked bitmap is printed over
724*cdf0e10cSrcweir             // empty background, we convert to a plain bitmap with
725*cdf0e10cSrcweir             // white background.
726*cdf0e10cSrcweir             if( ImplIsActionSpecial( *pCurrAct ) )
727*cdf0e10cSrcweir             {
728*cdf0e10cSrcweir                 bTransparent = true;
729*cdf0e10cSrcweir             }
730*cdf0e10cSrcweir         }
731*cdf0e10cSrcweir     }
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir     // #i10613# Determine set of connected components containing transparent objects. These are
734*cdf0e10cSrcweir     // then processed as bitmaps, the original actions are removed from the metafile.
735*cdf0e10cSrcweir 	if( !bTransparent )
736*cdf0e10cSrcweir     {
737*cdf0e10cSrcweir         // nothing transparent -> just copy
738*cdf0e10cSrcweir 		rOutMtf = rInMtf;
739*cdf0e10cSrcweir     }
740*cdf0e10cSrcweir 	else
741*cdf0e10cSrcweir 	{
742*cdf0e10cSrcweir         // #i10613#
743*cdf0e10cSrcweir         // This works as follows: we want a number of distinct sets of
744*cdf0e10cSrcweir         // connected components, where each set contains metafile
745*cdf0e10cSrcweir         // actions that are intersecting (note: there are possibly
746*cdf0e10cSrcweir         // more actions contained as are directly intersecting,
747*cdf0e10cSrcweir         // because we can only produce rectangular bitmaps later
748*cdf0e10cSrcweir         // on. Thus, each set of connected components is the smallest
749*cdf0e10cSrcweir         // enclosing, axis-aligned rectangle that completely bounds a
750*cdf0e10cSrcweir         // number of intersecting metafile actions, plus any action
751*cdf0e10cSrcweir         // that would otherwise be cut in two). Therefore, we
752*cdf0e10cSrcweir         // iteratively add metafile actions from the original metafile
753*cdf0e10cSrcweir         // to this connected components list (aCCList), by checking
754*cdf0e10cSrcweir         // each element's bounding box against intersection with the
755*cdf0e10cSrcweir         // metaaction at hand.
756*cdf0e10cSrcweir         // All those intersecting elements are removed from aCCList
757*cdf0e10cSrcweir         // and collected in a temporary list (aCCMergeList). After all
758*cdf0e10cSrcweir         // elements have been checked, the aCCMergeList elements are
759*cdf0e10cSrcweir         // merged with the metaaction at hand into one resulting
760*cdf0e10cSrcweir         // connected component, with one big bounding box, and
761*cdf0e10cSrcweir         // inserted into aCCList again.
762*cdf0e10cSrcweir         // The time complexity of this algorithm is O(n^3), where n is
763*cdf0e10cSrcweir         // the number of metafile actions, and it finds all distinct
764*cdf0e10cSrcweir         // regions of rectangle-bounded connected components. This
765*cdf0e10cSrcweir         // algorithm was designed by AF.
766*cdf0e10cSrcweir         //
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir         //
769*cdf0e10cSrcweir         //  STAGE 1: Detect background
770*cdf0e10cSrcweir         //  ==========================
771*cdf0e10cSrcweir         //
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir         // Receives uniform background content, and is _not_ merged
774*cdf0e10cSrcweir         // nor checked for intersection against other aCCList elements
775*cdf0e10cSrcweir         ConnectedComponents aBackgroundComponent;
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir         // create an OutputDevice to record mapmode changes and the like
778*cdf0e10cSrcweir 		VirtualDevice aMapModeVDev;
779*cdf0e10cSrcweir 		aMapModeVDev.mnDPIX = mnDPIX;
780*cdf0e10cSrcweir 		aMapModeVDev.mnDPIY = mnDPIY;
781*cdf0e10cSrcweir 		aMapModeVDev.EnableOutput(sal_False);
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir         int nLastBgAction, nActionNum;
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir         // weed out page-filling background objects (if they are
786*cdf0e10cSrcweir         // uniformly coloured). Keeping them outside the other
787*cdf0e10cSrcweir         // connected components often prevents whole-page bitmap
788*cdf0e10cSrcweir         // generation.
789*cdf0e10cSrcweir         bool bStillBackground=true; // true until first non-bg action
790*cdf0e10cSrcweir         nActionNum=0; nLastBgAction=-1;
791*cdf0e10cSrcweir 		pCurrAct=const_cast<GDIMetaFile&>(rInMtf).FirstAction();
792*cdf0e10cSrcweir         if( rBackground != Color( COL_TRANSPARENT ) )
793*cdf0e10cSrcweir         {
794*cdf0e10cSrcweir             aBackgroundComponent.aBgColor = rBackground;
795*cdf0e10cSrcweir             if( meOutDevType == OUTDEV_PRINTER )
796*cdf0e10cSrcweir             {
797*cdf0e10cSrcweir                 Printer* pThis = dynamic_cast<Printer*>(this);
798*cdf0e10cSrcweir                 Point aPageOffset = pThis->GetPageOffsetPixel();
799*cdf0e10cSrcweir                 aPageOffset = Point( 0, 0 ) - aPageOffset;
800*cdf0e10cSrcweir                 Size aSize  = pThis->GetPaperSizePixel();
801*cdf0e10cSrcweir                 aBackgroundComponent.aBounds = Rectangle( aPageOffset, aSize );
802*cdf0e10cSrcweir             }
803*cdf0e10cSrcweir             else
804*cdf0e10cSrcweir                 aBackgroundComponent.aBounds = Rectangle( Point( 0, 0 ), GetOutputSizePixel() );
805*cdf0e10cSrcweir         }
806*cdf0e10cSrcweir 		while( pCurrAct && bStillBackground )
807*cdf0e10cSrcweir 		{
808*cdf0e10cSrcweir             switch( pCurrAct->GetType() )
809*cdf0e10cSrcweir             {
810*cdf0e10cSrcweir                 case META_RECT_ACTION:
811*cdf0e10cSrcweir                 {
812*cdf0e10cSrcweir                     if( !checkRect(
813*cdf0e10cSrcweir                             aBackgroundComponent.aBounds,
814*cdf0e10cSrcweir                             aBackgroundComponent.aBgColor,
815*cdf0e10cSrcweir                             static_cast<const MetaRectAction*>(pCurrAct)->GetRect(),
816*cdf0e10cSrcweir                             aMapModeVDev) )
817*cdf0e10cSrcweir                         bStillBackground=false; // incomplete occlusion of background
818*cdf0e10cSrcweir                     else
819*cdf0e10cSrcweir                         nLastBgAction=nActionNum; // this _is_ background
820*cdf0e10cSrcweir                     break;
821*cdf0e10cSrcweir                 }
822*cdf0e10cSrcweir                 case META_POLYGON_ACTION:
823*cdf0e10cSrcweir                 {
824*cdf0e10cSrcweir                     const Polygon aPoly(
825*cdf0e10cSrcweir                         static_cast<const MetaPolygonAction*>(pCurrAct)->GetPolygon());
826*cdf0e10cSrcweir                     if( !basegfx::tools::isRectangle(
827*cdf0e10cSrcweir                             aPoly.getB2DPolygon()) ||
828*cdf0e10cSrcweir                         !checkRect(
829*cdf0e10cSrcweir                             aBackgroundComponent.aBounds,
830*cdf0e10cSrcweir                             aBackgroundComponent.aBgColor,
831*cdf0e10cSrcweir                             aPoly.GetBoundRect(),
832*cdf0e10cSrcweir                             aMapModeVDev) )
833*cdf0e10cSrcweir                         bStillBackground=false; // incomplete occlusion of background
834*cdf0e10cSrcweir                     else
835*cdf0e10cSrcweir                         nLastBgAction=nActionNum; // this _is_ background
836*cdf0e10cSrcweir                     break;
837*cdf0e10cSrcweir                 }
838*cdf0e10cSrcweir                 case META_POLYPOLYGON_ACTION:
839*cdf0e10cSrcweir                 {
840*cdf0e10cSrcweir                     const PolyPolygon aPoly(
841*cdf0e10cSrcweir                         static_cast<const MetaPolyPolygonAction*>(pCurrAct)->GetPolyPolygon());
842*cdf0e10cSrcweir                     if( aPoly.Count() != 1 ||
843*cdf0e10cSrcweir                         !basegfx::tools::isRectangle(
844*cdf0e10cSrcweir                             aPoly[0].getB2DPolygon()) ||
845*cdf0e10cSrcweir                         !checkRect(
846*cdf0e10cSrcweir                             aBackgroundComponent.aBounds,
847*cdf0e10cSrcweir                             aBackgroundComponent.aBgColor,
848*cdf0e10cSrcweir                             aPoly.GetBoundRect(),
849*cdf0e10cSrcweir                             aMapModeVDev) )
850*cdf0e10cSrcweir                         bStillBackground=false; // incomplete occlusion of background
851*cdf0e10cSrcweir                     else
852*cdf0e10cSrcweir                         nLastBgAction=nActionNum; // this _is_ background
853*cdf0e10cSrcweir                     break;
854*cdf0e10cSrcweir                 }
855*cdf0e10cSrcweir                 case META_WALLPAPER_ACTION:
856*cdf0e10cSrcweir                 {
857*cdf0e10cSrcweir                     if( !checkRect(
858*cdf0e10cSrcweir                             aBackgroundComponent.aBounds,
859*cdf0e10cSrcweir                             aBackgroundComponent.aBgColor,
860*cdf0e10cSrcweir                             static_cast<const MetaWallpaperAction*>(pCurrAct)->GetRect(),
861*cdf0e10cSrcweir                             aMapModeVDev) )
862*cdf0e10cSrcweir                         bStillBackground=false; // incomplete occlusion of background
863*cdf0e10cSrcweir                     else
864*cdf0e10cSrcweir                         nLastBgAction=nActionNum; // this _is_ background
865*cdf0e10cSrcweir                     break;
866*cdf0e10cSrcweir                 }
867*cdf0e10cSrcweir                 default:
868*cdf0e10cSrcweir                 {
869*cdf0e10cSrcweir                     if( ImplIsNotTransparent( *pCurrAct,
870*cdf0e10cSrcweir                                               aMapModeVDev ) )
871*cdf0e10cSrcweir                         bStillBackground=false; // non-transparent action, possibly
872*cdf0e10cSrcweir                                                 // not uniform
873*cdf0e10cSrcweir                     else
874*cdf0e10cSrcweir                         // extend current bounds (next uniform action
875*cdf0e10cSrcweir                         // needs to fully cover this area)
876*cdf0e10cSrcweir                         aBackgroundComponent.aBounds.Union(
877*cdf0e10cSrcweir                             ImplCalcActionBounds(*pCurrAct, aMapModeVDev) );
878*cdf0e10cSrcweir                     break;
879*cdf0e10cSrcweir                 }
880*cdf0e10cSrcweir             }
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir             // execute action to get correct MapModes etc.
883*cdf0e10cSrcweir             pCurrAct->Execute( &aMapModeVDev );
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir             pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction();
886*cdf0e10cSrcweir             ++nActionNum;
887*cdf0e10cSrcweir         }
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir         // clean up aMapModeVDev
890*cdf0e10cSrcweir         sal_uInt32 nCount = aMapModeVDev.GetGCStackDepth();
891*cdf0e10cSrcweir         while( nCount-- )
892*cdf0e10cSrcweir             aMapModeVDev.Pop();
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir         ConnectedComponentsList	aCCList; // list containing distinct sets of connected components as elements.
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir         // fast-forward until one after the last background action
897*cdf0e10cSrcweir         // (need to reconstruct map mode vdev state)
898*cdf0e10cSrcweir         nActionNum=0;
899*cdf0e10cSrcweir 		pCurrAct=const_cast<GDIMetaFile&>(rInMtf).FirstAction();
900*cdf0e10cSrcweir 		while( pCurrAct && nActionNum<=nLastBgAction )
901*cdf0e10cSrcweir 		{
902*cdf0e10cSrcweir             // up to and including last ink-generating background
903*cdf0e10cSrcweir             // action go to background component
904*cdf0e10cSrcweir             aBackgroundComponent.aComponentList.push_back(
905*cdf0e10cSrcweir                 ::std::make_pair(
906*cdf0e10cSrcweir                     pCurrAct, nActionNum) );
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir 			// execute action to get correct MapModes etc.
909*cdf0e10cSrcweir 			pCurrAct->Execute( &aMapModeVDev );
910*cdf0e10cSrcweir             pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction();
911*cdf0e10cSrcweir             ++nActionNum;
912*cdf0e10cSrcweir         }
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir         //
915*cdf0e10cSrcweir         //  STAGE 2: Generate connected components list
916*cdf0e10cSrcweir         //  ===========================================
917*cdf0e10cSrcweir         //
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir         // iterate over all actions (start where background action
920*cdf0e10cSrcweir         // search left off)
921*cdf0e10cSrcweir 		for( ;
922*cdf0e10cSrcweir              pCurrAct;
923*cdf0e10cSrcweir              pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction(), ++nActionNum )
924*cdf0e10cSrcweir 		{
925*cdf0e10cSrcweir 			// execute action to get correct MapModes etc.
926*cdf0e10cSrcweir 			pCurrAct->Execute( &aMapModeVDev );
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir             // cache bounds of current action
929*cdf0e10cSrcweir             const Rectangle aBBCurrAct( ImplCalcActionBounds(*pCurrAct, aMapModeVDev) );
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir             // accumulate collected bounds here, initialize with current action
932*cdf0e10cSrcweir             Rectangle								aTotalBounds( aBBCurrAct ); // thus,
933*cdf0e10cSrcweir             																	// aTotalComponents.aBounds
934*cdf0e10cSrcweir             																	// is
935*cdf0e10cSrcweir             																	// empty
936*cdf0e10cSrcweir             																	// for
937*cdf0e10cSrcweir             																	// non-output-generating
938*cdf0e10cSrcweir             																	// actions
939*cdf0e10cSrcweir             bool									bTreatSpecial( false );
940*cdf0e10cSrcweir             ConnectedComponents						aTotalComponents;
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir             //
943*cdf0e10cSrcweir             //  STAGE 2.1: Search for intersecting cc entries
944*cdf0e10cSrcweir             //  =============================================
945*cdf0e10cSrcweir             //
946*cdf0e10cSrcweir 
947*cdf0e10cSrcweir             // if aBBCurrAct is empty, it will intersect with no
948*cdf0e10cSrcweir             // aCCList member. Thus, we can save the check.
949*cdf0e10cSrcweir             // Furthermore, this ensures that non-output-generating
950*cdf0e10cSrcweir             // actions get their own aCCList entry, which is necessary
951*cdf0e10cSrcweir             // when copying them to the output metafile (see stage 4
952*cdf0e10cSrcweir             // below).
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir             // #107169# Wholly transparent objects need
955*cdf0e10cSrcweir             // not be considered for connected components,
956*cdf0e10cSrcweir             // too. Just put each of them into a separate
957*cdf0e10cSrcweir             // component.
958*cdf0e10cSrcweir             aTotalComponents.bIsFullyTransparent = !ImplIsNotTransparent(*pCurrAct, aMapModeVDev);
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir             if( !aBBCurrAct.IsEmpty() &&
961*cdf0e10cSrcweir                 !aTotalComponents.bIsFullyTransparent )
962*cdf0e10cSrcweir             {
963*cdf0e10cSrcweir                 if( !aBackgroundComponent.aComponentList.empty() &&
964*cdf0e10cSrcweir                     !aBackgroundComponent.aBounds.IsInside(aTotalBounds) )
965*cdf0e10cSrcweir                 {
966*cdf0e10cSrcweir                     // it seems the background is not large enough. to
967*cdf0e10cSrcweir                     // be on the safe side, combine with this component.
968*cdf0e10cSrcweir                     aTotalBounds.Union( aBackgroundComponent.aBounds );
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir                     // extract all aCurr actions to aTotalComponents
971*cdf0e10cSrcweir                     aTotalComponents.aComponentList.splice( aTotalComponents.aComponentList.end(),
972*cdf0e10cSrcweir                                                             aBackgroundComponent.aComponentList );
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir                     if( aBackgroundComponent.bIsSpecial )
975*cdf0e10cSrcweir                         bTreatSpecial = true;
976*cdf0e10cSrcweir                 }
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir                 ConnectedComponentsList::iterator 		aCurrCC;
979*cdf0e10cSrcweir                 const ConnectedComponentsList::iterator aLastCC( aCCList.end() );
980*cdf0e10cSrcweir                 bool									bSomeComponentsChanged;
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir                 // now, this is unfortunate: since changing anyone of
983*cdf0e10cSrcweir                 // the aCCList elements (e.g. by merging or addition
984*cdf0e10cSrcweir                 // of an action) might generate new intersection with
985*cdf0e10cSrcweir                 // other aCCList elements, have to repeat the whole
986*cdf0e10cSrcweir                 // element scanning, until nothing changes anymore.
987*cdf0e10cSrcweir                 // Thus, this loop here makes us O(n^3) in the worst
988*cdf0e10cSrcweir                 // case.
989*cdf0e10cSrcweir                 do
990*cdf0e10cSrcweir                 {
991*cdf0e10cSrcweir                     // only loop here if 'intersects' branch below was hit
992*cdf0e10cSrcweir                     bSomeComponentsChanged = false;
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir                     // iterate over all current members of aCCList
995*cdf0e10cSrcweir                     for( aCurrCC=aCCList.begin(); aCurrCC != aLastCC; )
996*cdf0e10cSrcweir                     {
997*cdf0e10cSrcweir                         // first check if current element's bounds are
998*cdf0e10cSrcweir                         // empty. This ensures that empty actions are not
999*cdf0e10cSrcweir                         // merged into one component, as a matter of fact,
1000*cdf0e10cSrcweir                         // they have no position.
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir                         // #107169# Wholly transparent objects need
1003*cdf0e10cSrcweir                         // not be considered for connected components,
1004*cdf0e10cSrcweir                         // too. Just put each of them into a separate
1005*cdf0e10cSrcweir                         // component.
1006*cdf0e10cSrcweir                         if( !aCurrCC->aBounds.IsEmpty() &&
1007*cdf0e10cSrcweir                             !aCurrCC->bIsFullyTransparent &&
1008*cdf0e10cSrcweir                             aCurrCC->aBounds.IsOver( aTotalBounds ) )
1009*cdf0e10cSrcweir                         {
1010*cdf0e10cSrcweir                             // union the intersecting aCCList element into aTotalComponents
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir                             // calc union bounding box
1013*cdf0e10cSrcweir                             aTotalBounds.Union( aCurrCC->aBounds );
1014*cdf0e10cSrcweir 
1015*cdf0e10cSrcweir                             // extract all aCurr actions to aTotalComponents
1016*cdf0e10cSrcweir                             aTotalComponents.aComponentList.splice( aTotalComponents.aComponentList.end(),
1017*cdf0e10cSrcweir                                                                     aCurrCC->aComponentList );
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir                             if( aCurrCC->bIsSpecial )
1020*cdf0e10cSrcweir                                 bTreatSpecial = true;
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir                             // remove and delete aCurrCC element from list (we've now merged its content)
1023*cdf0e10cSrcweir                             aCurrCC = aCCList.erase( aCurrCC );
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir                             // at least one component changed, need to rescan everything
1026*cdf0e10cSrcweir                             bSomeComponentsChanged = true;
1027*cdf0e10cSrcweir                         }
1028*cdf0e10cSrcweir                         else
1029*cdf0e10cSrcweir                         {
1030*cdf0e10cSrcweir                             ++aCurrCC;
1031*cdf0e10cSrcweir                         }
1032*cdf0e10cSrcweir                     }
1033*cdf0e10cSrcweir                 }
1034*cdf0e10cSrcweir                 while( bSomeComponentsChanged );
1035*cdf0e10cSrcweir             }
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir             //
1038*cdf0e10cSrcweir             //  STAGE 2.2: Determine special state for cc element
1039*cdf0e10cSrcweir             //  =================================================
1040*cdf0e10cSrcweir             //
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir             // now test whether the whole connected component must be
1043*cdf0e10cSrcweir             // treated specially (i.e. rendered as a bitmap): if the
1044*cdf0e10cSrcweir             // added action is the very first action, or all actions
1045*cdf0e10cSrcweir             // before it are completely transparent, the connected
1046*cdf0e10cSrcweir             // component need not be treated specially, not even if
1047*cdf0e10cSrcweir             // the added action contains transparency. This is because
1048*cdf0e10cSrcweir             // painting of transparent objects on _white background_
1049*cdf0e10cSrcweir             // works without alpha compositing (you just calculate the
1050*cdf0e10cSrcweir             // color). Note that for the test "all objects before me
1051*cdf0e10cSrcweir             // are transparent" no sorting is necessary, since the
1052*cdf0e10cSrcweir             // added metaaction pCurrAct is always in the order the
1053*cdf0e10cSrcweir             // metafile is painted. Generally, the order of the
1054*cdf0e10cSrcweir             // metaactions in the ConnectedComponents are not
1055*cdf0e10cSrcweir             // guaranteed to be the same as in the metafile.
1056*cdf0e10cSrcweir             if( bTreatSpecial )
1057*cdf0e10cSrcweir             {
1058*cdf0e10cSrcweir                 // prev component(s) special -> this one, too
1059*cdf0e10cSrcweir                 aTotalComponents.bIsSpecial = true;
1060*cdf0e10cSrcweir             }
1061*cdf0e10cSrcweir             else if( !ImplIsActionSpecial( *pCurrAct ) )
1062*cdf0e10cSrcweir             {
1063*cdf0e10cSrcweir                 // added action and none of prev components special ->
1064*cdf0e10cSrcweir                 // this one normal, too
1065*cdf0e10cSrcweir                 aTotalComponents.bIsSpecial = false;
1066*cdf0e10cSrcweir             }
1067*cdf0e10cSrcweir             else
1068*cdf0e10cSrcweir             {
1069*cdf0e10cSrcweir                 // added action is special and none of prev components
1070*cdf0e10cSrcweir                 // special -> do the detailed tests
1071*cdf0e10cSrcweir 
1072*cdf0e10cSrcweir                 // can the action handle transparency correctly
1073*cdf0e10cSrcweir                 // (i.e. when painted on white background, does the
1074*cdf0e10cSrcweir                 // action still look correct)?
1075*cdf0e10cSrcweir                 if( !ImplIsActionHandlingTransparency( *pCurrAct ) )
1076*cdf0e10cSrcweir                 {
1077*cdf0e10cSrcweir                     // no, action cannot handle its transparency on
1078*cdf0e10cSrcweir                     // a printer device, render to bitmap
1079*cdf0e10cSrcweir                     aTotalComponents.bIsSpecial = true;
1080*cdf0e10cSrcweir                 }
1081*cdf0e10cSrcweir                 else
1082*cdf0e10cSrcweir                 {
1083*cdf0e10cSrcweir                     // yes, action can handle its transparency, so
1084*cdf0e10cSrcweir                     // check whether we're on white background
1085*cdf0e10cSrcweir                     if( aTotalComponents.aComponentList.empty() )
1086*cdf0e10cSrcweir                     {
1087*cdf0e10cSrcweir                         // nothing between pCurrAct and page
1088*cdf0e10cSrcweir                         // background -> don't be special
1089*cdf0e10cSrcweir                         aTotalComponents.bIsSpecial = false;
1090*cdf0e10cSrcweir                     }
1091*cdf0e10cSrcweir                     else
1092*cdf0e10cSrcweir                     {
1093*cdf0e10cSrcweir                         // #107169# Fixes abnove now ensure that _no_
1094*cdf0e10cSrcweir                         // object in the list is fully transparent. Thus,
1095*cdf0e10cSrcweir                         // if the component list is not empty above, we
1096*cdf0e10cSrcweir                         // must assume that we have to treat this
1097*cdf0e10cSrcweir                         // component special.
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir                         // there are non-transparent objects between
1100*cdf0e10cSrcweir                         // pCurrAct and the empty sheet of paper -> be
1101*cdf0e10cSrcweir                         // special, then
1102*cdf0e10cSrcweir                         aTotalComponents.bIsSpecial = true;
1103*cdf0e10cSrcweir                     }
1104*cdf0e10cSrcweir                 }
1105*cdf0e10cSrcweir             }
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir             //
1109*cdf0e10cSrcweir             //  STAGE 2.3: Add newly generated CC list element
1110*cdf0e10cSrcweir             //  ==============================================
1111*cdf0e10cSrcweir             //
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir             // set new bounds and add action to list
1114*cdf0e10cSrcweir             aTotalComponents.aBounds = aTotalBounds;
1115*cdf0e10cSrcweir             aTotalComponents.aComponentList.push_back(
1116*cdf0e10cSrcweir                 ::std::make_pair(
1117*cdf0e10cSrcweir                     pCurrAct, nActionNum) );
1118*cdf0e10cSrcweir 
1119*cdf0e10cSrcweir             // add aTotalComponents as a new entry to aCCList
1120*cdf0e10cSrcweir             aCCList.push_back( aTotalComponents );
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir             DBG_ASSERT( !aTotalComponents.aComponentList.empty(),
1123*cdf0e10cSrcweir                         "Printer::GetPreparedMetaFile empty component" );
1124*cdf0e10cSrcweir             DBG_ASSERT( !aTotalComponents.aBounds.IsEmpty() ||
1125*cdf0e10cSrcweir                         (aTotalComponents.aBounds.IsEmpty() && aTotalComponents.aComponentList.size() == 1),
1126*cdf0e10cSrcweir                         "Printer::GetPreparedMetaFile non-output generating actions must be solitary");
1127*cdf0e10cSrcweir             DBG_ASSERT( !aTotalComponents.bIsFullyTransparent ||
1128*cdf0e10cSrcweir                         (aTotalComponents.bIsFullyTransparent && aTotalComponents.aComponentList.size() == 1),
1129*cdf0e10cSrcweir                         "Printer::GetPreparedMetaFile fully transparent actions must be solitary");
1130*cdf0e10cSrcweir         }
1131*cdf0e10cSrcweir 
1132*cdf0e10cSrcweir         // well now, we've got the list of disjunct connected
1133*cdf0e10cSrcweir         // components. Now we've got to create a map, which contains
1134*cdf0e10cSrcweir         // the corresponding aCCList element for every
1135*cdf0e10cSrcweir         // metaaction. Later on, we always process the complete
1136*cdf0e10cSrcweir         // metafile for each bitmap to be generated, but switch on
1137*cdf0e10cSrcweir         // output only for actions contained in the then current
1138*cdf0e10cSrcweir         // aCCList element. This ensures correct mapmode and attribute
1139*cdf0e10cSrcweir         // settings for all cases.
1140*cdf0e10cSrcweir 
1141*cdf0e10cSrcweir         // maps mtf actions to CC list entries
1142*cdf0e10cSrcweir         ::std::vector< const ConnectedComponents* > aCCList_MemberMap( rInMtf.GetActionCount() );
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir         // iterate over all aCCList members and their contained metaactions
1145*cdf0e10cSrcweir         ConnectedComponentsList::iterator 		aCurr( aCCList.begin() );
1146*cdf0e10cSrcweir         const ConnectedComponentsList::iterator aLast( aCCList.end() );
1147*cdf0e10cSrcweir         for( ; aCurr != aLast; ++aCurr )
1148*cdf0e10cSrcweir         {
1149*cdf0e10cSrcweir             ComponentList::iterator		  aCurrentAction( aCurr->aComponentList.begin() );
1150*cdf0e10cSrcweir             const ComponentList::iterator aLastAction( aCurr->aComponentList.end() );
1151*cdf0e10cSrcweir             for( ; aCurrentAction != aLastAction; ++aCurrentAction )
1152*cdf0e10cSrcweir             {
1153*cdf0e10cSrcweir                 // set pointer to aCCList element for corresponding index
1154*cdf0e10cSrcweir                 aCCList_MemberMap[ aCurrentAction->second ] = &(*aCurr);
1155*cdf0e10cSrcweir             }
1156*cdf0e10cSrcweir         }
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir         //
1159*cdf0e10cSrcweir         //  STAGE 3.1: Output background mtf actions (if there are any)
1160*cdf0e10cSrcweir         //  ===========================================================
1161*cdf0e10cSrcweir         //
1162*cdf0e10cSrcweir 
1163*cdf0e10cSrcweir         ComponentList::iterator		  aCurrAct( aBackgroundComponent.aComponentList.begin() );
1164*cdf0e10cSrcweir         const ComponentList::iterator aLastAct( aBackgroundComponent.aComponentList.end() );
1165*cdf0e10cSrcweir         for( ; aCurrAct != aLastAct; ++aCurrAct )
1166*cdf0e10cSrcweir         {
1167*cdf0e10cSrcweir             // simply add this action (above, we inserted the actions
1168*cdf0e10cSrcweir             // starting at index 0 up to and including nLastBgAction)
1169*cdf0e10cSrcweir             rOutMtf.AddAction( ( aCurrAct->first->Duplicate(), aCurrAct->first ) );
1170*cdf0e10cSrcweir         }
1171*cdf0e10cSrcweir 
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir         //
1174*cdf0e10cSrcweir         //  STAGE 3.2: Generate banded bitmaps for special regions
1175*cdf0e10cSrcweir         //  ====================================================
1176*cdf0e10cSrcweir         //
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir         Point aPageOffset;
1179*cdf0e10cSrcweir         Size aTmpSize( GetOutputSizePixel() );
1180*cdf0e10cSrcweir         if( mpPDFWriter )
1181*cdf0e10cSrcweir         {
1182*cdf0e10cSrcweir             aTmpSize = mpPDFWriter->getCurPageSize();
1183*cdf0e10cSrcweir             aTmpSize = LogicToPixel( aTmpSize, MapMode( MAP_POINT ) );
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir             // also add error code to PDFWriter
1186*cdf0e10cSrcweir             mpPDFWriter->insertError( vcl::PDFWriter::Warning_Transparency_Converted );
1187*cdf0e10cSrcweir         }
1188*cdf0e10cSrcweir         else if( meOutDevType == OUTDEV_PRINTER )
1189*cdf0e10cSrcweir         {
1190*cdf0e10cSrcweir             Printer* pThis = dynamic_cast<Printer*>(this);
1191*cdf0e10cSrcweir             aPageOffset = pThis->GetPageOffsetPixel();
1192*cdf0e10cSrcweir             aPageOffset = Point( 0, 0 ) - aPageOffset;
1193*cdf0e10cSrcweir             aTmpSize  = pThis->GetPaperSizePixel();
1194*cdf0e10cSrcweir         }
1195*cdf0e10cSrcweir         const Rectangle aOutputRect( aPageOffset, aTmpSize );
1196*cdf0e10cSrcweir         bool bTiling = dynamic_cast<Printer*>(this) != NULL;
1197*cdf0e10cSrcweir 
1198*cdf0e10cSrcweir         // iterate over all aCCList members and generate bitmaps for the special ones
1199*cdf0e10cSrcweir         for( aCurr = aCCList.begin(); aCurr != aLast; ++aCurr )
1200*cdf0e10cSrcweir         {
1201*cdf0e10cSrcweir             if( aCurr->bIsSpecial )
1202*cdf0e10cSrcweir             {
1203*cdf0e10cSrcweir                 Rectangle aBoundRect( aCurr->aBounds );
1204*cdf0e10cSrcweir                 aBoundRect.Intersection( aOutputRect );
1205*cdf0e10cSrcweir 
1206*cdf0e10cSrcweir                 const double fBmpArea( (double) aBoundRect.GetWidth() * aBoundRect.GetHeight() );
1207*cdf0e10cSrcweir                 const double fOutArea( (double) aOutputRect.GetWidth() * aOutputRect.GetHeight() );
1208*cdf0e10cSrcweir 
1209*cdf0e10cSrcweir                 // check if output doesn't exceed given size
1210*cdf0e10cSrcweir                 if( bReduceTransparency && bTransparencyAutoMode && ( fBmpArea > ( 0.25 * fOutArea ) ) )
1211*cdf0e10cSrcweir                 {
1212*cdf0e10cSrcweir                     // output normally. Therefore, we simply clear the
1213*cdf0e10cSrcweir                     // special attribute, as everything non-special is
1214*cdf0e10cSrcweir                     // copied to rOutMtf further below.
1215*cdf0e10cSrcweir                     aCurr->bIsSpecial = false;
1216*cdf0e10cSrcweir                 }
1217*cdf0e10cSrcweir                 else
1218*cdf0e10cSrcweir                 {
1219*cdf0e10cSrcweir                     // create new bitmap action first
1220*cdf0e10cSrcweir                     if( aBoundRect.GetWidth() && aBoundRect.GetHeight() )
1221*cdf0e10cSrcweir                     {
1222*cdf0e10cSrcweir                         Point           aDstPtPix( aBoundRect.TopLeft() );
1223*cdf0e10cSrcweir                         Size			aDstSzPix;
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir                         VirtualDevice	aMapVDev;	// here, we record only mapmode information
1226*cdf0e10cSrcweir                         aMapVDev.EnableOutput(sal_False);
1227*cdf0e10cSrcweir 
1228*cdf0e10cSrcweir                         VirtualDevice 	aPaintVDev; // into this one, we render.
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir                         rOutMtf.AddAction( new MetaPushAction( PUSH_MAPMODE ) );
1231*cdf0e10cSrcweir                         rOutMtf.AddAction( new MetaMapModeAction() );
1232*cdf0e10cSrcweir 
1233*cdf0e10cSrcweir                         aPaintVDev.SetDrawMode( GetDrawMode() );
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir                         while( aDstPtPix.Y() <= aBoundRect.Bottom() )
1236*cdf0e10cSrcweir                         {
1237*cdf0e10cSrcweir                             aDstPtPix.X() = aBoundRect.Left();
1238*cdf0e10cSrcweir                             aDstSzPix = bTiling ? Size( MAX_TILE_WIDTH, MAX_TILE_HEIGHT ) : aBoundRect.GetSize();
1239*cdf0e10cSrcweir 
1240*cdf0e10cSrcweir                             if( ( aDstPtPix.Y() + aDstSzPix.Height() - 1L ) > aBoundRect.Bottom() )
1241*cdf0e10cSrcweir                                 aDstSzPix.Height() = aBoundRect.Bottom() - aDstPtPix.Y() + 1L;
1242*cdf0e10cSrcweir 
1243*cdf0e10cSrcweir                             while( aDstPtPix.X() <= aBoundRect.Right() )
1244*cdf0e10cSrcweir                             {
1245*cdf0e10cSrcweir                                 if( ( aDstPtPix.X() + aDstSzPix.Width() - 1L ) > aBoundRect.Right() )
1246*cdf0e10cSrcweir                                     aDstSzPix.Width() = aBoundRect.Right() - aDstPtPix.X() + 1L;
1247*cdf0e10cSrcweir 
1248*cdf0e10cSrcweir                                 if( !Rectangle( aDstPtPix, aDstSzPix ).Intersection( aBoundRect ).IsEmpty() &&
1249*cdf0e10cSrcweir                                     aPaintVDev.SetOutputSizePixel( aDstSzPix ) )
1250*cdf0e10cSrcweir                                 {
1251*cdf0e10cSrcweir                                     aPaintVDev.Push();
1252*cdf0e10cSrcweir                                     aMapVDev.Push();
1253*cdf0e10cSrcweir 
1254*cdf0e10cSrcweir                                     aMapVDev.mnDPIX = aPaintVDev.mnDPIX = mnDPIX;
1255*cdf0e10cSrcweir                                     aMapVDev.mnDPIY = aPaintVDev.mnDPIY = mnDPIY;
1256*cdf0e10cSrcweir 
1257*cdf0e10cSrcweir                                     aPaintVDev.EnableOutput(sal_False);
1258*cdf0e10cSrcweir 
1259*cdf0e10cSrcweir                                     // iterate over all actions
1260*cdf0e10cSrcweir                                     for( pCurrAct=const_cast<GDIMetaFile&>(rInMtf).FirstAction(), nActionNum=0;
1261*cdf0e10cSrcweir                                          pCurrAct;
1262*cdf0e10cSrcweir                                          pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction(), ++nActionNum )
1263*cdf0e10cSrcweir                                     {
1264*cdf0e10cSrcweir                                         // enable output only for
1265*cdf0e10cSrcweir                                         // actions that are members of
1266*cdf0e10cSrcweir                                         // the current aCCList element
1267*cdf0e10cSrcweir                                         // (aCurr)
1268*cdf0e10cSrcweir                                         if( aCCList_MemberMap[nActionNum] == &(*aCurr) )
1269*cdf0e10cSrcweir                                             aPaintVDev.EnableOutput(sal_True);
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir                                         // but process every action
1272*cdf0e10cSrcweir                                         const sal_uInt16 nType( pCurrAct->GetType() );
1273*cdf0e10cSrcweir 
1274*cdf0e10cSrcweir                                         if( META_MAPMODE_ACTION == nType )
1275*cdf0e10cSrcweir                                         {
1276*cdf0e10cSrcweir                                             pCurrAct->Execute( &aMapVDev );
1277*cdf0e10cSrcweir 
1278*cdf0e10cSrcweir                                             MapMode 	aMtfMap( aMapVDev.GetMapMode() );
1279*cdf0e10cSrcweir                                             const Point aNewOrg( aMapVDev.PixelToLogic( aDstPtPix ) );
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir                                             aMtfMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) );
1282*cdf0e10cSrcweir                                             aPaintVDev.SetMapMode( aMtfMap );
1283*cdf0e10cSrcweir                                         }
1284*cdf0e10cSrcweir                                         else if( ( META_PUSH_ACTION == nType ) || ( META_POP_ACTION ) == nType )
1285*cdf0e10cSrcweir                                         {
1286*cdf0e10cSrcweir                                             pCurrAct->Execute( &aMapVDev );
1287*cdf0e10cSrcweir                                             pCurrAct->Execute( &aPaintVDev );
1288*cdf0e10cSrcweir                                         }
1289*cdf0e10cSrcweir                                         else if( META_GRADIENT_ACTION == nType )
1290*cdf0e10cSrcweir                                         {
1291*cdf0e10cSrcweir                                             MetaGradientAction* pGradientAction = static_cast<MetaGradientAction*>(pCurrAct);
1292*cdf0e10cSrcweir                                             Printer* pPrinter = dynamic_cast< Printer* >(this);
1293*cdf0e10cSrcweir                                             if( pPrinter )
1294*cdf0e10cSrcweir                                                 pPrinter->DrawGradientEx( &aPaintVDev, pGradientAction->GetRect(), pGradientAction->GetGradient() );
1295*cdf0e10cSrcweir                                             else
1296*cdf0e10cSrcweir                                                 DrawGradient( pGradientAction->GetRect(), pGradientAction->GetGradient() );
1297*cdf0e10cSrcweir                                         }
1298*cdf0e10cSrcweir                                         else
1299*cdf0e10cSrcweir                                         {
1300*cdf0e10cSrcweir                                             pCurrAct->Execute( &aPaintVDev );
1301*cdf0e10cSrcweir                                         }
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir                                         if( !( nActionNum % 8 ) )
1304*cdf0e10cSrcweir                                             Application::Reschedule();
1305*cdf0e10cSrcweir                                     }
1306*cdf0e10cSrcweir 
1307*cdf0e10cSrcweir                                     const sal_Bool bOldMap = mbMap;
1308*cdf0e10cSrcweir                                     mbMap = aPaintVDev.mbMap = sal_False;
1309*cdf0e10cSrcweir 
1310*cdf0e10cSrcweir                                     Bitmap aBandBmp( aPaintVDev.GetBitmap( Point(), aDstSzPix ) );
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir                                     // scale down bitmap, if requested
1313*cdf0e10cSrcweir                                     if( bDownsampleBitmaps )
1314*cdf0e10cSrcweir                                     {
1315*cdf0e10cSrcweir                                         aBandBmp = GetDownsampledBitmap( aDstSzPix,
1316*cdf0e10cSrcweir                                                                          Point(), aBandBmp.GetSizePixel(),
1317*cdf0e10cSrcweir                                                                          aBandBmp, nMaxBmpDPIX, nMaxBmpDPIY );
1318*cdf0e10cSrcweir                                     }
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir                                     rOutMtf.AddAction( new MetaCommentAction( "PRNSPOOL_TRANSPARENTBITMAP_BEGIN" ) );
1321*cdf0e10cSrcweir                                     rOutMtf.AddAction( new MetaBmpScaleAction( aDstPtPix, aDstSzPix, aBandBmp ) );
1322*cdf0e10cSrcweir                                     rOutMtf.AddAction( new MetaCommentAction( "PRNSPOOL_TRANSPARENTBITMAP_END" ) );
1323*cdf0e10cSrcweir 
1324*cdf0e10cSrcweir                                     aPaintVDev.mbMap = sal_True;
1325*cdf0e10cSrcweir                                     mbMap = bOldMap;
1326*cdf0e10cSrcweir                                     aMapVDev.Pop();
1327*cdf0e10cSrcweir                                     aPaintVDev.Pop();
1328*cdf0e10cSrcweir                                 }
1329*cdf0e10cSrcweir 
1330*cdf0e10cSrcweir                                 // overlapping bands to avoid missing lines (e.g. PostScript)
1331*cdf0e10cSrcweir                                 aDstPtPix.X() += aDstSzPix.Width();
1332*cdf0e10cSrcweir                             }
1333*cdf0e10cSrcweir 
1334*cdf0e10cSrcweir                             // overlapping bands to avoid missing lines (e.g. PostScript)
1335*cdf0e10cSrcweir                             aDstPtPix.Y() += aDstSzPix.Height();
1336*cdf0e10cSrcweir                         }
1337*cdf0e10cSrcweir 
1338*cdf0e10cSrcweir                         rOutMtf.AddAction( new MetaPopAction() );
1339*cdf0e10cSrcweir                     }
1340*cdf0e10cSrcweir                 }
1341*cdf0e10cSrcweir             }
1342*cdf0e10cSrcweir         }
1343*cdf0e10cSrcweir 
1344*cdf0e10cSrcweir         // clean up aMapModeVDev
1345*cdf0e10cSrcweir         nCount = aMapModeVDev.GetGCStackDepth();
1346*cdf0e10cSrcweir         while( nCount-- )
1347*cdf0e10cSrcweir             aMapModeVDev.Pop();
1348*cdf0e10cSrcweir 
1349*cdf0e10cSrcweir         //
1350*cdf0e10cSrcweir         //  STAGE 4: Copy actions to output metafile
1351*cdf0e10cSrcweir         //  ========================================
1352*cdf0e10cSrcweir         //
1353*cdf0e10cSrcweir 
1354*cdf0e10cSrcweir         // iterate over all actions and duplicate the ones not in a
1355*cdf0e10cSrcweir         // special aCCList member into rOutMtf
1356*cdf0e10cSrcweir         for( pCurrAct=const_cast<GDIMetaFile&>(rInMtf).FirstAction(), nActionNum=0;
1357*cdf0e10cSrcweir              pCurrAct;
1358*cdf0e10cSrcweir              pCurrAct=const_cast<GDIMetaFile&>(rInMtf).NextAction(), ++nActionNum )
1359*cdf0e10cSrcweir         {
1360*cdf0e10cSrcweir             const ConnectedComponents* pCurrAssociatedComponent = aCCList_MemberMap[nActionNum];
1361*cdf0e10cSrcweir 
1362*cdf0e10cSrcweir             // NOTE: This relies on the fact that map-mode or draw
1363*cdf0e10cSrcweir             // mode changing actions are solitary aCCList elements and
1364*cdf0e10cSrcweir             // have empty bounding boxes, see comment on stage 2.1
1365*cdf0e10cSrcweir             // above
1366*cdf0e10cSrcweir             if( pCurrAssociatedComponent &&
1367*cdf0e10cSrcweir                 (pCurrAssociatedComponent->aBounds.IsEmpty() ||
1368*cdf0e10cSrcweir                  !pCurrAssociatedComponent->bIsSpecial) )
1369*cdf0e10cSrcweir             {
1370*cdf0e10cSrcweir                 // #107169# Treat transparent bitmaps special, if they
1371*cdf0e10cSrcweir                 // are the first (or sole) action in their bounds
1372*cdf0e10cSrcweir                 // list. Note that we previously ensured that no
1373*cdf0e10cSrcweir                 // fully-transparent objects are before us here.
1374*cdf0e10cSrcweir                 if( ImplIsActionHandlingTransparency( *pCurrAct ) &&
1375*cdf0e10cSrcweir                     pCurrAssociatedComponent->aComponentList.begin()->first == pCurrAct )
1376*cdf0e10cSrcweir                 {
1377*cdf0e10cSrcweir                     // convert actions, where masked-out parts are of
1378*cdf0e10cSrcweir                     // given background color
1379*cdf0e10cSrcweir                     ImplConvertTransparentAction(rOutMtf,
1380*cdf0e10cSrcweir                                                  *pCurrAct,
1381*cdf0e10cSrcweir                                                  aMapModeVDev,
1382*cdf0e10cSrcweir                                                  aBackgroundComponent.aBgColor);
1383*cdf0e10cSrcweir                 }
1384*cdf0e10cSrcweir                 else
1385*cdf0e10cSrcweir                 {
1386*cdf0e10cSrcweir                     // simply add this action
1387*cdf0e10cSrcweir                     rOutMtf.AddAction( ( pCurrAct->Duplicate(), pCurrAct ) );
1388*cdf0e10cSrcweir                 }
1389*cdf0e10cSrcweir 
1390*cdf0e10cSrcweir                 pCurrAct->Execute(&aMapModeVDev);
1391*cdf0e10cSrcweir             }
1392*cdf0e10cSrcweir         }
1393*cdf0e10cSrcweir 
1394*cdf0e10cSrcweir         rOutMtf.SetPrefMapMode( rInMtf.GetPrefMapMode() );
1395*cdf0e10cSrcweir         rOutMtf.SetPrefSize( rInMtf.GetPrefSize() );
1396*cdf0e10cSrcweir 	}
1397*cdf0e10cSrcweir     return bTransparent;
1398*cdf0e10cSrcweir }
1399*cdf0e10cSrcweir 
1400*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1401*cdf0e10cSrcweir 
1402*cdf0e10cSrcweir Bitmap OutputDevice::GetDownsampledBitmap( const Size& rDstSz,
1403*cdf0e10cSrcweir                                            const Point& rSrcPt, const Size& rSrcSz,
1404*cdf0e10cSrcweir                                            const Bitmap& rBmp, long nMaxBmpDPIX, long nMaxBmpDPIY )
1405*cdf0e10cSrcweir {
1406*cdf0e10cSrcweir     Bitmap aBmp( rBmp );
1407*cdf0e10cSrcweir 
1408*cdf0e10cSrcweir     if( !aBmp.IsEmpty() )
1409*cdf0e10cSrcweir     {
1410*cdf0e10cSrcweir         Point           aPoint;
1411*cdf0e10cSrcweir         const Rectangle aBmpRect( aPoint, aBmp.GetSizePixel() );
1412*cdf0e10cSrcweir         Rectangle       aSrcRect( rSrcPt, rSrcSz );
1413*cdf0e10cSrcweir 
1414*cdf0e10cSrcweir         // do cropping if neccessary
1415*cdf0e10cSrcweir         if( aSrcRect.Intersection( aBmpRect ) != aBmpRect )
1416*cdf0e10cSrcweir         {
1417*cdf0e10cSrcweir             if( !aSrcRect.IsEmpty() )
1418*cdf0e10cSrcweir                 aBmp.Crop( aSrcRect );
1419*cdf0e10cSrcweir             else
1420*cdf0e10cSrcweir                 aBmp.SetEmpty();
1421*cdf0e10cSrcweir         }
1422*cdf0e10cSrcweir 
1423*cdf0e10cSrcweir         if( !aBmp.IsEmpty() )
1424*cdf0e10cSrcweir         {
1425*cdf0e10cSrcweir             // do downsampling if neccessary
1426*cdf0e10cSrcweir             Size aDstSizeTwip( PixelToLogic( LogicToPixel( rDstSz ), MAP_TWIP ) );
1427*cdf0e10cSrcweir 
1428*cdf0e10cSrcweir             // #103209# Normalize size (mirroring has to happen outside of this method)
1429*cdf0e10cSrcweir             aDstSizeTwip = Size( labs(aDstSizeTwip.Width()), labs(aDstSizeTwip.Height()) );
1430*cdf0e10cSrcweir 
1431*cdf0e10cSrcweir             const Size      aBmpSize( aBmp.GetSizePixel() );
1432*cdf0e10cSrcweir             const double    fBmpPixelX = aBmpSize.Width();
1433*cdf0e10cSrcweir             const double    fBmpPixelY = aBmpSize.Height();
1434*cdf0e10cSrcweir             const double    fMaxPixelX = aDstSizeTwip.Width() * nMaxBmpDPIX / 1440.0;
1435*cdf0e10cSrcweir             const double    fMaxPixelY = aDstSizeTwip.Height() * nMaxBmpDPIY / 1440.0;
1436*cdf0e10cSrcweir 
1437*cdf0e10cSrcweir             // check, if the bitmap DPI exceeds the maximum DPI (allow 4 pixel rounding tolerance)
1438*cdf0e10cSrcweir             if( ( ( fBmpPixelX > ( fMaxPixelX + 4 ) ) ||
1439*cdf0e10cSrcweir                   ( fBmpPixelY > ( fMaxPixelY + 4 ) ) ) &&
1440*cdf0e10cSrcweir                 ( fBmpPixelY > 0.0 ) && ( fMaxPixelY > 0.0 ) )
1441*cdf0e10cSrcweir             {
1442*cdf0e10cSrcweir                 // do scaling
1443*cdf0e10cSrcweir                 Size            aNewBmpSize;
1444*cdf0e10cSrcweir 		        const double    fBmpWH = fBmpPixelX / fBmpPixelY;
1445*cdf0e10cSrcweir 		        const double    fMaxWH = fMaxPixelX / fMaxPixelY;
1446*cdf0e10cSrcweir 
1447*cdf0e10cSrcweir 			    if( fBmpWH < fMaxWH )
1448*cdf0e10cSrcweir 			    {
1449*cdf0e10cSrcweir 				    aNewBmpSize.Width() = FRound( fMaxPixelY * fBmpWH );
1450*cdf0e10cSrcweir 				    aNewBmpSize.Height() = FRound( fMaxPixelY );
1451*cdf0e10cSrcweir 			    }
1452*cdf0e10cSrcweir 			    else if( fBmpWH > 0.0 )
1453*cdf0e10cSrcweir 			    {
1454*cdf0e10cSrcweir 				    aNewBmpSize.Width() = FRound( fMaxPixelX );
1455*cdf0e10cSrcweir 				    aNewBmpSize.Height() = FRound( fMaxPixelX / fBmpWH);
1456*cdf0e10cSrcweir 			    }
1457*cdf0e10cSrcweir 
1458*cdf0e10cSrcweir                 if( aNewBmpSize.Width() && aNewBmpSize.Height() )
1459*cdf0e10cSrcweir                     aBmp.Scale( aNewBmpSize );
1460*cdf0e10cSrcweir                 else
1461*cdf0e10cSrcweir                     aBmp.SetEmpty();
1462*cdf0e10cSrcweir             }
1463*cdf0e10cSrcweir         }
1464*cdf0e10cSrcweir     }
1465*cdf0e10cSrcweir 
1466*cdf0e10cSrcweir     return aBmp;
1467*cdf0e10cSrcweir }
1468*cdf0e10cSrcweir 
1469*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1470*cdf0e10cSrcweir 
1471*cdf0e10cSrcweir BitmapEx OutputDevice::GetDownsampledBitmapEx( const Size& rDstSz,
1472*cdf0e10cSrcweir                                                const Point& rSrcPt, const Size& rSrcSz,
1473*cdf0e10cSrcweir                                                const BitmapEx& rBmpEx, long nMaxBmpDPIX, long nMaxBmpDPIY )
1474*cdf0e10cSrcweir {
1475*cdf0e10cSrcweir     BitmapEx aBmpEx( rBmpEx );
1476*cdf0e10cSrcweir 
1477*cdf0e10cSrcweir     if( !aBmpEx.IsEmpty() )
1478*cdf0e10cSrcweir     {
1479*cdf0e10cSrcweir         Point           aPoint;
1480*cdf0e10cSrcweir         const Rectangle aBmpRect( aPoint, aBmpEx.GetSizePixel() );
1481*cdf0e10cSrcweir         Rectangle       aSrcRect( rSrcPt, rSrcSz );
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir         // do cropping if neccessary
1484*cdf0e10cSrcweir         if( aSrcRect.Intersection( aBmpRect ) != aBmpRect )
1485*cdf0e10cSrcweir         {
1486*cdf0e10cSrcweir             if( !aSrcRect.IsEmpty() )
1487*cdf0e10cSrcweir                 aBmpEx.Crop( aSrcRect );
1488*cdf0e10cSrcweir             else
1489*cdf0e10cSrcweir                 aBmpEx.SetEmpty();
1490*cdf0e10cSrcweir         }
1491*cdf0e10cSrcweir 
1492*cdf0e10cSrcweir         if( !aBmpEx.IsEmpty() )
1493*cdf0e10cSrcweir         {
1494*cdf0e10cSrcweir             // do downsampling if neccessary
1495*cdf0e10cSrcweir             Size aDstSizeTwip( PixelToLogic( LogicToPixel( rDstSz ), MAP_TWIP ) );
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir             // #103209# Normalize size (mirroring has to happen outside of this method)
1498*cdf0e10cSrcweir             aDstSizeTwip = Size( labs(aDstSizeTwip.Width()), labs(aDstSizeTwip.Height()) );
1499*cdf0e10cSrcweir 
1500*cdf0e10cSrcweir             const Size      aBmpSize( aBmpEx.GetSizePixel() );
1501*cdf0e10cSrcweir             const double    fBmpPixelX = aBmpSize.Width();
1502*cdf0e10cSrcweir             const double    fBmpPixelY = aBmpSize.Height();
1503*cdf0e10cSrcweir             const double    fMaxPixelX = aDstSizeTwip.Width() * nMaxBmpDPIX / 1440.0;
1504*cdf0e10cSrcweir             const double    fMaxPixelY = aDstSizeTwip.Height() * nMaxBmpDPIY / 1440.0;
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir             // check, if the bitmap DPI exceeds the maximum DPI (allow 4 pixel rounding tolerance)
1507*cdf0e10cSrcweir             if( ( ( fBmpPixelX > ( fMaxPixelX + 4 ) ) ||
1508*cdf0e10cSrcweir                   ( fBmpPixelY > ( fMaxPixelY + 4 ) ) ) &&
1509*cdf0e10cSrcweir                 ( fBmpPixelY > 0.0 ) && ( fMaxPixelY > 0.0 ) )
1510*cdf0e10cSrcweir             {
1511*cdf0e10cSrcweir                 // do scaling
1512*cdf0e10cSrcweir                 Size            aNewBmpSize;
1513*cdf0e10cSrcweir 		        const double    fBmpWH = fBmpPixelX / fBmpPixelY;
1514*cdf0e10cSrcweir 		        const double    fMaxWH = fMaxPixelX / fMaxPixelY;
1515*cdf0e10cSrcweir 
1516*cdf0e10cSrcweir 			    if( fBmpWH < fMaxWH )
1517*cdf0e10cSrcweir 			    {
1518*cdf0e10cSrcweir 				    aNewBmpSize.Width() = FRound( fMaxPixelY * fBmpWH );
1519*cdf0e10cSrcweir 				    aNewBmpSize.Height() = FRound( fMaxPixelY );
1520*cdf0e10cSrcweir 			    }
1521*cdf0e10cSrcweir 			    else if( fBmpWH > 0.0 )
1522*cdf0e10cSrcweir 			    {
1523*cdf0e10cSrcweir 				    aNewBmpSize.Width() = FRound( fMaxPixelX );
1524*cdf0e10cSrcweir 				    aNewBmpSize.Height() = FRound( fMaxPixelX / fBmpWH);
1525*cdf0e10cSrcweir 			    }
1526*cdf0e10cSrcweir 
1527*cdf0e10cSrcweir                 if( aNewBmpSize.Width() && aNewBmpSize.Height() )
1528*cdf0e10cSrcweir                     aBmpEx.Scale( aNewBmpSize );
1529*cdf0e10cSrcweir                 else
1530*cdf0e10cSrcweir                     aBmpEx.SetEmpty();
1531*cdf0e10cSrcweir             }
1532*cdf0e10cSrcweir         }
1533*cdf0e10cSrcweir     }
1534*cdf0e10cSrcweir 
1535*cdf0e10cSrcweir     return aBmpEx;
1536*cdf0e10cSrcweir }
1537*cdf0e10cSrcweir 
1538*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1539*cdf0e10cSrcweir 
1540*cdf0e10cSrcweir void Printer::DrawGradientEx( OutputDevice* pOut, const Rectangle& rRect, const Gradient& rGradient )
1541*cdf0e10cSrcweir {
1542*cdf0e10cSrcweir     const PrinterOptions& rPrinterOptions = GetPrinterOptions();
1543*cdf0e10cSrcweir 
1544*cdf0e10cSrcweir     if( rPrinterOptions.IsReduceGradients() )
1545*cdf0e10cSrcweir     {
1546*cdf0e10cSrcweir         if( PRINTER_GRADIENT_STRIPES == rPrinterOptions.GetReducedGradientMode() )
1547*cdf0e10cSrcweir         {
1548*cdf0e10cSrcweir             if( !rGradient.GetSteps() || ( rGradient.GetSteps() > rPrinterOptions.GetReducedGradientStepCount() ) )
1549*cdf0e10cSrcweir             {
1550*cdf0e10cSrcweir                 Gradient aNewGradient( rGradient );
1551*cdf0e10cSrcweir 
1552*cdf0e10cSrcweir                 aNewGradient.SetSteps( rPrinterOptions.GetReducedGradientStepCount() );
1553*cdf0e10cSrcweir                 pOut->DrawGradient( rRect, aNewGradient );
1554*cdf0e10cSrcweir             }
1555*cdf0e10cSrcweir             else
1556*cdf0e10cSrcweir                 pOut->DrawGradient( rRect, rGradient );
1557*cdf0e10cSrcweir         }
1558*cdf0e10cSrcweir         else
1559*cdf0e10cSrcweir         {
1560*cdf0e10cSrcweir             const Color&    rStartColor = rGradient.GetStartColor();
1561*cdf0e10cSrcweir             const Color&    rEndColor = rGradient.GetEndColor();
1562*cdf0e10cSrcweir             const long      nR = ( ( (long) rStartColor.GetRed() * rGradient.GetStartIntensity() ) / 100L +
1563*cdf0e10cSrcweir                                    ( (long) rEndColor.GetRed() * rGradient.GetEndIntensity() ) / 100L ) >> 1;
1564*cdf0e10cSrcweir             const long      nG = ( ( (long) rStartColor.GetGreen() * rGradient.GetStartIntensity() ) / 100L +
1565*cdf0e10cSrcweir                                    ( (long) rEndColor.GetGreen() * rGradient.GetEndIntensity() ) / 100L ) >> 1;
1566*cdf0e10cSrcweir             const long      nB = ( ( (long) rStartColor.GetBlue() * rGradient.GetStartIntensity() ) / 100L +
1567*cdf0e10cSrcweir                                    ( (long) rEndColor.GetBlue() * rGradient.GetEndIntensity() ) / 100L ) >> 1;
1568*cdf0e10cSrcweir             const Color     aColor( (sal_uInt8) nR, (sal_uInt8) nG, (sal_uInt8) nB );
1569*cdf0e10cSrcweir 
1570*cdf0e10cSrcweir             pOut->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
1571*cdf0e10cSrcweir             pOut->SetLineColor( aColor );
1572*cdf0e10cSrcweir             pOut->SetFillColor( aColor );
1573*cdf0e10cSrcweir             pOut->DrawRect( rRect );
1574*cdf0e10cSrcweir             pOut->Pop();
1575*cdf0e10cSrcweir         }
1576*cdf0e10cSrcweir     }
1577*cdf0e10cSrcweir     else
1578*cdf0e10cSrcweir         pOut->DrawGradient( rRect, rGradient );
1579*cdf0e10cSrcweir }
1580*cdf0e10cSrcweir 
1581*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1582*cdf0e10cSrcweir 
1583*cdf0e10cSrcweir void Printer::DrawGradientEx( OutputDevice* pOut, const PolyPolygon& rPolyPoly, const Gradient& rGradient )
1584*cdf0e10cSrcweir {
1585*cdf0e10cSrcweir     const PrinterOptions& rPrinterOptions = GetPrinterOptions();
1586*cdf0e10cSrcweir 
1587*cdf0e10cSrcweir     if( rPrinterOptions.IsReduceGradients() )
1588*cdf0e10cSrcweir     {
1589*cdf0e10cSrcweir         if( PRINTER_GRADIENT_STRIPES == rPrinterOptions.GetReducedGradientMode() )
1590*cdf0e10cSrcweir         {
1591*cdf0e10cSrcweir             if( !rGradient.GetSteps() || ( rGradient.GetSteps() > rPrinterOptions.GetReducedGradientStepCount() ) )
1592*cdf0e10cSrcweir             {
1593*cdf0e10cSrcweir                 Gradient aNewGradient( rGradient );
1594*cdf0e10cSrcweir 
1595*cdf0e10cSrcweir                 aNewGradient.SetSteps( rPrinterOptions.GetReducedGradientStepCount() );
1596*cdf0e10cSrcweir                 pOut->DrawGradient( rPolyPoly, aNewGradient );
1597*cdf0e10cSrcweir             }
1598*cdf0e10cSrcweir             else
1599*cdf0e10cSrcweir                 pOut->DrawGradient( rPolyPoly, rGradient );
1600*cdf0e10cSrcweir         }
1601*cdf0e10cSrcweir         else
1602*cdf0e10cSrcweir         {
1603*cdf0e10cSrcweir             const Color&    rStartColor = rGradient.GetStartColor();
1604*cdf0e10cSrcweir             const Color&    rEndColor = rGradient.GetEndColor();
1605*cdf0e10cSrcweir             const long      nR = ( ( (long) rStartColor.GetRed() * rGradient.GetStartIntensity() ) / 100L +
1606*cdf0e10cSrcweir                                    ( (long) rEndColor.GetRed() * rGradient.GetEndIntensity() ) / 100L ) >> 1;
1607*cdf0e10cSrcweir             const long      nG = ( ( (long) rStartColor.GetGreen() * rGradient.GetStartIntensity() ) / 100L +
1608*cdf0e10cSrcweir                                    ( (long) rEndColor.GetGreen() * rGradient.GetEndIntensity() ) / 100L ) >> 1;
1609*cdf0e10cSrcweir             const long      nB = ( ( (long) rStartColor.GetBlue() * rGradient.GetStartIntensity() ) / 100L +
1610*cdf0e10cSrcweir                                    ( (long) rEndColor.GetBlue() * rGradient.GetEndIntensity() ) / 100L ) >> 1;
1611*cdf0e10cSrcweir             const Color     aColor( (sal_uInt8) nR, (sal_uInt8) nG, (sal_uInt8) nB );
1612*cdf0e10cSrcweir 
1613*cdf0e10cSrcweir             pOut->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
1614*cdf0e10cSrcweir             pOut->SetLineColor( aColor );
1615*cdf0e10cSrcweir             pOut->SetFillColor( aColor );
1616*cdf0e10cSrcweir             pOut->DrawPolyPolygon( rPolyPoly );
1617*cdf0e10cSrcweir             pOut->Pop();
1618*cdf0e10cSrcweir         }
1619*cdf0e10cSrcweir     }
1620*cdf0e10cSrcweir     else
1621*cdf0e10cSrcweir         pOut->DrawGradient( rPolyPoly, rGradient );
1622*cdf0e10cSrcweir }
1623