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