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 #ifndef _MSDFFIMP_HXX
25 #define _MSDFFIMP_HXX
26 
27 #include <com/sun/star/uno/Reference.h>
28 #include <com/sun/star/embed/XEmbeddedObject.hpp>
29 #include <tools/solar.h>		// UINTXX
30 #include <svl/svarray.hxx>
31 #include <tools/color.hxx>
32 #include <tools/gen.hxx>
33 #include <tools/table.hxx>
34 #include <svx/msdffdef.hxx>
35 #include <filter/msfilter/dffpropset.hxx>
36 #include <filter/msfilter/dffrecordheader.hxx>
37 #include <filter/msfilter/msfiltertracer.hxx>
38 #include <vcl/graph.hxx>
39 #include <string.h>
40 #include <map>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <filter/msfilter/msfilterdllapi.h>
43 #include <sot/storage.hxx>
44 
45 class Graphic;
46 class SvStream;
47 class SdrObject;
48 class SdrOle2Obj;
49 class SotStorageRef;
50 class Polygon;
51 class PolyPolygon;
52 class FmFormModel;
53 class SdrModel;
54 class DffRecordHeader;
55 
56 class SwFlyFrmFmt;
57 
58 struct SvxMSDffBLIPInfo;
59 struct SvxMSDffShapeInfo;
60 struct SvxMSDffShapeOrder;
61 
62 class SvxMSDffManager;
63 
64 class SfxItemSet;
65 class SdrObject;
66 struct DffObjData;
67 
68 class MSFILTER_DLLPUBLIC DffPropertyReader : public DffPropSet
69 {
70 	const SvxMSDffManager&	rManager;
71 	DffPropSet*				pDefaultPropSet;
72 
73 	void		ApplyCustomShapeTextAttributes( SfxItemSet& rSet ) const;
74 	void		CheckAndCorrectExcelTextRotation( SvStream& rIn, SfxItemSet& rSet, DffObjData& rObjData ) const;
75 	void		ApplyCustomShapeAdjustmentAttributes( SfxItemSet& rSet ) const;
76 	void		ApplyCustomShapeGeometryAttributes( SvStream& rIn, SfxItemSet& rSet, const DffObjData& rObjData ) const;
77 	void		ApplyLineAttributes( SfxItemSet& rSet, const MSO_SPT eShapeType ) const; // #i28269#
78 	void		ApplyFillAttributes( SvStream& rIn, SfxItemSet& rSet, const DffObjData& rObjData ) const;
79 
80 public:
81 
82 	sal_Int32					mnFix16Angle;
83 	sal_Bool					mbRotateGranientFillWithAngle;
84 
85 	DffPropertyReader( const SvxMSDffManager& rManager );
86 	~DffPropertyReader();
87 	sal_Int32		Fix16ToAngle( sal_Int32 nAngle ) const;
88 
89 #ifdef DBG_CUSTOMSHAPE
90 	void		ReadPropSet( SvStream& rIn, void* pClientData, sal_uInt32 nShapeType = 0 ) const;
91 #else
92 	void		ReadPropSet( SvStream& rIn, void* pClientData ) const;
93 #endif
94 
95 	void		SetDefaultPropSet( SvStream& rIn, sal_uInt32 nOffDgg ) const;
96 	void		ApplyAttributes( SvStream& rIn, SfxItemSet& rSet ) const;
97 	void		ApplyAttributes( SvStream& rIn, SfxItemSet& rSet, DffObjData& rObjData ) const;
98 	void		ImportGradientColor( SfxItemSet& aSet, MSO_FillType eMSO_FillType, double dTrans = 1.0 , double dBackTrans = 1.0 ) const;
99 };
100 
101 
102 #define COL_DEFAULT RGB_COLORDATA( 0xFA, 0xFB, 0xFC )
103 
104 typedef SvxMSDffBLIPInfo*  SvxMSDffBLIPInfo_Ptr;
105 
106 typedef SvxMSDffShapeInfo* SvxMSDffShapeInfo_Ptr;
107 
108 typedef SvxMSDffShapeOrder* SvxMSDffShapeOrder_Ptr;
109 
110 typedef ::std::map< sal_Int32, SdrObject* > SvxMSDffShapeIdContainer;
111 
112 #define SVEXT_PERSIST_STREAM "\002OlePres000"
113 
114 // nach der Reihenfolge des Auftretens sortiert werden:
115 //
116 SV_DECL_PTRARR_DEL(SvxMSDffBLIPInfos,	SvxMSDffBLIPInfo_Ptr,	16,16)
117 
118 SV_DECL_PTRARR_DEL(SvxMSDffShapeOrders,	SvxMSDffShapeOrder_Ptr,	16,16)
119 
120 // explizit sortiert werden:
121 //
122 SV_DECL_PTRARR_SORT_DEL_VISIBILITY(SvxMSDffShapeInfos,	SvxMSDffShapeInfo_Ptr,	16,16, MSFILTER_DLLPUBLIC)
123 
124 SV_DECL_PTRARR_SORT_VISIBILITY(SvxMSDffShapeTxBxSort,	SvxMSDffShapeOrder_Ptr,	16,16, MSFILTER_DLLPUBLIC)
125 
126 #define SVXMSDFF_SETTINGS_CROP_BITMAPS		1
127 #define SVXMSDFF_SETTINGS_IMPORT_PPT		2
128 #define SVXMSDFF_SETTINGS_IMPORT_EXCEL		4
129 
130 #define SP_FGROUP		0x001	// This shape is a group shape
131 #define SP_FCHILD		0x002	// Not a top-level shape
132 #define SP_FPATRIARCH	0x004	// This is the topmost group shape.
133 								// Exactly one of these per drawing.
134 #define SP_FDELETED		0x008	// The shape has been deleted
135 #define SP_FOLESHAPE	0x010	// The shape is an OLE object
136 #define SP_FHAVEMASTER	0x020	// Shape has a hspMaster property
137 #define SP_FFLIPH		0x040	// Shape is flipped horizontally
138 #define SP_FFLIPV		0x080	// Shape is flipped vertically
139 #define SP_FCONNECTOR	0x100	// Connector type of shape
140 #define SP_FHAVEANCHOR	0x200	// Shape has an anchor of some kind
141 #define SP_FBACKGROUND	0x400	// Background shape
142 #define SP_FHAVESPT		0x800	// Shape has a shape type property
143 
144 // for the CreateSdrOLEFromStorage we need the information, how we handle
145 // convert able OLE-Objects - this ist stored in
146 #define OLE_MATHTYPE_2_STARMATH				0x0001
147 #define OLE_WINWORD_2_STARWRITER			0x0002
148 #define OLE_EXCEL_2_STARCALC				0x0004
149 #define OLE_POWERPOINT_2_STARIMPRESS		0x0008
150 
151 struct SvxMSDffConnectorRule
152 {
153 	sal_uInt32	nRuleId;
154 	sal_uInt32  nShapeA;		// SPID of shape A
155 
156 	sal_uInt32  nShapeB;		// SPID of shape B
157 	sal_uInt32  nShapeC;		// SPID of connector shape
158 	sal_uInt32  ncptiA;			// Connection site Index of shape A
159 	sal_uInt32  ncptiB;			// Connection site Index of shape B
160     sal_uInt32  nSpFlagsA;      // SpFlags of shape A ( the original mirror flags must be known when solving the Solver Container )
161     sal_uInt32  nSpFlagsB;      // SpFlags of shape A
162 
163 	SdrObject* pAObj;		// pPtr of object ( corresponding to shape A )
164 	SdrObject* pBObj;		//	 "
165 	SdrObject* pCObj;		//	 "  of connector object
166 
SvxMSDffConnectorRuleSvxMSDffConnectorRule167 	SvxMSDffConnectorRule() : nSpFlagsA( 0 ), nSpFlagsB( 0 ), pAObj( NULL ), pBObj( NULL ), pCObj( NULL ) {};
168 
169     friend SvStream& operator>>( SvStream& rIn, SvxMSDffConnectorRule& rAtom );
170 };
171 struct MSFILTER_DLLPUBLIC SvxMSDffSolverContainer
172 {
173 	List	aCList;
174 
175 			SvxMSDffSolverContainer();
176 			~SvxMSDffSolverContainer();
177 
178 	MSFILTER_DLLPUBLIC friend SvStream& operator>>( SvStream& rIn, SvxMSDffSolverContainer& rAtom );
179 };
180 
181 struct FIDCL
182 {
183 	sal_uInt32	dgid;		// DG owning the SPIDs in this cluster
184 	sal_uInt32	cspidCur;	// number of SPIDs used so far
185 };
186 
187 //---------------------------------------------------------------------------
188 //  von SvxMSDffManager fuer jedes in der Gruppe enthaltene Shape geliefert
189 //---------------------------------------------------------------------------
190 struct MSDffTxId
191 {
192 	sal_uInt16 nTxBxS;
193 	sal_uInt16 nSequence;
MSDffTxIdMSDffTxId194 	MSDffTxId(sal_uInt16 nTxBxS_, sal_uInt16 nSequence_ )
195 			: nTxBxS(			  nTxBxS_		),
196 			  nSequence(		  nSequence_	){}
MSDffTxIdMSDffTxId197 	MSDffTxId(const MSDffTxId& rCopy)
198 			: nTxBxS(			  rCopy.nTxBxS    ),
199 			  nSequence(		  rCopy.nSequence ){}
200 };
201 
202 struct MSFILTER_DLLPUBLIC SvxMSDffImportRec
203 {
204 	SdrObject*	pObj;
205 	Polygon*	pWrapPolygon;
206 	char*		pClientAnchorBuffer;
207 	sal_uInt32		nClientAnchorLen;
208 	char*		pClientDataBuffer;
209 	sal_uInt32		nClientDataLen;
210 	sal_uInt32		nXAlign;
211 	sal_uInt32		nXRelTo;
212 	sal_uInt32		nYAlign;
213 	sal_uInt32		nYRelTo;
214 	sal_uInt32		nLayoutInTableCell;
215     sal_uInt32      nFlags;
216 	long		nTextRotationAngle;
217 	long		nDxTextLeft;	// Abstand der Textbox vom umgebenden Shape
218 	long		nDyTextTop;
219 	long		nDxTextRight;
220 	long		nDyTextBottom;
221 	long		nDxWrapDistLeft;
222 	long		nDyWrapDistTop;
223 	long		nDxWrapDistRight;
224 	long		nDyWrapDistBottom;
225 	long		nCropFromTop;
226 	long		nCropFromBottom;
227 	long		nCropFromLeft;
228 	long		nCropFromRight;
229 	MSDffTxId	aTextId;		// Kennungen fuer Textboxen
230 	sal_uLong		nNextShapeId;	// fuer verlinkte Textboxen
231 	sal_uLong		nShapeId;
232 	MSO_SPT		eShapeType;
233 	MSO_LineStyle eLineStyle;	// Umrandungs-Arten
234 	sal_Bool		bDrawHell		:1;
235 	sal_Bool		bHidden			:1;
236 	sal_Bool		bReplaceByFly	:1;
237 	sal_Bool		bLastBoxInChain	:1;
238 	sal_Bool		bHasUDefProp	:1;
239 	sal_Bool 		bVFlip :1;
240 	sal_Bool 		bHFlip :1;
241 	sal_Bool		bAutoWidth      :1;
242 
243 	SvxMSDffImportRec();
244 	SvxMSDffImportRec(const SvxMSDffImportRec& rCopy);
245 	~SvxMSDffImportRec();
operator ==SvxMSDffImportRec246 	sal_Bool operator==( const SvxMSDffImportRec& rEntry ) const
247 	{   return nShapeId == rEntry.nShapeId; }
operator <SvxMSDffImportRec248 	sal_Bool operator<( const SvxMSDffImportRec& rEntry ) const
249 	{   return nShapeId < rEntry.nShapeId;  }
250 };
251 typedef SvxMSDffImportRec* MSDffImportRec_Ptr;
252 
253 // Liste aller SvxMSDffImportRec fuer eine Gruppe
254 SV_DECL_PTRARR_SORT_DEL_VISIBILITY(MSDffImportRecords, MSDffImportRec_Ptr, 16,16, MSFILTER_DLLPUBLIC)
255 
256 //---------------------------------------------------------------------------
257 //   Import-/Export-Parameterblock fuer 1 x ImportObjAtCurrentStreamPos()
258 //---------------------------------------------------------------------------
259 struct SvxMSDffImportData
260 {
261 	MSDffImportRecords	aRecords;	// Shape-Pointer, -Ids und private Daten
262 	Rectangle			aParentRect;// Rectangle der umgebenden Gruppe
263 									// bzw. von aussen reingegebenes Rect
264 	Rectangle 			aNewRect;	// mit diesem Shape definiertes Rectangle
265 
SvxMSDffImportDataSvxMSDffImportData266 	SvxMSDffImportData()
267 		{}
SvxMSDffImportDataSvxMSDffImportData268 	SvxMSDffImportData(const Rectangle& rParentRect)
269 		:aParentRect( rParentRect )
270 		{}
SetNewRectSvxMSDffImportData271 	void SetNewRect(sal_Int32 l, sal_Int32 o,
272 					sal_Int32 r, sal_Int32 u ){	aNewRect = Rectangle(l,o, r,u); }
HasParRectSvxMSDffImportData273 	sal_Bool HasParRect() const { return aParentRect.IsEmpty(); }
HasNewRectSvxMSDffImportData274 	sal_Bool HasNewRect() const { return aNewRect.IsEmpty()   ; }
HasRecordsSvxMSDffImportData275 	sal_Bool HasRecords() const { return 0 != aRecords.Count(); }
GetRecCountSvxMSDffImportData276 	sal_uInt16				GetRecCount() const { return aRecords.Count();	}
GetRecordSvxMSDffImportData277 	SvxMSDffImportRec*	GetRecord(sal_uInt16 iRecord) const
278 							{  return aRecords.GetObject( iRecord ); }
279 };
280 
281 struct DffObjData
282 {
283 	const DffRecordHeader&	rSpHd;
284 
285 	Rectangle	aBoundRect;
286 	Rectangle	aChildAnchor;
287 
288 	sal_uInt32		nShapeId;
289 	sal_uInt32		nSpFlags;
290 	MSO_SPT		eShapeType;
291 
292 	sal_Bool bShapeType				: 1;
293 	sal_Bool bClientAnchor			: 1;
294 	sal_Bool bClientData			: 1;
295 	sal_Bool bChildAnchor			: 1;
296 	sal_Bool bOpt					: 1;
297 	sal_Bool bOpt2					: 1;
298 	sal_Bool bIsAutoText			: 1;
299 	sal_Bool bRotateTextWithShape	: 1;
300 
301 	int nCalledByGroup;
302 
DffObjDataDffObjData303 	DffObjData( const DffRecordHeader& rObjHd,
304 				const Rectangle& rBoundRect,
305 				int 			 nClByGroup ) :
306 		rSpHd( rObjHd ),
307 		aBoundRect(	rBoundRect ),
308 		nShapeId( 0 ),
309 		nSpFlags( 0 ),
310 		eShapeType( mso_sptNil ),
311 		bShapeType( sal_False ),
312 		bClientAnchor( sal_False ),
313 		bClientData( sal_False ),
314 		bChildAnchor( sal_False ),
315 		bOpt( sal_False ),
316 		bOpt2( sal_False ),
317 		bIsAutoText( sal_False ),
318 		bRotateTextWithShape( sal_True ),
319 		nCalledByGroup(	nClByGroup ){}
320 };
321 
322 #define DFF_RECORD_MANAGER_BUF_SIZE			64
323 
324 struct DffRecordList
325 {
326 		sal_uInt32				nCount;
327 		sal_uInt32				nCurrent;
328 		DffRecordList*		pPrev;
329 		DffRecordList*		pNext;
330 
331 		DffRecordHeader		mHd[ DFF_RECORD_MANAGER_BUF_SIZE ];
332 
333 							DffRecordList( DffRecordList* pList );
334 							~DffRecordList();
335 };
336 
337 enum DffSeekToContentMode
338 {
339 	SEEK_FROM_BEGINNING,
340 	SEEK_FROM_CURRENT,
341 	SEEK_FROM_CURRENT_AND_RESTART
342 };
343 
344 class MSFILTER_DLLPUBLIC DffRecordManager : public DffRecordList
345 {
346 	public :
347 
348 		DffRecordList*		pCList;
349 
350 		void				Clear();
351 		void				Consume( SvStream& rIn, sal_Bool bAppend = sal_False, sal_uInt32 nStOfs = 0 );
352 
353 		sal_Bool				SeekToContent( SvStream& rIn, sal_uInt16 nRecType, DffSeekToContentMode eMode = SEEK_FROM_BEGINNING );
354 		DffRecordHeader*	GetRecordHeader( sal_uInt16 nRecType,  DffSeekToContentMode eMode = SEEK_FROM_BEGINNING );
355 
356 							DffRecordManager();
357 							DffRecordManager( SvStream& rIn );
358 							~DffRecordManager();
359 
360 		DffRecordHeader*	Current();
361 		DffRecordHeader*	First();
362 		DffRecordHeader*	Next();
363 		DffRecordHeader*	Prev();
364 		DffRecordHeader*	Last();
365 };
366 
367 /*
368 	SvxMSDffManager - abstrakte Basis-Klasse fuer Escher-Import
369 	===============
370 	Zweck:	Zugriff auf Objekte im Drawing File Format
371 	Stand:	Zugriff nur auf BLIPs (wird spaeter erweitert)
372 
373 	Beachte: in der zwecks PowerPoint-, ODER Word- ODER Excel-Import
374 	======== abgeleiteten Klasse
375 			 MUSS jeweils die Methode ProcessUserDefinedRecord()
376 			 implementiert werden!
377 */
378 class MSFILTER_DLLPUBLIC SvxMSDffManager : public DffPropertyReader
379 {
380 	FmFormModel*			pFormModel;
381 	SvxMSDffBLIPInfos*		pBLIPInfos;
382 	SvxMSDffShapeInfos*		pShapeInfos;
383 	SvxMSDffShapeOrders*	pShapeOrders;
384 	sal_uLong					nDefaultFontHeight;
385 	long					nOffsDgg;
386 	sal_uInt16					nBLIPCount;
387 	sal_uInt16					nShapeCount;
388 	sal_uInt32				nGroupShapeFlags;
389 
390 	void CheckTxBxStoryChain();
391 	void GetFidclData( long nOffsDgg );
392 
393 protected :
394 
395     String                  maBaseURL;
396     sal_uInt32                  mnCurMaxShapeId;    // we need this information to
397 	sal_uInt32					mnDrawingsSaved;	// access the right drawing
398 	sal_uInt32					mnIdClusters;		// while only knowing the shapeid
399 	FIDCL*					mpFidcls;
400 	Table					maDgOffsetTable;	// array of fileoffsets
401 
402 	friend class DffPropertyReader;
403 
404 	SvStream&		rStCtrl;
405 	SvStream*		pStData;
406 	SvStream*		pStData2;
407 	SdrModel*		pSdrModel;
408 
409 	long			nMapMul;
410 	long			nMapDiv;
411 	long			nMapXOfs;
412 	long			nMapYOfs;
413 	long			nEmuMul;
414 	long			nEmuDiv;
415 	long			nPntMul;
416 	long			nPntDiv;
417 	FASTBOOL		bNeedMap;
418 	sal_uInt32			nSvxMSDffSettings;
419 	sal_uInt32			nSvxMSDffOLEConvFlags;
420 
421 	/** stores a reference to an imported SdrObject with its shape id if
422 		it has one
423 	*/
424 	SvxMSDffShapeIdContainer	maShapeIdContainer;
425 
426 	void GetCtrlData( long nOffsDgg );
427     void GetDrawingGroupContainerData( SvStream& rSt,
428                                        sal_uLong nLenDgg );
429     // --> OD 2008-08-01 #156763#
430     // Add internal drawing container id as parameter to the sub methods of
431     // reading the control information about the drawing objects.
432     // The drawing container id is used to distinguish the text ids of drawing
433     // objects in different drawing containers.
434     void GetDrawingContainerData( SvStream& rSt,
435                                   sal_uLong nLenDg,
436                                   const unsigned long nDrawingContainerId );
437     sal_Bool GetShapeGroupContainerData( SvStream& rSt,
438                                      sal_uLong nLenShapeGroupCont,
439                                      sal_Bool bPatriarch,
440                                      const unsigned long nDrawingContainerId );
441     sal_Bool GetShapeContainerData( SvStream& rSt,
442                                 sal_uLong nLenShapeCont,
443                                 sal_uLong nPosGroup,
444                                 const unsigned long nDrawingContainerId );
445     // <--
446 
447 	FASTBOOL ReadGraphic( SvStream& rSt, sal_uLong nIndex, Graphic& rGraphic ) const;
448 	SdrObject* ImportFontWork( SvStream&, SfxItemSet&, Rectangle& rBoundRect ) const;
449 	SdrObject* ImportGraphic( SvStream&, SfxItemSet&, const DffObjData& ) const;
450     // --> OD 2004-12-14 #i32596# - pass <nCalledByGroup> to method
451     // Needed in the Writer Microsoft Word import to avoid import of OLE objects
452     // inside groups. Instead a graphic object is created.
453     virtual SdrObject* ImportOLE( long nOLEId,
454                                   const Graphic& rGraf,
455                                   const Rectangle& rBoundRect,
456 								  const Rectangle& rVisArea,
457 								  const int _nCalledByGroup,
458 								  sal_Int64 nAspect ) const;
459     // <--
460 	SdrObject* GetAutoForm( MSO_SPT eTyp ) const;
461 #ifndef SVX_LIGHT
462     static com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject > CheckForConvertToSOObj(
463                 sal_uInt32 nConvertFlags, SotStorage& rSrcStg,
464                 const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xDestStg,
465                 const Graphic& rGrf,
466 				const Rectangle& rVisArea );
467 #endif
468 
469 /*
470 		folgende Methoden sind zum Excel-Import zu ueberschreiben:
471 */
472 	virtual sal_Bool ProcessClientAnchor(SvStream& rStData, sal_uLong nDatLen, char*& rpBuff, sal_uInt32& rBuffLen ) const;
473 	virtual void ProcessClientAnchor2( SvStream& rStData, DffRecordHeader& rHd, void* pData, DffObjData& );
474 	virtual sal_Bool ProcessClientData(  SvStream& rStData, sal_uLong nDatLen, char*& rpBuff, sal_uInt32& rBuffLen ) const;
475 	virtual SdrObject* ProcessObj( SvStream& rSt, DffObjData& rData, void* pData, Rectangle& rTextRect, SdrObject* pObj = NULL);
476 	virtual sal_uLong Calc_nBLIPPos( sal_uLong nOrgVal, sal_uLong nStreamPos ) const;
477 	virtual FASTBOOL GetColorFromPalette(sal_uInt16 nNum, Color& rColor) const;
478 
479 	// SJ: New implementation of ReadObjText is used by Fontwork objects, because
480 	// the old one does not properly import multiple paragraphs
481 	void ReadObjText( const String& rText, SdrObject* pObj ) const;
482 	// -----------------------------------------------------------------------
483 
484 	/*
485 		folgende Methode ist von allen zu ueberschreiben, die OLE-Objecte
486 		importieren moechten:
487 	*/
488 	virtual sal_Bool GetOLEStorageName( long nOLEId, String& rStorageName,
489 									SotStorageRef& rSrcStorage,
490                 com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xDestStg
491                                     ) const;
492 
493 	/*
494 		folgende Methode ist von allen zu ueberschreiben, die verhindern
495 		moechten, dass (abgerundete) Rechtecke mit umgebrochenem Text
496 		immer in SdrRectObj( OBJ_TEXT ) umgewandelt werden:
497 		sal_True bedeutet umwandeln.
498 	*/
499 	virtual sal_Bool ShapeHasText(sal_uLong nShapeId, sal_uLong nFilePos) const;
500 
501 public:
502 
503 	void*				pSvxMSDffDummy1;
504 	void*				pSvxMSDffDummy2;
505 	DffPropertyReader*	pSecPropSet;
506 	List*				pEscherBlipCache;
507 
508 	DffRecordManager	maShapeRecords;
509 	ColorData			mnDefaultColor;
510 
511 	MSFilterTracer*		mpTracer;
512 	sal_Bool			mbTracing;
513 
514 	Color MSO_TEXT_CLR_ToColor( sal_uInt32 nColorCode ) const;
515 	Color MSO_CLR_ToColor( sal_uInt32 nColorCode, sal_uInt16 nContextProperty = DFF_Prop_lineColor ) const;
516 	virtual sal_Bool SeekToShape( SvStream& rSt, void* pClientData, sal_uInt32 nId ) const;
517 	FASTBOOL SeekToRec( SvStream& rSt, sal_uInt16 nRecId, sal_uLong nMaxFilePos, DffRecordHeader* pRecHd = NULL, sal_uLong nSkipCount = 0 ) const;
518 	FASTBOOL SeekToRec2( sal_uInt16 nRecId1, sal_uInt16 nRecId2, sal_uLong nMaxFilePos, DffRecordHeader* pRecHd = NULL, sal_uLong nSkipCount = 0 ) const;
519 
520 	// -----------------------------------------------------------------------
521 	static void MSDFFReadZString( SvStream& rIn, String& rStr, sal_uLong nMaxLen, FASTBOOL bUniCode = sal_False );
522 
523 	static sal_Bool ReadCommonRecordHeader( DffRecordHeader& rRec, SvStream& rIn );
524 	static sal_Bool ReadCommonRecordHeader( SvStream& rSt,
525 										sal_uInt8&     rVer,
526 										sal_uInt16&   rInst,
527 										sal_uInt16&   rFbt,
528 										sal_uInt32&    rLength );
529 /*
530 	Konstruktor
531 	===========
532 	Input:	rStCtrl	  - Verwaltungsstream mit Containern,
533 						FBSE Objekten und Shapes
534 						( muss immer uebergeben werden;
535 						  Stream muss bereits offen sein )
536 
537 			nOffsDgg  -	Offset im rStCtrl: Beginn des Drawing Group Containers
538 
539 			pStData	  - Datenstream, in dem die BLIPs gespeichert sind
540 						( falls Null, wird angenommen, dass die
541 						  BLIPs ebenfalls im rStCtrl gespeichert sind;
542 						  dieser Stream muss ebenfalls bereits offen sein )
543 			pSdrModel_  kann beim Ctor-Aufruf leer bleiben, muss dann aber
544 						spaeter ueber SetModel() gesetzt werden!
545 
546 	setzt nBLIPCount
547 */
548 	SvxMSDffManager( SvStream& rStCtrl,
549                      const String& rBaseURL,
550 					 long      nOffsDgg,
551 					 SvStream* pStData,
552 					 SdrModel* pSdrModel_			=  0,
553 					 long      nApplicationScale	=  0,
554 					 ColorData mnDefaultColor_		=  COL_DEFAULT,
555 					 sal_uLong     nDefaultFontHeight_	= 24,
556 					 SvStream* pStData2_			=  0,
557 					 MSFilterTracer* pTracer		= NULL );
558 
559 	// in PPT werden die Parameter DGGContainerOffset und PicStream
560 	// mit Hilfe einer Init Routine Uebergeben.
561     SvxMSDffManager( SvStream& rStCtrl, const String& rBaseURL, MSFilterTracer* pTracer );
562 	void InitSvxMSDffManager( long nOffsDgg_, SvStream* pStData_, sal_uInt32 nSvxMSDffOLEConvFlags );
563 	void SetDgContainer( SvStream& rSt );
564 
565 	virtual ~SvxMSDffManager();
566 
GetSvxMSDffSettings() const567 	sal_uInt32	GetSvxMSDffSettings() const { return nSvxMSDffSettings; };
SetSvxMSDffSettings(sal_uInt32 nSettings)568 	void	SetSvxMSDffSettings( sal_uInt32 nSettings ) { nSvxMSDffSettings = nSettings; };
569 
570 	static sal_Bool     MakeContentStream( SotStorage * pStor, const GDIMetaFile & );
571     static sal_Bool     ConvertToOle2( SvStream& rStm, sal_uInt32 nLen, const GDIMetaFile*,
572 								const SotStorageRef & rDest );
573 
574 	void SetModel(SdrModel* pModel, long nApplicationScale);
GetModel() const575 	SdrModel*  GetModel() const { return pSdrModel; }
576 	void Scale(sal_Int32& rVal) const;
577 	void Scale(Point& rPos) const;
578 	void Scale(Size& rSiz) const;
579 	void Scale(Rectangle& rRect) const;
580 	void Scale(Polygon& rPoly) const;
581 	void Scale(PolyPolygon& rPoly) const;
582 	void ScaleEmu(sal_Int32& rVal) const;
583 	sal_uInt32 ScalePt( sal_uInt32 nPt ) const;
584 	sal_Int32 ScalePoint( sal_Int32 nVal ) const;
585 
586 /*
587 	GetBLIP()			- Anforderung eines bestimmten BLIP
588 	=========
589 	Input:	nIdx		- Nummer des angeforderten BLIP
590 						  ( muss immer uebergeben werden )
591 
592 	Output:	rData		- bereits fertig konvertierte Daten
593 						  ( direkt als Grafik in unsere Dokumente einzusetzen )
594 
595 	Rueckgabewert: sal_True, im Erfolgsfalls, sal_False bei Fehler
596 */
597 	sal_Bool GetBLIP( sal_uLong nIdx, Graphic& rData, Rectangle* pVisArea = NULL ) const;
598 
599 /*
600 	GetBLIPDirect()		-Einlesen eines BLIP aus schon positioniertem Stream
601 	===============
602 	Input:	rBLIPStream	-bereits korrekt positionierter Stream
603 						  ( muss immer uebergeben werden )
604 
605 	Output:	rData		-bereits fertig konvertierte Daten
606 						  ( direkt als Grafik in unsere Dokumente einzusetzen )
607 
608 	Rueckgabewert: sal_True, im Erfolgsfalls, sal_False bei Fehler
609 */
610 	sal_Bool GetBLIPDirect(SvStream& rBLIPStream, Graphic& rData, Rectangle* pVisArea = NULL ) const;
611 
612 	sal_Bool GetShape(sal_uLong nId,
613 				  SdrObject*& rpData, SvxMSDffImportData& rData);
614 
615 /*
616 	GetBLIPCount()	- Abfrage der verwalteten BLIP Anzahl
617 	==============
618 	Input:	./.
619 	Output:	./.
620 	Rueckgabewert: nBLIPCount	- Anzahl der im pStData (bzw. rStCtrl) enthaltenen BLIPs
621 								  ( sprich: Anzahl der FBSEs im Drawing Group Container )
622 
623 						Werte:	0	- Struktur Ok, jedoch keine BLIPs vorhanden
624 								1..	- Anzahl der BLIPs
625 						USHRT_MAX	- Fehler: kein korrektes Drawing File Format
626 */
GetBLIPCount() const627 	sal_uInt16 GetBLIPCount() const{ return nBLIPCount; }
628 
629 /*
630 	ZCodecDecompressed()  - Dekomprimierung eines komp. WMF oder Enhanced WMF
631 	====================
632 	Input:	rIn		-bereits korrekt positionierter Stream,
633 					 der das komprimierte Bild enthaelt
634 			rOut	-bereits korrekt positionierter Ausgabe-Stream,
635 
636 		bLookForEnd -Flag, ob das komp. Bild bis zum Stream-Ende reicht.
637 					 Falls sal_True, wird jeweils geprueft, ob das gelesene	noch
638 														zum Bild gehoert.
639 					 Falls sal_False, wird bis zum Stream-Ende gelesen.
640 
641 	Output:	rIn     -Der Stream steht hinter dem Ende des komp. Bildes.
642 					 (es kann aber noch eine Ende-Kennung und CRC-Sum folgen)
643 			rOut	-Der Stream enthaelt das dekomprimierte Bild.
644 					 Der Stream wird auf den Anfang des Bildes positioniert.
645 					 (also dorthin, wo der Stream vor der Verarbeitung stand)
646 
647 	Rueckgabewert:	sal_True, im Erfolgsfall
648 					sal_False bei Fehler oder Null Bytes geschrieben
649 */
650 //	static sal_Bool ZCodecDecompressed(	SvStream& rIn,
651 //									SvStream& rOut,
652 //									sal_Bool bLookForEnd );
653 //
654 	SdrObject* ImportObj(SvStream& rSt, void* pData,
655         Rectangle& rClientRect, const Rectangle& rGlobalChildRect, int nCalledByGroup = 0, sal_Int32* pShapeId = NULL);
656 
657 	SdrObject* ImportGroup( const DffRecordHeader& rHd, SvStream& rSt, void* pData,
658         Rectangle& rClientRect, const Rectangle& rGlobalChildRect, int nCalledByGroup = 0, sal_Int32* pShapeId = NULL );
659 
660 	SdrObject* ImportShape( const DffRecordHeader& rHd, SvStream& rSt, void* pData,
661         Rectangle& rClientRect, const Rectangle& rGlobalChildRect, int nCalledByGroup = 0, sal_Int32* pShapeId = NULL, sal_Bool bShapeGroup = sal_False);
662 
663 	Rectangle GetGlobalChildAnchor( const DffRecordHeader& rHd, SvStream& rSt, Rectangle& aClientRect );
664 	void GetGroupAnchors( const DffRecordHeader& rHd, SvStream& rSt,
665 								Rectangle& rGroupClientAnchor, Rectangle& rGroupChildAnchor,
666 									const Rectangle& rClientRect, const Rectangle& rGlobalChildRect );
667 
GetShapeInfos(void) const668 	inline const SvxMSDffShapeInfos* GetShapeInfos( void ) const
669 		{
670 			return pShapeInfos;
671 		}
672 
GetShapeOrders(void) const673 	inline const SvxMSDffShapeOrders* GetShapeOrders( void ) const
674 		{
675 			return pShapeOrders;
676 		}
677 
678 	void StoreShapeOrder(sal_uLong			nId,
679 						 sal_uLong			nTxBx,
680 						 SdrObject*		pObject,
681 						 SwFlyFrmFmt*	pFly = 0,
682 						 short			nHdFtSection = 0) const;
683 
684 	void ExchangeInShapeOrder(SdrObject* pOldObject,
685 							  sal_uLong nTxBx,
686 							  SwFlyFrmFmt* pFly,
687 							  SdrObject*   pObject) const;
688 
689 	void RemoveFromShapeOrder( SdrObject* pObject ) const;
690 
GetConvertFlags() const691 	sal_uInt32	GetConvertFlags() const { return nSvxMSDffOLEConvFlags; }
692 
693 	static SdrOle2Obj* CreateSdrOLEFromStorage( const String& rStorageName,
694 												SotStorageRef& rSrcStorage,
695                                                 const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xDestStg,
696 												const Graphic& rGraf,
697 												const Rectangle& rBoundRect,
698 												const Rectangle& rVisArea,
699 												SvStream* pDataStrrm,
700                                                 ErrCode& rError,
701 												sal_uInt32 nConvertFlags,
702 												sal_Int64 nAspect );
703 
704 	/* the method SolveSolver will create connections between shapes, it should be called after a page is imported.
705 	The SvxMSDffSolverContainer is containing necessary data data that is collected during the import of each shape
706 	*/
707     void SolveSolver( const SvxMSDffSolverContainer& rSolver );
708 
709 	static sal_Bool SetPropValue(
710 		const ::com::sun::star::uno::Any& rAny,
711 			const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
712 				const String& rPropertyName,
713 					sal_Bool bTestPropertyAvailability = sal_False );
714 
715 	void insertShapeId( sal_Int32 nShapeId, SdrObject* pShape );
716 	void removeShapeId( SdrObject* pShape );
717 	SdrObject* getShapeForId( sal_Int32 nShapeId );
718 };
719 
720 struct SvxMSDffBLIPInfo
721 {
722 	sal_uInt16 nBLIPType;	// Art des BLIP: z.B. 6 fuer PNG
723 	sal_uLong  nFilePos;	// Offset des BLIP im Daten-Stream
724 	sal_uLong  nBLIPSize;	// Anzahl Bytes, die der BLIP im Stream einnimmt
SvxMSDffBLIPInfoSvxMSDffBLIPInfo725 	SvxMSDffBLIPInfo(sal_uInt16 nBType, sal_uLong nFPos, sal_uLong nBSize):
726 		nBLIPType( nBType ), nFilePos( nFPos ), nBLIPSize( nBSize ){}
727 };
728 
729 struct SvxMSDffShapeInfo
730 {
731 	sal_uInt32 nShapeId;	 // Shape Id, verwendet im PLCF SPA und im mso_fbtSp (FSP)
732 	sal_uLong nFilePos;	 // Offset des Shape im Kontroll-Stream fuer eventuelle
733 					 // erneute Zugriffe auf dieses Shape
734 	sal_uInt32 nTxBxComp;
735 
736 	sal_Bool bReplaceByFly  :1; // Shape darf im Writer durch Rahmen ersetzt werden.
737 	sal_Bool bSortByShapeId :1;
738 	sal_Bool bLastBoxInChain:1;
739 
SvxMSDffShapeInfoSvxMSDffShapeInfo740 	SvxMSDffShapeInfo(sal_uLong nFPos, sal_uInt32 nId=0, // sal_uLong nBIdx=0,
741 					  sal_uInt16 nSeqId=0, sal_uInt16 nBoxId=0):
742 		nShapeId( nId ),
743 		nFilePos( nFPos ),
744 		nTxBxComp( (nSeqId << 16) + nBoxId )
745 		{
746 			bReplaceByFly	= sal_False;
747 			bSortByShapeId	= sal_False;
748 			bLastBoxInChain	= sal_True;
749 		}
SvxMSDffShapeInfoSvxMSDffShapeInfo750 	SvxMSDffShapeInfo(SvxMSDffShapeInfo& rInfo):
751 		nShapeId( rInfo.nShapeId ),
752 		nFilePos( rInfo.nFilePos ),
753 		nTxBxComp( rInfo.nTxBxComp )
754 		{
755 			bReplaceByFly	= rInfo.bReplaceByFly;
756 			bSortByShapeId	= rInfo.bSortByShapeId;
757 			bLastBoxInChain	= rInfo.bLastBoxInChain;
758 		}
operator ==SvxMSDffShapeInfo759 	sal_Bool operator==( const SvxMSDffShapeInfo& rEntry ) const
760 	{
761 		return bSortByShapeId ? (nShapeId  == rEntry.nShapeId)
762 							  : (nTxBxComp == rEntry.nTxBxComp && this == &rEntry);
763 	}
operator <SvxMSDffShapeInfo764 	sal_Bool operator<( const SvxMSDffShapeInfo& rEntry ) const
765 	{
766 		return bSortByShapeId ? (nShapeId  < rEntry.nShapeId)
767 							  : (nTxBxComp < rEntry.nTxBxComp);
768 	}
769 };
770 
771 struct SvxMSDffShapeOrder
772 {
773 	sal_uLong nShapeId;		// Shape Id, verwendet im PLCF SPA und im mso_fbtSp (FSP)
774 
775 	sal_uLong nTxBxComp;	// Ketten- und Boxnummer in der Text-Box-Story (bzw. Null)
776 
777 	SwFlyFrmFmt* pFly;	// Frame-Format eines statt des Sdr-Text-Objektes im
778 						// Writer eingefuegten Rahmens: zur Verkettung benoetigt!
779 
780 	short nHdFtSection; // used by Writer to find out if linked frames are in the
781 						// same header or footer of the same section
782 
783 	SdrObject*	pObj;	// Zeiger auf das Draw-Objekt (bzw. Null, falls nicht verwendet)
784 
785 	// Vorgehensweise:  im Ctor des SvxMSDffManager werden im der Shape-Order-Array
786 	//					nur die Shape-Ids vermerkt,
787 	//					Text-Box-Nummer und der Objekt-Pointer werden nur dann
788 	//					gespeichert, wenn das Shape tatsaechlich importiert wird!
SvxMSDffShapeOrderSvxMSDffShapeOrder789 	SvxMSDffShapeOrder( sal_uLong nId ):
790 		nShapeId( nId ), nTxBxComp( 0 ), pFly( 0 ), nHdFtSection( 0 ), pObj( 0 ){}
791 
operator ==SvxMSDffShapeOrder792 	sal_Bool operator==( const SvxMSDffShapeOrder& rEntry ) const
793 	{
794 		return (nTxBxComp == rEntry.nTxBxComp);
795 	}
operator <SvxMSDffShapeOrder796 	sal_Bool operator<( const SvxMSDffShapeOrder& rEntry ) const
797 	{
798 		return (nTxBxComp < rEntry.nTxBxComp);
799 	}
800 };
801 
802 #endif
803 
804