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