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