xref: /aoo41x/main/svx/source/svdraw/svdfmtf.cxx (revision 468982e4)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include "svdfmtf.hxx"
28 #include <editeng/editdata.hxx>
29 #include <math.h>
30 #include <svx/xpoly.hxx>
31 #include <vcl/svapp.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <editeng/fhgtitem.hxx>
34 #include <editeng/wghtitem.hxx>
35 #include <editeng/postitem.hxx>
36 #include <editeng/udlnitem.hxx>
37 #include <editeng/crsditem.hxx>
38 #include <editeng/shdditem.hxx>
39 #include <svx/xlnclit.hxx>
40 #include <svx/xlncapit.hxx>
41 #include <svx/xlnwtit.hxx>
42 #include <svx/xflclit.hxx>
43 #include <svx/xgrad.hxx>
44 #include <svx/xflgrit.hxx>
45 #include <editeng/fontitem.hxx>
46 #include <editeng/akrnitem.hxx>
47 #include <editeng/wrlmitem.hxx>
48 #include <editeng/cntritem.hxx>
49 #include <editeng/colritem.hxx>
50 #include <vcl/metric.hxx>
51 #include <editeng/charscaleitem.hxx>
52 #include <svx/xflhtit.hxx>
53 #include <svx/svdattr.hxx>
54 #include <svx/svdmodel.hxx>
55 #include <svx/svdpage.hxx>
56 #include <svx/svdobj.hxx>
57 #include "svx/svditext.hxx"
58 #include <svx/svdotext.hxx>
59 #include <svx/svdorect.hxx>
60 #include <svx/svdocirc.hxx>
61 #include <svx/svdograf.hxx>
62 #include <svx/svdopath.hxx>
63 #include <svx/svdetc.hxx>
64 #include <svl/itemset.hxx>
65 #include <basegfx/polygon/b2dpolygon.hxx>
66 #include <vcl/salbtype.hxx>		// FRound
67 #include <basegfx/matrix/b2dhommatrix.hxx>
68 #include <basegfx/matrix/b2dhommatrixtools.hxx>
69 #include <svx/xlinjoit.hxx>
70 #include <svx/xlndsit.hxx>
71 #include <basegfx/polygon/b2dpolygonclipper.hxx>
72 #include <svx/xbtmpit.hxx>
73 #include <svx/xfltrit.hxx>
74 #include <vcl/bmpacc.hxx>
75 #include <svx/xflbmtit.hxx>
76 #include <svx/xflbstit.hxx>
77 #include <svx/svdpntv.hxx>
78 
79 ////////////////////////////////////////////////////////////////////////////////////////////////////
80 
81 ImpSdrGDIMetaFileImport::ImpSdrGDIMetaFileImport(
82     SdrModel& rModel,
83     SdrLayerID nLay,
84     const Rectangle& rRect)
85 :   maTmpList(),
86     maVD(),
87     maScaleRect(rRect),
88     mnMapScalingOfs(0),
89 	mpLineAttr(0),
90     mpFillAttr(0),
91     mpTextAttr(0),
92     mpModel(&rModel),
93     mnLayer(nLay),
94     maOldLineColor(),
95 	mnLineWidth(0),
96 	maLineJoin(basegfx::B2DLINEJOIN_NONE),
97 	maLineCap(com::sun::star::drawing::LineCap_BUTT),
98 	maDash(XDASH_RECT, 0, 0, 0, 0, 0),
99     mbMov(false),
100     mbSize(false),
101     maOfs(0, 0),
102     mfScaleX(1.0),
103     mfScaleY(1.0),
104     maScaleX(1.0),
105     maScaleY(1.0),
106 	mbFntDirty(true),
107 	mbLastObjWasPolyWithoutLine(false),
108     mbNoLine(false),
109     mbNoFill(false),
110     mbLastObjWasLine(false),
111     maClip()
112 {
113 	maVD.EnableOutput(false);
114     maVD.SetLineColor();
115     maVD.SetFillColor();
116 	maOldLineColor.SetRed( maVD.GetLineColor().GetRed() + 1 );
117 	mpLineAttr = new SfxItemSet(rModel.GetItemPool(), XATTR_LINE_FIRST, XATTR_LINE_LAST, 0, 0);
118 	mpFillAttr = new SfxItemSet(rModel.GetItemPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST, 0, 0);
119 	mpTextAttr = new SfxItemSet(rModel.GetItemPool(), EE_ITEMS_START, EE_ITEMS_END, 0, 0);
120     checkClip();
121 }
122 
123 ImpSdrGDIMetaFileImport::~ImpSdrGDIMetaFileImport()
124 {
125 	delete mpLineAttr;
126 	delete mpFillAttr;
127 	delete mpTextAttr;
128 }
129 
130 void ImpSdrGDIMetaFileImport::DoLoopActions(GDIMetaFile& rMtf, SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport)
131 {
132     const sal_uLong nCount(rMtf.GetActionCount());
133 
134     for(sal_uLong a(0); a < nCount; a++)
135     {
136         MetaAction* pAct = rMtf.GetAction(a);
137 
138         if(!pAct)
139         {
140             OSL_ENSURE(false, "OOps, no action at valid position (!)");
141             pAct = rMtf.GetAction(0);
142         }
143 
144 		switch (pAct->GetType())
145 		{
146 			case META_PIXEL_ACTION          : DoAction((MetaPixelAction          &)*pAct); break;
147 			case META_POINT_ACTION          : DoAction((MetaPointAction          &)*pAct); break;
148 			case META_LINE_ACTION           : DoAction((MetaLineAction           &)*pAct); break;
149 			case META_RECT_ACTION           : DoAction((MetaRectAction           &)*pAct); break;
150 			case META_ROUNDRECT_ACTION      : DoAction((MetaRoundRectAction      &)*pAct); break;
151 			case META_ELLIPSE_ACTION        : DoAction((MetaEllipseAction        &)*pAct); break;
152 			case META_ARC_ACTION            : DoAction((MetaArcAction            &)*pAct); break;
153 			case META_PIE_ACTION            : DoAction((MetaPieAction            &)*pAct); break;
154 			case META_CHORD_ACTION          : DoAction((MetaChordAction          &)*pAct); break;
155 			case META_POLYLINE_ACTION	    : DoAction((MetaPolyLineAction		 &)*pAct); break;
156 			case META_POLYGON_ACTION        : DoAction((MetaPolygonAction        &)*pAct); break;
157 			case META_POLYPOLYGON_ACTION    : DoAction((MetaPolyPolygonAction    &)*pAct); break;
158 			case META_TEXT_ACTION           : DoAction((MetaTextAction           &)*pAct); break;
159 			case META_TEXTARRAY_ACTION      : DoAction((MetaTextArrayAction      &)*pAct); break;
160 			case META_STRETCHTEXT_ACTION    : DoAction((MetaStretchTextAction    &)*pAct); break;
161 			case META_BMP_ACTION			: DoAction((MetaBmpAction			 &)*pAct); break;
162 			case META_BMPSCALE_ACTION		: DoAction((MetaBmpScaleAction		 &)*pAct); break;
163 			case META_BMPEX_ACTION			: DoAction((MetaBmpExAction			 &)*pAct); break;
164 			case META_BMPEXSCALE_ACTION		: DoAction((MetaBmpExScaleAction	 &)*pAct); break;
165 			case META_LINECOLOR_ACTION      : DoAction((MetaLineColorAction      &)*pAct); break;
166 			case META_FILLCOLOR_ACTION      : DoAction((MetaFillColorAction      &)*pAct); break;
167 			case META_TEXTCOLOR_ACTION      : DoAction((MetaTextColorAction      &)*pAct); break;
168 			case META_TEXTFILLCOLOR_ACTION  : DoAction((MetaTextFillColorAction  &)*pAct); break;
169 			case META_FONT_ACTION           : DoAction((MetaFontAction           &)*pAct); break;
170 			case META_TEXTALIGN_ACTION		: DoAction((MetaTextAlignAction		 &)*pAct); break;
171 			case META_MAPMODE_ACTION        : DoAction((MetaMapModeAction        &)*pAct); break;
172 			case META_CLIPREGION_ACTION     : DoAction((MetaClipRegionAction     &)*pAct); break;
173 			case META_MOVECLIPREGION_ACTION : DoAction((MetaMoveClipRegionAction &)*pAct); break;
174 			case META_ISECTRECTCLIPREGION_ACTION: DoAction((MetaISectRectClipRegionAction&)*pAct); break;
175 			case META_ISECTREGIONCLIPREGION_ACTION: DoAction((MetaISectRegionClipRegionAction&)*pAct); break;
176 			case META_RASTEROP_ACTION       : DoAction((MetaRasterOpAction       &)*pAct); break;
177 			case META_PUSH_ACTION           : DoAction((MetaPushAction           &)*pAct); break;
178 			case META_POP_ACTION            : DoAction((MetaPopAction            &)*pAct); break;
179 			case META_HATCH_ACTION			: DoAction((MetaHatchAction          &)*pAct); break;
180 			case META_COMMENT_ACTION		: DoAction((MetaCommentAction        &)*pAct, &rMtf); break;
181 
182             // missing actions added
183             case META_TEXTRECT_ACTION       : DoAction((MetaTextRectAction&)*pAct); break;
184             case META_BMPSCALEPART_ACTION   : DoAction((MetaBmpScalePartAction&)*pAct); break;
185             case META_BMPEXSCALEPART_ACTION : DoAction((MetaBmpExScalePartAction&)*pAct); break;
186             case META_MASK_ACTION           : DoAction((MetaMaskAction&)*pAct); break;
187             case META_MASKSCALE_ACTION      : DoAction((MetaMaskScaleAction&)*pAct); break;
188             case META_MASKSCALEPART_ACTION  : DoAction((MetaMaskScalePartAction&)*pAct); break;
189             case META_GRADIENT_ACTION       : DoAction((MetaGradientAction&)*pAct); break;
190             case META_WALLPAPER_ACTION      : DoAction((MetaWallpaperAction&)*pAct); break;
191             case META_TRANSPARENT_ACTION    : DoAction((MetaTransparentAction&)*pAct); break;
192             case META_EPS_ACTION            : DoAction((MetaEPSAction&)*pAct); break;
193             case META_REFPOINT_ACTION       : DoAction((MetaRefPointAction&)*pAct); break;
194             case META_TEXTLINECOLOR_ACTION  : DoAction((MetaTextLineColorAction&)*pAct); break;
195             case META_TEXTLINE_ACTION       : DoAction((MetaTextLineAction&)*pAct); break;
196             case META_FLOATTRANSPARENT_ACTION : DoAction((MetaFloatTransparentAction&)*pAct); break;
197             case META_GRADIENTEX_ACTION     : DoAction((MetaGradientExAction&)*pAct); break;
198             case META_LAYOUTMODE_ACTION     : DoAction((MetaLayoutModeAction&)*pAct); break;
199             case META_TEXTLANGUAGE_ACTION   : DoAction((MetaTextLanguageAction&)*pAct); break;
200             case META_OVERLINECOLOR_ACTION  : DoAction((MetaOverlineColorAction&)*pAct); break;
201 		}
202 
203 		if(pProgrInfo && pActionsToReport)
204 		{
205             (*pActionsToReport)++;
206 
207             if(*pActionsToReport >= 16) // Alle 16 Action updaten
208             {
209                 if(!pProgrInfo->ReportActions(*pActionsToReport))
210                     break;
211 
212                 *pActionsToReport = 0;
213             }
214 		}
215 	}
216 }
217 
218 sal_uInt32 ImpSdrGDIMetaFileImport::DoImport(
219     const GDIMetaFile& rMtf,
220 	SdrObjList& rOL,
221 	sal_uInt32 nInsPos,
222 	SvdProgressInfo* pProgrInfo)
223 {
224 	// setup some global scale parameter
225 	// mfScaleX, mfScaleY, maScaleX, maScaleY, mbMov, mbSize
226     mfScaleX = mfScaleY = 1.0;
227 	const Size aMtfSize(rMtf.GetPrefSize());
228 
229     if(aMtfSize.Width() & aMtfSize.Height() && (!maScaleRect.IsEmpty()))
230     {
231 		maOfs = maScaleRect.TopLeft();
232 
233         if(aMtfSize.Width() != (maScaleRect.GetWidth() - 1))
234         {
235             mfScaleX = (double)( maScaleRect.GetWidth() - 1 ) / (double)aMtfSize.Width();
236         }
237 
238         if(aMtfSize.Height() != (maScaleRect.GetHeight() - 1))
239         {
240             mfScaleY = (double)( maScaleRect.GetHeight() - 1 ) / (double)aMtfSize.Height();
241         }
242     }
243 
244 	mbMov = maOfs.X()!=0 || maOfs.Y()!=0;
245     mbSize = false;
246 	maScaleX = Fraction( 1, 1 );
247 	maScaleY = Fraction( 1, 1 );
248 
249     if(aMtfSize.Width() != (maScaleRect.GetWidth() - 1))
250     {
251         maScaleX = Fraction(maScaleRect.GetWidth() - 1, aMtfSize.Width());
252         mbSize = true;
253     }
254 
255     if(aMtfSize.Height() != (maScaleRect.GetHeight() - 1))
256     {
257         maScaleY = Fraction(maScaleRect.GetHeight() - 1, aMtfSize.Height());
258         mbSize = true;
259     }
260 
261 	if(pProgrInfo)
262     {
263 		pProgrInfo->SetActionCount(rMtf.GetActionCount());
264     }
265 
266 	sal_uInt32 nActionsToReport(0);
267 
268     // execute
269     DoLoopActions(const_cast< GDIMetaFile& >(rMtf), pProgrInfo, &nActionsToReport);
270 
271     if(pProgrInfo)
272 	{
273 		pProgrInfo->ReportActions(nActionsToReport);
274 		nActionsToReport = 0;
275 	}
276 
277 	// MapMode-Scaling  vornehmen
278 	MapScaling();
279 
280 	// Beim berechnen der Fortschrittsanzeige wird GetActionCount()*3 benutzt.
281 	// Da in maTmpList allerdings weniger eintraege als GetActionCount()
282 	// existieren koennen, muessen hier die zuviel vermuteten Actionen wieder
283 	// hinzugefuegt werden.
284 	nActionsToReport = (rMtf.GetActionCount() - maTmpList.size()) * 2;
285 
286 	// Alle noch nicht gemeldeten Rescales melden
287 	if(pProgrInfo)
288 	{
289 		pProgrInfo->ReportRescales(nActionsToReport);
290 		pProgrInfo->SetInsertCount(maTmpList.size());
291 	}
292 
293     nActionsToReport = 0;
294 
295 	// alle in maTmpList zwischengespeicherten Objekte nun in rOL ab der Position nInsPos einfuegen
296 	if(nInsPos > rOL.GetObjCount())
297     {
298         nInsPos = rOL.GetObjCount();
299     }
300 
301 	SdrInsertReason aReason(SDRREASON_VIEWCALL);
302 
303 	for(sal_uInt32 i(0); i < maTmpList.size(); i++)
304 	{
305 		SdrObject* pObj = maTmpList[i];
306 		rOL.NbcInsertObject(pObj, nInsPos, &aReason);
307 		nInsPos++;
308 
309 		if(pProgrInfo)
310 		{
311 			nActionsToReport++;
312 
313             if(nActionsToReport >= 32) // Alle 32 Action updaten
314 			{
315 				pProgrInfo->ReportInserts(nActionsToReport);
316 				nActionsToReport = 0;
317 			}
318 		}
319 	}
320 
321 	// ein letztesmal alle verbliebennen Inserts reporten
322 	if(pProgrInfo)
323 	{
324 		pProgrInfo->ReportInserts(nActionsToReport);
325 	}
326 
327 	return maTmpList.size();
328 }
329 
330 void ImpSdrGDIMetaFileImport::SetAttributes(SdrObject* pObj, bool bForceTextAttr)
331 {
332 	mbNoLine = false;
333     mbNoFill = false;
334 	bool bLine(!bForceTextAttr);
335 	bool bFill(!pObj || (pObj->IsClosedObj() && !bForceTextAttr));
336 	bool bText(bForceTextAttr || (pObj && pObj->GetOutlinerParaObject()));
337 
338 	if(bLine)
339 	{
340 		if(mnLineWidth)
341         {
342 			mpLineAttr->Put(XLineWidthItem(mnLineWidth));
343         }
344         else
345         {
346 			mpLineAttr->Put(XLineWidthItem(0));
347         }
348 
349 		maOldLineColor = maVD.GetLineColor();
350 
351         if(maVD.IsLineColor())
352 		{
353 			mpLineAttr->Put(XLineStyleItem(XLINE_SOLID));
354 			mpLineAttr->Put(XLineColorItem(String(), maVD.GetLineColor()));
355 		}
356 		else
357         {
358 			mpLineAttr->Put(XLineStyleItem(XLINE_NONE));
359         }
360 
361 		switch(maLineJoin)
362 		{
363 			default : // basegfx::B2DLINEJOIN_NONE
364 				mpLineAttr->Put(XLineJointItem(com::sun::star::drawing::LineJoint_NONE));
365 				break;
366 			case basegfx::B2DLINEJOIN_MIDDLE:
367 				mpLineAttr->Put(XLineJointItem(com::sun::star::drawing::LineJoint_MIDDLE));
368 				break;
369 			case basegfx::B2DLINEJOIN_BEVEL:
370 				mpLineAttr->Put(XLineJointItem(com::sun::star::drawing::LineJoint_BEVEL));
371 				break;
372 			case basegfx::B2DLINEJOIN_MITER:
373 				mpLineAttr->Put(XLineJointItem(com::sun::star::drawing::LineJoint_MITER));
374 				break;
375 			case basegfx::B2DLINEJOIN_ROUND:
376 				mpLineAttr->Put(XLineJointItem(com::sun::star::drawing::LineJoint_ROUND));
377 				break;
378 		}
379 
380         // Add LineCap support
381         mpLineAttr->Put(XLineCapItem(maLineCap));
382 
383 		if(((maDash.GetDots() && maDash.GetDotLen()) || (maDash.GetDashes() && maDash.GetDashLen())) && maDash.GetDistance())
384 		{
385 			mpLineAttr->Put(XLineDashItem(String(), maDash));
386 		}
387         else
388         {
389 			mpLineAttr->Put(XLineDashItem(String(), XDash(XDASH_RECT)));
390         }
391 	}
392 	else
393     {
394 		mbNoLine = true;
395     }
396 
397 	if(bFill)
398 	{
399 		if(maVD.IsFillColor())
400 		{
401 			mpFillAttr->Put(XFillStyleItem(XFILL_SOLID));
402 			mpFillAttr->Put(XFillColorItem(String(), maVD.GetFillColor()));
403 		}
404 		else
405         {
406 			mpFillAttr->Put(XFillStyleItem(XFILL_NONE));
407         }
408 	}
409 	else
410     {
411 		mbNoFill = true;
412     }
413 
414 	if(bText && mbFntDirty)
415 	{
416 		Font aFnt(maVD.GetFont());
417 		const sal_uInt32 nHeight(FRound(aFnt.GetSize().Height() * mfScaleY));
418 
419         mpTextAttr->Put( SvxFontItem( aFnt.GetFamily(), aFnt.GetName(), aFnt.GetStyleName(), aFnt.GetPitch(), aFnt.GetCharSet(), EE_CHAR_FONTINFO ) );
420 		mpTextAttr->Put( SvxFontItem( aFnt.GetFamily(), aFnt.GetName(), aFnt.GetStyleName(), aFnt.GetPitch(), aFnt.GetCharSet(), EE_CHAR_FONTINFO_CJK ) );
421 		mpTextAttr->Put( SvxFontItem( aFnt.GetFamily(), aFnt.GetName(), aFnt.GetStyleName(), aFnt.GetPitch(), aFnt.GetCharSet(), EE_CHAR_FONTINFO_CTL ) );
422         mpTextAttr->Put(SvxPostureItem(aFnt.GetItalic(), EE_CHAR_ITALIC));
423         mpTextAttr->Put(SvxWeightItem(aFnt.GetWeight(), EE_CHAR_WEIGHT));
424 		mpTextAttr->Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
425 		mpTextAttr->Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
426 		mpTextAttr->Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CTL ) );
427         mpTextAttr->Put(SvxCharScaleWidthItem(100, EE_CHAR_FONTWIDTH));
428         mpTextAttr->Put(SvxUnderlineItem(aFnt.GetUnderline(), EE_CHAR_UNDERLINE));
429         mpTextAttr->Put(SvxOverlineItem(aFnt.GetOverline(), EE_CHAR_OVERLINE));
430         mpTextAttr->Put(SvxCrossedOutItem(aFnt.GetStrikeout(), EE_CHAR_STRIKEOUT));
431         mpTextAttr->Put(SvxShadowedItem(aFnt.IsShadow(), EE_CHAR_SHADOW));
432 
433         // #i118485# Setting this item leads to problems (written #i118498# for this)
434         // mpTextAttr->Put(SvxAutoKernItem(aFnt.IsKerning(), EE_CHAR_KERNING));
435 
436         mpTextAttr->Put(SvxWordLineModeItem(aFnt.IsWordLineMode(), EE_CHAR_WLM));
437         mpTextAttr->Put(SvxContourItem(aFnt.IsOutline(), EE_CHAR_OUTLINE));
438         mpTextAttr->Put(SvxColorItem(maVD.GetTextColor(), EE_CHAR_COLOR));
439 		//... svxfont textitem svditext
440 		mbFntDirty = false;
441 	}
442 
443     if(pObj)
444 	{
445 		pObj->SetLayer(mnLayer);
446 
447         if(bLine)
448         {
449             pObj->SetMergedItemSet(*mpLineAttr);
450         }
451 
452 		if(bFill)
453         {
454             pObj->SetMergedItemSet(*mpFillAttr);
455         }
456 
457 		if(bText)
458 		{
459 			pObj->SetMergedItemSet(*mpTextAttr);
460 			pObj->SetMergedItem(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_LEFT));
461 		}
462 	}
463 }
464 
465 void ImpSdrGDIMetaFileImport::InsertObj(SdrObject* pObj, bool bScale)
466 {
467     if(bScale && !maScaleRect.IsEmpty())
468     {
469 		if(mbSize)
470         {
471 			pObj->NbcResize(Point(), maScaleX, maScaleY);
472         }
473 
474         if(mbMov)
475         {
476 			pObj->NbcMove(Size(maOfs.X(), maOfs.Y()));
477         }
478 	}
479 
480     if(isClip())
481     {
482         const basegfx::B2DPolyPolygon aPoly(pObj->TakeXorPoly());
483         const basegfx::B2DRange aOldRange(aPoly.getB2DRange());
484     	const SdrLayerID aOldLayer(pObj->GetLayer());
485     	const SfxItemSet aOldItemSet(pObj->GetMergedItemSet());
486         const SdrGrafObj* pSdrGrafObj = dynamic_cast< SdrGrafObj* >(pObj);
487         BitmapEx aBitmapEx;
488 
489         if(pSdrGrafObj)
490         {
491         	aBitmapEx = pSdrGrafObj->GetGraphic().GetBitmapEx();
492         }
493 
494         SdrObject::Free(pObj);
495 
496         if(!aOldRange.isEmpty())
497         {
498             // clip against ClipRegion
499             const basegfx::B2DPolyPolygon aNewPoly(
500                 basegfx::tools::clipPolyPolygonOnPolyPolygon(
501                     aPoly,
502                     maClip,
503                     true,
504                     aPoly.isClosed() ? false : true));
505             const basegfx::B2DRange aNewRange(aNewPoly.getB2DRange());
506 
507             if(!aNewRange.isEmpty())
508             {
509                 pObj = new SdrPathObj(
510                     aNewPoly.isClosed() ? OBJ_POLY : OBJ_PLIN,
511                     aNewPoly);
512 
513 		        pObj->SetLayer(aOldLayer);
514 		        pObj->SetMergedItemSet(aOldItemSet);
515 
516                 if(!!aBitmapEx)
517                 {
518                     // aNewRange is inside of aOldRange and defines which part of aBitmapEx is used
519                     const double fScaleX(aBitmapEx.GetSizePixel().Width() / (aOldRange.getWidth() ? aOldRange.getWidth() : 1.0));
520                     const double fScaleY(aBitmapEx.GetSizePixel().Height() / (aOldRange.getHeight() ? aOldRange.getHeight() : 1.0));
521                     basegfx::B2DRange aPixel(aNewRange);
522                     basegfx::B2DHomMatrix aTrans;
523 
524                     aTrans.translate(-aOldRange.getMinX(), -aOldRange.getMinY());
525                     aTrans.scale(fScaleX, fScaleY);
526                     aPixel.transform(aTrans);
527 
528                     const Size aOrigSizePixel(aBitmapEx.GetSizePixel());
529                     const Point aClipTopLeft(
530                         basegfx::fround(floor(std::max(0.0, aPixel.getMinX()))),
531                         basegfx::fround(floor(std::max(0.0, aPixel.getMinY()))));
532                     const Size aClipSize(
533                         basegfx::fround(ceil(std::min((double)aOrigSizePixel.Width(), aPixel.getWidth()))),
534                         basegfx::fround(ceil(std::min((double)aOrigSizePixel.Height(), aPixel.getHeight()))));
535                     const BitmapEx aClippedBitmap(
536                         aBitmapEx,
537                         aClipTopLeft,
538                         aClipSize);
539 
540                     pObj->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
541                     pObj->SetMergedItem(XFillBitmapItem(String(), Graphic(aClippedBitmap)));
542                     pObj->SetMergedItem(XFillBmpTileItem(false));
543                     pObj->SetMergedItem(XFillBmpStretchItem(true));
544                 }
545             }
546         }
547     }
548 
549     if(pObj)
550     {
551         // #i111954# check object for visibility
552         // used are SdrPathObj, SdrRectObj, SdrCircObj, SdrGrafObj
553         bool bVisible(false);
554 
555         if(pObj->HasLineStyle())
556         {
557             bVisible = true;
558         }
559 
560         if(!bVisible && pObj->HasFillStyle())
561         {
562             bVisible = true;
563         }
564 
565         if(!bVisible)
566         {
567             SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >(pObj);
568 
569             if(pTextObj && pTextObj->HasText())
570             {
571                 bVisible = true;
572             }
573         }
574 
575         if(!bVisible)
576         {
577             SdrGrafObj* pGrafObj = dynamic_cast< SdrGrafObj* >(pObj);
578 
579             if(pGrafObj)
580             {
581                 // this may be refined to check if the graphic really is visible. It
582                 // is here to ensure that graphic objects without fill, line and text
583                 // get created
584                 bVisible = true;
585             }
586         }
587 
588         if(!bVisible)
589         {
590             SdrObject::Free(pObj);
591         }
592         else
593         {
594 	        maTmpList.push_back(pObj);
595 
596             if(dynamic_cast< SdrPathObj* >(pObj))
597 	        {
598 		        const bool bClosed(pObj->IsClosedObj());
599 
600                 mbLastObjWasPolyWithoutLine = mbNoLine && bClosed;
601 		        mbLastObjWasLine = !bClosed;
602 	        }
603 	        else
604 	        {
605 		        mbLastObjWasPolyWithoutLine = false;
606 		        mbLastObjWasLine = false;
607 	        }
608         }
609     }
610 }
611 
612 /**************************************************************************************************/
613 
614 void ImpSdrGDIMetaFileImport::DoAction(MetaPixelAction& /*rAct*/)
615 {
616 }
617 
618 void ImpSdrGDIMetaFileImport::DoAction(MetaPointAction& /*rAct*/)
619 {
620 }
621 
622 void ImpSdrGDIMetaFileImport::DoAction(MetaLineAction& rAct)
623 {
624 	// #i73407# reformulation to use new B2DPolygon classes
625 	const basegfx::B2DPoint aStart(rAct.GetStartPoint().X(), rAct.GetStartPoint().Y());
626 	const basegfx::B2DPoint aEnd(rAct.GetEndPoint().X(), rAct.GetEndPoint().Y());
627 
628 	if(!aStart.equal(aEnd))
629 	{
630 		basegfx::B2DPolygon aLine;
631 		const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
632 
633 		aLine.append(aStart);
634 		aLine.append(aEnd);
635 		aLine.transform(aTransform);
636 
637 		const LineInfo& rLineInfo = rAct.GetLineInfo();
638 		const sal_Int32 nNewLineWidth(rLineInfo.GetWidth());
639 		bool bCreateLineObject(true);
640 
641 		if(mbLastObjWasLine && (nNewLineWidth == mnLineWidth) && CheckLastLineMerge(aLine))
642 		{
643 			bCreateLineObject = false;
644 		}
645 
646 		if(bCreateLineObject)
647 		{
648 			SdrPathObj* pPath = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aLine));
649 			mnLineWidth = nNewLineWidth;
650 			maLineJoin = rLineInfo.GetLineJoin();
651             maLineCap = rLineInfo.GetLineCap();
652 			maDash = XDash(XDASH_RECT,
653 				rLineInfo.GetDotCount(), rLineInfo.GetDotLen(),
654 				rLineInfo.GetDashCount(), rLineInfo.GetDashLen(),
655 				rLineInfo.GetDistance());
656 			SetAttributes(pPath);
657 			mnLineWidth = 0;
658 			maLineJoin = basegfx::B2DLINEJOIN_NONE;
659 			maDash = XDash();
660 			InsertObj(pPath, false);
661 		}
662 	}
663 }
664 
665 void ImpSdrGDIMetaFileImport::DoAction(MetaRectAction& rAct)
666 {
667     SdrRectObj* pRect=new SdrRectObj(rAct.GetRect());
668 	SetAttributes(pRect);
669 	InsertObj(pRect);
670 }
671 
672 void ImpSdrGDIMetaFileImport::DoAction(MetaRoundRectAction& rAct)
673 {
674     SdrRectObj* pRect=new SdrRectObj(rAct.GetRect());
675 	SetAttributes(pRect);
676 	long nRad=(rAct.GetHorzRound()+rAct.GetVertRound())/2;
677 	if (nRad!=0) {
678 		SfxItemSet aSet(*mpLineAttr->GetPool(), SDRATTR_ECKENRADIUS, SDRATTR_ECKENRADIUS, 0, 0);
679 		aSet.Put(SdrEckenradiusItem(nRad));
680 		pRect->SetMergedItemSet(aSet);
681 	}
682 	InsertObj(pRect);
683 }
684 
685 /**************************************************************************************************/
686 
687 void ImpSdrGDIMetaFileImport::DoAction(MetaEllipseAction& rAct)
688 {
689     SdrCircObj* pCirc=new SdrCircObj(OBJ_CIRC,rAct.GetRect());
690 	SetAttributes(pCirc);
691 	InsertObj(pCirc);
692 }
693 
694 void ImpSdrGDIMetaFileImport::DoAction(MetaArcAction& rAct)
695 {
696     Point aCenter(rAct.GetRect().Center());
697 	long nStart=GetAngle(rAct.GetStartPoint()-aCenter);
698 	long nEnd=GetAngle(rAct.GetEndPoint()-aCenter);
699 	SdrCircObj* pCirc=new SdrCircObj(OBJ_CARC,rAct.GetRect(),nStart,nEnd);
700 	SetAttributes(pCirc);
701 	InsertObj(pCirc);
702 }
703 
704 void ImpSdrGDIMetaFileImport::DoAction(MetaPieAction& rAct)
705 {
706     Point aCenter(rAct.GetRect().Center());
707 	long nStart=GetAngle(rAct.GetStartPoint()-aCenter);
708 	long nEnd=GetAngle(rAct.GetEndPoint()-aCenter);
709 	SdrCircObj* pCirc=new SdrCircObj(OBJ_SECT,rAct.GetRect(),nStart,nEnd);
710 	SetAttributes(pCirc);
711 	InsertObj(pCirc);
712 }
713 
714 void ImpSdrGDIMetaFileImport::DoAction(MetaChordAction& rAct)
715 {
716     Point aCenter(rAct.GetRect().Center());
717 	long nStart=GetAngle(rAct.GetStartPoint()-aCenter);
718 	long nEnd=GetAngle(rAct.GetEndPoint()-aCenter);
719 	SdrCircObj* pCirc=new SdrCircObj(OBJ_CCUT,rAct.GetRect(),nStart,nEnd);
720 	SetAttributes(pCirc);
721 	InsertObj(pCirc);
722 }
723 
724 /**************************************************************************************************/
725 
726 bool ImpSdrGDIMetaFileImport::CheckLastLineMerge(const basegfx::B2DPolygon& rSrcPoly)
727 {
728 	// #i102706# Do not merge closed polygons
729 	if(rSrcPoly.isClosed())
730 	{
731 		return false;
732 	}
733 
734 	// #i73407# reformulation to use new B2DPolygon classes
735 	if(mbLastObjWasLine && (maOldLineColor == maVD.GetLineColor()) && rSrcPoly.count())
736 	{
737 		SdrObject* pTmpObj = maTmpList.size() ? maTmpList[maTmpList.size() - 1] : 0;
738 		SdrPathObj* pLastPoly = dynamic_cast< SdrPathObj* >(pTmpObj);
739 
740 		if(pLastPoly)
741 		{
742 			if(1L == pLastPoly->GetPathPoly().count())
743 			{
744 				bool bOk(false);
745 				basegfx::B2DPolygon aDstPoly(pLastPoly->GetPathPoly().getB2DPolygon(0L));
746 
747 				// #i102706# Do not merge closed polygons
748 				if(aDstPoly.isClosed())
749 				{
750 					return false;
751 				}
752 
753 				if(aDstPoly.count())
754 				{
755 					const sal_uInt32 nMaxDstPnt(aDstPoly.count() - 1L);
756 					const sal_uInt32 nMaxSrcPnt(rSrcPoly.count() - 1L);
757 
758 					if(aDstPoly.getB2DPoint(nMaxDstPnt) == rSrcPoly.getB2DPoint(0L))
759 					{
760 						aDstPoly.append(rSrcPoly, 1L, rSrcPoly.count() - 1L);
761 						bOk = true;
762 					}
763 					else if(aDstPoly.getB2DPoint(0L) == rSrcPoly.getB2DPoint(nMaxSrcPnt))
764 					{
765 						basegfx::B2DPolygon aNew(rSrcPoly);
766 						aNew.append(aDstPoly, 1L, aDstPoly.count() - 1L);
767 						aDstPoly = aNew;
768 						bOk = true;
769 					}
770 					else if(aDstPoly.getB2DPoint(0L) == rSrcPoly.getB2DPoint(0L))
771 					{
772 						aDstPoly.flip();
773 						aDstPoly.append(rSrcPoly, 1L, rSrcPoly.count() - 1L);
774 						bOk = true;
775 					}
776 					else if(aDstPoly.getB2DPoint(nMaxDstPnt) == rSrcPoly.getB2DPoint(nMaxSrcPnt))
777 					{
778 						basegfx::B2DPolygon aNew(rSrcPoly);
779 						aNew.flip();
780 						aDstPoly.append(aNew, 1L, aNew.count() - 1L);
781 						bOk = true;
782 					}
783 				}
784 
785 				if(bOk)
786 				{
787 					pLastPoly->NbcSetPathPoly(basegfx::B2DPolyPolygon(aDstPoly));
788 				}
789 
790 				return bOk;
791 			}
792 		}
793 	}
794 
795 	return false;
796 }
797 
798 bool ImpSdrGDIMetaFileImport::CheckLastPolyLineAndFillMerge(const basegfx::B2DPolyPolygon & rPolyPolygon)
799 {
800 	// #i73407# reformulation to use new B2DPolygon classes
801 	if(mbLastObjWasPolyWithoutLine)
802 	{
803 		SdrObject* pTmpObj = maTmpList.size() ? maTmpList[maTmpList.size() - 1] : 0;
804 		SdrPathObj* pLastPoly = dynamic_cast< SdrPathObj* >(pTmpObj);
805 
806 		if(pLastPoly)
807 		{
808 			if(pLastPoly->GetPathPoly() == rPolyPolygon)
809 			{
810 				SetAttributes(NULL);
811 
812 				if(!mbNoLine && mbNoFill)
813 				{
814 					pLastPoly->SetMergedItemSet(*mpLineAttr);
815 
816 					return true;
817 				}
818 			}
819 		}
820 	}
821 
822 	return false;
823 }
824 
825 void ImpSdrGDIMetaFileImport::checkClip()
826 {
827     if(maVD.IsClipRegion())
828     {
829         maClip = maVD.GetClipRegion().GetAsB2DPolyPolygon();
830 
831         if(isClip())
832         {
833     		const basegfx::B2DHomMatrix aTransform(
834                 basegfx::tools::createScaleTranslateB2DHomMatrix(
835                     mfScaleX,
836                     mfScaleY,
837                     maOfs.X(),
838                     maOfs.Y()));
839 
840             maClip.transform(aTransform);
841         }
842     }
843 }
844 
845 bool ImpSdrGDIMetaFileImport::isClip() const
846 {
847     return !maClip.getB2DRange().isEmpty();
848 }
849 
850 void ImpSdrGDIMetaFileImport::DoAction( MetaPolyLineAction& rAct )
851 {
852 	// #i73407# reformulation to use new B2DPolygon classes
853 	basegfx::B2DPolygon aSource(rAct.GetPolygon().getB2DPolygon());
854 
855 	if(aSource.count())
856 	{
857 		const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
858 		aSource.transform(aTransform);
859 	}
860 
861 	const LineInfo& rLineInfo = rAct.GetLineInfo();
862 	const sal_Int32 nNewLineWidth(rLineInfo.GetWidth());
863 	bool bCreateLineObject(true);
864 
865 	if(mbLastObjWasLine && (nNewLineWidth == mnLineWidth) && CheckLastLineMerge(aSource))
866 	{
867 		bCreateLineObject = false;
868 	}
869 	else if(mbLastObjWasPolyWithoutLine && CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource)))
870 	{
871 		bCreateLineObject = false;
872 	}
873 
874 	if(bCreateLineObject)
875 	{
876         SdrPathObj* pPath = new SdrPathObj(
877 			aSource.isClosed() ? OBJ_POLY : OBJ_PLIN,
878 			basegfx::B2DPolyPolygon(aSource));
879 		mnLineWidth = nNewLineWidth;
880 		maLineJoin = rLineInfo.GetLineJoin();
881         maLineCap = rLineInfo.GetLineCap();
882 		maDash = XDash(XDASH_RECT,
883 			rLineInfo.GetDotCount(), rLineInfo.GetDotLen(),
884 			rLineInfo.GetDashCount(), rLineInfo.GetDashLen(),
885 			rLineInfo.GetDistance());
886 		SetAttributes(pPath);
887 		mnLineWidth = 0;
888 		maLineJoin = basegfx::B2DLINEJOIN_NONE;
889 		maDash = XDash();
890 		InsertObj(pPath, false);
891 	}
892 }
893 
894 void ImpSdrGDIMetaFileImport::DoAction( MetaPolygonAction& rAct )
895 {
896 	// #i73407# reformulation to use new B2DPolygon classes
897 	basegfx::B2DPolygon aSource(rAct.GetPolygon().getB2DPolygon());
898 
899 	if(aSource.count())
900 	{
901 		const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
902 		aSource.transform(aTransform);
903 
904 		if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource)))
905 		{
906 			// #i73407# make sure polygon is closed, it's a filled primitive
907 			aSource.setClosed(true);
908             SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aSource));
909 			SetAttributes(pPath);
910 			InsertObj(pPath, false);
911 		}
912 	}
913 }
914 
915 void ImpSdrGDIMetaFileImport::DoAction(MetaPolyPolygonAction& rAct)
916 {
917 	// #i73407# reformulation to use new B2DPolygon classes
918 	basegfx::B2DPolyPolygon aSource(rAct.GetPolyPolygon().getB2DPolyPolygon());
919 
920 	if(aSource.count())
921 	{
922 		const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
923 		aSource.transform(aTransform);
924 
925 		if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource))
926 		{
927 			// #i73407# make sure polygon is closed, it's a filled primitive
928 			aSource.setClosed(true);
929             SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
930 			SetAttributes(pPath);
931 			InsertObj(pPath, false);
932 		}
933 	}
934 }
935 
936 /**************************************************************************************************/
937 
938 void ImpSdrGDIMetaFileImport::ImportText( const Point& rPos, const XubString& rStr, const MetaAction& rAct )
939 {
940 	// calc text box size, add 5% to make it fit safely
941 
942 	FontMetric aFontMetric( maVD.GetFontMetric() );
943 	Font aFnt( maVD.GetFont() );
944 	FontAlign eAlg( aFnt.GetAlign() );
945 
946     sal_Int32 nTextWidth = (sal_Int32)( maVD.GetTextWidth( rStr ) * mfScaleX );
947     sal_Int32 nTextHeight = (sal_Int32)( maVD.GetTextHeight() * mfScaleY );
948 	//sal_Int32 nDxWidth = 0;
949 	//sal_Int32 nLen = rStr.Len();
950 
951 	Point aPos( FRound(rPos.X() * mfScaleX + maOfs.X()), FRound(rPos.Y() * mfScaleY + maOfs.Y()) );
952     Size aSize( nTextWidth, nTextHeight );
953 
954 	if ( eAlg == ALIGN_BASELINE )
955 		aPos.Y() -= FRound(aFontMetric.GetAscent() * mfScaleY);
956 	else if ( eAlg == ALIGN_BOTTOM )
957 		aPos.Y() -= nTextHeight;
958 
959 	Rectangle aTextRect( aPos, aSize );
960 	SdrRectObj* pText =new SdrRectObj( OBJ_TEXT, aTextRect );
961 
962 	if ( aFnt.GetWidth() || ( rAct.GetType() == META_STRETCHTEXT_ACTION ) )
963 	{
964 		pText->ClearMergedItem( SDRATTR_TEXT_AUTOGROWWIDTH );
965 		pText->SetMergedItem( SdrTextAutoGrowHeightItem( false ) );
966 		// don't let the margins eat the space needed for the text
967 		pText->SetMergedItem ( SdrTextUpperDistItem (0));
968 		pText->SetMergedItem ( SdrTextLowerDistItem (0));
969 		pText->SetMergedItem ( SdrTextRightDistItem (0));
970 		pText->SetMergedItem ( SdrTextLeftDistItem (0));
971 		pText->SetMergedItem( SdrTextFitToSizeTypeItem( SDRTEXTFIT_ALLLINES ) );
972 	}
973 	else
974 		pText->SetMergedItem( SdrTextAutoGrowWidthItem( true ) );
975 
976 	pText->SetModel(mpModel);
977 	pText->SetLayer(mnLayer);
978 	pText->NbcSetText( rStr );
979 	SetAttributes( pText, true );
980 	pText->SetSnapRect( aTextRect );
981 
982 	if (!aFnt.IsTransparent())
983 	{
984 		SfxItemSet aAttr(*mpFillAttr->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST, 0, 0);
985 		aAttr.Put(XFillStyleItem(XFILL_SOLID));
986 		aAttr.Put(XFillColorItem(String(), aFnt.GetFillColor()));
987 		pText->SetMergedItemSet(aAttr);
988 	}
989 	sal_uInt32 nWink = aFnt.GetOrientation();
990 	if ( nWink )
991 	{
992 		nWink*=10;
993 		double a=nWink*nPi180;
994 		double nSin=sin(a);
995 		double nCos=cos(a);
996 		pText->NbcRotate(aPos,nWink,nSin,nCos);
997 	}
998 	InsertObj( pText, false );
999 }
1000 
1001 void ImpSdrGDIMetaFileImport::DoAction(MetaTextAction& rAct)
1002 {
1003 	XubString aStr(rAct.GetText());
1004 	aStr.Erase(0,rAct.GetIndex());
1005 	aStr.Erase(rAct.GetLen());
1006 	ImportText( rAct.GetPoint(), aStr, rAct );
1007 }
1008 
1009 void ImpSdrGDIMetaFileImport::DoAction(MetaTextArrayAction& rAct)
1010 {
1011 	XubString aStr(rAct.GetText());
1012 	aStr.Erase(0,rAct.GetIndex());
1013 	aStr.Erase(rAct.GetLen());
1014 	ImportText( rAct.GetPoint(), aStr, rAct );
1015 }
1016 
1017 void ImpSdrGDIMetaFileImport::DoAction(MetaStretchTextAction& rAct)
1018 {
1019 	XubString aStr(rAct.GetText());
1020 	aStr.Erase(0,rAct.GetIndex());
1021 	aStr.Erase(rAct.GetLen());
1022 	ImportText( rAct.GetPoint(), aStr, rAct );
1023 }
1024 
1025 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpAction& rAct)
1026 {
1027 	Rectangle aRect(rAct.GetPoint(),rAct.GetBitmap().GetSizePixel());
1028 	aRect.Right()++; aRect.Bottom()++;
1029     SdrGrafObj* pGraf=new SdrGrafObj(Graphic(rAct.GetBitmap()),aRect);
1030 
1031     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1032     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1033     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1034     InsertObj(pGraf);
1035 }
1036 
1037 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpScaleAction& rAct)
1038 {
1039 	Rectangle aRect(rAct.GetPoint(),rAct.GetSize());
1040 	aRect.Right()++; aRect.Bottom()++;
1041     SdrGrafObj* pGraf=new SdrGrafObj(Graphic(rAct.GetBitmap()),aRect);
1042 
1043     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1044     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1045     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1046     InsertObj(pGraf);
1047 }
1048 
1049 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExAction& rAct)
1050 {
1051 	Rectangle aRect(rAct.GetPoint(),rAct.GetBitmapEx().GetSizePixel());
1052 	aRect.Right()++; aRect.Bottom()++;
1053     SdrGrafObj* pGraf=new SdrGrafObj( rAct.GetBitmapEx(), aRect );
1054 
1055     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1056     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1057     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1058     InsertObj(pGraf);
1059 }
1060 
1061 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExScaleAction& rAct)
1062 {
1063 	Rectangle aRect(rAct.GetPoint(),rAct.GetSize());
1064 	aRect.Right()++; aRect.Bottom()++;
1065     SdrGrafObj* pGraf=new SdrGrafObj( rAct.GetBitmapEx(), aRect );
1066 
1067     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1068     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1069     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1070 	InsertObj(pGraf);
1071 }
1072 
1073 ////////////////////////////////////////////////////////////////////////////////////////////////////
1074 
1075 void ImpSdrGDIMetaFileImport::DoAction( MetaHatchAction& rAct )
1076 {
1077 	// #i73407# reformulation to use new B2DPolygon classes
1078 	basegfx::B2DPolyPolygon aSource(rAct.GetPolyPolygon().getB2DPolyPolygon());
1079 
1080 	if(aSource.count())
1081 	{
1082 		const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
1083 		aSource.transform(aTransform);
1084 
1085 		if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource))
1086 		{
1087 			const Hatch& rHatch = rAct.GetHatch();
1088             SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
1089 			SfxItemSet aHatchAttr(mpModel->GetItemPool(), XATTR_FILLSTYLE, XATTR_FILLSTYLE, XATTR_FILLHATCH, XATTR_FILLHATCH, 0, 0);
1090 			XHatchStyle eStyle;
1091 
1092 			switch(rHatch.GetStyle())
1093 			{
1094 				case(HATCH_TRIPLE) :
1095 				{
1096 					eStyle = XHATCH_TRIPLE;
1097 					break;
1098 				}
1099 
1100 				case(HATCH_DOUBLE) :
1101 				{
1102 					eStyle = XHATCH_DOUBLE;
1103 					break;
1104 				}
1105 
1106 				default:
1107 				{
1108 					eStyle = XHATCH_SINGLE;
1109 					break;
1110 				}
1111 			}
1112 
1113 			SetAttributes(pPath);
1114 			aHatchAttr.Put(XFillStyleItem(XFILL_HATCH));
1115 			aHatchAttr.Put(XFillHatchItem(&mpModel->GetItemPool(), XHatch(rHatch.GetColor(), eStyle, rHatch.GetDistance(), rHatch.GetAngle())));
1116 			pPath->SetMergedItemSet(aHatchAttr);
1117 
1118 			InsertObj(pPath, false);
1119 		}
1120 	}
1121 }
1122 
1123 ////////////////////////////////////////////////////////////////////////////////////////////////////
1124 
1125 void ImpSdrGDIMetaFileImport::DoAction(MetaLineColorAction& rAct)
1126 {
1127 	rAct.Execute(&maVD);
1128 }
1129 
1130 void ImpSdrGDIMetaFileImport::DoAction(MetaMapModeAction& rAct)
1131 {
1132 	MapScaling();
1133 	rAct.Execute(&maVD);
1134 	mbLastObjWasPolyWithoutLine = false;
1135 	mbLastObjWasLine = false;
1136 }
1137 
1138 void ImpSdrGDIMetaFileImport::MapScaling()
1139 {
1140 	const sal_uInt32 nAnz(maTmpList.size());
1141 	sal_uInt32 i(0);
1142 	const MapMode& rMap = maVD.GetMapMode();
1143 	Point aMapOrg( rMap.GetOrigin() );
1144 	bool bMov2(aMapOrg.X() != 0 || aMapOrg.Y() != 0);
1145 
1146     if(bMov2)
1147     {
1148 		for(i = mnMapScalingOfs; i < nAnz; i++)
1149         {
1150 			SdrObject* pObj = maTmpList[i];
1151 
1152             pObj->NbcMove(Size(aMapOrg.X(), aMapOrg.Y()));
1153 		}
1154 	}
1155 
1156     mnMapScalingOfs = nAnz;
1157 }
1158 
1159 ////////////////////////////////////////////////////////////////////////////////////////////////////
1160 
1161 void ImpSdrGDIMetaFileImport::DoAction( MetaCommentAction& rAct, GDIMetaFile* pMtf )
1162 {
1163 	ByteString aSkipComment;
1164 
1165 	if( rAct.GetComment().CompareIgnoreCaseToAscii( "XGRAD_SEQ_BEGIN" ) == COMPARE_EQUAL )
1166 	{
1167 		MetaGradientExAction* pAct = (MetaGradientExAction*) pMtf->NextAction();
1168 
1169 		if( pAct && pAct->GetType() == META_GRADIENTEX_ACTION )
1170 		{
1171 			// #i73407# reformulation to use new B2DPolygon classes
1172 			basegfx::B2DPolyPolygon aSource(pAct->GetPolyPolygon().getB2DPolyPolygon());
1173 
1174 			if(aSource.count())
1175 			{
1176 				if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource))
1177 				{
1178 					const Gradient&	rGrad = pAct->GetGradient();
1179                     SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
1180 					SfxItemSet aGradAttr(mpModel->GetItemPool(), XATTR_FILLSTYLE, XATTR_FILLSTYLE, XATTR_FILLGRADIENT, XATTR_FILLGRADIENT, 0, 0);
1181 					XGradient aXGradient;
1182 
1183 					aXGradient.SetGradientStyle((XGradientStyle)rGrad.GetStyle());
1184 					aXGradient.SetStartColor(rGrad.GetStartColor());
1185 					aXGradient.SetEndColor(rGrad.GetEndColor());
1186 					aXGradient.SetAngle((sal_uInt16)rGrad.GetAngle());
1187 					aXGradient.SetBorder(rGrad.GetBorder());
1188 					aXGradient.SetXOffset(rGrad.GetOfsX());
1189 					aXGradient.SetYOffset(rGrad.GetOfsY());
1190 					aXGradient.SetStartIntens(rGrad.GetStartIntensity());
1191 					aXGradient.SetEndIntens(rGrad.GetEndIntensity());
1192 					aXGradient.SetSteps(rGrad.GetSteps());
1193 
1194                     // no need to use SetAttributes(..) here since line and fill style
1195                     // need to be set individually
1196                     // SetAttributes(pPath);
1197 
1198                     // switch line off; when there was one there will be a
1199                     // META_POLYLINE_ACTION following creating another object
1200                     aGradAttr.Put(XLineStyleItem(XLINE_NONE));
1201 
1202                     // add detected gradient fillstyle
1203                     aGradAttr.Put(XFillStyleItem(XFILL_GRADIENT));
1204                     aGradAttr.Put(XFillGradientItem(&mpModel->GetItemPool(), aXGradient));
1205 
1206                     pPath->SetMergedItemSet(aGradAttr);
1207 
1208 					InsertObj(pPath);
1209 				}
1210 			}
1211 
1212 			aSkipComment = "XGRAD_SEQ_END";
1213 		}
1214 	}
1215 
1216 	if(aSkipComment.Len())
1217 	{
1218 		MetaAction* pSkipAct = pMtf->NextAction();
1219 
1220 		while( pSkipAct
1221 			&& ((pSkipAct->GetType() != META_COMMENT_ACTION )
1222 				|| (((MetaCommentAction*)pSkipAct)->GetComment().CompareIgnoreCaseToAscii(aSkipComment.GetBuffer()) != COMPARE_EQUAL)))
1223 		{
1224 			pSkipAct = pMtf->NextAction();
1225 		}
1226 	}
1227 }
1228 
1229 ////////////////////////////////////////////////////////////////////////////////////////////////////
1230 
1231 void ImpSdrGDIMetaFileImport::DoAction(MetaTextRectAction& rAct)
1232 {
1233     GDIMetaFile aTemp;
1234 
1235     maVD.AddTextRectActions(rAct.GetRect(), rAct.GetText(), rAct.GetStyle(), aTemp);
1236     DoLoopActions(aTemp, 0, 0);
1237 }
1238 
1239 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpScalePartAction& rAct)
1240 {
1241 	Rectangle aRect(rAct.GetDestPoint(), rAct.GetDestSize());
1242     Bitmap aBitmap(rAct.GetBitmap());
1243 
1244     aRect.Right()++;
1245     aRect.Bottom()++;
1246     aBitmap.Crop(Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize()));
1247     SdrGrafObj* pGraf = new SdrGrafObj(aBitmap, aRect);
1248 
1249     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1250     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1251     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1252     InsertObj(pGraf);
1253 }
1254 
1255 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExScalePartAction& rAct)
1256 {
1257 	Rectangle aRect(rAct.GetDestPoint(),rAct.GetDestSize());
1258     BitmapEx aBitmapEx(rAct.GetBitmapEx());
1259 
1260     aRect.Right()++;
1261     aRect.Bottom()++;
1262     aBitmapEx.Crop(Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize()));
1263     SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);
1264 
1265     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1266     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1267     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1268     InsertObj(pGraf);
1269 }
1270 
1271 void ImpSdrGDIMetaFileImport::DoAction(MetaMaskAction& rAct)
1272 {
1273 	Rectangle aRect(rAct.GetPoint(), rAct.GetBitmap().GetSizePixel());
1274     BitmapEx aBitmapEx(rAct.GetBitmap(), rAct.GetColor());
1275 
1276     aRect.Right()++; aRect.Bottom()++;
1277     SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);
1278 
1279     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1280     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1281     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1282     InsertObj(pGraf);
1283 }
1284 
1285 void ImpSdrGDIMetaFileImport::DoAction(MetaMaskScaleAction& rAct)
1286 {
1287 	Rectangle aRect(rAct.GetPoint(), rAct.GetSize());
1288     BitmapEx aBitmapEx(rAct.GetBitmap(), rAct.GetColor());
1289 
1290     aRect.Right()++; aRect.Bottom()++;
1291     SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);
1292 
1293     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1294     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1295     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1296     InsertObj(pGraf);
1297 }
1298 
1299 void ImpSdrGDIMetaFileImport::DoAction(MetaMaskScalePartAction& rAct)
1300 {
1301 	Rectangle aRect(rAct.GetDestPoint(), rAct.GetDestSize());
1302     BitmapEx aBitmapEx(rAct.GetBitmap(), rAct.GetColor());
1303 
1304     aRect.Right()++; aRect.Bottom()++;
1305     aBitmapEx.Crop(Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize()));
1306     SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);
1307 
1308     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
1309     pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1310     pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1311     InsertObj(pGraf);
1312 }
1313 
1314 XGradientStyle getXGradientStyleFromGradientStyle(const GradientStyle& rGradientStyle)
1315 {
1316     XGradientStyle aXGradientStyle(XGRAD_LINEAR);
1317 
1318     switch(rGradientStyle)
1319     {
1320         case GRADIENT_LINEAR: aXGradientStyle = XGRAD_LINEAR; break;
1321         case GRADIENT_AXIAL: aXGradientStyle = XGRAD_AXIAL; break;
1322         case GRADIENT_RADIAL: aXGradientStyle = XGRAD_RADIAL; break;
1323         case GRADIENT_ELLIPTICAL: aXGradientStyle = XGRAD_ELLIPTICAL; break;
1324         case GRADIENT_SQUARE: aXGradientStyle = XGRAD_SQUARE; break;
1325         case GRADIENT_RECT: aXGradientStyle = XGRAD_RECT; break;
1326 
1327         // Needed due to GRADIENT_FORCE_EQUAL_SIZE; this again is needed
1328         // to force the enum defines in VCL to a defined size for the compilers,
1329         // so despite it is never used it cannot be removed (would break the
1330         // API implementation probably).
1331         default: break;
1332     }
1333 
1334     return aXGradientStyle;
1335 }
1336 
1337 void ImpSdrGDIMetaFileImport::DoAction(MetaGradientAction& rAct)
1338 {
1339     basegfx::B2DRange aRange(rAct.GetRect().Left(), rAct.GetRect().Top(), rAct.GetRect().Right(), rAct.GetRect().Bottom());
1340 
1341 	if(!aRange.isEmpty())
1342 	{
1343 		const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
1344 		aRange.transform(aTransform);
1345         const Gradient& rGradient = rAct.GetGradient();
1346         SdrRectObj* pRect = new SdrRectObj(
1347             Rectangle(
1348                 floor(aRange.getMinX()),
1349                 floor(aRange.getMinY()),
1350                 ceil(aRange.getMaxX()),
1351                 ceil(aRange.getMaxY())));
1352 		SfxItemSet aGradientAttr(mpModel->GetItemPool(), XATTR_FILLSTYLE, XATTR_FILLSTYLE, XATTR_FILLGRADIENT, XATTR_FILLGRADIENT, 0, 0);
1353         const XGradientStyle aXGradientStyle(getXGradientStyleFromGradientStyle(rGradient.GetStyle()));
1354         const XFillGradientItem aXFillGradientItem(
1355             &mpModel->GetItemPool(),
1356             XGradient(
1357                 rGradient.GetStartColor(),
1358                 rGradient.GetEndColor(),
1359                 aXGradientStyle,
1360                 rGradient.GetAngle(),
1361                 rGradient.GetOfsX(),
1362                 rGradient.GetOfsY(),
1363                 rGradient.GetBorder(),
1364                 rGradient.GetStartIntensity(),
1365                 rGradient.GetEndIntensity(),
1366                 rGradient.GetSteps()));
1367 
1368 		SetAttributes(pRect);
1369 		aGradientAttr.Put(XFillStyleItem(XFILL_HATCH));
1370 		aGradientAttr.Put(aXFillGradientItem);
1371 		pRect->SetMergedItemSet(aGradientAttr);
1372 
1373 		InsertObj(pRect, false);
1374 	}
1375 }
1376 
1377 void ImpSdrGDIMetaFileImport::DoAction(MetaWallpaperAction& /*rAct*/)
1378 {
1379     OSL_ENSURE(false, "Tried to construct SdrObject from MetaWallpaperAction: not supported (!)");
1380 }
1381 
1382 void ImpSdrGDIMetaFileImport::DoAction(MetaTransparentAction& rAct)
1383 {
1384 	basegfx::B2DPolyPolygon aSource(rAct.GetPolyPolygon().getB2DPolyPolygon());
1385 
1386 	if(aSource.count())
1387 	{
1388 		const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
1389 		aSource.transform(aTransform);
1390     	aSource.setClosed(true);
1391 
1392         SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
1393 		SetAttributes(pPath);
1394         pPath->SetMergedItem(XFillTransparenceItem(rAct.GetTransparence()));
1395 		InsertObj(pPath, false);
1396 	}
1397 }
1398 
1399 void ImpSdrGDIMetaFileImport::DoAction(MetaEPSAction& /*rAct*/)
1400 {
1401     OSL_ENSURE(false, "Tried to construct SdrObject from MetaEPSAction: not supported (!)");
1402 }
1403 
1404 void ImpSdrGDIMetaFileImport::DoAction(MetaTextLineAction& /*rAct*/)
1405 {
1406     OSL_ENSURE(false, "Tried to construct SdrObject from MetaTextLineAction: not supported (!)");
1407 }
1408 
1409 void ImpSdrGDIMetaFileImport::DoAction(MetaGradientExAction& rAct)
1410 {
1411 	basegfx::B2DPolyPolygon aSource(rAct.GetPolyPolygon().getB2DPolyPolygon());
1412 
1413 	if(aSource.count())
1414 	{
1415 		const basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y()));
1416 		aSource.transform(aTransform);
1417 
1418 		if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource))
1419 		{
1420         	const Gradient& rGradient = rAct.GetGradient();
1421             SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
1422 			SfxItemSet aGradientAttr(mpModel->GetItemPool(), XATTR_FILLSTYLE, XATTR_FILLSTYLE, XATTR_FILLGRADIENT, XATTR_FILLGRADIENT, 0, 0);
1423             const XGradientStyle aXGradientStyle(getXGradientStyleFromGradientStyle(rGradient.GetStyle()));
1424             const XFillGradientItem aXFillGradientItem(
1425                 &mpModel->GetItemPool(),
1426                 XGradient(
1427                     rGradient.GetStartColor(),
1428                     rGradient.GetEndColor(),
1429                     aXGradientStyle,
1430                     rGradient.GetAngle(),
1431                     rGradient.GetOfsX(),
1432                     rGradient.GetOfsY(),
1433                     rGradient.GetBorder(),
1434                     rGradient.GetStartIntensity(),
1435                     rGradient.GetEndIntensity(),
1436                     rGradient.GetSteps()));
1437 
1438 			SetAttributes(pPath);
1439 			aGradientAttr.Put(XFillStyleItem(XFILL_HATCH));
1440 			aGradientAttr.Put(aXFillGradientItem);
1441 			pPath->SetMergedItemSet(aGradientAttr);
1442 
1443 			InsertObj(pPath, false);
1444 		}
1445 	}
1446 }
1447 
1448 void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction& rAct)
1449 {
1450 	const GDIMetaFile& rMtf = rAct.GetGDIMetaFile();
1451 
1452     if(rMtf.GetActionCount())
1453     {
1454 	    const Rectangle aRect(rAct.GetPoint(),rAct.GetSize());
1455 
1456         Rectangle aHairline;
1457         const Rectangle aBoundRect(rMtf.GetBoundRect(*Application::GetDefaultDevice(), &aHairline));
1458 
1459         // convert metafile sub-content to BitmapEx
1460         BitmapEx aBitmapEx(
1461             convertMetafileToBitmapEx(
1462                 rMtf,
1463                 basegfx::B2DRange(
1464                     aRect.Left(), aRect.Top(),
1465                     aRect.Right(), aRect.Bottom()),
1466                 125000));
1467 
1468         // handle colors
1469         const Gradient& rGradient = rAct.GetGradient();
1470 	    basegfx::BColor aStart(rGradient.GetStartColor().getBColor());
1471 	    basegfx::BColor aEnd(rGradient.GetEndColor().getBColor());
1472 
1473         if(100 != rGradient.GetStartIntensity())
1474 	    {
1475             aStart *= (double)rGradient.GetStartIntensity() / 100.0;
1476 	    }
1477 
1478         if(100 != rGradient.GetEndIntensity())
1479 	    {
1480             aEnd *= (double)rGradient.GetEndIntensity() / 100.0;
1481 	    }
1482 
1483         const bool bEqualColors(aStart == aEnd);
1484         const bool bNoSteps(1 == rGradient.GetSteps());
1485         bool bCreateObject(true);
1486         bool bHasNewMask(false);
1487         AlphaMask aNewMask;
1488         double fTransparence(0.0);
1489         bool bFixedTransparence(false);
1490 
1491         if(bEqualColors || bNoSteps)
1492         {
1493             // single transparence
1494             const basegfx::BColor aMedium(basegfx::average(aStart, aEnd));
1495             fTransparence = aMedium.luminance();
1496 
1497             if(basegfx::fTools::lessOrEqual(fTransparence, 0.0))
1498             {
1499                 // no transparence needed, all done
1500             }
1501             else if(basegfx::fTools::moreOrEqual(fTransparence, 1.0))
1502             {
1503                 // all transparent, no object
1504                 bCreateObject = false;
1505             }
1506             else
1507             {
1508                 // 0.0 < transparence < 1.0, apply fixed transparence
1509                 bFixedTransparence = true;
1510             }
1511         }
1512         else
1513         {
1514             // gradient transparence
1515             VirtualDevice aVDev;
1516 
1517             aVDev.SetOutputSizePixel(aBitmapEx.GetBitmap().GetSizePixel());
1518             aVDev.DrawGradient(Rectangle(Point(0, 0), aVDev.GetOutputSizePixel()), rGradient);
1519 
1520             aNewMask = AlphaMask(aVDev.GetBitmap(Point(0, 0), aVDev.GetOutputSizePixel()));
1521             bHasNewMask = true;
1522         }
1523 
1524         if(bCreateObject)
1525         {
1526             if(bHasNewMask || bFixedTransparence)
1527             {
1528                 if(!aBitmapEx.IsAlpha() && !aBitmapEx.IsTransparent())
1529                 {
1530                     // no transparence yet, apply new one
1531                     if(bFixedTransparence)
1532                     {
1533                         sal_uInt8 aAlpha(basegfx::fround(fTransparence * 255.0));
1534 
1535                         aNewMask = AlphaMask(aBitmapEx.GetBitmap().GetSizePixel(), &aAlpha);
1536                     }
1537 
1538                     aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aNewMask);
1539                 }
1540                 else
1541                 {
1542                     // mix existing and new alpha mask
1543                     AlphaMask aOldMask;
1544 
1545                     if(aBitmapEx.IsAlpha())
1546                     {
1547                         aOldMask = aBitmapEx.GetAlpha();
1548                     }
1549                     else if(TRANSPARENT_BITMAP == aBitmapEx.GetTransparentType())
1550                     {
1551                         aOldMask = aBitmapEx.GetMask();
1552                     }
1553                     else if(TRANSPARENT_COLOR == aBitmapEx.GetTransparentType())
1554                     {
1555                         aOldMask = aBitmapEx.GetBitmap().CreateMask(aBitmapEx.GetTransparentColor());
1556                     }
1557 
1558                     BitmapWriteAccess* pOld = aOldMask.AcquireWriteAccess();
1559 
1560                     if(pOld)
1561                     {
1562                         const double fFactor(1.0 / 255.0);
1563 
1564                         if(bFixedTransparence)
1565                         {
1566                             const double fOpNew(1.0 - fTransparence);
1567 
1568                             for(sal_uInt32 y(0); y < static_cast< sal_uInt32 >(pOld->Height()); y++)
1569                             {
1570                                 for(sal_uInt32 x(0); x < static_cast< sal_uInt32 >(pOld->Width()); x++)
1571                                 {
1572                                     const double fOpOld(1.0 - (pOld->GetPixel(y, x).GetIndex() * fFactor));
1573                                     const sal_uInt8 aCol(basegfx::fround((1.0 - (fOpOld * fOpNew)) * 255.0));
1574 
1575                                     pOld->SetPixel(y, x, BitmapColor(aCol));
1576                                 }
1577                             }
1578                         }
1579                         else
1580                         {
1581                             BitmapReadAccess* pNew = aNewMask.AcquireReadAccess();
1582 
1583                             if(pNew)
1584                             {
1585                                 if(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height())
1586                                 {
1587                                     for(sal_uInt32 y(0); y < static_cast< sal_uInt32 >(pOld->Height()); y++)
1588                                     {
1589                                         for(sal_uInt32 x(0); x < static_cast< sal_uInt32 >(pOld->Width()); x++)
1590                                         {
1591                                             const double fOpOld(1.0 - (pOld->GetPixel(y, x).GetIndex() * fFactor));
1592                                             const double fOpNew(1.0 - (pNew->GetPixel(y, x).GetIndex() * fFactor));
1593                                             const sal_uInt8 aCol(basegfx::fround((1.0 - (fOpOld * fOpNew)) * 255.0));
1594 
1595                                             pOld->SetPixel(y, x, BitmapColor(aCol));
1596                                         }
1597                                     }
1598                                 }
1599                                 else
1600                                 {
1601                                     OSL_ENSURE(false, "Alpha masks have different sizes (!)");
1602                                 }
1603 
1604                                 aNewMask.ReleaseAccess(pNew);
1605                             }
1606                             else
1607                             {
1608                                 OSL_ENSURE(false, "Got no access to new alpha mask (!)");
1609                             }
1610                         }
1611 
1612                         aOldMask.ReleaseAccess(pOld);
1613                     }
1614                     else
1615                     {
1616                         OSL_ENSURE(false, "Got no access to old alpha mask (!)");
1617                     }
1618 
1619                     // apply combined bitmap as mask
1620                     aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aOldMask);
1621                 }
1622             }
1623 
1624             // create and add object
1625             SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);
1626 
1627             // for MetaFloatTransparentAction, do not use SetAttributes(...)
1628             // since these metafile content is not used to draw line/fill
1629             // dependent of these setting at the device content
1630             pGraf->SetMergedItem(XLineStyleItem(XLINE_NONE));
1631             pGraf->SetMergedItem(XFillStyleItem(XFILL_NONE));
1632             InsertObj(pGraf);
1633         }
1634     }
1635 }
1636 
1637 ////////////////////////////////////////////////////////////////////////////////////////////////////
1638 // eof
1639