1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdfmtf.cxx,v $
10 * $Revision: 1.20.84.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "svdfmtf.hxx"
35 #include <svx/editdata.hxx>
37 #include <svx/xpoly.hxx>
38 #include <vcl/svapp.hxx>
39 #include <svx/eeitem.hxx>
40 #include <svx/fhgtitem.hxx>
41 #include <svx/wghtitem.hxx>
42 #include <svx/postitem.hxx>
43 #include <svx/udlnitem.hxx>
44 #include <svx/crsditem.hxx>
45 #include <svx/shdditem.hxx>
46 #include <svx/xlnclit.hxx>
47 #include <svx/xlnwtit.hxx>
48 #include <svx/xflclit.hxx>
50 #include <svx/xgrad.hxx>
51 #include <svx/xflgrit.hxx>
52 #include <fontitem.hxx>
53 #include <svx/akrnitem.hxx>
54 #include <svx/wrlmitem.hxx>
55 #include <svx/cntritem.hxx>
56 #include <svx/colritem.hxx>
57 #include <vcl/metric.hxx>
59 #include <svx/charscaleitem.hxx>
61 #include <svx/xflhtit.hxx>
62 #include <svx/svdattr.hxx>
63 #include <svx/svdmodel.hxx>
64 #include <svx/svdpage.hxx>
65 #include <svx/svdobj.hxx>
66 #include "svditext.hxx"
67 #include <svx/svdotext.hxx>
68 #include <svx/svdorect.hxx>
69 #include <svx/svdocirc.hxx>
70 #include <svx/svdograf.hxx>
71 #include <svx/svdopath.hxx>
72 #include <svx/svdetc.hxx>
73 #include <svtools/itemset.hxx>
74 #include <basegfx/polygon/b2dpolygon.hxx>
75 #include <vcl/salbtype.hxx> // FRound
78 #include <basegfx/matrix/b2dhommatrix.hxx>
80 ////////////////////////////////////////////////////////////////////////////////////////////////////
82 ImpSdrGDIMetaFileImport::ImpSdrGDIMetaFileImport(SdrModel
& rModel
):
84 pLineAttr(NULL
),pFillAttr(NULL
),pTextAttr(NULL
),
85 pPage(NULL
),pModel(NULL
),nLayer(0),
88 bLastObjWasPolyWithoutLine(FALSE
),bNoLine(FALSE
),bNoFill(FALSE
),bLastObjWasLine(FALSE
)
90 aVD
.EnableOutput(FALSE
);
91 aOldLineColor
.SetRed( aVD
.GetLineColor().GetRed() + 1 ); // invalidate old line color
92 pLineAttr
=new SfxItemSet(rModel
.GetItemPool(),XATTR_LINE_FIRST
,XATTR_LINE_LAST
);
93 pFillAttr
=new SfxItemSet(rModel
.GetItemPool(),XATTR_FILL_FIRST
,XATTR_FILL_LAST
);
94 pTextAttr
=new SfxItemSet(rModel
.GetItemPool(),EE_ITEMS_START
,EE_ITEMS_END
);
98 ImpSdrGDIMetaFileImport::~ImpSdrGDIMetaFileImport()
105 ULONG
ImpSdrGDIMetaFileImport::DoImport(const GDIMetaFile
& rMtf
,
108 SvdProgressInfo
*pProgrInfo
)
110 pPage
= rOL
.GetPage();
111 GDIMetaFile
* pTmpMtf
=NULL
;
112 GDIMetaFile
* pMtf
= (GDIMetaFile
*) &rMtf
;
113 ULONG nActionAnz
=pMtf
->GetActionCount();
114 sal_Bool bError
= sal_False
;
117 // setup some global scale parameter
118 // fScaleX, fScaleY, aScaleX, aScaleY, bMov, bSize
119 fScaleX
= fScaleY
= 1.0;
120 Size
aMtfSize( pMtf
->GetPrefSize() );
121 if ( aMtfSize
.Width() & aMtfSize
.Height() && ( aScaleRect
.IsEmpty() == sal_False
) )
123 aOfs
= aScaleRect
.TopLeft();
124 if ( aMtfSize
.Width() != ( aScaleRect
.GetWidth() - 1 ) )
125 fScaleX
= (double)( aScaleRect
.GetWidth() - 1 ) / (double)aMtfSize
.Width();
126 if ( aMtfSize
.Height() != ( aScaleRect
.GetHeight() - 1 ) )
127 fScaleY
= (double)( aScaleRect
.GetHeight() - 1 ) / (double)aMtfSize
.Height();
130 bMov
= aOfs
.X()!=0 || aOfs
.Y()!=0;
133 aScaleX
= Fraction( 1, 1 );
134 aScaleY
= Fraction( 1, 1 );
135 if ( aMtfSize
.Width() != ( aScaleRect
.GetWidth() - 1 ) )
137 aScaleX
= Fraction( aScaleRect
.GetWidth() - 1, aMtfSize
.Width() );
140 if ( aMtfSize
.Height() != ( aScaleRect
.GetHeight() - 1 ) )
142 aScaleY
= Fraction( aScaleRect
.GetHeight() - 1, aMtfSize
.Height() );
146 if(65000 < nActionAnz
)
153 pProgrInfo
->SetActionCount(nActionAnz
);
155 ULONG nActionsToReport
= 0;
157 for( MetaAction
* pAct
= pMtf
->FirstAction(); pAct
; pAct
= pMtf
->NextAction() )
159 switch (pAct
->GetType())
161 case META_PIXEL_ACTION
: DoAction((MetaPixelAction
&)*pAct
); break;
162 case META_POINT_ACTION
: DoAction((MetaPointAction
&)*pAct
); break;
163 case META_LINE_ACTION
: DoAction((MetaLineAction
&)*pAct
); break;
164 case META_RECT_ACTION
: DoAction((MetaRectAction
&)*pAct
); break;
165 case META_ROUNDRECT_ACTION
: DoAction((MetaRoundRectAction
&)*pAct
); break;
166 case META_ELLIPSE_ACTION
: DoAction((MetaEllipseAction
&)*pAct
); break;
167 case META_ARC_ACTION
: DoAction((MetaArcAction
&)*pAct
); break;
168 case META_PIE_ACTION
: DoAction((MetaPieAction
&)*pAct
); break;
169 case META_CHORD_ACTION
: DoAction((MetaChordAction
&)*pAct
); break;
170 case META_POLYLINE_ACTION
: DoAction((MetaPolyLineAction
&)*pAct
); break;
171 case META_POLYGON_ACTION
: DoAction((MetaPolygonAction
&)*pAct
); break;
172 case META_POLYPOLYGON_ACTION
: DoAction((MetaPolyPolygonAction
&)*pAct
); break;
173 case META_TEXT_ACTION
: DoAction((MetaTextAction
&)*pAct
); break;
174 case META_TEXTARRAY_ACTION
: DoAction((MetaTextArrayAction
&)*pAct
); break;
175 case META_STRETCHTEXT_ACTION
: DoAction((MetaStretchTextAction
&)*pAct
); break;
176 case META_BMP_ACTION
: DoAction((MetaBmpAction
&)*pAct
); break;
177 case META_BMPSCALE_ACTION
: DoAction((MetaBmpScaleAction
&)*pAct
); break;
178 case META_BMPEX_ACTION
: DoAction((MetaBmpExAction
&)*pAct
); break;
179 case META_BMPEXSCALE_ACTION
: DoAction((MetaBmpExScaleAction
&)*pAct
); break;
180 case META_LINECOLOR_ACTION
: DoAction((MetaLineColorAction
&)*pAct
); break;
181 case META_FILLCOLOR_ACTION
: DoAction((MetaFillColorAction
&)*pAct
); break;
182 case META_TEXTCOLOR_ACTION
: DoAction((MetaTextColorAction
&)*pAct
); break;
183 case META_TEXTFILLCOLOR_ACTION
: DoAction((MetaTextFillColorAction
&)*pAct
); break;
184 case META_FONT_ACTION
: DoAction((MetaFontAction
&)*pAct
); break;
185 case META_TEXTALIGN_ACTION
: DoAction((MetaTextAlignAction
&)*pAct
); break;
186 case META_MAPMODE_ACTION
: DoAction((MetaMapModeAction
&)*pAct
); break;
187 case META_CLIPREGION_ACTION
: DoAction((MetaClipRegionAction
&)*pAct
); break;
188 case META_MOVECLIPREGION_ACTION
: DoAction((MetaMoveClipRegionAction
&)*pAct
); break;
189 case META_ISECTRECTCLIPREGION_ACTION
: DoAction((MetaISectRectClipRegionAction
&)*pAct
); break;
190 case META_ISECTREGIONCLIPREGION_ACTION
: DoAction((MetaISectRegionClipRegionAction
&)*pAct
); break;
191 case META_RASTEROP_ACTION
: DoAction((MetaRasterOpAction
&)*pAct
); break;
192 case META_PUSH_ACTION
: DoAction((MetaPushAction
&)*pAct
); break;
193 case META_POP_ACTION
: DoAction((MetaPopAction
&)*pAct
); break;
194 case META_HATCH_ACTION
: DoAction((MetaHatchAction
&)*pAct
); break;
195 case META_COMMENT_ACTION
: DoAction((MetaCommentAction
&)*pAct
, pMtf
); break;
199 if(pProgrInfo
!= NULL
)
202 if(nActionsToReport
>= 16) // Alle 16 Action updaten
204 if(!pProgrInfo
->ReportActions(nActionsToReport
))
206 nActionsToReport
= 0;
211 if(pProgrInfo
!= NULL
)
213 pProgrInfo
->ReportActions(nActionsToReport
);
214 nActionsToReport
= 0;
217 // MapMode-Scaling vornehmen
219 // Objekte in vorgegebenes Rechteck hineinskalieren
220 ULONG nAnz
=aTmpList
.GetObjCount();
222 // Beim berechnen der Fortschrittsanzeige wird GetActionCount()*3 benutzt.
223 // Da in aTmpList allerdings weniger eintraege als GetActionCount()
224 // existieren koennen, muessen hier die zuviel vermuteten Actionen wieder
225 // hinzugefuegt werden.
226 nActionsToReport
= (pMtf
->GetActionCount() - nAnz
)*2;
229 // Alle noch nicht gemeldeten Rescales melden
232 pProgrInfo
->ReportRescales(nActionsToReport
);
233 pProgrInfo
->SetInsertCount(nAnz
);
235 nActionsToReport
= 0;
237 // alle in aTmpList zwischengespeicherten Objekte nun in rOL ab der Position nInsPos einfuegen
238 if (nInsPos
>rOL
.GetObjCount()) nInsPos
=rOL
.GetObjCount();
239 SdrInsertReason
aReason(SDRREASON_VIEWCALL
);
240 for (ULONG i
=0; i
<nAnz
; i
++)
242 SdrObject
* pObj
=aTmpList
.GetObj(i
);
243 rOL
.NbcInsertObject(pObj
,nInsPos
,&aReason
);
246 if(pProgrInfo
!= NULL
)
249 if(nActionsToReport
>= 32) // Alle 32 Action updaten
251 pProgrInfo
->ReportInserts(nActionsToReport
);
252 nActionsToReport
= 0;
256 if (pTmpMtf
!=NULL
) delete pTmpMtf
;
258 // ein letztesmal alle verbliebennen Inserts reporten
259 if(pProgrInfo
!= NULL
)
261 pProgrInfo
->ReportInserts(nActionsToReport
);
263 pProgrInfo
->ReportError();
266 return aTmpList
.GetObjCount();
269 void ImpSdrGDIMetaFileImport::SetAttributes(SdrObject
* pObj
, FASTBOOL bForceTextAttr
)
271 bNoLine
= FALSE
; bNoFill
= FALSE
;
272 FASTBOOL bLine
=TRUE
&& !bForceTextAttr
;
273 FASTBOOL bFill
=pObj
==NULL
|| pObj
->IsClosedObj() && !bForceTextAttr
;
274 FASTBOOL bText
=bForceTextAttr
|| (pObj
!=NULL
&& pObj
->GetOutlinerParaObject()!=NULL
);
279 pLineAttr
->Put( XLineWidthItem( nLineWidth
) );
280 aOldLineColor
= aVD
.GetLineColor();
281 if( aVD
.IsLineColor() )
283 pLineAttr
->Put(XLineStyleItem(XLINE_SOLID
));
284 pLineAttr
->Put(XLineColorItem(String(), aVD
.GetLineColor()));
287 pLineAttr
->Put(XLineStyleItem(XLINE_NONE
));
294 if( aVD
.IsFillColor() )
296 pFillAttr
->Put(XFillStyleItem(XFILL_SOLID
));
297 pFillAttr
->Put(XFillColorItem(String(), aVD
.GetFillColor()));
300 pFillAttr
->Put(XFillStyleItem(XFILL_NONE
));
305 if ( bText
&& bFntDirty
)
307 Font
aFnt(aVD
.GetFont());
308 pTextAttr
->Put( SvxFontItem( aFnt
.GetFamily(), aFnt
.GetName(), aFnt
.GetStyleName(),
309 aFnt
.GetPitch(), aFnt
.GetCharSet(), EE_CHAR_FONTINFO
) );
310 pTextAttr
->Put( SvxFontItem( aFnt
.GetFamily(), aFnt
.GetName(), aFnt
.GetStyleName(),
311 aFnt
.GetPitch(), aFnt
.GetCharSet(), EE_CHAR_FONTINFO_CJK
) );
312 pTextAttr
->Put( SvxFontItem( aFnt
.GetFamily(), aFnt
.GetName(), aFnt
.GetStyleName(),
313 aFnt
.GetPitch(), aFnt
.GetCharSet(), EE_CHAR_FONTINFO_CTL
) );
314 pTextAttr
->Put(SvxPostureItem(aFnt
.GetItalic(), EE_CHAR_ITALIC
));
315 pTextAttr
->Put(SvxWeightItem(aFnt
.GetWeight(), EE_CHAR_WEIGHT
));
316 sal_uInt32 nHeight
= FRound(aFnt
.GetSize().Height() * fScaleY
);
317 pTextAttr
->Put( SvxFontHeightItem( nHeight
, 100, EE_CHAR_FONTHEIGHT
) );
318 pTextAttr
->Put( SvxFontHeightItem( nHeight
, 100, EE_CHAR_FONTHEIGHT_CJK
) );
319 pTextAttr
->Put( SvxFontHeightItem( nHeight
, 100, EE_CHAR_FONTHEIGHT_CTL
) );
320 pTextAttr
->Put(SvxCharScaleWidthItem(100, EE_CHAR_FONTWIDTH
));
321 pTextAttr
->Put(SvxUnderlineItem(aFnt
.GetUnderline(), EE_CHAR_UNDERLINE
));
322 pTextAttr
->Put(SvxOverlineItem(aFnt
.GetOverline(), EE_CHAR_OVERLINE
));
323 pTextAttr
->Put(SvxCrossedOutItem(aFnt
.GetStrikeout(), EE_CHAR_STRIKEOUT
));
324 pTextAttr
->Put(SvxShadowedItem(aFnt
.IsShadow(), EE_CHAR_SHADOW
));
325 pTextAttr
->Put(SvxAutoKernItem(aFnt
.IsKerning(), EE_CHAR_KERNING
));
326 pTextAttr
->Put(SvxWordLineModeItem(aFnt
.IsWordLineMode(), EE_CHAR_WLM
));
327 pTextAttr
->Put(SvxContourItem(aFnt
.IsOutline(), EE_CHAR_OUTLINE
));
328 pTextAttr
->Put(SvxColorItem(aFnt
.GetColor(), EE_CHAR_COLOR
));
329 //... svxfont textitem svditext
334 pObj
->SetLayer(nLayer
);
335 if (bLine
) pObj
->SetMergedItemSet(*pLineAttr
);
336 if (bFill
) pObj
->SetMergedItemSet(*pFillAttr
);
339 pObj
->SetMergedItemSet(*pTextAttr
);
340 pObj
->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_LEFT
) );
345 void ImpSdrGDIMetaFileImport::InsertObj( SdrObject
* pObj
, sal_Bool bScale
)
347 if ( bScale
&& !aScaleRect
.IsEmpty() )
350 pObj
->NbcResize( Point(), aScaleX
, aScaleY
);
352 pObj
->NbcMove( Size( aOfs
.X(), aOfs
.Y() ) );
355 aTmpList
.InsertObject( pObj
);
356 if ( HAS_BASE( SdrPathObj
, pObj
) )
358 FASTBOOL bClosed
=pObj
->IsClosedObj();
359 bLastObjWasPolyWithoutLine
=bNoLine
&& bClosed
;
360 bLastObjWasLine
=!bClosed
;
364 bLastObjWasPolyWithoutLine
= FALSE
;
365 bLastObjWasLine
= FALSE
;
369 /**************************************************************************************************/
371 void ImpSdrGDIMetaFileImport::DoAction(MetaPixelAction
& /*rAct*/)
375 void ImpSdrGDIMetaFileImport::DoAction(MetaPointAction
& /*rAct*/)
379 void ImpSdrGDIMetaFileImport::DoAction(MetaLineAction
& rAct
)
381 // #i73407# reformulation to use new B2DPolygon classes
382 const basegfx::B2DPoint
aStart(rAct
.GetStartPoint().X(), rAct
.GetStartPoint().Y());
383 const basegfx::B2DPoint
aEnd(rAct
.GetEndPoint().X(), rAct
.GetEndPoint().Y());
385 if(!aStart
.equal(aEnd
))
387 basegfx::B2DPolygon aLine
;
388 basegfx::B2DHomMatrix aTransform
;
390 aLine
.append(aStart
);
392 aTransform
.scale(fScaleX
, fScaleY
);
393 aTransform
.translate(aOfs
.X(), aOfs
.Y());
394 aLine
.transform(aTransform
);
396 const LineInfo
& rLineInfo
= rAct
.GetLineInfo();
397 const sal_Int32
nNewLineWidth(rLineInfo
.GetWidth());
398 bool bCreateLineObject(true);
400 if(bLastObjWasLine
&& (nNewLineWidth
== nLineWidth
) && CheckLastLineMerge(aLine
))
402 bCreateLineObject
= false;
405 nLineWidth
= nNewLineWidth
;
407 if(bCreateLineObject
)
409 SdrPathObj
* pPath
= new SdrPathObj(OBJ_LINE
, basegfx::B2DPolyPolygon(aLine
));
410 SetAttributes(pPath
);
411 InsertObj(pPath
, false);
416 void ImpSdrGDIMetaFileImport::DoAction(MetaRectAction
& rAct
)
418 SdrRectObj
* pRect
=new SdrRectObj(rAct
.GetRect());
419 SetAttributes(pRect
);
423 void ImpSdrGDIMetaFileImport::DoAction(MetaRoundRectAction
& rAct
)
425 SdrRectObj
* pRect
=new SdrRectObj(rAct
.GetRect());
426 SetAttributes(pRect
);
427 long nRad
=(rAct
.GetHorzRound()+rAct
.GetVertRound())/2;
429 SfxItemSet
aSet(*pLineAttr
->GetPool(),SDRATTR_ECKENRADIUS
,SDRATTR_ECKENRADIUS
);
430 aSet
.Put(SdrEckenradiusItem(nRad
));
431 pRect
->SetMergedItemSet(aSet
);
436 /**************************************************************************************************/
438 void ImpSdrGDIMetaFileImport::DoAction(MetaEllipseAction
& rAct
)
440 SdrCircObj
* pCirc
=new SdrCircObj(OBJ_CIRC
,rAct
.GetRect());
441 SetAttributes(pCirc
);
445 void ImpSdrGDIMetaFileImport::DoAction(MetaArcAction
& rAct
)
447 Point
aCenter(rAct
.GetRect().Center());
448 long nStart
=GetAngle(rAct
.GetStartPoint()-aCenter
);
449 long nEnd
=GetAngle(rAct
.GetEndPoint()-aCenter
);
450 SdrCircObj
* pCirc
=new SdrCircObj(OBJ_CARC
,rAct
.GetRect(),nStart
,nEnd
);
451 SetAttributes(pCirc
);
455 void ImpSdrGDIMetaFileImport::DoAction(MetaPieAction
& rAct
)
457 Point
aCenter(rAct
.GetRect().Center());
458 long nStart
=GetAngle(rAct
.GetStartPoint()-aCenter
);
459 long nEnd
=GetAngle(rAct
.GetEndPoint()-aCenter
);
460 SdrCircObj
* pCirc
=new SdrCircObj(OBJ_SECT
,rAct
.GetRect(),nStart
,nEnd
);
461 SetAttributes(pCirc
);
465 void ImpSdrGDIMetaFileImport::DoAction(MetaChordAction
& rAct
)
467 Point
aCenter(rAct
.GetRect().Center());
468 long nStart
=GetAngle(rAct
.GetStartPoint()-aCenter
);
469 long nEnd
=GetAngle(rAct
.GetEndPoint()-aCenter
);
470 SdrCircObj
* pCirc
=new SdrCircObj(OBJ_CCUT
,rAct
.GetRect(),nStart
,nEnd
);
471 SetAttributes(pCirc
);
475 /**************************************************************************************************/
477 bool ImpSdrGDIMetaFileImport::CheckLastLineMerge(const basegfx::B2DPolygon
& rSrcPoly
)
479 // #i102706# Do not merge closed polygons
480 if(rSrcPoly
.isClosed())
485 // #i73407# reformulation to use new B2DPolygon classes
486 if(bLastObjWasLine
&& (aOldLineColor
== aVD
.GetLineColor()) && rSrcPoly
.count())
488 SdrObject
* pTmpObj
= aTmpList
.GetObj(aTmpList
.GetObjCount() - 1);
489 SdrPathObj
* pLastPoly
= PTR_CAST(SdrPathObj
, pTmpObj
);
493 if(1L == pLastPoly
->GetPathPoly().count())
496 basegfx::B2DPolygon
aDstPoly(pLastPoly
->GetPathPoly().getB2DPolygon(0L));
498 // #i102706# Do not merge closed polygons
499 if(aDstPoly
.isClosed())
506 const sal_uInt32
nMaxDstPnt(aDstPoly
.count() - 1L);
507 const sal_uInt32
nMaxSrcPnt(rSrcPoly
.count() - 1L);
509 if(aDstPoly
.getB2DPoint(nMaxDstPnt
) == rSrcPoly
.getB2DPoint(0L))
511 aDstPoly
.append(rSrcPoly
, 1L, rSrcPoly
.count() - 1L);
514 else if(aDstPoly
.getB2DPoint(0L) == rSrcPoly
.getB2DPoint(nMaxSrcPnt
))
516 basegfx::B2DPolygon
aNew(rSrcPoly
);
517 aNew
.append(aDstPoly
, 1L, aDstPoly
.count() - 1L);
521 else if(aDstPoly
.getB2DPoint(0L) == rSrcPoly
.getB2DPoint(0L))
524 aDstPoly
.append(rSrcPoly
, 1L, rSrcPoly
.count() - 1L);
527 else if(aDstPoly
.getB2DPoint(nMaxDstPnt
) == rSrcPoly
.getB2DPoint(nMaxSrcPnt
))
529 basegfx::B2DPolygon
aNew(rSrcPoly
);
531 aDstPoly
.append(aNew
, 1L, aNew
.count() - 1L);
538 pLastPoly
->NbcSetPathPoly(basegfx::B2DPolyPolygon(aDstPoly
));
549 bool ImpSdrGDIMetaFileImport::CheckLastPolyLineAndFillMerge(const basegfx::B2DPolyPolygon
& rPolyPolygon
)
551 // #i73407# reformulation to use new B2DPolygon classes
552 if(bLastObjWasPolyWithoutLine
)
554 SdrObject
* pTmpObj
= aTmpList
.GetObj(aTmpList
.GetObjCount() - 1);
555 SdrPathObj
* pLastPoly
= PTR_CAST(SdrPathObj
, pTmpObj
);
559 if(pLastPoly
->GetPathPoly() == rPolyPolygon
)
563 if(!bNoLine
&& bNoFill
)
565 pLastPoly
->SetMergedItemSet(*pLineAttr
);
577 void ImpSdrGDIMetaFileImport::DoAction( MetaPolyLineAction
& rAct
)
579 // #i73407# reformulation to use new B2DPolygon classes
580 basegfx::B2DPolygon
aSource(rAct
.GetPolygon().getB2DPolygon());
584 basegfx::B2DHomMatrix aTransform
;
586 aTransform
.scale(fScaleX
, fScaleY
);
587 aTransform
.translate(aOfs
.X(), aOfs
.Y());
588 aSource
.transform(aTransform
);
591 const LineInfo
& rLineInfo
= rAct
.GetLineInfo();
592 const sal_Int32
nNewLineWidth(rLineInfo
.GetWidth());
593 bool bCreateLineObject(true);
595 if(bLastObjWasLine
&& (nNewLineWidth
== nLineWidth
) && CheckLastLineMerge(aSource
))
597 bCreateLineObject
= false;
599 else if(bLastObjWasPolyWithoutLine
&& CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource
)))
601 bCreateLineObject
= false;
604 nLineWidth
= nNewLineWidth
;
606 if(bCreateLineObject
)
608 SdrPathObj
* pPath
= new SdrPathObj(OBJ_PLIN
, basegfx::B2DPolyPolygon(aSource
));
609 SetAttributes(pPath
);
610 InsertObj(pPath
, false);
614 void ImpSdrGDIMetaFileImport::DoAction( MetaPolygonAction
& rAct
)
616 // #i73407# reformulation to use new B2DPolygon classes
617 basegfx::B2DPolygon
aSource(rAct
.GetPolygon().getB2DPolygon());
621 basegfx::B2DHomMatrix aTransform
;
623 aTransform
.scale(fScaleX
, fScaleY
);
624 aTransform
.translate(aOfs
.X(), aOfs
.Y());
625 aSource
.transform(aTransform
);
627 if(!bLastObjWasPolyWithoutLine
|| !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource
)))
629 // #i73407# make sure polygon is closed, it's a filled primitive
630 aSource
.setClosed(true);
632 SdrPathObj
* pPath
= new SdrPathObj(OBJ_POLY
, basegfx::B2DPolyPolygon(aSource
));
633 SetAttributes(pPath
);
634 InsertObj(pPath
, false);
639 void ImpSdrGDIMetaFileImport::DoAction(MetaPolyPolygonAction
& rAct
)
641 // #i73407# reformulation to use new B2DPolygon classes
642 basegfx::B2DPolyPolygon
aSource(rAct
.GetPolyPolygon().getB2DPolyPolygon());
646 basegfx::B2DHomMatrix aTransform
;
648 aTransform
.scale(fScaleX
, fScaleY
);
649 aTransform
.translate(aOfs
.X(), aOfs
.Y());
650 aSource
.transform(aTransform
);
652 if(!bLastObjWasPolyWithoutLine
|| !CheckLastPolyLineAndFillMerge(aSource
))
654 // #i73407# make sure polygon is closed, it's a filled primitive
655 aSource
.setClosed(true);
657 SdrPathObj
* pPath
= new SdrPathObj(OBJ_POLY
, aSource
);
658 SetAttributes(pPath
);
659 InsertObj(pPath
, false);
664 /**************************************************************************************************/
666 void ImpSdrGDIMetaFileImport::ImportText( const Point
& rPos
, const XubString
& rStr
, const MetaAction
& rAct
)
668 // calc text box size, add 5% to make it fit safely
670 FontMetric
aFontMetric( aVD
.GetFontMetric() );
671 Font
aFnt( aVD
.GetFont() );
672 FontAlign
eAlg( aFnt
.GetAlign() );
674 sal_Int32 nTextWidth
= (sal_Int32
)( aVD
.GetTextWidth( rStr
) * fScaleX
);
675 sal_Int32 nTextHeight
= (sal_Int32
)( aVD
.GetTextHeight() * fScaleY
);
676 //sal_Int32 nDxWidth = 0;
677 //sal_Int32 nLen = rStr.Len();
679 Point
aPos( FRound(rPos
.X() * fScaleX
+ aOfs
.X()), FRound(rPos
.Y() * fScaleY
+ aOfs
.Y()) );
680 Size
aSize( nTextWidth
, nTextHeight
);
682 if ( eAlg
== ALIGN_BASELINE
)
683 aPos
.Y() -= FRound(aFontMetric
.GetAscent() * fScaleY
);
684 else if ( eAlg
== ALIGN_BOTTOM
)
685 aPos
.Y() -= nTextHeight
;
687 Rectangle
aTextRect( aPos
, aSize
);
688 SdrRectObj
* pText
=new SdrRectObj( OBJ_TEXT
, aTextRect
);
690 if ( aFnt
.GetWidth() || ( rAct
.GetType() == META_STRETCHTEXT_ACTION
) )
692 pText
->ClearMergedItem( SDRATTR_TEXT_AUTOGROWWIDTH
);
693 pText
->SetMergedItem( SdrTextAutoGrowHeightItem( FALSE
) );
694 // don't let the margins eat the space needed for the text
695 pText
->SetMergedItem ( SdrTextUpperDistItem (0));
696 pText
->SetMergedItem ( SdrTextLowerDistItem (0));
697 pText
->SetMergedItem ( SdrTextRightDistItem (0));
698 pText
->SetMergedItem ( SdrTextLeftDistItem (0));
699 pText
->SetMergedItem( SdrTextFitToSizeTypeItem( SDRTEXTFIT_ALLLINES
) );
702 pText
->SetMergedItem( SdrTextAutoGrowWidthItem( sal_True
) );
704 pText
->SetModel( pModel
);
705 pText
->SetLayer( nLayer
);
706 pText
->NbcSetText( rStr
);
707 SetAttributes( pText
, TRUE
);
708 pText
->SetSnapRect( aTextRect
);
710 if (!aFnt
.IsTransparent())
712 SfxItemSet
aAttr(*pFillAttr
->GetPool(),XATTR_FILL_FIRST
,XATTR_FILL_LAST
);
713 pFillAttr
->Put(XFillStyleItem(XFILL_SOLID
));
714 pFillAttr
->Put(XFillColorItem(String(), aFnt
.GetFillColor()));
715 pText
->SetMergedItemSet(aAttr
);
717 sal_uInt32 nWink
= aFnt
.GetOrientation();
721 double a
=nWink
*nPi180
;
724 pText
->NbcRotate(aPos
,nWink
,nSin
,nCos
);
726 InsertObj( pText
, sal_False
);
729 void ImpSdrGDIMetaFileImport::DoAction(MetaTextAction
& rAct
)
731 XubString
aStr(rAct
.GetText());
732 aStr
.Erase(0,rAct
.GetIndex());
733 aStr
.Erase(rAct
.GetLen());
734 ImportText( rAct
.GetPoint(), aStr
, rAct
);
737 void ImpSdrGDIMetaFileImport::DoAction(MetaTextArrayAction
& rAct
)
739 XubString
aStr(rAct
.GetText());
740 aStr
.Erase(0,rAct
.GetIndex());
741 aStr
.Erase(rAct
.GetLen());
742 ImportText( rAct
.GetPoint(), aStr
, rAct
);
745 void ImpSdrGDIMetaFileImport::DoAction(MetaStretchTextAction
& rAct
)
747 XubString
aStr(rAct
.GetText());
748 aStr
.Erase(0,rAct
.GetIndex());
749 aStr
.Erase(rAct
.GetLen());
750 ImportText( rAct
.GetPoint(), aStr
, rAct
);
753 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpAction
& rAct
)
755 Rectangle
aRect(rAct
.GetPoint(),rAct
.GetBitmap().GetSizePixel());
756 aRect
.Right()++; aRect
.Bottom()++;
757 SdrGrafObj
* pGraf
=new SdrGrafObj(Graphic(rAct
.GetBitmap()),aRect
);
761 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpScaleAction
& rAct
)
763 Rectangle
aRect(rAct
.GetPoint(),rAct
.GetSize());
764 aRect
.Right()++; aRect
.Bottom()++;
765 SdrGrafObj
* pGraf
=new SdrGrafObj(Graphic(rAct
.GetBitmap()),aRect
);
769 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExAction
& rAct
)
771 Rectangle
aRect(rAct
.GetPoint(),rAct
.GetBitmapEx().GetSizePixel());
772 aRect
.Right()++; aRect
.Bottom()++;
773 SdrGrafObj
* pGraf
=new SdrGrafObj( rAct
.GetBitmapEx(), aRect
);
777 void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExScaleAction
& rAct
)
779 Rectangle
aRect(rAct
.GetPoint(),rAct
.GetSize());
780 aRect
.Right()++; aRect
.Bottom()++;
781 SdrGrafObj
* pGraf
=new SdrGrafObj( rAct
.GetBitmapEx(), aRect
);
785 ////////////////////////////////////////////////////////////////////////////////////////////////////
787 void ImpSdrGDIMetaFileImport::DoAction( MetaHatchAction
& rAct
)
789 // #i73407# reformulation to use new B2DPolygon classes
790 basegfx::B2DPolyPolygon
aSource(rAct
.GetPolyPolygon().getB2DPolyPolygon());
794 basegfx::B2DHomMatrix aTransform
;
795 aTransform
.scale(fScaleX
, fScaleY
);
796 aTransform
.translate(aOfs
.X(), aOfs
.Y());
797 aSource
.transform(aTransform
);
799 if(!bLastObjWasPolyWithoutLine
|| !CheckLastPolyLineAndFillMerge(aSource
))
801 const Hatch
& rHatch
= rAct
.GetHatch();
802 SdrPathObj
* pPath
= new SdrPathObj(OBJ_POLY
, aSource
);
803 SfxItemSet
aHatchAttr(pModel
->GetItemPool(),
804 XATTR_FILLSTYLE
, XATTR_FILLSTYLE
,
805 XATTR_FILLHATCH
, XATTR_FILLHATCH
, 0, 0 );
808 switch(rHatch
.GetStyle())
812 eStyle
= XHATCH_TRIPLE
;
818 eStyle
= XHATCH_DOUBLE
;
824 eStyle
= XHATCH_SINGLE
;
829 SetAttributes(pPath
);
830 aHatchAttr
.Put(XFillStyleItem(XFILL_HATCH
));
831 aHatchAttr
.Put(XFillHatchItem(&pModel
->GetItemPool(), XHatch(rHatch
.GetColor(), eStyle
, rHatch
.GetDistance(), rHatch
.GetAngle())));
832 pPath
->SetMergedItemSet(aHatchAttr
);
834 InsertObj(pPath
, false);
839 ////////////////////////////////////////////////////////////////////////////////////////////////////
841 void ImpSdrGDIMetaFileImport::DoAction(MetaLineColorAction
& rAct
)
846 void ImpSdrGDIMetaFileImport::DoAction(MetaMapModeAction
& rAct
)
850 bLastObjWasPolyWithoutLine
=FALSE
;
851 bLastObjWasLine
=FALSE
;
854 void ImpSdrGDIMetaFileImport::MapScaling()
856 sal_uInt32 i
, nAnz
= aTmpList
.GetObjCount();
857 const MapMode
& rMap
= aVD
.GetMapMode();
858 Point
aMapOrg( rMap
.GetOrigin() );
859 sal_Bool bMov2
= aMapOrg
.X() != 0 || aMapOrg
.Y() != 0;
862 for ( i
= nMapScalingOfs
; i
< nAnz
; i
++ )
864 SdrObject
* pObj
= aTmpList
.GetObj(i
);
866 pObj
->NbcMove( Size( aMapOrg
.X(), aMapOrg
.Y() ) );
869 nMapScalingOfs
= nAnz
;
872 ////////////////////////////////////////////////////////////////////////////////////////////////////
874 void ImpSdrGDIMetaFileImport::DoAction( MetaCommentAction
& rAct
, GDIMetaFile
* pMtf
)
876 ByteString aSkipComment
;
878 if( rAct
.GetComment().CompareIgnoreCaseToAscii( "XGRAD_SEQ_BEGIN" ) == COMPARE_EQUAL
)
880 MetaGradientExAction
* pAct
= (MetaGradientExAction
*) pMtf
->NextAction();
882 if( pAct
&& pAct
->GetType() == META_GRADIENTEX_ACTION
)
884 // #i73407# reformulation to use new B2DPolygon classes
885 basegfx::B2DPolyPolygon
aSource(pAct
->GetPolyPolygon().getB2DPolyPolygon());
889 basegfx::B2DHomMatrix aTransform
;
891 aTransform
.scale(fScaleX
, fScaleY
);
892 aTransform
.translate(aOfs
.X(), aOfs
.Y());
893 aSource
.transform(aTransform
);
895 if(!bLastObjWasPolyWithoutLine
|| !CheckLastPolyLineAndFillMerge(aSource
))
897 const Gradient
& rGrad
= pAct
->GetGradient();
898 SdrPathObj
* pPath
= new SdrPathObj(OBJ_POLY
, aSource
);
899 SfxItemSet
aGradAttr(pModel
->GetItemPool(),
900 XATTR_FILLSTYLE
, XATTR_FILLSTYLE
,
901 XATTR_FILLGRADIENT
, XATTR_FILLGRADIENT
, 0, 0 );
902 XGradient aXGradient
;
904 aXGradient
.SetGradientStyle((XGradientStyle
)rGrad
.GetStyle());
905 aXGradient
.SetStartColor(rGrad
.GetStartColor());
906 aXGradient
.SetEndColor(rGrad
.GetEndColor());
907 aXGradient
.SetAngle((USHORT
)rGrad
.GetAngle());
908 aXGradient
.SetBorder(rGrad
.GetBorder());
909 aXGradient
.SetXOffset(rGrad
.GetOfsX());
910 aXGradient
.SetYOffset(rGrad
.GetOfsY());
911 aXGradient
.SetStartIntens(rGrad
.GetStartIntensity());
912 aXGradient
.SetEndIntens(rGrad
.GetEndIntensity());
913 aXGradient
.SetSteps(rGrad
.GetSteps());
915 SetAttributes(pPath
);
916 aGradAttr
.Put(XFillStyleItem(XFILL_GRADIENT
));
917 aGradAttr
.Put(XFillGradientItem(&pModel
->GetItemPool(), aXGradient
));
918 pPath
->SetMergedItemSet(aGradAttr
);
924 aSkipComment
= "XGRAD_SEQ_END";
928 if(aSkipComment
.Len())
930 MetaAction
* pSkipAct
= pMtf
->NextAction();
933 && ((pSkipAct
->GetType() != META_COMMENT_ACTION
)
934 || (((MetaCommentAction
*)pSkipAct
)->GetComment().CompareIgnoreCaseToAscii(aSkipComment
.GetBuffer()) != COMPARE_EQUAL
)))
936 pSkipAct
= pMtf
->NextAction();