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