xref: /trunk/main/filter/source/msfilter/svdfppt.cxx (revision f6675432)
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_filter.hxx"
26 #include <osl/endian.h>
27 #include <vcl/svapp.hxx>
28 #include <unotools/tempfile.hxx>
29 #include <math.h>
30 #include <editeng/eeitem.hxx>
31 #include <sot/storage.hxx>
32 #include <sot/storinfo.hxx>
33 #include <sot/stg.hxx>
34 #include <com/sun/star/embed/Aspects.hpp>
35 #include <com/sun/star/office/XAnnotation.hpp>
36 #include <com/sun/star/office/XAnnotationAccess.hpp>
37 #include <com/sun/star/text/XText.hpp>
38 #include <com/sun/star/geometry/RealPoint2D.hpp>
39 #include <com/sun/star/util/DateTime.hpp>
40 #include <com/sun/star/drawing/BitmapMode.hpp>
41 #include <unotools/streamwrap.hxx>
42 #include <filter/msfilter/svdfppt.hxx>
43 #include <svx/xpoly.hxx>
44 #include <svx/svdtrans.hxx>
45 #include <svx/svdmodel.hxx>
46 #include <svx/svdpage.hxx>
47 #include <svx/svdobj.hxx>
48 #include <svx/svdogrp.hxx>
49 #include <svx/svdorect.hxx>
50 #include <svx/svdopage.hxx>
51 #include <svx/svdograf.hxx>
52 #include <svx/svdopath.hxx>
53 #include <svx/svdocirc.hxx>
54 #include <svx/svdocapt.hxx>
55 #include <svx/svdotable.hxx>
56 #include <editeng/outlobj.hxx>
57 #include <svx/svdattr.hxx>
58 #include "svx/xattr.hxx"
59 #include "svx/svditext.hxx"
60 #include <svx/svdetc.hxx>
61 #include <editeng/bulitem.hxx>
62 #include <svx/polysc3d.hxx>
63 #include <svx/extrud3d.hxx>
64 #include <svx/svdoashp.hxx>
65 #include <editeng/tstpitem.hxx>
66 #include <editeng/unoprnms.hxx>
67 #include <editeng/editids.hrc>
68 
69 #if defined(JOEENV) && defined(JOEDEBUG)
70 #include "impinccv.h" // etwas Testkram
71 #endif
72 
73 #if defined(DBG_EXTRACTOLEOBJECTS) || defined(DBG_EXTRACTFONTMETRICS)
74 #include <tools/urlobj.hxx>
75 #include <unotools/localfilehelper.hxx>
76 #endif
77 
78 #define ITEMVALUE(ItemSet,Id,Cast)  ((const Cast&)(ItemSet).Get(Id)).GetValue()
79 #include <editeng/adjitem.hxx>
80 #include <editeng/escpitem.hxx>
81 #include <editeng/colritem.hxx>
82 #include <editeng/fhgtitem.hxx>
83 #include <editeng/wghtitem.hxx>
84 #include <editeng/postitem.hxx>
85 #include <editeng/udlnitem.hxx>
86 #include <editeng/crsditem.hxx>
87 #include <editeng/shdditem.hxx>
88 #include <editeng/charreliefitem.hxx>
89 #include <editeng/fontitem.hxx>
90 #include <svx/svdoutl.hxx>
91 #include <editeng/editeng.hxx>
92 #include <editeng/lspcitem.hxx>
93 #include <editeng/ulspitem.hxx>
94 #include <editeng/lrspitem.hxx>
95 #include <vcl/metric.hxx>
96 #include <vcl/bmpacc.hxx>
97 #include <svx/svditer.hxx>
98 #include <svx/svdoedge.hxx>
99 #include <svx/sxekitm.hxx>
100 #include <editeng/flditem.hxx>
101 #include <svtools/sychconv.hxx>
102 #include <tools/zcodec.hxx>
103 #include <filter/msfilter/svxmsbas.hxx>
104 #include <sfx2/objsh.hxx>
105 #include <editeng/brshitem.hxx>
106 #include <editeng/langitem.hxx>
107 #include <svx/svdoole2.hxx>
108 #include <svx/unoapi.hxx>
109 #include <toolkit/helper/vclunohelper.hxx>
110 #include <com/sun/star/container/XIndexContainer.hpp>
111 #include <com/sun/star/drawing/XShapes.hpp>
112 #include <com/sun/star/drawing/XControlShape.hpp>
113 #include <com/sun/star/form/XFormComponent.hpp>
114 #include <com/sun/star/beans/XPropertySet.hpp>
115 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
116 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
117 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
118 #include <com/sun/star/awt/Size.hpp>
119 #include <com/sun/star/awt/Point.hpp>
120 #include <com/sun/star/drawing/FillStyle.hpp>
121 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
122 #include <editeng/writingmodeitem.hxx>
123 #include <vcl/print.hxx>
124 #include <editeng/svxfont.hxx>
125 #include <editeng/frmdiritem.hxx>
126 #include <svx/sdtfchim.hxx>
127 #include <unotools/ucbstreamhelper.hxx>
128 #include <editeng/scripttypeitem.hxx>
129 #include "com/sun/star/awt/Gradient.hpp"
130 #include <com/sun/star/table/XMergeableCellRange.hpp>
131 #include <com/sun/star/table/BorderLine.hpp>
132 #include <vcl/virdev.hxx>
133 #include <algorithm>
134 #include <set>
135 
136 ////////////////////////////////////////////////////////////////////////////////////////////////////
137 
138 // PPT ColorScheme Slots
139 #define PPT_COLSCHEME						(0x08000000)
140 #define PPT_COLSCHEME_HINTERGRUND			(0x08000000)
141 #define PPT_COLSCHEME_TEXT_UND_ZEILEN		(0x08000001)
142 #define PPT_COLSCHEME_SCHATTEN				(0x08000002)
143 #define PPT_COLSCHEME_TITELTEXT				(0x08000003)
144 #define PPT_COLSCHEME_FUELLBEREICHE			(0x08000004)
145 #define PPT_COLSCHEME_AKZENT				(0x08000005)
146 #define PPT_COLSCHEME_A_UND_HYPERLINK		(0x08000006)
147 #define PPT_COLSCHEME_A_H_GESICHERT			(0x08000007)
148 
149 ////////////////////////////////////////////////////////////////////////////////////////////////////
150 
151 #define ANSI_CHARSET			0
152 #define DEFAULT_CHARSET			1
153 #define SYMBOL_CHARSET			2
154 #define SHIFTJIS_CHARSET		128
155 #define HANGEUL_CHARSET			129
156 #define CHINESEBIG5_CHARSET		136
157 #define OEM_CHARSET				255
158 
159 ////////////////////////////////////////////////////////////////////////////////////////////////////
160 
161 /* Font Families */
162 #define FF_DONTCARE				0x00
163 #define FF_ROMAN				0x10
164 #define FF_SWISS				0x20
165 #define FF_MODERN				0x30
166 #define FF_SCRIPT				0x40
167 #define FF_DECORATIVE			0x50
168 
169 ////////////////////////////////////////////////////////////////////////////////////////////////////
170 
171 #define DEFAULT_PITCH			0x00
172 #define FIXED_PITCH				0x01
173 #define VARIABLE_PITCH			0x02
174 
175 using namespace ::com::sun::star	;
176 using namespace uno					;
177 using namespace beans				;
178 using namespace drawing				;
179 using namespace container			;
180 using namespace table				;
181 
182 ////////////////////////////////////////////////////////////////////////////////////////////////////
183 
PowerPointImportParam(SvStream & rDocStrm,sal_uInt32 nFlags,MSFilterTracer * pT)184 PowerPointImportParam::PowerPointImportParam( SvStream& rDocStrm, sal_uInt32 nFlags, MSFilterTracer* pT ) :
185 	rDocStream		( rDocStrm ),
186 	nImportFlags	( nFlags ),
187 	pTracer			( pT )
188 {
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////////////////////////
192 
operator >>(SvStream & rIn,PptCurrentUserAtom & rAtom)193 SvStream& operator>>( SvStream& rIn, PptCurrentUserAtom& rAtom )
194 {
195 	DffRecordHeader aHd;
196 	rIn >> aHd;
197 	if ( aHd.nRecType == PPT_PST_CurrentUserAtom )
198 	{
199 		sal_uInt32 nLen;
200 		sal_uInt16 nUserNameLen, nPad;
201 		rIn >> nLen
202 			>> rAtom.nMagic
203 			>> rAtom.nCurrentUserEdit
204 			>> nUserNameLen
205 			>> rAtom.nDocFileVersion
206 			>> rAtom.nMajorVersion
207 			>> rAtom.nMinorVersion
208 			>> nPad;
209 		SvxMSDffManager::MSDFFReadZString( rIn, rAtom.aCurrentUser, nUserNameLen, sal_True );
210 	}
211 	aHd.SeekToEndOfRecord( rIn );
212 	return rIn;
213 }
214 
Clear()215 void PptSlidePersistAtom::Clear()
216 {
217 	nReserved = nPsrReference = nFlags = nNumberTexts = nSlideId = 0;
218 }
219 
operator >>(SvStream & rIn,PptSlidePersistAtom & rAtom)220 SvStream& operator>>( SvStream& rIn, PptSlidePersistAtom& rAtom )
221 {
222 	DffRecordHeader aHd;
223 	rIn >> aHd
224 		>> rAtom.nPsrReference
225 		>> rAtom.nFlags
226 		>> rAtom.nNumberTexts
227 		>> rAtom.nSlideId;
228 //		>> rAtom.nReserved;
229 	aHd.SeekToEndOfRecord( rIn );
230 	return rIn;
231 }
232 
233 SV_IMPL_PTRARR(_PptSlidePersistList,PptSlidePersistEntry*);
234 
FindPage(sal_uInt32 nId) const235 sal_uInt16 PptSlidePersistList::FindPage(sal_uInt32 nId) const
236 {
237 	for ( sal_uInt16 i=0; i < Count(); i++ )
238 	{
239 		if (operator[](i)->GetSlideId()==nId) return i;
240 	}
241 	return PPTSLIDEPERSIST_ENTRY_NOTFOUND;
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////////////////////////
245 
operator >>(SvStream & rIn,PptInteractiveInfoAtom & rAtom)246 SvStream& operator>>( SvStream& rIn, PptInteractiveInfoAtom& rAtom )
247 {
248 	rIn >> rAtom.nSoundRef
249 		>> rAtom.nExHyperlinkId
250 		>> rAtom.nAction
251 		>> rAtom.nOleVerb
252 		>> rAtom.nJump
253 		>> rAtom.nFlags
254 		>> rAtom.nHyperlinkType
255 		>> rAtom.nUnknown1
256 		>> rAtom.nUnknown2
257 		>> rAtom.nUnknown3;
258 	return rIn;
259 }
260 
operator >>(SvStream & rIn,PptExOleObjAtom & rAtom)261 SvStream& operator>>( SvStream& rIn, PptExOleObjAtom& rAtom )
262 {
263 	rIn >> rAtom.nAspect
264 		>> rAtom.nDummy1
265 		>> rAtom.nId
266 		>> rAtom.nDummy2
267 		>> rAtom.nPersistPtr
268 		>> rAtom.nDummy4;
269 	return rIn;
270 }
271 
GetPageSize(const Size & rSiz) const272 Size PptDocumentAtom::GetPageSize(const Size& rSiz) const
273 {
274 	return rSiz;
275 /*
276 	Size aRet;
277 	switch ( eSlidesPageFormat )
278 	{
279 		// Wenn man in PowerPoint als Seitenformat "Bildschirmgroesse"
280 		// einstellt, dann zeigt dieser Dialog zwar 24x18cm an, die
281 		// angezeigte Seite ist aber anders. Das sieht man, wenn man
282 		// ein Rechteck seitenfuellend aufzieht und sich dessen Groesse
283 		// ansieht. Die importierten Abmessungen sind auf jeden Fall
284 		// die, die auch im Ppt-File stehen. Ich denke, das es sich
285 		// hier eher um ein Bug in PowerPoint handelt, das im
286 		// Seitenformat-Dialog bei "Bildschirmgroesse" falsche Masse
287 		// angezeigt werden (vielleicht ja auch bildschirmabhaengig?).
288 //		case PPTPF_SCREEN  : aRet.Width()=4082; aRet.Height()=5443; break;
289 		case PPTPF_USLETTER: aRet.Width()=4896; aRet.Height()=6336; break;
290 		case PPTPF_A4      : aRet.Width()=4762; aRet.Height()=6735; break;
291 //		case PPTPF_35MMDIA : aRet.Width()=4082; aRet.Height()=6123; break;
292 //		case PPTPF_OVERHEAD: aRet.Width()=4082; aRet.Height()=5443; break;
293 	}
294 	if ( aRet.Width() )
295 	{
296 		if ( rSiz.Width() > rSiz.Height() )
297 		{	// Querformat
298 			long nMerk = aRet.Width();
299 			aRet.Width() = aRet.Height();
300 			aRet.Height() = nMerk;
301 		}
302 	}
303 	else	// CustomFormat oder Unbekannt oder Screen,Dia,Overhead
304 		aRet = rSiz;
305 	return aRet;
306 */
307 }
308 
operator >>(SvStream & rIn,PptDocumentAtom & rAtom)309 SvStream& operator>>(SvStream& rIn, PptDocumentAtom& rAtom)
310 {
311 // Tatsaechliches Format:
312 //  00 aSlidePageSizeXY  8
313 //  08 aNotesPageSizeXY  8
314 //  16 aZoomRatio (OLE)  8
315 //  24 nNotesMasterPersist   4
316 //  28 nHandoutMasterPersist 4
317 //  32 n1stPageNumber    2
318 //  34 ePageFormat       2
319 //  36 bEmbeddedTrueType 1
320 //  37 bOmitTitlePlace   1
321 //  38 bRightToLeft      1
322 //  39 bShowComments     1
323 
324 	DffRecordHeader aHd;
325 	sal_Int32	nSlideX,nSlideY, nNoticeX, nNoticeY, nDummy;
326 	sal_uInt16	nSlidePageFormat;
327 	sal_Int8	nEmbeddedTrueType, nTitlePlaceHoldersOmitted, nRightToLeft, nShowComments;
328 
329 	rIn >> aHd
330 		>> nSlideX >> nSlideY
331 		>> nNoticeX >> nNoticeY
332 		>> nDummy >> nDummy				// ZoomRation ueberspringen
333 		>> rAtom.nNotesMasterPersist
334 		>> rAtom.nHandoutMasterPersist
335 		>> rAtom.n1stPageNumber
336 		>> nSlidePageFormat
337 		>> nEmbeddedTrueType
338 		>> nTitlePlaceHoldersOmitted
339 		>> nRightToLeft
340 		>> nShowComments;
341 	rAtom.aSlidesPageSize.Width() = nSlideX;
342 	rAtom.aSlidesPageSize.Height() = nSlideY;
343 	rAtom.aNotesPageSize.Width() = nNoticeX;
344 	rAtom.aNotesPageSize.Height() = nNoticeY;
345 	rAtom.eSlidesPageFormat = (PptPageFormat)nSlidePageFormat;
346 	rAtom.bEmbeddedTrueType = nEmbeddedTrueType;
347 	rAtom.bTitlePlaceholdersOmitted = nTitlePlaceHoldersOmitted;
348 	rAtom.bRightToLeft = nRightToLeft;
349 	rAtom.bShowComments = nShowComments;
350 	aHd.SeekToEndOfRecord( rIn );
351 	return rIn;
352 }
353 
354 ////////////////////////////////////////////////////////////////////////////////////////////////////
355 
Clear()356 void PptSlideLayoutAtom::Clear()
357 {
358 	eLayout = 0;
359 	for ( sal_uInt16 i = 0; i < 8; i++ )
360 	{
361 		aPlaceholderId[ i ] = 0;
362 		aPlacementId[ i ] = 0;
363 	}
364 }
365 
operator >>(SvStream & rIn,PptSlideLayoutAtom & rAtom)366 SvStream& operator>>( SvStream& rIn, PptSlideLayoutAtom& rAtom )
367 {
368 	rIn >> rAtom.eLayout;
369 	rIn.Read( rAtom.aPlaceholderId, 8 );
370 	return rIn;
371 }
372 
373 ////////////////////////////////////////////////////////////////////////////////////////////////////
374 
operator >>(SvStream & rIn,PptSlideAtom & rAtom)375 SvStream& operator>>( SvStream& rIn, PptSlideAtom& rAtom )
376 {
377 	DffRecordHeader aHd;
378 	rIn	>> aHd
379 		>> rAtom.aLayout
380 		>> rAtom.nMasterId
381 		>> rAtom.nNotesId
382 		>> rAtom.nFlags;
383 	aHd.SeekToEndOfRecord( rIn );
384 	return rIn;
385 }
386 
Clear()387 void PptSlideAtom::Clear()
388 {
389 	nMasterId = nNotesId = 0;
390 	nFlags = 0;
391 }
392 
393 ////////////////////////////////////////////////////////////////////////////////////////////////////
394 
operator >>(SvStream & rIn,PptNotesAtom & rAtom)395 SvStream& operator>>( SvStream& rIn, PptNotesAtom& rAtom )
396 {
397 	DffRecordHeader aHd;
398 	rIn >> aHd
399 		>> rAtom.nSlideId
400 		>> rAtom.nFlags;
401 	aHd.SeekToEndOfRecord( rIn );
402 	return rIn;
403 }
404 
Clear()405 void PptNotesAtom::Clear()
406 {
407 	nSlideId = 0;
408 	nFlags = 0;
409 }
410 
411 ////////////////////////////////////////////////////////////////////////////////////////////////////
412 
Clear()413 void PptColorSchemeAtom::Clear()
414 {
415 	memset(&aData[0], 0, 32);
416 }
417 
GetColor(sal_uInt16 nNum) const418 Color PptColorSchemeAtom::GetColor( sal_uInt16 nNum ) const
419 {
420 	Color aRetval;
421 	if ( nNum < 8 )
422 	{
423 		nNum <<= 2;
424 		aRetval.SetRed( aData[ nNum++ ] );
425 		aRetval.SetGreen( aData[ nNum++ ] );
426 		aRetval.SetBlue( aData[ nNum++ ] );
427 	}
428 	return aRetval;
429 }
430 
operator >>(SvStream & rIn,PptColorSchemeAtom & rAtom)431 SvStream& operator>>( SvStream& rIn, PptColorSchemeAtom& rAtom )
432 {
433 	DffRecordHeader aHd;
434 	rIn >> aHd;
435 	rIn.Read( rAtom.aData, 32 );
436 	aHd.SeekToEndOfRecord( rIn );
437 	return rIn;
438 }
439 
440 ////////////////////////////////////////////////////////////////////////////////////////////////////
441 
operator >>(SvStream & rIn,PptFontEntityAtom & rAtom)442 SvStream& operator>>( SvStream& rIn, PptFontEntityAtom& rAtom )
443 {
444 	DffRecordHeader aHd;
445 	rIn >> aHd;
446 	sal_Unicode	nTemp, cData[ 32 ];
447 	rIn.Read( cData, 64 );
448 
449 	sal_uInt8	lfCharset, lfPitchAndFamily;
450 
451 	rIn >> lfCharset
452 		>> rAtom.lfClipPrecision
453 		>> rAtom.lfQuality
454 		>> lfPitchAndFamily;
455 
456 	switch( lfCharset )
457 	{
458 		case SYMBOL_CHARSET	:
459 			rAtom.eCharSet = RTL_TEXTENCODING_SYMBOL;
460 		break;
461 		case ANSI_CHARSET :
462 			rAtom.eCharSet = RTL_TEXTENCODING_MS_1252;
463 		break;
464 
465 //		case DEFAULT_CHARSET :
466 //		case SHIFTJIS_CHARSET :
467 //		case HANGEUL_CHARSET :
468 //		case CHINESEBIG5_CHARSET :
469 //		case OEM_CHARSET :
470 		default :
471 			rAtom.eCharSet = gsl_getSystemTextEncoding();
472 	}
473 	switch ( lfPitchAndFamily & 0xf0 )
474 	{
475 		case FF_ROMAN:
476 			rAtom.eFamily = FAMILY_ROMAN;
477 		break;
478 
479 		case FF_SWISS:
480 			rAtom.eFamily = FAMILY_SWISS;
481 		break;
482 
483 		case FF_MODERN:
484 			rAtom.eFamily = FAMILY_MODERN;
485 		break;
486 
487 		case FF_SCRIPT:
488 			rAtom.eFamily = FAMILY_SCRIPT;
489 		break;
490 
491 		case FF_DECORATIVE:
492 			 rAtom.eFamily = FAMILY_DECORATIVE;
493 		break;
494 
495 		default:
496 			rAtom.eFamily = FAMILY_DONTKNOW;
497 		break;
498 	}
499 
500 	switch ( lfPitchAndFamily & 0x0f )
501 	{
502 		case FIXED_PITCH:
503 			rAtom.ePitch = PITCH_FIXED;
504 		break;
505 
506 		case DEFAULT_PITCH:
507 		case VARIABLE_PITCH:
508 		default:
509 			rAtom.ePitch = PITCH_VARIABLE;
510 		break;
511 	}
512 	sal_uInt16 i;
513 	for ( i = 0; i < 32; i++ )
514 	{
515 		nTemp = cData[ i ];
516 		if ( !nTemp )
517 			break;
518 #ifdef OSL_BIGENDIAN
519 		cData[ i ] = ( nTemp >> 8 ) | ( nTemp << 8 );
520 #endif
521 	}
522 	rAtom.aName = String( cData, i );
523 	OutputDevice* pDev = (OutputDevice*)Application::GetDefaultDevice();
524 	rAtom.bAvailable = pDev->IsFontAvailable( rAtom.aName );
525 	aHd.SeekToEndOfRecord( rIn );
526 	return rIn;
527 }
528 
529 SV_DECL_PTRARR_DEL( PptFontEntityAtomList, PptFontEntityAtom*, 16, 16 )
530 SV_IMPL_PTRARR( PptFontEntityAtomList, PptFontEntityAtom* );
531 
532 class PptFontCollection: public PptFontEntityAtomList {
533 };
534 
535 ////////////////////////////////////////////////////////////////////////////////////////////////////
536 
operator >>(SvStream & rIn,PptUserEditAtom & rAtom)537 SvStream& operator>>( SvStream& rIn, PptUserEditAtom& rAtom )
538 {
539 	rIn >> rAtom.aHd
540 		>> rAtom.nLastSlideID
541 		>> rAtom.nVersion
542 		>> rAtom.nOffsetLastEdit
543 		>> rAtom.nOffsetPersistDirectory
544 		>> rAtom.nDocumentRef
545 		>> rAtom.nMaxPersistWritten
546 		>> rAtom.eLastViewType;
547 	rAtom.aHd.SeekToEndOfRecord(rIn);
548 	return rIn;
549 }
550 
551 ////////////////////////////////////////////////////////////////////////////////////////////////////
552 
Clear()553 void PptOEPlaceholderAtom::Clear()
554 {
555 	nPlacementId = 0;
556 	nPlaceholderSize = nPlaceholderId = 0;
557 }
558 
operator >>(SvStream & rIn,PptOEPlaceholderAtom & rAtom)559 SvStream& operator>>( SvStream& rIn, PptOEPlaceholderAtom& rAtom )
560 {
561 	rIn	>> rAtom.nPlacementId
562 		>> rAtom.nPlaceholderId
563 		>> rAtom.nPlaceholderSize;
564 	return rIn;
565 }
566 
567 ////////////////////////////////////////////////////////////////////////////////////////////////////
568 
PptSlidePersistEntry()569 PptSlidePersistEntry::PptSlidePersistEntry() :
570 	pStyleSheet				( NULL ),
571 	pHeaderFooterEntry		( NULL ),
572 	pSolverContainer		( NULL ),
573 	nSlidePersistStartOffset( 0 ),
574 	nSlidePersistEndOffset	( 0 ),
575 	nBackgroundOffset		( 0 ),
576 	nDrawingDgId			( 0xffffffff ),
577 	pPresentationObjects	( NULL ),
578 	pBObj					( NULL ),
579 	bBObjIsTemporary		( sal_True ),
580 	ePageKind				( PPT_MASTERPAGE ),
581 	bNotesMaster			( sal_False ),
582 	bHandoutMaster			( sal_False ),
583 	bStarDrawFiller			( sal_False )
584 {
585 	HeaderFooterOfs[ 0 ] = 	HeaderFooterOfs[ 1 ] = HeaderFooterOfs[ 2 ] = HeaderFooterOfs[ 3 ] = 0;
586 }
587 
588 
~PptSlidePersistEntry()589 PptSlidePersistEntry::~PptSlidePersistEntry()
590 {
591 	delete pStyleSheet;
592 	delete pHeaderFooterEntry;
593 	delete pSolverContainer;
594 	delete[] pPresentationObjects;
595 };
596 
597 ////////////////////////////////////////////////////////////////////////////////////////////////////
598 ////////////////////////////////////////////////////////////////////////////////////////////////////
599 ////////////////////////////////////////////////////////////////////////////////////////////////////
600 
SdrEscherImport(PowerPointImportParam & rParam,const String & rBaseURL)601 SdrEscherImport::SdrEscherImport( PowerPointImportParam& rParam, const String& rBaseURL ) :
602 	SvxMSDffManager			( rParam.rDocStream, rBaseURL, rParam.pTracer ),
603 	pFonts					( NULL ),
604 	nStreamLen				( 0 ),
605 	nTextStylesIndex		( 0xffff ),
606 	eCharSetSystem			( gsl_getSystemTextEncoding() ),
607 	bWingdingsChecked		( sal_False ),
608 	bWingdingsAvailable		( sal_False ),
609 	bMonotypeSortsChecked	( sal_False ),
610 	bMonotypeSortsAvailable	( sal_False ),
611 	bTimesNewRomanChecked	( sal_False ),
612 	bTimesNewRomanAvailable	( sal_False ),
613 	rImportParam			( rParam )
614 {
615 }
616 
~SdrEscherImport()617 SdrEscherImport::~SdrEscherImport()
618 {
619 	void* pPtr;
620 	for ( pPtr = aOleObjectList.First(); pPtr; pPtr = aOleObjectList.Next() )
621 		delete (PPTOleEntry*)pPtr;
622 	delete pFonts;
623 }
624 
GetSlideLayoutAtom() const625 const PptSlideLayoutAtom* SdrEscherImport::GetSlideLayoutAtom() const
626 {
627 	return NULL;
628 }
629 
ReadString(String & rStr) const630 sal_Bool SdrEscherImport::ReadString( String& rStr ) const
631 {
632 	sal_Bool bRet = sal_False;
633 	DffRecordHeader aStrHd;
634 	rStCtrl >> aStrHd;
635 	if (aStrHd.nRecType == PPT_PST_TextBytesAtom
636 		|| aStrHd.nRecType == PPT_PST_TextCharsAtom
637 		|| aStrHd.nRecType == PPT_PST_CString)
638 	{
639 		sal_Bool bUniCode =
640 			(aStrHd.nRecType == PPT_PST_TextCharsAtom
641 			|| aStrHd.nRecType == PPT_PST_CString);
642 		bRet=sal_True;
643 		sal_uLong nBytes = aStrHd.nRecLen;
644 		MSDFFReadZString( rStCtrl, rStr, nBytes, bUniCode );
645 		aStrHd.SeekToEndOfRecord( rStCtrl );
646 	}
647 	else
648 		aStrHd.SeekToBegOfRecord( rStCtrl );
649 	return bRet;
650 }
651 
GetColorFromPalette(sal_uInt16,Color &) const652 FASTBOOL SdrEscherImport::GetColorFromPalette(sal_uInt16 /*nNum*/, Color& /*rColor*/) const
653 {
654 	return sal_False;
655 }
656 
SeekToShape(SvStream &,void *,sal_uInt32) const657 sal_Bool SdrEscherImport::SeekToShape( SvStream& /*rSt*/, void* /*pClientData*/, sal_uInt32 /*nId*/) const
658 {
659 	return sal_False;
660 }
661 
GetFontEnityAtom(sal_uInt32 nNum) const662 PptFontEntityAtom* SdrEscherImport::GetFontEnityAtom( sal_uInt32 nNum ) const
663 {
664 	PptFontEntityAtom* pRetValue = NULL;
665 	if ( pFonts && ( nNum < pFonts->Count() ) )
666 		pRetValue = (*pFonts)[ (sal_uInt16)nNum ];
667 	return pRetValue;
668 }
669 
GetCharSet(sal_uInt32 nNum) const670 CharSet SdrEscherImport::GetCharSet( sal_uInt32 nNum ) const
671 {
672 	CharSet eRetValue( eCharSetSystem );
673 	if ( pFonts && ( nNum < pFonts->Count() ) )
674 		eRetValue = (*pFonts)[ (sal_uInt16)nNum ]->eCharSet;
675 	return eRetValue;
676 }
677 
IsFontAvailable(sal_uInt32 nNum) const678 sal_Bool SdrEscherImport::IsFontAvailable( sal_uInt32 nNum ) const
679 {
680 	sal_Bool bRetValue = sal_False;
681 	if ( pFonts && ( nNum < pFonts->Count() ) )
682 		bRetValue = (*pFonts)[ (sal_uInt16)nNum ]->bAvailable;
683 	return bRetValue;
684 }
685 
ReadObjText(PPTTextObj *,SdrObject * pObj,SdPage *) const686 SdrObject* SdrEscherImport::ReadObjText( PPTTextObj* /*pTextObj*/, SdrObject* pObj, SdPage* /*pPage*/) const
687 {
688 	return pObj;
689 }
690 
ProcessClientAnchor2(SvStream & rSt,DffRecordHeader & rHd,void *,DffObjData & rObj)691 void SdrEscherImport::ProcessClientAnchor2( SvStream& rSt, DffRecordHeader& rHd, void* /*pData*/, DffObjData& rObj )
692 {
693 	sal_Int32 l, t, r, b;
694 	if ( rHd.nRecLen == 16 )
695 	{
696 		rSt >> l >> t >> r >> b;
697 	}
698 	else
699 	{
700 		sal_Int16 ls, ts, rs, bs;
701 		rSt >> ts >> ls >> rs >> bs; // etwas seltsame Koordinatenreihenfolge ...
702 		l = ls, t = ts, r = rs, b = bs;
703 	}
704 	Scale( l );
705 	Scale( t );
706 	Scale( r );
707 	Scale( b );
708 	rObj.aChildAnchor = Rectangle( l, t, r, b );
709 	rObj.bChildAnchor = sal_True;
710 	return;
711 };
712 
RecolorGraphic(SvStream & rSt,sal_uInt32 nRecLen,Graphic & rGraphic)713 void SdrEscherImport::RecolorGraphic( SvStream& rSt, sal_uInt32 nRecLen, Graphic& rGraphic )
714 {
715 	if ( rGraphic.GetType() == GRAPHIC_GDIMETAFILE )
716 	{
717 		sal_uInt16 nX, nGlobalColorsCount, nFillColorsCount;
718 
719 		rSt >> nX
720 			>> nGlobalColorsCount
721 			>> nFillColorsCount
722 			>> nX
723 			>> nX
724 			>> nX;
725 
726 		if ( ( nGlobalColorsCount <= 64 ) && ( nFillColorsCount <= 64 ) )
727 		{
728 			if ( (sal_uInt32)( ( nGlobalColorsCount + nFillColorsCount ) * 44 + 12 ) == nRecLen )
729 			{
730 				sal_uInt32 OriginalGlobalColors[ 64 ];
731 				sal_uInt32 NewGlobalColors[ 64 ];
732 				sal_uInt32 OriginalFillColors[ 64 ];
733 				sal_uInt32 NewFillColors[ 64 ];
734 
735 				sal_uInt32 i, j, nGlobalColorsChanged, nFillColorsChanged;
736 				nGlobalColorsChanged = nFillColorsChanged = 0;
737 
738 				sal_uInt32* pCurrentOriginal = OriginalGlobalColors;
739 				sal_uInt32* pCurrentNew = NewGlobalColors;
740 				sal_uInt32* pCount = &nGlobalColorsChanged;
741 				i = nGlobalColorsCount;
742 
743 				for ( j = 0; j < 2; j++ )
744 				{
745 					for ( ; i > 0; i-- )
746 					{
747 						sal_uInt32 nIndex, nPos = rSt.Tell();
748 						sal_uInt8  nDummy, nRed, nGreen, nBlue;
749 						sal_uInt16 nChanged;
750 						rSt >> nChanged;
751 						if ( nChanged & 1 )
752 						{
753 							sal_uInt32 nColor = 0;
754 							rSt >> nDummy
755 								>> nRed
756 								>> nDummy
757 								>> nGreen
758 								>> nDummy
759 								>> nBlue
760 								>> nIndex;
761 
762 							if ( nIndex < 8 )
763 							{
764 								Color aColor = MSO_CLR_ToColor( nIndex << 24 );
765 								nRed = aColor.GetRed();
766 								nGreen = aColor.GetGreen();
767 								nBlue = aColor.GetBlue();
768 							}
769 							nColor = nRed | ( nGreen << 8 ) | ( nBlue << 16 );
770 							*pCurrentNew++ = nColor;
771 							rSt >> nDummy
772 								>> nRed
773 								>> nDummy
774 								>> nGreen
775 								>> nDummy
776 								>> nBlue;
777 							nColor = nRed | ( nGreen << 8 ) | ( nBlue << 16 );
778 							*pCurrentOriginal++ = nColor;
779 							(*pCount)++;
780 						}
781 						rSt.Seek( nPos + 44 );
782 					}
783 					pCurrentOriginal = OriginalFillColors;
784 					pCurrentNew = NewFillColors;
785 					pCount = &nFillColorsChanged;
786 					i = nFillColorsCount;
787 				}
788 				if ( nGlobalColorsChanged || nFillColorsChanged )
789 				{
790 					Color* pSearchColors = new Color[ nGlobalColorsChanged ];
791 					Color* pReplaceColors = new Color[ nGlobalColorsChanged ];
792 
793 					for ( j = 0; j < nGlobalColorsChanged; j++ )
794 					{
795 						sal_uInt32 nSearch = OriginalGlobalColors[ j ];
796 						sal_uInt32 nReplace = NewGlobalColors[ j ];
797 
798 						pSearchColors[ j ].SetRed( (sal_uInt8)nSearch );
799 						pSearchColors[ j ].SetGreen( (sal_uInt8)( nSearch >> 8 ) );
800 						pSearchColors[ j ].SetBlue( (sal_uInt8)( nSearch >> 16 ) );
801 
802 						pReplaceColors[ j ].SetRed( (sal_uInt8)nReplace );
803 						pReplaceColors[ j ].SetGreen( (sal_uInt8)( nReplace >> 8 ) );
804 						pReplaceColors[ j ].SetBlue( (sal_uInt8)( nReplace >> 16 ) );
805 					}
806 					GDIMetaFile aGdiMetaFile( rGraphic.GetGDIMetaFile() );
807 					aGdiMetaFile.ReplaceColors( pSearchColors, pReplaceColors,
808 						nGlobalColorsChanged, NULL );
809 					rGraphic = aGdiMetaFile;
810 
811 					delete[] pSearchColors;
812 					delete[] pReplaceColors;
813 				}
814 			}
815 		}
816 	}
817 }
818 
819 /* ProcessObject is called from ImplSdPPTImport::ProcessObj to handle all application specific things,
820    such as the import of text, animation effects, header footer and placeholder.
821 
822    The parameter pOriginalObj is the object as it was imported by our general escher import, it must either
823    be deleted or it can be returned to be inserted into the sdr page.
824 */
ProcessObj(SvStream & rSt,DffObjData & rObjData,void * pData,Rectangle & rTextRect,SdrObject * pOriginalObj)825 SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, void* pData, Rectangle& rTextRect, SdrObject* pOriginalObj )
826 {
827 	if ( pOriginalObj && pOriginalObj->ISA( SdrObjCustomShape ) )
828 		pOriginalObj->SetMergedItem( SdrTextFixedCellHeightItem( sal_True ) );
829 
830 	// we are initializing our return value with the object that was imported by our escher import
831 	SdrObject* pRet = pOriginalObj;
832 
833 	ProcessData& rData = *((ProcessData*)pData);
834 	PptSlidePersistEntry& rPersistEntry = rData.rPersistEntry;
835 
836 	if ( ! ( rObjData.nSpFlags & SP_FGROUP  ) )		// sj: #114758# ...
837 	{
838 		PptOEPlaceholderAtom aPlaceholderAtom;
839 		sal_Int16 nHeaderFooterInstance = -1;
840 
841 		if ( maShapeRecords.SeekToContent( rSt, DFF_msofbtClientData, SEEK_FROM_CURRENT_AND_RESTART ) )
842 		{
843 			DffRecordHeader aClientDataHd;
844 			while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < maShapeRecords.Current()->GetRecEndFilePos() ) )
845 			{
846 				rSt >> aClientDataHd;
847 				switch ( aClientDataHd.nRecType )
848 				{
849 					// importing header/footer object from master page
850 					case PPT_PST_OEPlaceholderAtom :
851 					{
852 						rSt >> aPlaceholderAtom;
853 						if ( nHeaderFooterInstance == -1 )
854 						{
855 							switch ( aPlaceholderAtom.nPlaceholderId )
856 							{
857 								case PPT_PLACEHOLDER_MASTERSLIDENUMBER :	nHeaderFooterInstance++;
858 								case PPT_PLACEHOLDER_MASTERFOOTER :			nHeaderFooterInstance++;
859 								case PPT_PLACEHOLDER_MASTERHEADER :			nHeaderFooterInstance++;
860 								case PPT_PLACEHOLDER_MASTERDATE :			nHeaderFooterInstance++; break;
861 							}
862 							if ( ! ( nHeaderFooterInstance & 0xfffc ) )		// is this a valid instance ( 0->3 )
863 								rPersistEntry.HeaderFooterOfs[ nHeaderFooterInstance ] = rObjData.rSpHd.GetRecBegFilePos();
864 						}
865 					}
866 					break;
867 
868 					case PPT_PST_RecolorInfoAtom :
869 					{
870 						if ( pRet && ( pRet->ISA( SdrGrafObj ) && ((SdrGrafObj*)pRet)->HasGDIMetaFile() ) )
871 						{
872 							Graphic aGraphic( ((SdrGrafObj*)pRet)->GetGraphic() );
873 							RecolorGraphic( rSt, aClientDataHd.nRecLen, aGraphic );
874 							((SdrGrafObj*)pRet)->SetGraphic( aGraphic );
875 						}
876 					}
877 					break;
878 				}
879 				aClientDataHd.SeekToEndOfRecord( rSt );
880 			}
881 		}
882 		if ( ( aPlaceholderAtom.nPlaceholderId == PPT_PLACEHOLDER_NOTESSLIDEIMAGE ) && ( rPersistEntry.bNotesMaster == sal_False ) )
883 		{
884 			sal_uInt16 nPageNum = pSdrModel->GetPageCount();
885 			if ( nPageNum > 0 )
886 				nPageNum--;
887 
888 			// replacing the object which we will return with a SdrPageObj
889 			SdrObject::Free( pRet );
890 			pRet = new SdrPageObj( rObjData.aBoundRect, pSdrModel->GetPage( nPageNum - 1 ) );
891 		}
892 		else
893 		{
894 			// try to load some ppt text
895 			PPTTextObj aTextObj( rSt, (SdrPowerPointImport&)*this, rPersistEntry, &rObjData );
896 			if ( ( aTextObj.Count() || aTextObj.GetOEPlaceHolderAtom() ) )
897 			{
898 				sal_Bool bVerticalText = sal_False;
899 				// and if the text object is not empty, it must be applied to pRet, the object we
900 				// initially got from our escher import
901 				sal_Int32 nTextRotationAngle = 0;
902 				if ( IsProperty( DFF_Prop_txflTextFlow ) )
903 				{
904 					MSO_TextFlow eTextFlow = (MSO_TextFlow)( GetPropertyValue( DFF_Prop_txflTextFlow ) & 0xFFFF );
905 					switch( eTextFlow )
906 					{
907 						case mso_txflBtoT :						// Bottom to Top non-@, unten -> oben
908 							nTextRotationAngle += 9000;
909 						break;
910 						case mso_txflTtoBA :	/* #68110# */	// Top to Bottom @-font, oben -> unten
911 						case mso_txflTtoBN :					// Top to Bottom non-@, oben -> unten
912 						case mso_txflVertN :					// Vertical, non-@, oben -> unten
913 							bVerticalText = !bVerticalText;		// nTextRotationAngle += 27000;
914 						break;
915 	//					case mso_txflHorzN :					// Horizontal non-@, normal
916 	//					case mso_txflHorzA :					// Horizontal @-font, normal
917 						default: break;
918 					}
919 				}
920 				sal_Int32 nFontDirection = GetPropertyValue( DFF_Prop_cdirFont, mso_cdir0 );
921 				nTextRotationAngle -= nFontDirection * 9000;
922 				if ( ( nFontDirection == 1 ) || ( nFontDirection == 3 ) )		// #104546#
923 				{
924 					bVerticalText = !bVerticalText;
925 /*
926 					sal_Int32 nHalfWidth = ( rTextRect.GetWidth() + 1 ) >> 1;
927 					sal_Int32 nHalfHeight = ( rTextRect.GetHeight() + 1 ) >> 1;
928 					Point aTopLeft( rTextRect.Left() + nHalfWidth - nHalfHeight,
929 									rTextRect.Top() + nHalfHeight - nHalfWidth );
930 					Size aNewSize( rTextRect.GetHeight(), rTextRect.GetWidth() );
931 					Rectangle aNewRect( aTopLeft, aNewSize );
932 					rTextRect = aNewRect;
933 */
934 				}
935 				aTextObj.SetVertical( bVerticalText );
936 				if ( pRet )
937 				{
938 					sal_Bool bDeleteSource = aTextObj.GetOEPlaceHolderAtom() != 0;
939 					if ( bDeleteSource  && ( pRet->ISA( SdrGrafObj ) == sal_False )		// we are not allowed to get
940 							&& ( pRet->ISA( SdrObjGroup ) == sal_False )				// grouped placeholder objects
941 								&& ( pRet->ISA( SdrOle2Obj ) == sal_False ) )
942 						SdrObject::Free( pRet );
943 				}
944 				sal_uInt32 nTextFlags = aTextObj.GetTextFlags();
945 				sal_Int32 nTextLeft = GetPropertyValue( DFF_Prop_dxTextLeft, 25 * 3600 );   // 0.25 cm (emu)
946 				sal_Int32 nTextRight = GetPropertyValue( DFF_Prop_dxTextRight, 25 * 3600 ); // 0.25 cm (emu)
947 				sal_Int32 nTextTop = GetPropertyValue( DFF_Prop_dyTextTop, 13 * 3600 );     // 0.13 cm (emu)
948 				sal_Int32 nTextBottom = GetPropertyValue( DFF_Prop_dyTextBottom, 13 * 3600 );
949 				ScaleEmu( nTextLeft );
950 				ScaleEmu( nTextRight );
951 				ScaleEmu( nTextTop );
952 				ScaleEmu( nTextBottom );
953 
954 				sal_Int32	nMinFrameWidth = 0;
955 				sal_Int32	nMinFrameHeight = 0;
956 				sal_Bool	bAutoGrowWidth, bAutoGrowHeight;
957 
958 				SdrTextVertAdjust eTVA;
959 				SdrTextHorzAdjust eTHA;
960 
961 				nTextFlags &= PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT   | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT
962 							| PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK;
963 
964 				if ( bVerticalText )
965 				{
966 					eTVA = SDRTEXTVERTADJUST_BLOCK;
967 					eTHA = SDRTEXTHORZADJUST_CENTER;
968 
969 					// Textverankerung lesen
970 					MSO_Anchor eTextAnchor = (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop );
971 
972 					switch( eTextAnchor )
973 					{
974 						case mso_anchorTop:
975 						case mso_anchorTopCentered:
976 						case mso_anchorTopBaseline:
977 						case mso_anchorTopCenteredBaseline:
978 							eTHA = SDRTEXTHORZADJUST_RIGHT;
979 						break;
980 
981 						case mso_anchorMiddle :
982 						case mso_anchorMiddleCentered:
983 							eTHA = SDRTEXTHORZADJUST_CENTER;
984 						break;
985 
986 						case mso_anchorBottom:
987 						case mso_anchorBottomCentered:
988 						case mso_anchorBottomBaseline:
989 						case mso_anchorBottomCenteredBaseline:
990 							eTHA = SDRTEXTHORZADJUST_LEFT;
991 						break;
992 					}
993 					// if there is a 100% use of following attributes, the textbox can been aligned also in vertical direction
994 					switch ( eTextAnchor )
995 					{
996 						case mso_anchorTopCentered :
997 						case mso_anchorMiddleCentered :
998 						case mso_anchorBottomCentered :
999 						case mso_anchorTopCenteredBaseline:
1000 						case mso_anchorBottomCenteredBaseline:
1001 						{
1002 							// check if it is sensible to use the centered alignment
1003 							sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT;
1004 							if ( ( nTextFlags & nMask ) != nMask )  // if the textobject has left and also right aligned paragraphs
1005 								eTVA = SDRTEXTVERTADJUST_CENTER;    // the text has to be displayed using the full width;
1006 						}
1007 						break;
1008 
1009 						default :
1010 						{
1011 							if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT )
1012 								eTVA = SDRTEXTVERTADJUST_TOP;
1013 							else if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT )
1014 								eTVA = SDRTEXTVERTADJUST_BOTTOM;
1015 						}
1016 						break;
1017 					}
1018 					nMinFrameWidth = rTextRect.GetWidth() - ( nTextLeft + nTextRight );
1019 				}
1020 				else
1021 				{
1022 					eTVA = SDRTEXTVERTADJUST_CENTER;
1023 					eTHA = SDRTEXTHORZADJUST_BLOCK;
1024 
1025 					// Textverankerung lesen
1026 					MSO_Anchor eTextAnchor = (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop );
1027 
1028 					switch( eTextAnchor )
1029 					{
1030 						case mso_anchorTop:
1031 						case mso_anchorTopCentered:
1032 						case mso_anchorTopBaseline:
1033 						case mso_anchorTopCenteredBaseline:
1034 							eTVA = SDRTEXTVERTADJUST_TOP;
1035 						break;
1036 
1037 						case mso_anchorMiddle :
1038 						case mso_anchorMiddleCentered:
1039 							eTVA = SDRTEXTVERTADJUST_CENTER;
1040 						break;
1041 
1042 						case mso_anchorBottom:
1043 						case mso_anchorBottomCentered:
1044 						case mso_anchorBottomBaseline:
1045 						case mso_anchorBottomCenteredBaseline:
1046 							eTVA = SDRTEXTVERTADJUST_BOTTOM;
1047 						break;
1048 					}
1049 					// if there is a 100% usage of following attributes, the textbox can be aligned also in horizontal direction
1050 					switch ( eTextAnchor )
1051 					{
1052 						case mso_anchorTopCentered :
1053 						case mso_anchorMiddleCentered :
1054 						case mso_anchorBottomCentered :
1055 						case mso_anchorTopCenteredBaseline:
1056 						case mso_anchorBottomCenteredBaseline:
1057 						{
1058 							// check if it is sensible to use the centered alignment
1059 							sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT;
1060 							if ( ( nTextFlags & nMask ) != nMask )  // if the textobject has left and also right aligned paragraphs
1061 								eTHA = SDRTEXTHORZADJUST_CENTER;    // the text has to be displayed using the full width;
1062 						}
1063 						break;
1064 
1065 						default :
1066 						{
1067 							if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT )
1068 								eTHA = SDRTEXTHORZADJUST_LEFT;
1069 							else if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT )
1070 								eTHA = SDRTEXTHORZADJUST_RIGHT;
1071 						}
1072 						break;
1073 					}
1074 					nMinFrameHeight = rTextRect.GetHeight() - ( nTextTop + nTextBottom );
1075 				}
1076 
1077 				SdrObjKind eTextKind = OBJ_RECT;
1078 				if ( ( aPlaceholderAtom.nPlaceholderId == PPT_PLACEHOLDER_NOTESSLIDEIMAGE )
1079 					|| ( aPlaceholderAtom.nPlaceholderId == PPT_PLACEHOLDER_MASTERNOTESSLIDEIMAGE ) )
1080 				{
1081 					aTextObj.SetInstance( 2 );
1082 					eTextKind = OBJ_TITLETEXT;
1083 				}
1084 				else if ( ( aPlaceholderAtom.nPlaceholderId == PPT_PLACEHOLDER_MASTERNOTESBODYIMAGE )
1085 					|| ( aPlaceholderAtom.nPlaceholderId == PPT_PLACEHOLDER_NOTESBODY ) )
1086 				{
1087 					aTextObj.SetInstance( 2 );
1088 					eTextKind = OBJ_TEXT;
1089 				}
1090 
1091 				sal_uInt32 nDestinationInstance = aTextObj.GetInstance();
1092 				if ( rPersistEntry.ePageKind == PPT_MASTERPAGE )
1093 				{
1094 					if ( !rPersistEntry.pPresentationObjects )
1095 					{
1096 						rPersistEntry.pPresentationObjects = new sal_uInt32[ PPT_STYLESHEETENTRYS ];
1097 						memset( rPersistEntry.pPresentationObjects, 0, PPT_STYLESHEETENTRYS * 4 );
1098 					}
1099 					if ( !rPersistEntry.pPresentationObjects[ nDestinationInstance ] )
1100 						rPersistEntry.pPresentationObjects[ nDestinationInstance ] = rObjData.rSpHd.GetRecBegFilePos();
1101 				}
1102 				switch ( nDestinationInstance )
1103 				{
1104 					case TSS_TYPE_PAGETITLE :
1105 					case TSS_TYPE_TITLE	:
1106 					{
1107 						if ( GetSlideLayoutAtom()->eLayout == PPT_LAYOUT_TITLEMASTERSLIDE )
1108 							nDestinationInstance = TSS_TYPE_TITLE;
1109 						else
1110 							nDestinationInstance = TSS_TYPE_PAGETITLE;
1111 					}
1112 					break;
1113 					case TSS_TYPE_BODY :
1114 	//				case TSS_TYPE_SUBTITLE :
1115 					case TSS_TYPE_HALFBODY :
1116 					case TSS_TYPE_QUARTERBODY :
1117 						nDestinationInstance = TSS_TYPE_BODY;
1118 					break;
1119 				}
1120 				aTextObj.SetDestinationInstance( (sal_uInt16)nDestinationInstance );
1121 
1122 				switch ( aTextObj.GetInstance() )
1123 				{
1124 					case TSS_TYPE_PAGETITLE :
1125 					case TSS_TYPE_TITLE	: eTextKind = OBJ_TITLETEXT; break;
1126 					case TSS_TYPE_SUBTITLE : eTextKind = OBJ_TEXT; break;
1127 					case TSS_TYPE_BODY :
1128 					case TSS_TYPE_HALFBODY :
1129 					case TSS_TYPE_QUARTERBODY : eTextKind = OBJ_OUTLINETEXT; break;
1130 				}
1131 				if ( aTextObj.GetDestinationInstance() != TSS_TYPE_TEXT_IN_SHAPE )
1132 				{
1133 					if ( !aTextObj.GetOEPlaceHolderAtom() || !aTextObj.GetOEPlaceHolderAtom()->nPlaceholderId )
1134 					{
1135 						aTextObj.SetDestinationInstance( TSS_TYPE_TEXT_IN_SHAPE );
1136 						eTextKind = OBJ_RECT;
1137 					}
1138 				}
1139 				SdrObject* pTObj = NULL;
1140 				sal_Bool bWordWrap = (MSO_WrapMode)GetPropertyValue( DFF_Prop_WrapText, mso_wrapSquare ) != mso_wrapNone;
1141 				sal_Bool bFitShapeToText = ( GetPropertyValue( DFF_Prop_FitTextToShape ) & 2 ) != 0;
1142 
1143 				if ( pRet && pRet->ISA( SdrObjCustomShape ) && ( eTextKind == OBJ_RECT ) )
1144 				{
1145 					bAutoGrowHeight = bFitShapeToText;
1146 					if ( bWordWrap )
1147 						bAutoGrowWidth = sal_False;
1148 					else
1149 						bAutoGrowWidth = sal_True;
1150 					pTObj = pRet;
1151 					pRet = NULL;
1152 				}
1153 				else
1154 				{
1155 					if ( pRet && pRet->ISA( SdrObjCustomShape ) )
1156 					{
1157 						SdrObject::Free( pRet );
1158 						pRet = NULL;
1159 					}
1160 					pTObj = new SdrRectObj( eTextKind != OBJ_RECT ? eTextKind : OBJ_TEXT );
1161 					pTObj->SetModel( pSdrModel );
1162 					SfxItemSet aSet( pSdrModel->GetItemPool() );
1163 					if ( !pRet )
1164 						((SdrEscherImport*)this)->ApplyAttributes( rSt, aSet, rObjData );
1165 					pTObj->SetMergedItemSet( aSet );
1166 					if ( pRet )
1167 					{
1168 						pTObj->SetMergedItem( XLineStyleItem( XLINE_NONE ) );
1169 						pTObj->SetMergedItem( XFillStyleItem( XFILL_NONE ) );
1170 					}
1171 					if ( bVerticalText )
1172 					{
1173 						bAutoGrowWidth = bFitShapeToText;
1174 						bAutoGrowHeight = sal_False;
1175 					}
1176 					else
1177 					{
1178 						bAutoGrowWidth = sal_False;
1179 
1180 						// #119885# re-activationg bFitShapeToText here, could not find deeper explanations
1181 						// for it (it was from 2005). Keeping the old comment here for reference
1182 						// old comment: // bFitShapeToText;	can't be used, because we cut the text if it is too height,
1183 						bAutoGrowHeight = bFitShapeToText;
1184 					}
1185 				}
1186 				pTObj->SetMergedItem( SvxFrameDirectionItem( bVerticalText ? FRMDIR_VERT_TOP_RIGHT : FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
1187 
1188 			if ( !pTObj->ISA( SdrObjCustomShape ) )
1189 			{
1190 		 		pTObj->SetMergedItem( SdrTextAutoGrowWidthItem( bAutoGrowWidth ) );
1191 				pTObj->SetMergedItem( SdrTextAutoGrowHeightItem( bAutoGrowHeight ) );
1192 			}
1193 			else
1194 			{
1195 				pTObj->SetMergedItem( SdrTextWordWrapItem( bWordWrap ) );
1196 				pTObj->SetMergedItem( SdrTextAutoGrowHeightItem( bFitShapeToText ) );
1197 			}
1198 
1199 				pTObj->SetMergedItem( SdrTextVertAdjustItem( eTVA ) );
1200 				pTObj->SetMergedItem( SdrTextHorzAdjustItem( eTHA ) );
1201 
1202 				if ( nMinFrameHeight < 0 )
1203 					nMinFrameHeight = 0;
1204 			if ( !pTObj->ISA( SdrObjCustomShape ) )
1205 				pTObj->SetMergedItem( SdrTextMinFrameHeightItem( nMinFrameHeight ) );
1206 
1207 				if ( nMinFrameWidth < 0 )
1208 					nMinFrameWidth = 0;
1209 			if ( !pTObj->ISA( SdrObjCustomShape ) )
1210 				pTObj->SetMergedItem( SdrTextMinFrameWidthItem( nMinFrameWidth ) );
1211 
1212 				// Abstaende an den Raendern der Textbox setzen
1213 				pTObj->SetMergedItem( SdrTextLeftDistItem( nTextLeft ) );
1214 				pTObj->SetMergedItem( SdrTextRightDistItem( nTextRight ) );
1215 				pTObj->SetMergedItem( SdrTextUpperDistItem( nTextTop ) );
1216 				pTObj->SetMergedItem( SdrTextLowerDistItem( nTextBottom ) );
1217 				pTObj->SetMergedItem( SdrTextFixedCellHeightItem( sal_True ) );
1218 
1219 				if ( !pTObj->ISA( SdrObjCustomShape ) )
1220 					pTObj->SetSnapRect( rTextRect );
1221 				pTObj = ReadObjText( &aTextObj, pTObj, rData.pPage );
1222 				if ( pTObj )
1223 				{
1224 					/* check if our new snaprect makes trouble,
1225 					because we do not display the ADJUST_BLOCK
1226 					properly if the textsize is bigger than the
1227 					snaprect of the object. Then we will use
1228 					ADJUST_CENTER instead of ADJUST_BLOCK.
1229 					*/
1230 					if ( !pTObj->ISA( SdrObjCustomShape ) && !bFitShapeToText && !bWordWrap )
1231 					{
1232 						SdrTextObj* pText = PTR_CAST( SdrTextObj, pTObj );
1233 						if ( pText )
1234 						{
1235 							if ( bVerticalText )
1236 							{
1237 								if ( eTVA == SDRTEXTVERTADJUST_BLOCK )
1238 								{
1239 									Size aTextSize( pText->GetTextSize() );
1240 									aTextSize.Width() += nTextLeft + nTextRight;
1241 									aTextSize.Height() += nTextTop + nTextBottom;
1242 									if ( rTextRect.GetHeight() < aTextSize.Height() )
1243 										pTObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
1244 								}
1245 							}
1246 							else
1247 							{
1248 								if ( eTHA == SDRTEXTHORZADJUST_BLOCK )
1249 								{
1250 									Size aTextSize( pText->GetTextSize() );
1251 									aTextSize.Width() += nTextLeft + nTextRight;
1252 									aTextSize.Height() += nTextTop + nTextBottom;
1253 									if ( rTextRect.GetWidth() < aTextSize.Width() )
1254 										pTObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_CENTER ) );
1255 								}
1256 							}
1257 						}
1258 					}
1259 					// rotate text with shape ?
1260 					sal_Int32 nAngle = ( rObjData.nSpFlags & SP_FFLIPV ) ? -mnFix16Angle : mnFix16Angle;	// #72116# vertical flip -> rotate by using the other way
1261 					nAngle += nTextRotationAngle;
1262 
1263 					if ( pTObj->ISA( SdrObjCustomShape ) )
1264 					{
1265 /*
1266 						if ( nTextRotationAngle )
1267 						{
1268 							double fTextRotateAngle = (double)nTextRotationAngle / 100.0;
1269 							SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)((SdrObjCustomShape*)pTObj)->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1270 							const rtl::OUString sTextRotateAngle( RTL_CONSTASCII_USTRINGPARAM ( "TextRotateAngle" ) );
1271 							PropertyValue aPropValue;
1272 							aPropValue.Name = sTextRotateAngle;
1273 							aPropValue.Value <<= fTextRotateAngle;
1274 							aGeometryItem.SetPropertyValue( aPropValue );
1275 							((SdrObjCustomShape*)pTObj)->SetMergedItem( aGeometryItem );
1276 						}
1277 */
1278 					}
1279 					else
1280 					{
1281 						if ( rObjData.nSpFlags & SP_FFLIPV )
1282 						{
1283 							double a = 18000 * nPi180;
1284 							pTObj->Rotate( rTextRect.Center(), 18000, sin( a ), cos( a ) );
1285 						}
1286 						if ( rObjData.nSpFlags & SP_FFLIPH )
1287 							nAngle = 36000 - nAngle;
1288 						if ( nAngle )
1289 						{
1290 							double a = nAngle * nPi180;
1291 							pTObj->NbcRotate( rObjData.aBoundRect.Center(), nAngle, sin( a ), cos( a ) );
1292 						}
1293 					}
1294 					if ( pRet )
1295 					{
1296 						SdrObject* pGroup = new SdrObjGroup;
1297 						pGroup->GetSubList()->NbcInsertObject( pRet );
1298 						pGroup->GetSubList()->NbcInsertObject( pTObj );
1299 						pRet = pGroup;
1300 					}
1301 					else
1302 						pRet = pTObj;
1303 				}
1304 			}
1305 		}
1306 	}
1307 	else
1308 	{
1309 		if ( maShapeRecords.SeekToContent( rSt, DFF_msofbtUDefProp, SEEK_FROM_CURRENT_AND_RESTART ) )
1310 		{
1311 			maShapeRecords.Current()->SeekToBegOfRecord( rSt );
1312 			DffPropertyReader aSecPropSet( *this );
1313 			aSecPropSet.ReadPropSet( rSt, (ProcessData*)pData );
1314 			sal_Int32 nTableProperties = aSecPropSet.GetPropertyValue( DFF_Prop_tableProperties, 0 );
1315 			if ( nTableProperties & 3 )
1316 			{
1317 				if ( aSecPropSet.SeekToContent( DFF_Prop_tableRowProperties, rSt ) )
1318 				{
1319 					sal_Int16 i, nRowCount = 0;
1320 					rSt >> nRowCount >> i >> i;
1321 					if ( nRowCount )
1322 					{
1323 						sal_uInt32* pTableArry = new sal_uInt32[ nRowCount + 2 ];
1324 						pTableArry[ 0 ] = nTableProperties;
1325 						pTableArry[ 1 ] = nRowCount;
1326 						for ( i = 0; i < nRowCount; i++ )
1327 							rSt >> pTableArry[ i + 2 ];
1328 						rData.pTableRowProperties = pTableArry;
1329 					}
1330 				}
1331 			}
1332 		}
1333 	}
1334 	if ( pRet )	// sj: #i38501#, and and taking care of connections to group objects
1335 	{
1336 		if ( rObjData.nSpFlags & SP_FBACKGROUND )
1337 		{
1338 			pRet->NbcSetSnapRect( Rectangle( Point(), ((SdrPage*)rData.pPage)->GetSize() ) );	// Groesse setzen
1339 		}
1340 		if ( rPersistEntry.pSolverContainer )
1341 		{
1342 			for ( SvxMSDffConnectorRule* pPtr = (SvxMSDffConnectorRule*)rPersistEntry.pSolverContainer->aCList.First();
1343 				pPtr; pPtr = (SvxMSDffConnectorRule*)rPersistEntry.pSolverContainer->aCList.Next() )
1344 			{
1345 				if ( rObjData.nShapeId == pPtr->nShapeC )
1346 					pPtr->pCObj = pRet;
1347 				else
1348 				{
1349 					SdrObject* pConnectObj = pRet;
1350 					if ( pOriginalObj && pRet->ISA( SdrObjGroup ) )
1351 					{	/* check if the original object from the escherimport is part of the group object,
1352 						if this is the case, we will use the original object to connect to */
1353 						SdrObjListIter aIter( *pRet, IM_DEEPWITHGROUPS );
1354 						while( aIter.IsMore() )
1355 						{
1356 							SdrObject* pPartObj = aIter.Next();
1357 							if ( pPartObj == pOriginalObj )
1358 							{
1359 								pConnectObj = pPartObj;
1360 								break;
1361 							}
1362 						}
1363 					}
1364 					if ( rObjData.nShapeId == pPtr->nShapeA )
1365 					{
1366 						pPtr->pAObj = pConnectObj;
1367 						pPtr->nSpFlagsA = rObjData.nSpFlags;
1368 					}
1369 					if ( rObjData.nShapeId == pPtr->nShapeB )
1370 					{
1371 						pPtr->pBObj = pConnectObj;
1372 						pPtr->nSpFlagsB = rObjData.nSpFlags;
1373 					}
1374 				}
1375 			}
1376 		}
1377 		if ( rPersistEntry.ePageKind == PPT_MASTERPAGE )
1378 		{	// maybe the escher clusterlist is not correct, but we have to got the right page by using the
1379 			// spMaster property, so we are patching the table
1380 			if ( rPersistEntry.nDrawingDgId != 0xffffffff )
1381 			{
1382 				sal_uInt32 nSec = ( rObjData.nShapeId >> 10 ) - 1;
1383 				if ( mpFidcls && ( nSec < mnIdClusters ) )
1384 					mpFidcls[ nSec ].dgid = rPersistEntry.nDrawingDgId;	// insert the correct drawing id;
1385 			}
1386 		}
1387 		if ( GetPropertyValue( DFF_Prop_fNoFillHitTest ) & 0x10 )
1388 		{
1389 			if ( (MSO_FillType)GetPropertyValue( DFF_Prop_fillType, mso_fillSolid ) == mso_fillBackground )
1390 			{
1391 				if ( !rData.pBackgroundColoredObjects )
1392 					rData.pBackgroundColoredObjects = new List;
1393 				rData.pBackgroundColoredObjects->Insert( pRet, LIST_APPEND );
1394 			}
1395 		}
1396 	}
1397 	return pRet;
1398 }
1399 
1400 ////////////////////////////////////////////////////////////////////////////////////////////////////
1401 
CheckWingdings() const1402 void SdrEscherImport::CheckWingdings() const
1403 {
1404 	OutputDevice* pDev = (OutputDevice*)Application::GetDefaultDevice();
1405 	((SdrEscherImport*)this)->bWingdingsAvailable = pDev->IsFontAvailable( String( RTL_CONSTASCII_USTRINGPARAM( "WINGDINGS" ) ) );
1406 	((SdrEscherImport*)this)->bWingdingsChecked = sal_True;
1407 }
1408 
CheckMonotypeSorts() const1409 void SdrEscherImport::CheckMonotypeSorts() const
1410 {
1411 	OutputDevice* pDev = (OutputDevice*)Application::GetDefaultDevice();
1412 	((SdrEscherImport*)this)->bMonotypeSortsAvailable = pDev->IsFontAvailable( String( RTL_CONSTASCII_USTRINGPARAM( "MONOTYPE SORTS" ) ) );
1413 	((SdrEscherImport*)this)->bMonotypeSortsChecked = sal_True;
1414 }
1415 
CheckTimesNewRoman() const1416 void SdrEscherImport::CheckTimesNewRoman() const
1417 {
1418 	OutputDevice* pDev = (OutputDevice*)Application::GetDefaultDevice();
1419 	((SdrEscherImport*)this)->bTimesNewRomanAvailable = pDev->IsFontAvailable( String( RTL_CONSTASCII_USTRINGPARAM( "TIMES NEW ROMAN" ) ) );
1420 	((SdrEscherImport*)this)->bTimesNewRomanChecked = sal_True;
1421 }
1422 
1423 ////////////////////////////////////////////////////////////////////////////////////////////////////
1424 ////////////////////////////////////////////////////////////////////////////////////////////////////
1425 ////////////////////////////////////////////////////////////////////////////////////////////////////
1426 
SdrPowerPointImport(PowerPointImportParam & rParam,const String & rBaseURL)1427 SdrPowerPointImport::SdrPowerPointImport( PowerPointImportParam& rParam, const String& rBaseURL ) :
1428 	SdrEscherImport		( rParam, rBaseURL ),
1429 	bOk					( rStCtrl.GetErrorCode() == SVSTREAM_OK ),
1430 	pPersistPtr			( NULL ),
1431 	nPersistPtrAnz		( 0 ),
1432 	pDefaultSheet		( NULL ),
1433 	pMasterPages		( NULL ),
1434 	pSlidePages			( NULL ),
1435 	pNotePages			( NULL ),
1436 	nAktPageNum			( 0 ),
1437 	nDocStreamPos		( 0 ),
1438 	nPageColorsNum		( 0xFFFF ),
1439 	ePageColorsKind		( PPT_MASTERPAGE ),
1440 	eAktPageKind		( PPT_MASTERPAGE )
1441 {
1442 	DffRecordHeader* pHd;
1443 	if ( bOk )
1444 	{
1445 		rStCtrl.Seek( STREAM_SEEK_TO_END );
1446 		nStreamLen = rStCtrl.Tell();
1447 
1448 		// try to allocate the UserEditAtom via CurrentUserAtom
1449 		sal_uInt32 nCurrentUserEdit = rParam.aCurrentUserAtom.nCurrentUserEdit;
1450 		if ( nCurrentUserEdit )
1451 		{
1452 			rStCtrl.Seek( nCurrentUserEdit );
1453 			rStCtrl >> aUserEditAtom;
1454 		}
1455 		if ( !aUserEditAtom.nOffsetPersistDirectory )
1456 		{	// if there is no UserEditAtom try to search the last one
1457 
1458 			rStCtrl.Seek( 0 );
1459 			DffRecordManager aPptRecManager;							// contains all first level container and atoms
1460 			aPptRecManager.Consume( rStCtrl, sal_False, nStreamLen );
1461 			for ( pHd = aPptRecManager.Last(); pHd; pHd = aPptRecManager.Prev() )
1462 			{
1463 				if ( pHd->nRecType == PPT_PST_UserEditAtom )
1464 				{
1465 					pHd->SeekToBegOfRecord( rStCtrl );
1466 					rStCtrl >> aUserEditAtom;
1467 					break;
1468 				}
1469 			}
1470 			if ( !pHd )
1471 				bOk = sal_False;
1472 		}
1473 	}
1474 	if ( rStCtrl.GetError() != 0 )
1475 		bOk = sal_False;
1476 
1477 	if ( bOk )
1478 	{
1479 		nPersistPtrAnz = aUserEditAtom.nMaxPersistWritten + 1;
1480 		if ( ( nPersistPtrAnz >> 2 ) > nStreamLen )		// sj: at least nPersistPtrAnz is not allowed to be greater than filesize
1481 			bOk = sal_False;								// (it should not be greater than the PPT_PST_PersistPtrIncrementalBlock, but
1482 														// we are reading this block later, so we do not have access yet)
1483 
1484 		if ( bOk && ( nPersistPtrAnz < ( SAL_MAX_UINT32 / sizeof( sal_uInt32 ) ) ) )
1485 			pPersistPtr = new (std::nothrow) sal_uInt32[ nPersistPtrAnz ];
1486 		if ( !pPersistPtr )
1487 			bOk = sal_False;
1488 		if ( bOk )
1489 		{
1490 			memset( pPersistPtr, 0x00, nPersistPtrAnz * 4 );
1491 
1492 			// SJ: new search mechanism from bottom to top (Issue 21122)
1493 			PptUserEditAtom aCurrentEditAtom( aUserEditAtom );
1494 			sal_uInt32 nCurrentEditAtomStrmPos = aCurrentEditAtom.aHd.GetRecEndFilePos();
1495 			while( nCurrentEditAtomStrmPos )
1496 			{
1497 				sal_uInt32 nPersistIncPos = aCurrentEditAtom.nOffsetPersistDirectory;
1498 				if ( nPersistIncPos )
1499 				{
1500 					rStCtrl.Seek( nPersistIncPos );
1501 					DffRecordHeader aPersistHd;
1502 					rStCtrl >> aPersistHd;
1503 					if ( aPersistHd.nRecType == PPT_PST_PersistPtrIncrementalBlock )
1504 					{
1505 						sal_uLong nPibLen = aPersistHd.GetRecEndFilePos();
1506 						while ( bOk && ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < nPibLen ) )
1507 						{
1508 							sal_uInt32 nOfs, nAnz;
1509 							rStCtrl >> nOfs;
1510 							nAnz = nOfs;
1511 							nOfs &= 0x000FFFFF;
1512 							nAnz >>= 20;
1513 							while ( bOk && ( rStCtrl.GetError() == 0 ) && ( nAnz > 0 ) && ( nOfs <= nPersistPtrAnz ) )
1514 							{
1515 								sal_uInt32 nPt;
1516 								rStCtrl >> nPt;
1517 								if ( !pPersistPtr[ nOfs ] )
1518 								{
1519 									pPersistPtr[ nOfs ] = nPt;
1520 									if ( pPersistPtr[ nOfs ] > nStreamLen )
1521 									{
1522 										bOk = sal_False;
1523 										DBG_ERROR("SdrPowerPointImport::Ctor(): Ungueltiger Eintrag im Persist-Directory!");
1524 									}
1525 								}
1526 								nAnz--;
1527 								nOfs++;
1528 							}
1529 							if ( bOk && nAnz > 0 )
1530 							{
1531 								DBG_ERROR("SdrPowerPointImport::Ctor(): Nicht alle Persist-Directory Entraege gelesen!");
1532 								bOk = sal_False;
1533 							}
1534 						}
1535 					}
1536 				}
1537 				nCurrentEditAtomStrmPos = aCurrentEditAtom.nOffsetLastEdit < nCurrentEditAtomStrmPos ? aCurrentEditAtom.nOffsetLastEdit : 0;
1538 				if ( nCurrentEditAtomStrmPos )
1539 				{
1540 					rStCtrl.Seek( nCurrentEditAtomStrmPos );
1541 					rStCtrl >> aCurrentEditAtom;
1542 				}
1543 			}
1544 		}
1545 	}
1546 	if ( rStCtrl.GetError() != 0 )
1547 		bOk = sal_False;
1548 	if ( bOk )
1549 	{	// Document PersistEntry checken
1550 		nDocStreamPos = aUserEditAtom.nDocumentRef;
1551 		if ( nDocStreamPos > nPersistPtrAnz )
1552 		{
1553 			DBG_ERROR("SdrPowerPointImport::Ctor(): aUserEditAtom.nDocumentRef ungueltig!");
1554 			bOk = sal_False;
1555 		}
1556 	}
1557 	if ( bOk )
1558 	{	// Document FilePos checken
1559 		nDocStreamPos = pPersistPtr[ nDocStreamPos ];
1560 		if ( nDocStreamPos >= nStreamLen )
1561 		{
1562 			DBG_ERROR("SdrPowerPointImport::Ctor(): nDocStreamPos >= nStreamLen!");
1563 			bOk = sal_False;
1564 		}
1565 	}
1566 	if ( bOk )
1567 	{
1568 		rStCtrl.Seek( nDocStreamPos );
1569 		aDocRecManager.Consume( rStCtrl );
1570 
1571 		DffRecordHeader aDocHd;
1572 		rStCtrl >> aDocHd;
1573 		// DocumentAtom lesen
1574 		DffRecordHeader aDocAtomHd;
1575 		rStCtrl >> aDocAtomHd;
1576 		if ( aDocHd.nRecType == PPT_PST_Document && aDocAtomHd.nRecType == PPT_PST_DocumentAtom )
1577 		{
1578 			aDocAtomHd.SeekToBegOfRecord( rStCtrl );
1579 			rStCtrl >> aDocAtom;
1580 		}
1581 		else
1582 			bOk = sal_False;
1583 
1584 		if ( bOk )
1585 		{
1586 			if ( !pFonts )
1587 				ReadFontCollection();
1588 
1589 			// reading TxPF, TxSI
1590 			PPTTextCharacterStyleAtomInterpreter	aTxCFStyle;	// SJ: ToDo, this atom needs to be interpreted, it contains character default styles for standard objects (instance4)
1591             PPTTextParagraphStyleAtomInterpreter    aTxPFStyle;
1592 			PPTTextSpecInfoAtomInterpreter          aTxSIStyle; // styles (default language setting ... )
1593 
1594 			DffRecordHeader* pEnvHd = aDocRecManager.GetRecordHeader( PPT_PST_Environment );
1595 			if ( pEnvHd )
1596 			{
1597 				pEnvHd->SeekToContent( rStCtrl );
1598                 DffRecordHeader aTxPFStyleRecHd;
1599                 if ( SeekToRec( rStCtrl, PPT_PST_TxPFStyleAtom, pEnvHd->GetRecEndFilePos(), &aTxPFStyleRecHd ) )
1600                     aTxPFStyle.Read( rStCtrl, aTxPFStyleRecHd );
1601 
1602 				pEnvHd->SeekToContent( rStCtrl );
1603 				DffRecordHeader aTxSIStyleRecHd;
1604 				if ( SeekToRec( rStCtrl, PPT_PST_TxSIStyleAtom, pEnvHd->GetRecEndFilePos(), &aTxSIStyleRecHd ) )
1605                 {
1606 					aTxSIStyle.Read( rStCtrl, aTxSIStyleRecHd, PPT_PST_TxSIStyleAtom );
1607 #ifdef DBG_UTIL
1608                     if ( !aTxSIStyle.bValid )
1609                     {
1610                         if (!(rImportParam.nImportFlags & PPT_IMPORTFLAGS_NO_TEXT_ASSERT ))
1611                         {
1612     		                DBG_ERROR( "SdrTextSpecInfoAtomInterpreter::Ctor(): parsing error, this document needs to be analysed (SJ)" );
1613                         }
1614                     }
1615 #endif
1616                 }
1617 			}
1618 
1619             // todo:: PPT_PST_TxPFStyleAtom
1620 
1621             // SlidePersists Lesen
1622             pMasterPages=new PptSlidePersistList;
1623             pSlidePages =new PptSlidePersistList;
1624             pNotePages  =new PptSlidePersistList;
1625 
1626 			// now always creating the handout page, it will be the first in our masterpage list
1627             PptSlidePersistEntry* pE = new PptSlidePersistEntry;
1628             pE->aPersistAtom.nPsrReference = aDocAtom.nHandoutMasterPersist;
1629 			pE->bHandoutMaster = sal_True;
1630             if ( !aDocAtom.nHandoutMasterPersist )
1631 				pE->bStarDrawFiller = sal_True;		// this is a dummy master page
1632 			pMasterPages->C40_INSERT( PptSlidePersistEntry, pE, 0 );
1633 
1634             sal_uInt16 nPageListNum = 0;
1635 			DffRecordHeader* pSlideListWithTextHd = aDocRecManager.GetRecordHeader( PPT_PST_SlideListWithText );
1636 			PptSlidePersistEntry* pPreviousPersist = NULL;
1637 			while ( pSlideListWithTextHd && ( nPageListNum < 3 ) )
1638 			{
1639 				pSlideListWithTextHd->SeekToContent( rStCtrl );
1640                 PptSlidePersistList* pPageList = GetPageList( PptPageKind( nPageListNum ) );
1641 				sal_uInt32 nSlideListWithTextHdEndOffset = pSlideListWithTextHd->GetRecEndFilePos();
1642 				while ( SeekToRec( rStCtrl, PPT_PST_SlidePersistAtom, nSlideListWithTextHdEndOffset ) )
1643 				{
1644 					if ( pPreviousPersist )
1645 						pPreviousPersist->nSlidePersistEndOffset = rStCtrl.Tell();
1646 					PptSlidePersistEntry* pE2 = new PptSlidePersistEntry;
1647 					rStCtrl >> pE2->aPersistAtom;
1648 					pE2->nSlidePersistStartOffset = rStCtrl.Tell();
1649 					pE2->ePageKind = PptPageKind( nPageListNum );
1650 					pPageList->C40_INSERT( PptSlidePersistEntry, pE2, pPageList->Count() );
1651 					pPreviousPersist = pE2;
1652 				}
1653 				if ( pPreviousPersist )
1654 					pPreviousPersist->nSlidePersistEndOffset = nSlideListWithTextHdEndOffset;
1655 				pSlideListWithTextHd = aDocRecManager.GetRecordHeader( PPT_PST_SlideListWithText, SEEK_FROM_CURRENT );
1656 				nPageListNum++;
1657 			}
1658 
1659 			// we will ensure that there is at least one master page
1660 			if ( pMasterPages->Count() == 1 )	// -> there is only a handout page available
1661 			{
1662 				PptSlidePersistEntry* pE2 = new PptSlidePersistEntry;
1663 				pE2->bStarDrawFiller = sal_True;			// this is a dummy master page
1664 				pMasterPages->C40_INSERT( PptSlidePersistEntry, pE2, 1 );
1665 			}
1666 
1667 			// now we will insert at least one notes master for each master page
1668 			sal_uInt16 nMasterPage;
1669 			sal_uInt16 nMasterPages = pMasterPages->Count() - 1;
1670 			for ( nMasterPage = 0; nMasterPage < nMasterPages; nMasterPage++ )
1671 			{
1672 				PptSlidePersistEntry* pE2 = new PptSlidePersistEntry;
1673 				pE2->bNotesMaster = sal_True;
1674 				pE2->bStarDrawFiller = sal_True;			// this is a dummy master page
1675 				if ( !nMasterPage && aDocAtom.nNotesMasterPersist )
1676 				{	// special treatment for the first notes master
1677 					pE2->aPersistAtom.nPsrReference = aDocAtom.nNotesMasterPersist;
1678 					pE2->bStarDrawFiller = sal_False;	// this is a dummy master page
1679 				}
1680 				pMasterPages->C40_INSERT( PptSlidePersistEntry, pE2, ( nMasterPage + 1 ) << 1 );
1681 			}
1682 
1683             // Zu jeder Page noch das SlideAtom bzw. NotesAtom lesen, soweit vorhanden
1684             nPageListNum = 0;
1685             for ( nPageListNum = 0; nPageListNum < 3; nPageListNum++ )
1686 			{
1687                 PptSlidePersistList* pPageList = GetPageList( PptPageKind( nPageListNum ) );
1688                 for ( sal_uInt16 nPageNum = 0; nPageNum < pPageList->Count(); nPageNum++ )
1689 				{
1690                     PptSlidePersistEntry* pE2 = (*pPageList)[ nPageNum ];
1691                     sal_uLong nPersist = pE2->aPersistAtom.nPsrReference;
1692                     if ( ( nPersist > 0 ) && ( nPersist < nPersistPtrAnz ) )
1693 					{
1694                         sal_uLong nFPos = pPersistPtr[ nPersist ];
1695                         if ( nFPos < nStreamLen )
1696 						{
1697 							rStCtrl.Seek( nFPos );
1698 							DffRecordHeader aSlideHd;
1699 							rStCtrl >> aSlideHd;
1700 							if ( SeekToRec( rStCtrl, PPT_PST_SlideAtom, aSlideHd.GetRecEndFilePos() ) )
1701 								rStCtrl >> pE2->aSlideAtom;
1702 							else if ( SeekToRec( rStCtrl, PPT_PST_NotesAtom, aSlideHd.GetRecEndFilePos() ) )
1703 								rStCtrl >> pE2->aNotesAtom;
1704 							aSlideHd.SeekToContent( rStCtrl );
1705 
1706 							DffRecordHeader aPPTDrawingHd;
1707 							if ( SeekToRec( rStCtrl, PPT_PST_PPDrawing, aSlideHd.GetRecEndFilePos(), &aPPTDrawingHd ) )
1708 							{
1709 								DffRecordHeader aPPTDgContainer;
1710 								if ( SeekToRec( rStCtrl, DFF_msofbtDgContainer, aPPTDrawingHd.GetRecEndFilePos(), &aPPTDgContainer ) )
1711 								{
1712 									if ( SeekToRec( rStCtrl, DFF_msofbtDg, aPPTDrawingHd.GetRecEndFilePos() ) )
1713 									{
1714 										DffRecordHeader aDgRecordHeader;
1715 										rStCtrl >> aDgRecordHeader;
1716 										pE2->nDrawingDgId = aDgRecordHeader.nRecInstance;
1717 										aDgRecordHeader.SeekToEndOfRecord( rStCtrl );
1718 									}
1719 									if ( SeekToRec( rStCtrl, DFF_msofbtSolverContainer, aPPTDgContainer.GetRecEndFilePos() ) )
1720 									{
1721 										pE2->pSolverContainer = new SvxMSDffSolverContainer;
1722 										rStCtrl >> *( pE2->pSolverContainer );
1723 									}
1724 									aPPTDgContainer.SeekToBegOfRecord( rStCtrl );
1725 									SetDgContainer( rStCtrl );	// set this, so that the escherimport is knowing of our drawings
1726 								}
1727 							}
1728                     		// office xp is supporting more than one stylesheet
1729                             if ( ( pE2->ePageKind == PPT_MASTERPAGE ) && ( pE2->aSlideAtom.nMasterId == 0 ) && ( pE2->bNotesMaster == 0 ) )
1730                             {
1731 			                    PPTTextSpecInfo aTxSI( 0 );
1732 			                    if ( aTxSIStyle.bValid && aTxSIStyle.aList.Count() )
1733 				                    aTxSI = *( ( (PPTTextSpecInfo*)aTxSIStyle.aList.GetObject( 0 ) ) );
1734 
1735     			                pE2->pStyleSheet = new PPTStyleSheet( aSlideHd, rStCtrl, *this, aTxCFStyle, aTxPFStyle, aTxSI );
1736                                 pDefaultSheet = pE2->pStyleSheet;
1737                             }
1738 							if ( SeekToRec( rStCtrl, PPT_PST_ColorSchemeAtom, aSlideHd.GetRecEndFilePos() ) )
1739 								rStCtrl >> pE2->aColorScheme;
1740 							else
1741 							{
1742 								DBG_ERROR( "SdrPowerPointImport::Ctor(): could not get SlideColorScheme! (SJ)" );
1743 							}
1744                         }
1745 						else
1746 						{
1747                             DBG_ERROR("SdrPowerPointImport::Ctor(): Persist-Eintrag fehlerhaft! (SJ)");
1748                         }
1749                     }
1750                 }
1751             }
1752 			DffRecordHeader* pHeadersFootersHd = aDocRecManager.GetRecordHeader( PPT_PST_HeadersFooters, SEEK_FROM_BEGINNING );
1753 			if ( pHeadersFootersHd )
1754 			{
1755 				HeaderFooterEntry aNormalMaster, aNotesMaster;
1756 				for ( ; pHeadersFootersHd; pHeadersFootersHd = aDocRecManager.GetRecordHeader( PPT_PST_HeadersFooters, SEEK_FROM_CURRENT ) )
1757 				{
1758 					if ( pHeadersFootersHd->nRecInstance == 3 )			// normal master
1759 						ImportHeaderFooterContainer( *pHeadersFootersHd, aNormalMaster );
1760 					else if ( pHeadersFootersHd->nRecInstance == 4 )	// notes master
1761 						ImportHeaderFooterContainer( *pHeadersFootersHd, aNotesMaster );
1762 				}
1763 				for ( sal_uInt16 i = 0; i < pMasterPages->Count(); i++ )
1764 				{
1765 					if ( (*pMasterPages)[ i ]->bNotesMaster )
1766 						(*pMasterPages)[ i ]->pHeaderFooterEntry = new HeaderFooterEntry( aNotesMaster );
1767 					else
1768 						(*pMasterPages)[ i ]->pHeaderFooterEntry = new HeaderFooterEntry( aNormalMaster );
1769 				}
1770 			}
1771 		}
1772 	}
1773 	if ( ( rStCtrl.GetError() != 0 ) || ( pDefaultSheet == NULL ) )
1774 		bOk = sal_False;
1775 	pPPTStyleSheet = pDefaultSheet;
1776 	rStCtrl.Seek( 0 );
1777 }
1778 
~SdrPowerPointImport()1779 SdrPowerPointImport::~SdrPowerPointImport()
1780 {
1781 	for ( void* pPtr = aHyperList.First(); pPtr; pPtr = aHyperList.Next() )
1782 		delete (SdHyperlinkEntry*)pPtr;
1783 	delete pMasterPages;
1784 	delete pSlidePages;
1785 	delete pNotePages;
1786 	delete[] pPersistPtr;
1787 }
1788 
InsertControl(const com::sun::star::uno::Reference<com::sun::star::form::XFormComponent> & rFComp,const com::sun::star::awt::Size & rSize,com::sun::star::uno::Reference<com::sun::star::drawing::XShape> * pShape,sal_Bool)1789 sal_Bool PPTConvertOCXControls::InsertControl(
1790 		const com::sun::star::uno::Reference<
1791 		com::sun::star::form::XFormComponent > &rFComp,
1792 		const com::sun::star::awt::Size& rSize,
1793 		com::sun::star::uno::Reference<
1794 		com::sun::star::drawing::XShape > *pShape,
1795 		sal_Bool /*bFloatingCtrl*/)
1796 {
1797 	sal_Bool bRetValue = sal_False;
1798 	try
1799 	{
1800 		::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >  xShape;
1801 
1802 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > & rFormComps =
1803 			GetFormComps();
1804 
1805 		::com::sun::star::uno::Any aTmp( &rFComp, ::getCppuType((const ::com::sun::star::uno::Reference<
1806 			com::sun::star::form::XFormComponent >*)0) );
1807 
1808 		rFormComps->insertByIndex( rFormComps->getCount(), aTmp );
1809 
1810 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rServiceFactory =
1811 			GetServiceFactory();
1812 		if( rServiceFactory.is() )
1813 		{
1814 			::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  xCreate = rServiceFactory
1815 				->createInstance(String( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.ControlShape" ) ) );
1816 			if( xCreate.is() )
1817 			{
1818 				xShape = ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >(xCreate, ::com::sun::star::uno::UNO_QUERY);
1819 				if ( xShape.is() )
1820 				{
1821 					xShape->setSize(rSize);
1822 //					GetShapes()->add( xShape );
1823 					// Das Control-Model am Control-Shape setzen
1824 					::com::sun::star::uno::Reference< ::com::sun::star::drawing::XControlShape >  xControlShape( xShape,
1825 						::com::sun::star::uno::UNO_QUERY );
1826 					::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >  xControlModel( rFComp,
1827 						::com::sun::star::uno::UNO_QUERY );
1828 					if ( xControlShape.is() && xControlModel.is() )
1829 					{
1830 						xControlShape->setControl( xControlModel );
1831 						if (pShape)
1832 							*pShape = xShape;
1833 						bRetValue = sal_True;
1834 					}
1835 				}
1836 			}
1837 		}
1838 	}
1839 	catch( ... )
1840 	{
1841 		bRetValue = sal_False;
1842 	}
1843 	return bRetValue;
1844 };
1845 
GetDrawPage()1846 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& PPTConvertOCXControls::GetDrawPage()
1847 {
1848 	if( !xDrawPage.is() && pDocSh )
1849 	{
1850 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xModel( pDocSh->GetModel() );
1851 		::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPages > xDrawPages;
1852         switch( ePageKind )
1853         {
1854             case PPT_SLIDEPAGE :
1855             case PPT_NOTEPAGE :
1856 			{
1857 				::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPagesSupplier >
1858 						xDrawPagesSupplier( xModel, ::com::sun::star::uno::UNO_QUERY);
1859 				if ( xDrawPagesSupplier.is() )
1860 					xDrawPages = xDrawPagesSupplier->getDrawPages();
1861 			}
1862             break;
1863 
1864             case PPT_MASTERPAGE :
1865 			{
1866 				::com::sun::star::uno::Reference< ::com::sun::star::drawing::XMasterPagesSupplier >
1867 						xMasterPagesSupplier( xModel, ::com::sun::star::uno::UNO_QUERY);
1868 				if ( xMasterPagesSupplier.is() )
1869 					xDrawPages = xMasterPagesSupplier->getMasterPages();
1870 			}
1871 			break;
1872 		}
1873 		if ( xDrawPages.is() && xDrawPages->getCount() )
1874 		{
1875 			xDrawPages->getCount();
1876 			::com::sun::star::uno::Any aAny( xDrawPages->getByIndex( xDrawPages->getCount() - 1 ) );
1877 			aAny >>= xDrawPage;
1878 		}
1879 	}
1880 	return xDrawPage;
1881 }
1882 
SdrPowerPointOLEDecompress(SvStream & rOutput,SvStream & rInput,sal_uInt32 nInputSize)1883 sal_Bool SdrPowerPointOLEDecompress( SvStream& rOutput, SvStream& rInput, sal_uInt32 nInputSize )
1884 {
1885 	sal_uInt32 nOldPos = rInput.Tell();
1886 	char* pBuf = new char[ nInputSize ];
1887 	rInput.Read( pBuf, nInputSize );
1888 	ZCodec aZCodec( 0x8000, 0x8000 );
1889 	aZCodec.BeginCompression();
1890 	SvMemoryStream aSource( pBuf, nInputSize, STREAM_READ );
1891 	aZCodec.Decompress( aSource, rOutput );
1892 	const sal_Bool bSuccess(0L != aZCodec.EndCompression());
1893 	delete[] pBuf;
1894 	rInput.Seek( nOldPos );
1895 	return bSuccess;
1896 }
1897 
1898 // --> OD 2004-12-14 #i32596# - add new parameter <_nCalledByGroup>
ImportOLE(long nOLEId,const Graphic & rGraf,const Rectangle & rBoundRect,const Rectangle & rVisArea,const int,sal_Int64) const1899 SdrObject* SdrPowerPointImport::ImportOLE( long nOLEId,
1900                                            const Graphic& rGraf,
1901                                            const Rectangle& rBoundRect,
1902 										   const Rectangle& rVisArea,
1903                                            const int /*_nCalledByGroup*/,
1904 										   sal_Int64 /*nAspect*/ ) const
1905 // <--
1906 {
1907 	SdrObject* pRet = NULL;
1908 
1909 	sal_uInt32 nOldPos = rStCtrl.Tell();
1910 
1911 	Graphic aGraphic( rGraf );
1912 
1913 	if ( ((SdrPowerPointImport*)this)->maShapeRecords.SeekToContent( rStCtrl, DFF_msofbtClientData, SEEK_FROM_CURRENT_AND_RESTART ) )
1914 	{
1915 		DffRecordHeader aPlaceHd;
1916 		while ( ( rStCtrl.GetError() == 0 )
1917 			&& ( rStCtrl.Tell() < ((SdrPowerPointImport*)this)->maShapeRecords.Current()->GetRecEndFilePos() ) )
1918 		{
1919 			rStCtrl >> aPlaceHd;
1920 			if ( aPlaceHd.nRecType == PPT_PST_RecolorInfoAtom )
1921 			{
1922 				((SdrPowerPointImport*)this)->RecolorGraphic( rStCtrl, aPlaceHd.nRecLen, aGraphic );
1923 				break;
1924 			}
1925 			else
1926 				aPlaceHd.SeekToEndOfRecord( rStCtrl );
1927 		}
1928 	}
1929 
1930 	PPTOleEntry* pOe;
1931 	for ( pOe = (PPTOleEntry*)((SdrPowerPointImport*)this)->aOleObjectList.First(); pOe;
1932 			pOe = (PPTOleEntry*)((SdrPowerPointImport*)this)->aOleObjectList.Next() )
1933 	{
1934 		if ( pOe->nId != (sal_uInt32)nOLEId )
1935 			continue;
1936 
1937 		rStCtrl.Seek( pOe->nRecHdOfs );
1938 
1939 		DffRecordHeader aHd;
1940 		rStCtrl >> aHd;
1941 
1942 		sal_uInt32 nLen = aHd.nRecLen - 4;
1943 		if ( (sal_Int32)nLen > 0 )
1944 		{
1945 			sal_Bool bSuccess = sal_False;
1946 
1947 			rStCtrl.SeekRel( 4 );
1948 
1949 			::utl::TempFile aTmpFile;
1950 			aTmpFile.EnableKillingFile( sal_True );
1951 
1952 			if ( aTmpFile.IsValid() )
1953 			{
1954 				SvStream* pDest = ::utl::UcbStreamHelper::CreateStream( aTmpFile.GetURL(), STREAM_TRUNC | STREAM_WRITE );
1955 				if ( pDest )
1956 					bSuccess = SdrPowerPointOLEDecompress( *pDest, rStCtrl, nLen );
1957 				delete pDest;
1958 			}
1959 			if ( bSuccess )
1960 			{
1961 				SvStream* pDest = ::utl::UcbStreamHelper::CreateStream( aTmpFile.GetURL(), STREAM_READ );
1962 				Storage* pObjStor = pDest ? new Storage( *pDest, sal_True ) : NULL;
1963 				if ( pObjStor )
1964 				{
1965 					SotStorageRef xObjStor( new SotStorage( pObjStor ) );
1966 					if ( xObjStor.Is() && !xObjStor->GetError() )
1967 					{
1968 						if ( xObjStor->GetClassName() == SvGlobalName() )
1969 						{
1970 							ClsId aId( pObjStor->GetClassId() );
1971 							xObjStor->SetClass( SvGlobalName( aId.n1, aId.n2, aId.n3, aId.n4, aId.n5, aId.n6, aId.n7, aId.n8, aId.n9, aId.n10, aId.n11 ),
1972 								pObjStor->GetFormat(), pObjStor->GetUserName() );
1973 						}
1974 						SotStorageStreamRef xSrcTst = xObjStor->OpenSotStream( String( RTL_CONSTASCII_USTRINGPARAM( "\1Ole" ) ) );
1975 						if ( xSrcTst.Is() )
1976 						{
1977 							sal_uInt8 aTestA[ 10 ];
1978 							sal_Bool bGetItAsOle = ( sizeof( aTestA ) == xSrcTst->Read( aTestA, sizeof( aTestA ) ) );
1979 							if ( !bGetItAsOle )
1980 							{	// maybe there is a contentsstream in here
1981 								xSrcTst = xObjStor->OpenSotStream( String( RTL_CONSTASCII_USTRINGPARAM( "Contents" ) ), STREAM_READWRITE | STREAM_NOCREATE );
1982 								bGetItAsOle = ( xSrcTst.Is() && sizeof( aTestA ) == xSrcTst->Read( aTestA, sizeof( aTestA ) ) );
1983 							}
1984 							if ( bGetItAsOle )
1985 							{
1986                                 ::rtl::OUString aNm;
1987                                 // if ( nSvxMSDffOLEConvFlags )
1988 								{
1989                                     uno::Reference < embed::XStorage > xDestStorage( pOe->pShell->GetStorage() );
1990                                     uno::Reference < embed::XEmbeddedObject > xObj =
1991                                         CheckForConvertToSOObj( nSvxMSDffOLEConvFlags, *xObjStor, xDestStorage, rGraf, rVisArea );
1992                                     if( xObj.is() )
1993                                     {
1994                                         pOe->pShell->getEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aNm );
1995 
1996                                         svt::EmbeddedObjectRef aObj( xObj, pOe->nAspect );
1997 
1998                                         // TODO/LATER: need MediaType for Graphic
1999                                         aObj.SetGraphic( rGraf, ::rtl::OUString() );
2000                                         pRet = new SdrOle2Obj( aObj, aNm, rBoundRect, sal_False );
2001                                     }
2002 								}
2003 								if ( !pRet && ( pOe->nType == PPT_PST_ExControl ) )
2004 								{
2005 									PPTConvertOCXControls aPPTConvertOCXControls( pOe->pShell, eAktPageKind );
2006 									::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape;
2007 									if ( aPPTConvertOCXControls.ReadOCXStream( xObjStor, &xShape, sal_False ) )
2008 										pRet = GetSdrObjectFromXShape( xShape );
2009 								}
2010 								if ( !pRet )
2011 								{
2012 									aNm = pOe->pShell->getEmbeddedObjectContainer().CreateUniqueObjectName();
2013 									ErrCode aErrCode = 0;
2014 
2015 									// object is not an own object
2016 									SotStorageRef xTarget = SotStorage::OpenOLEStorage( pOe->pShell->GetStorage(), aNm, STREAM_READWRITE );
2017 									if ( xObjStor.Is() && xTarget.Is() )
2018 									{
2019 										xObjStor->CopyTo( xTarget );
2020 										if( !xTarget->GetError() )
2021 											xTarget->Commit();
2022 										if( xTarget->GetError() )
2023 											aErrCode = xTarget->GetError();
2024 									}
2025 									xTarget.Clear();
2026 
2027                                     uno::Reference < embed::XEmbeddedObject > xObj =
2028                                         pOe->pShell->getEmbeddedObjectContainer().GetEmbeddedObject( aNm );
2029                                     if ( xObj.is() )
2030                                     {
2031 										if ( pOe->nAspect != embed::Aspects::MSOLE_ICON )
2032 										{
2033                                         	//TODO/LATER: keep on hacking?!
2034                                         	// modifiziert wollen wir nicht werden
2035                                         	//xInplaceObj->EnableSetModified( sal_False );
2036 											if ( rVisArea.IsEmpty() )
2037 											{
2038 												MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( pOe->nAspect ) );
2039 												Size aSize( OutputDevice::LogicToLogic( aGraphic.GetPrefSize(),
2040 													aGraphic.GetPrefMapMode(), MapMode( aMapUnit ) ) );
2041 
2042 												awt::Size aSz;
2043 												aSz.Width = aSize.Width();
2044 												aSz.Height = aSize.Height();
2045 												xObj->setVisualAreaSize( pOe->nAspect, aSz );
2046 											}
2047 											else
2048 											{
2049 												awt::Size aSize( rVisArea.GetSize().Width(), rVisArea.GetSize().Height() );
2050 												xObj->setVisualAreaSize( pOe->nAspect, aSize );
2051 											}
2052                                         	//xInplaceObj->EnableSetModified( sal_True );
2053 										}
2054 
2055                                         svt::EmbeddedObjectRef aObj( xObj, pOe->nAspect );
2056 
2057                                         // TODO/LATER: need MediaType for Graphic
2058                                         aObj.SetGraphic( aGraphic, ::rtl::OUString() );
2059 
2060                                         pRet = new SdrOle2Obj( aObj, aNm, rBoundRect, sal_False );
2061                                     }
2062 								}
2063 							}
2064 						}
2065 					}
2066 				}
2067 				delete pDest;
2068 			}
2069 		}
2070 	}
2071 	rStCtrl.Seek( nOldPos );
2072 
2073 	return pRet;
2074 }
2075 
ImportExOleObjStg(sal_uInt32 nPersistPtr,sal_uInt32 & nOleId) const2076 SvMemoryStream* SdrPowerPointImport::ImportExOleObjStg( sal_uInt32 nPersistPtr, sal_uInt32& nOleId ) const
2077 {
2078 	SvMemoryStream* pRet = NULL;
2079 	if ( nPersistPtr && ( nPersistPtr < nPersistPtrAnz ) )
2080 	{
2081 		sal_uInt32 nOldPos, nOfs = pPersistPtr[ nPersistPtr ];
2082 		nOldPos = rStCtrl.Tell();
2083 		rStCtrl.Seek( nOfs );
2084 		DffRecordHeader aHd;
2085 		rStCtrl >> aHd;
2086 		if ( aHd.nRecType == DFF_PST_ExOleObjStg )
2087 		{
2088 			sal_uInt32 nLen = aHd.nRecLen - 4;
2089 			if ( (sal_Int32)nLen > 0 )
2090 			{
2091 				rStCtrl >> nOleId;
2092 				pRet = new SvMemoryStream;
2093 				ZCodec aZCodec( 0x8000, 0x8000 );
2094 				aZCodec.BeginCompression();
2095 				aZCodec.Decompress( rStCtrl, *pRet );
2096 				if ( !aZCodec.EndCompression() )
2097 					delete pRet, pRet = NULL;
2098 			}
2099 		}
2100 		rStCtrl.Seek( nOldPos );
2101 	}
2102 	return pRet;
2103 }
2104 
SeekOle(SfxObjectShell * pShell,sal_uInt32 nFilterOptions)2105 void SdrPowerPointImport::SeekOle( SfxObjectShell* pShell, sal_uInt32 nFilterOptions )
2106 {
2107 	if ( pShell )
2108 	{
2109 		DffRecordHeader*	pHd;
2110 
2111 		sal_uInt32 nOldPos = rStCtrl.Tell();
2112 		if ( nFilterOptions & 1 )
2113 		{
2114 			pHd = aDocRecManager.GetRecordHeader( PPT_PST_List, SEEK_FROM_BEGINNING );
2115 			if ( pHd )
2116 			{
2117 				// we try to locate the basic atom
2118 				pHd->SeekToContent( rStCtrl );
2119 				if ( SeekToRec( rStCtrl, PPT_PST_VBAInfo, pHd->GetRecEndFilePos(), pHd ) )
2120 				{
2121 					if ( SeekToRec( rStCtrl, PPT_PST_VBAInfoAtom, pHd->GetRecEndFilePos(), pHd ) )
2122 					{
2123 						sal_uInt32 nPersistPtr, nIDoNotKnow1, nIDoNotKnow2;
2124 						rStCtrl >> nPersistPtr
2125 								>> nIDoNotKnow1
2126 								>> nIDoNotKnow2;
2127 
2128 						sal_uInt32 nOleId;
2129 						SvMemoryStream* pBas = ImportExOleObjStg( nPersistPtr, nOleId );
2130 						if ( pBas )
2131 						{
2132 							SotStorageRef xSource( new SotStorage( pBas, sal_True ) );
2133 							SotStorageRef xDest( new SotStorage( new SvMemoryStream(), sal_True ) );
2134 							if ( xSource.Is() && xDest.Is() )
2135 							{
2136 								// is this a visual basic storage ?
2137 								SotStorageRef xSubStorage = xSource->OpenSotStorage( String( RTL_CONSTASCII_USTRINGPARAM( "VBA" ) ),
2138 									STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYALL );
2139 								if( xSubStorage.Is() && ( SVSTREAM_OK == xSubStorage->GetError() ) )
2140 								{
2141 									SotStorageRef xMacros = xDest->OpenSotStorage( String( RTL_CONSTASCII_USTRINGPARAM( "MACROS" ) ) );
2142 									if ( xMacros.Is() )
2143 									{
2144 										SvStorageInfoList aList;
2145 										xSource->FillInfoList( &aList );
2146 										sal_uInt32 i;
2147 
2148 										sal_Bool bCopied = sal_True;
2149 										for ( i = 0; i < aList.Count(); i++ )	// copy all entrys
2150 										{
2151 											const SvStorageInfo& rInfo = aList[ i ];
2152 											if ( !xSource->CopyTo( rInfo.GetName(), xMacros, rInfo.GetName() ) )
2153 												bCopied = sal_False;
2154 										}
2155 										if ( i && bCopied )
2156 										{
2157 											SvxImportMSVBasic aMSVBas( *pShell, *xDest, sal_True, sal_False );
2158 											//int nSuccess = aMSVBas.Import( String( RTL_CONSTASCII_USTRINGPARAM( "MACROS" ) ),
2159 											//		String( RTL_CONSTASCII_USTRINGPARAM( "VBA" ) ), TRUE, FALSE );
2160 
2161                                             uno::Reference < embed::XStorage > xDoc( pShell->GetStorage() );
2162                                             if ( xDoc.is() )
2163 											{
2164                                                 SotStorageRef xVBA = SotStorage::OpenOLEStorage( xDoc, String( RTL_CONSTASCII_USTRINGPARAM( "_MS_VBA_Macros" ) ) );
2165 												if ( xVBA.Is() && ( xVBA->GetError() == SVSTREAM_OK ) )
2166 												{
2167 													SotStorageRef xSubVBA = xVBA->OpenSotStorage( String( RTL_CONSTASCII_USTRINGPARAM( "_MS_VBA_Overhead" ) ) );
2168 													if ( xSubVBA.Is() && ( xSubVBA->GetError() == SVSTREAM_OK ) )
2169 													{
2170 														SotStorageStreamRef xOriginal = xSubVBA->OpenSotStream( String( RTL_CONSTASCII_USTRINGPARAM( "_MS_VBA_Overhead2" ) ) );
2171 														if ( xOriginal.Is() && ( xOriginal->GetError() == SVSTREAM_OK ) )
2172 														{
2173 															if ( nPersistPtr && ( nPersistPtr < nPersistPtrAnz ) )
2174 															{
2175 																rStCtrl.Seek( pPersistPtr[ nPersistPtr ] );
2176 																rStCtrl >> *pHd;
2177 
2178 																*xOriginal	<< nIDoNotKnow1
2179 																				<< nIDoNotKnow2;
2180 
2181 																sal_uInt32 nSource, nToCopy, nBufSize;
2182 																nSource = rStCtrl.Tell();
2183 																nToCopy = pHd->nRecLen;
2184 																sal_uInt8* pBuf = new sal_uInt8[ 0x40000 ];	// 256KB Buffer
2185 																if ( pBuf )
2186 																{
2187 																	while ( nToCopy )
2188 																	{
2189 																		nBufSize = ( nToCopy >= 0x40000 ) ? 0x40000 : nToCopy;
2190 																		rStCtrl.Read( pBuf, nBufSize );
2191 																		xOriginal->Write( pBuf, nBufSize );
2192 																		nToCopy -= nBufSize;
2193 																	}
2194 																	delete[] pBuf;
2195 																}
2196 															}
2197 														}
2198 													}
2199 												}
2200 											}
2201 										}
2202 									}
2203 								}
2204 							}
2205 						}
2206 					}
2207 				}
2208 			}
2209 		}
2210 		pHd = aDocRecManager.GetRecordHeader( PPT_PST_ExObjList, SEEK_FROM_BEGINNING );
2211 		if ( pHd )
2212 		{
2213 			DffRecordManager*	pExObjListManager = NULL;
2214 			DffRecordHeader*	pExEmbed = NULL;
2215 
2216 			pHd->SeekToBegOfRecord( rStCtrl );
2217 			pExObjListManager = new DffRecordManager( rStCtrl );
2218 			sal_uInt16 i, nRecType(PPT_PST_ExEmbed);
2219 
2220 			for ( i = 0; i < 2; i++ )
2221 			{
2222 				switch ( i )
2223 				{
2224 					case 0 : nRecType = PPT_PST_ExEmbed; break;
2225 					case 1 : nRecType = PPT_PST_ExControl; break;
2226 				}
2227 				for ( pExEmbed = pExObjListManager->GetRecordHeader( nRecType, SEEK_FROM_BEGINNING );
2228 						pExEmbed; pExEmbed = pExObjListManager->GetRecordHeader( nRecType, SEEK_FROM_CURRENT ) )
2229 				{
2230 					pExEmbed->SeekToContent( rStCtrl );
2231 
2232 					DffRecordHeader aExOleAtHd;
2233 					if ( SeekToRec( rStCtrl, PPT_PST_ExOleObjAtom, pExEmbed->GetRecEndFilePos(), &aExOleAtHd ) )
2234 					{
2235 						PptExOleObjAtom aAt;
2236 						rStCtrl >> aAt;
2237 
2238 						if ( aAt.nPersistPtr && ( aAt.nPersistPtr < nPersistPtrAnz ) )
2239 						{
2240 							sal_uInt32 nId;
2241 							rStCtrl.Seek( pPersistPtr[ aAt.nPersistPtr ] );
2242 							DffRecordHeader aHd;
2243 							rStCtrl >> aHd;
2244 							if ( aHd.nRecType == DFF_PST_ExOleObjStg )
2245 							{
2246 								rStCtrl >> nId;
2247 								aOleObjectList.Insert(
2248 									new PPTOleEntry( aAt.nId, aHd.nFilePos, pShell, nRecType, aAt.nAspect ) );
2249 							}
2250 						}
2251 					}
2252 				}
2253 			}
2254 			delete pExObjListManager;
2255 		}
2256 		rStCtrl.Seek( nOldPos );
2257 	}
2258 }
2259 
ReadFontCollection()2260 sal_Bool SdrPowerPointImport::ReadFontCollection()
2261 {
2262 	sal_Bool bRet = sal_False;
2263 	DffRecordHeader* pEnvHd = aDocRecManager.GetRecordHeader( PPT_PST_Environment );
2264 	if ( pEnvHd )
2265 	{
2266 		sal_uLong nFPosMerk = rStCtrl.Tell(); // FilePos merken fuer spaetere Restauration
2267 		pEnvHd->SeekToContent( rStCtrl );
2268 		DffRecordHeader aListHd;
2269 		if ( SeekToRec( rStCtrl, PPT_PST_FontCollection, pEnvHd->GetRecEndFilePos(), &aListHd ) )
2270 		{
2271 			sal_uInt16 nCount2 = 0;
2272 			VirtualDevice* pVDev = NULL;
2273 			while ( SeekToRec( rStCtrl, PPT_PST_FontEntityAtom, aListHd.GetRecEndFilePos() ) )
2274 			{
2275                 bRet = sal_True;
2276                 if ( !pFonts )
2277                     pFonts = new PptFontCollection;
2278                 PptFontEntityAtom* pFont = new PptFontEntityAtom;
2279                 rStCtrl >> *pFont;
2280 
2281 			    Font aFont;
2282 			    aFont.SetCharSet( pFont->eCharSet );
2283 			    aFont.SetName( pFont->aName );
2284 			    aFont.SetFamily( pFont->eFamily );
2285 			    aFont.SetPitch( pFont->ePitch );
2286                 aFont.SetHeight( 100 );
2287 
2288 				if ( mbTracing && !pFont->bAvailable )
2289 					mpTracer->Trace( rtl::OUString::createFromAscii( "sd1000" ), pFont->aName );
2290 
2291 #ifdef DBG_EXTRACTFONTMETRICS
2292 
2293 				SvxFont aTmpFont( aFont );
2294 
2295                 if ( !pVDev )
2296                     pVDev = new VirtualDevice;
2297 		        aTmpFont.SetPhysFont( pVDev );
2298 		        FontMetric aMetric( pVDev->GetFontMetric() );
2299                 sal_uInt16 nTxtHeight = (sal_uInt16)aMetric.GetAscent() + (sal_uInt16)aMetric.GetDescent();
2300 
2301 	            String	aFileURLStr;
2302 	            if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( Application::GetAppFileName(), aFileURLStr ) )
2303 	            {
2304 		            INetURLObject	aURL( aFileURLStr );
2305 		            aURL.SetName( String( RTL_CONSTASCII_STRINGPARAM( "dbgfontmetrics.txt" ) ) );
2306 
2307 		            SvStream* pDbgOut = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
2308 		            if( pDbgOut )
2309 		            {
2310 			            pDbgOut->Seek( STREAM_SEEK_TO_END );
2311 
2312                         Printer* pPrinter = NULL;
2313 		                if ( pSdrModel->GetRefDevice() && pSdrModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER )
2314 			                pPrinter = (Printer*)pSdrModel->GetRefDevice();
2315                         if ( pPrinter )
2316                         {
2317 		                    Font aOldFont( pPrinter->GetFont() );
2318                     		aFont.SetKerning( sal_True );
2319                     		pPrinter->SetFont( aFont );
2320 		                    aMetric = pPrinter->GetFontMetric();
2321                     		pPrinter->SetFont( aOldFont );
2322                         }
2323 
2324                         if ( ( pPrinter == NULL ) || ( aMetric.GetIntLeading() == 0 ) )
2325                         {
2326                             VirtualDevice aVirDev( 1 );
2327                             aVirDev.SetFont( aFont );
2328 		                    aMetric = aVirDev.GetFontMetric();
2329                         }
2330                         ByteString aFontName( aFont.GetName(), RTL_TEXTENCODING_UTF8 );
2331                         ByteString aHeight( ByteString::CreateFromInt32( aMetric.GetLineHeight() ) );
2332                         ByteString aAscent( ByteString::CreateFromInt32( aMetric.GetAscent() ) );
2333                         ByteString aDescent( ByteString::CreateFromInt32( aMetric.GetDescent() ) );
2334                         ByteString aLeading( ByteString::CreateFromInt32( aMetric.GetIntLeading() ) );
2335                         ByteString aPhysHeight( ByteString::CreateFromInt32( nTxtHeight ) );
2336 
2337                         *pDbgOut                                             << (sal_uInt8)0xa
2338                                  << "FontName  : " << aFontName.GetBuffer()  << (sal_uInt8)0xa
2339                                  << "    Height: " << aHeight.GetBuffer()    << (sal_uInt8)0xa
2340                                  << "    Ascent: " << aAscent.GetBuffer()    << (sal_uInt8)0xa
2341                                  << "    Descent:" << aDescent.GetBuffer()   << (sal_uInt8)0xa
2342                                  << "    Leading:" << aLeading.GetBuffer()   << (sal_uInt8)0xa
2343                                  << "PhysHeight :" << aPhysHeight.GetBuffer()<< (sal_uInt8)0xa;
2344 		            }
2345 		            delete pDbgOut;
2346                  }
2347 #endif
2348                 // following block is necessary, because our old PowerPoint export did not set the
2349                 // correct charset
2350 				if ( pFont->aName.EqualsIgnoreCaseAscii( "Wingdings" ) ||
2351 				    pFont->aName.EqualsIgnoreCaseAscii( "Wingdings 2" ) ||
2352         		        pFont->aName.EqualsIgnoreCaseAscii( "Wingdings 3" ) ||
2353 				            pFont->aName.EqualsIgnoreCaseAscii( "Monotype Sorts" ) ||
2354                                 pFont->aName.EqualsIgnoreCaseAscii( "Monotype Sorts 2" ) ||
2355 				                    pFont->aName.EqualsIgnoreCaseAscii( "Webdings" ) ||
2356     				                    pFont->aName.EqualsIgnoreCaseAscii( "StarBats" ) ||
2357                                             pFont->aName.EqualsIgnoreCaseAscii( "StarMath" ) ||
2358 				                                pFont->aName.EqualsIgnoreCaseAscii( "ZapfDingbats" ) )
2359                 {
2360                     pFont->eCharSet = RTL_TEXTENCODING_SYMBOL;
2361                 };
2362                 pFonts->C40_INSERT( PptFontEntityAtom, pFont, nCount2++ );
2363             }
2364             delete pVDev;
2365 		}
2366 		rStCtrl.Seek( nFPosMerk ); // FilePos restaurieren
2367 	}
2368 	return bRet;
2369 }
2370 
GetPageList(PptPageKind ePageKind) const2371 PptSlidePersistList* SdrPowerPointImport::GetPageList(PptPageKind ePageKind) const
2372 {
2373 	if ( ePageKind == PPT_MASTERPAGE )
2374 		return pMasterPages;
2375 	if ( ePageKind == PPT_SLIDEPAGE )
2376 		return pSlidePages;
2377 	if ( ePageKind == PPT_NOTEPAGE )
2378 		return pNotePages;
2379 	return NULL;
2380 }
2381 
GetDrawOutliner(SdrTextObj * pSdrText) const2382 SdrOutliner* SdrPowerPointImport::GetDrawOutliner( SdrTextObj* pSdrText ) const
2383 {
2384 	if ( !pSdrText )
2385 		return NULL;
2386 	else
2387 		return &pSdrText->ImpGetDrawOutliner();
2388 }
2389 
2390 
ReadObjText(PPTTextObj * pTextObj,SdrObject * pSdrObj,SdPage * pPage) const2391 SdrObject* SdrPowerPointImport::ReadObjText( PPTTextObj* pTextObj, SdrObject* pSdrObj, SdPage* pPage ) const
2392 {
2393 	SdrTextObj* pText = PTR_CAST( SdrTextObj, pSdrObj );
2394 	if ( pText )
2395 	{
2396 		if ( !ApplyTextObj( pTextObj, pText, pPage, NULL, NULL ) )
2397 			pSdrObj = NULL;
2398 	}
2399 	return pSdrObj;
2400 }
2401 
2402 
ApplyTextObj(PPTTextObj * pTextObj,SdrTextObj * pSdrText,SdPage *,SfxStyleSheet * pSheet,SfxStyleSheet ** ppStyleSheetAry) const2403 SdrObject* SdrPowerPointImport::ApplyTextObj( PPTTextObj* pTextObj, SdrTextObj* pSdrText, SdPage* /*pPage*/,
2404 												SfxStyleSheet* pSheet, SfxStyleSheet** ppStyleSheetAry ) const
2405 {
2406 	SdrTextObj* pText = pSdrText;
2407 	if ( pTextObj->Count() )
2408 	{
2409 		sal_uInt32 nDestinationInstance = pTextObj->GetDestinationInstance() ;
2410         SdrOutliner& rOutliner = pText->ImpGetDrawOutliner();
2411         if ( ( pText->GetObjInventor() == SdrInventor ) && ( pText->GetObjIdentifier() == OBJ_TITLETEXT ) )	// Outliner-Style fuer Titel-Textobjekt?!? (->von DL)
2412             rOutliner.Init( OUTLINERMODE_TITLEOBJECT );				// Outliner reset
2413 
2414 		sal_Bool bOldUpdateMode = rOutliner.GetUpdateMode();
2415 		rOutliner.SetUpdateMode( sal_False );
2416 		if ( pSheet )
2417 		{
2418 			if ( rOutliner.GetStyleSheet( 0 ) != pSheet )
2419 				rOutliner.SetStyleSheet( 0, pSheet );
2420 		}
2421 		rOutliner.SetVertical( pTextObj->GetVertical() );
2422 		const PPTParagraphObj* pPreviousParagraph = NULL;
2423 		for ( PPTParagraphObj* pPara = pTextObj->First(); pPara; pPara = pTextObj->Next() )
2424 		{
2425 			sal_uInt32 nTextSize = pPara->GetTextSize();
2426 			if ( ! ( nTextSize & 0xffff0000 ) )
2427 			{
2428 				PPTPortionObj* pPortion;
2429 				sal_Unicode* pParaText = new sal_Unicode[ nTextSize ];
2430 				sal_uInt32 nCurrentIndex = 0;
2431 				for ( pPortion = pPara->First(); pPortion; pPortion = pPara->Next() )
2432 				{
2433 					if ( pPortion->mpFieldItem )
2434 						pParaText[ nCurrentIndex++ ] = ' ';
2435 					else
2436 					{
2437                         sal_uInt32 nCharacters = pPortion->Count();
2438                         const sal_Unicode* pSource = pPortion->maString.GetBuffer();
2439                         sal_Unicode* pDest = pParaText + nCurrentIndex;
2440 
2441                         sal_uInt32 nFont;
2442                         pPortion->GetAttrib( PPT_CharAttr_Font, nFont, pTextObj->GetInstance() );
2443 			            PptFontEntityAtom* pFontEnityAtom = GetFontEnityAtom( nFont );
2444             			if ( pFontEnityAtom && ( pFontEnityAtom->eCharSet == RTL_TEXTENCODING_SYMBOL ) )
2445                         {
2446                             sal_uInt32 i;
2447                             sal_Unicode nUnicode;
2448                             for ( i = 0; i < nCharacters; i++ )
2449                             {
2450                                 nUnicode = pSource[ i ];
2451                                 if ( ! ( nUnicode & 0xff00 ) )
2452                                     nUnicode |= 0xf000;
2453                                 pDest[ i ] = nUnicode;
2454                             }
2455                         }
2456                         else
2457 						    memcpy( pDest, pSource, nCharacters << 1 );
2458 						nCurrentIndex += nCharacters;
2459 					}
2460 				}
2461 				sal_uInt32	nParaIndex = pTextObj->GetCurrentIndex();
2462 				SfxStyleSheet* pS = ( ppStyleSheetAry ) ? ppStyleSheetAry[ pPara->pParaSet->mnDepth ] : pSheet;
2463 
2464 				ESelection aSelection( nParaIndex, 0, nParaIndex, 0 );
2465 				rOutliner.Insert( String(), nParaIndex, pPara->pParaSet->mnDepth );
2466 				rOutliner.QuickInsertText( String( pParaText, (sal_uInt16)nCurrentIndex ), aSelection );
2467 				rOutliner.SetParaAttribs( nParaIndex, rOutliner.GetEmptyItemSet() );
2468 				if ( pS )
2469 					rOutliner.SetStyleSheet( nParaIndex, pS );
2470 
2471 				for ( pPortion = pPara->First(); pPortion; pPortion = pPara->Next() )
2472 				{
2473 					SfxItemSet aPortionAttribs( rOutliner.GetEmptyItemSet() );
2474 					SvxFieldItem* pFieldItem = pPortion->GetTextField();
2475 					if ( pFieldItem )
2476 					{
2477 						rOutliner.QuickInsertField( *pFieldItem, ESelection( nParaIndex, aSelection.nEndPos, nParaIndex, aSelection.nEndPos + 1 ) );
2478 						aSelection.nEndPos++;
2479 						delete pFieldItem;
2480 					}
2481 					else
2482 					{
2483 						const sal_Unicode *pF, *pPtr = pPortion->maString.GetBuffer();
2484 						const sal_Unicode *pMax = pPtr + pPortion->maString.Len();
2485 						sal_Int32 nLen;
2486 						for ( pF = pPtr; pPtr < pMax; pPtr++ )
2487 						{
2488 							if ( *pPtr == 0xb )
2489 							{
2490 								nLen = pPtr - pF;
2491 								if ( nLen )
2492 									aSelection.nEndPos =
2493                                         sal::static_int_cast< sal_uInt16 >(
2494                                             aSelection.nEndPos + nLen );
2495 								pF = pPtr + 1;
2496 								rOutliner.QuickInsertLineBreak( ESelection( nParaIndex, aSelection.nEndPos, nParaIndex, aSelection.nEndPos + 1 ) );
2497 								aSelection.nEndPos++;
2498 							}
2499 						}
2500 						nLen = pPtr - pF;
2501 						if ( nLen )
2502 							aSelection.nEndPos = sal::static_int_cast< sal_uInt16 >(
2503                                 aSelection.nEndPos + nLen );
2504 					}
2505 					pPortion->ApplyTo( aPortionAttribs, (SdrPowerPointImport&)*this, nDestinationInstance, pTextObj );
2506 					rOutliner.QuickSetAttribs( aPortionAttribs, aSelection );
2507 					aSelection.nStartPos = aSelection.nEndPos;
2508 				}
2509 				boost::optional< sal_Int16 > oStartNumbering;
2510 				SfxItemSet aParagraphAttribs( rOutliner.GetEmptyItemSet() );
2511 				pPara->ApplyTo( aParagraphAttribs, oStartNumbering, (SdrPowerPointImport&)*this, nDestinationInstance, pPreviousParagraph );
2512 
2513 				sal_uInt32	nIsBullet2 = 0; //, nInstance = nDestinationInstance != 0xffffffff ? nDestinationInstance : pTextObj->GetInstance();
2514 				pPara->GetAttrib( PPT_ParaAttr_BulletOn, nIsBullet2, nDestinationInstance );
2515 				if ( !nIsBullet2 )
2516 					aParagraphAttribs.Put( SfxBoolItem( EE_PARA_BULLETSTATE, sal_False ) );
2517 
2518 
2519 				pPreviousParagraph = pPara;
2520 				if ( !aSelection.nStartPos )	// in PPT empty paragraphs never gets a bullet
2521 				{
2522 					aParagraphAttribs.Put( SfxBoolItem( EE_PARA_BULLETSTATE, sal_False ) );
2523 //					rOutliner.SetDepth( rOutliner.GetParagraph( nParaIndex ), -1 );
2524 				}
2525 				aSelection.nStartPos = 0;
2526 				rOutliner.QuickSetAttribs( aParagraphAttribs, aSelection );
2527 				delete[] pParaText;
2528 			}
2529 		}
2530 		OutlinerParaObject* pNewText = rOutliner.CreateParaObject();
2531 		rOutliner.Clear();
2532 		rOutliner.SetUpdateMode( bOldUpdateMode );
2533 		pText->SetOutlinerParaObject( pNewText );
2534 	}
2535 	return pText;
2536 }
2537 
SeekToDocument(DffRecordHeader * pRecHd) const2538 sal_Bool SdrPowerPointImport::SeekToDocument( DffRecordHeader* pRecHd ) const
2539 {
2540 	sal_Bool bRet;
2541 	sal_uLong nFPosMerk = rStCtrl.Tell(); // FilePos merken fuer ggf. spaetere Restauration
2542 	rStCtrl.Seek( nDocStreamPos );
2543 	DffRecordHeader aDocHd;
2544 	rStCtrl >> aDocHd;
2545 	bRet = aDocHd.nRecType == PPT_PST_Document;
2546 	if ( bRet )
2547 	{
2548 		if ( pRecHd )
2549 			*pRecHd = aDocHd;
2550 		else
2551 			aDocHd.SeekToBegOfRecord( rStCtrl );
2552 	}
2553 	if ( !bRet )
2554 		rStCtrl.Seek( nFPosMerk ); // FilePos restaurieren
2555 	return bRet;
2556 }
2557 
SeekToContentOfProgTag(sal_Int32 nVersion,SvStream & rSt,const DffRecordHeader & rSourceHd,DffRecordHeader & rContentHd)2558 sal_Bool SdrPowerPointImport::SeekToContentOfProgTag( sal_Int32 nVersion, SvStream& rSt,
2559 								const DffRecordHeader& rSourceHd, DffRecordHeader& rContentHd )
2560 {
2561 	sal_Bool    bRetValue = sal_False;
2562 	sal_uInt32  nOldPos = rSt.Tell();
2563 
2564 	DffRecordHeader aProgTagsHd, aProgTagBinaryDataHd;
2565 	rSourceHd.SeekToContent( rSt );
2566 	sal_Bool bFound = rSourceHd.nRecType == PPT_PST_ProgTags;
2567 	if ( !bFound )
2568 		bFound = SeekToRec( rSt, PPT_PST_ProgTags, rSourceHd.GetRecEndFilePos(), &aProgTagsHd );
2569 	if ( bFound )
2570 	{
2571 		while( SeekToRec( rSt, PPT_PST_ProgBinaryTag, aProgTagsHd.GetRecEndFilePos(), &aProgTagBinaryDataHd ) )
2572 		{
2573 			rSt >> rContentHd;
2574 			if ( rContentHd.nRecType == PPT_PST_CString )
2575 			{
2576 				sal_uInt16	n = 6;
2577 				sal_uInt32  i = rContentHd.nRecLen >> 1;
2578 				if ( i > n )
2579 				{
2580 		            String aPre, aSuf;
2581 		            sal_Unicode	*pTmp = aPre.AllocBuffer( n );
2582 		            while ( n-- )
2583 			            rSt >> *pTmp++;
2584                     n = (sal_uInt16)( i - 6 );
2585                     pTmp = aSuf.AllocBuffer( n );
2586 		            while ( n-- )
2587 			            rSt >> *pTmp++;
2588                     sal_Int32 nV = aSuf.ToInt32();
2589 		            if ( ( nV == nVersion ) && ( aPre == String( RTL_CONSTASCII_USTRINGPARAM( "___PPT" ) ) ) )
2590 		            {
2591 			            rContentHd.SeekToEndOfRecord( rSt );
2592 			            rSt >> rContentHd;
2593 			            if ( rContentHd.nRecType == PPT_PST_BinaryTagData )
2594                         {
2595 				            bRetValue = sal_True;
2596                             break;
2597                         }
2598 		            }
2599                 }
2600 	        }
2601             aProgTagBinaryDataHd.SeekToEndOfRecord( rSt );
2602 		}
2603 	}
2604 	if ( !bRetValue )
2605 		rSt.Seek( nOldPos );
2606 	return bRetValue;
2607 }
2608 
GetAktPageId()2609 sal_uInt32 SdrPowerPointImport::GetAktPageId()
2610 {
2611 	PptSlidePersistList* pList = GetPageList( eAktPageKind );
2612 	if ( pList && nAktPageNum < pList->Count() )
2613 		return (*pList)[ (sal_uInt16)nAktPageNum ]->aPersistAtom.nSlideId;
2614 	return 0;
2615 }
2616 
SeekToAktPage(DffRecordHeader * pRecHd) const2617 sal_Bool SdrPowerPointImport::SeekToAktPage( DffRecordHeader* pRecHd ) const
2618 {
2619 	sal_Bool bRet = sal_False;
2620 	PptSlidePersistList* pList = GetPageList( eAktPageKind );
2621 	if ( pList && ( nAktPageNum < pList->Count() ) )
2622 	{
2623 		sal_uLong nPersist = (*pList)[ (sal_uInt16)nAktPageNum ]->aPersistAtom.nPsrReference;
2624 		if ( nPersist > 0 && nPersist < nPersistPtrAnz )
2625 		{
2626 			sal_uLong nFPos = 0;
2627 			nFPos = pPersistPtr[ nPersist ];
2628 			if ( nFPos < nStreamLen )
2629 			{
2630 				rStCtrl.Seek( nFPos );
2631 				if ( pRecHd )
2632 					rStCtrl >> *pRecHd;
2633 				bRet = sal_True;
2634 			}
2635 		}
2636 	}
2637 	return bRet;
2638 }
2639 
GetPageCount(PptPageKind ePageKind) const2640 sal_uInt16 SdrPowerPointImport::GetPageCount( PptPageKind ePageKind ) const
2641 {
2642 	PptSlidePersistList* pList = GetPageList( ePageKind );
2643 	if ( pList )
2644 		return pList->Count();
2645 	return 0;
2646 }
2647 
SetPageNum(sal_uInt16 nPageNum,PptPageKind eKind)2648 void SdrPowerPointImport::SetPageNum( sal_uInt16 nPageNum, PptPageKind eKind )
2649 {
2650 	eAktPageKind = eKind;
2651 	nAktPageNum = nPageNum;
2652 
2653 	pPPTStyleSheet = NULL;
2654 
2655 	sal_Bool bHasMasterPage = sal_True;
2656 	sal_uInt16 nMasterIndex = 0;
2657 
2658 	if ( eKind == PPT_MASTERPAGE )
2659 		nMasterIndex = nPageNum;
2660 	else
2661 	{
2662 		if ( HasMasterPage( nPageNum, eKind ) )
2663 			nMasterIndex = GetMasterPageIndex( nPageNum, eKind );
2664 		else
2665 			bHasMasterPage = sal_False;
2666 	}
2667 	if ( bHasMasterPage )
2668 	{
2669 		PptSlidePersistList* pPageList = GetPageList( PPT_MASTERPAGE );
2670 		if ( pPageList && nMasterIndex < pPageList->Count() )
2671 		{
2672 			PptSlidePersistEntry* pMasterPersist = (*pPageList)[ nMasterIndex ];
2673 			if ( ( pMasterPersist->pStyleSheet == NULL ) && pMasterPersist->aSlideAtom.nMasterId )
2674 			{
2675 				nMasterIndex = pMasterPages->FindPage( pMasterPersist->aSlideAtom.nMasterId );
2676 				if ( nMasterIndex != PPTSLIDEPERSIST_ENTRY_NOTFOUND )
2677 					pMasterPersist = (*pPageList)[ nMasterIndex ];
2678 			}
2679 			pPPTStyleSheet = pMasterPersist->pStyleSheet;
2680 		}
2681 	}
2682 	if ( !pPPTStyleSheet )
2683 		pPPTStyleSheet = pDefaultSheet;
2684 }
2685 
GetPageSize() const2686 Size SdrPowerPointImport::GetPageSize() const
2687 {
2688 	Size aRet( IsNoteOrHandout( nAktPageNum, eAktPageKind ) ? aDocAtom.GetNotesPageSize() : aDocAtom.GetSlidesPageSize() );
2689 	Scale( aRet );
2690 	// PPT arbeitet nur mit Einheiten zu 576DPI. Um Ungenauigkeiten zu
2691 	// vermeiden runde ich die letzte Nachkommastelle metrisch weg.
2692 	if ( nMapMul > 2 * nMapDiv )
2693 	{
2694 		MapUnit eMap = pSdrModel->GetScaleUnit();
2695 		bool bInch = IsInch( eMap );
2696 		long nInchMul = 1, nInchDiv = 1;
2697 		if ( bInch )
2698 		{	// Size temporaer (zum runden) in nach metric konvertieren
2699 			Fraction aFact(GetMapFactor(eMap,MAP_100TH_MM).X());
2700 			nInchMul = aFact.GetNumerator();
2701 			nInchDiv = aFact.GetDenominator();
2702 			aRet.Width() = BigMulDiv( aRet.Width(), nInchMul, nInchDiv );
2703 			aRet.Height() = BigMulDiv( aRet.Height(), nInchMul, nInchDiv );
2704 		}
2705 		aRet.Width() += 5; aRet.Width() /= 10; aRet.Width()*=10;
2706 		aRet.Height() += 5; aRet.Height() /= 10; aRet.Height()*=10;
2707 		if ( bInch )
2708 		{
2709 			aRet.Width() = BigMulDiv( aRet.Width(), nInchDiv, nInchMul );
2710 			aRet.Height() = BigMulDiv( aRet.Height(), nInchDiv, nInchMul );
2711 		}
2712 	}
2713 	return aRet;
2714 }
2715 
GetColorFromPalette(sal_uInt16 nNum,Color & rColor) const2716 FASTBOOL SdrPowerPointImport::GetColorFromPalette( sal_uInt16 nNum, Color& rColor ) const
2717 {
2718 	if ( nPageColorsNum != nAktPageNum || ePageColorsKind != eAktPageKind )
2719 	{
2720 		sal_uInt16 nSlideFlags = 0;
2721 		PptSlidePersistList* pPageList = GetPageList( eAktPageKind );
2722 		if ( pPageList && ( nAktPageNum < pPageList->Count() ) )
2723 		{
2724 			PptSlidePersistEntry* pE = (*pPageList)[ nAktPageNum ];
2725 			if ( pE )
2726 				nSlideFlags = pE->aSlideAtom.nFlags;
2727 			if ( ! ( nSlideFlags & 2 ) )
2728 				((SdrPowerPointImport*)this)->aPageColors = pE->aColorScheme;
2729 		}
2730 		if ( nSlideFlags & 2 ) // follow master colorscheme?
2731 		{
2732 			PptSlidePersistList* pPageList2 = GetPageList( PPT_MASTERPAGE );
2733 			if ( pPageList2 )
2734 			{
2735 				PptSlidePersistEntry* pMasterPersist = NULL;
2736 				if ( eAktPageKind == PPT_MASTERPAGE )
2737 					pMasterPersist = (*pPageList2)[ nAktPageNum ];
2738 				else
2739 				{
2740 					if ( HasMasterPage( nAktPageNum, eAktPageKind ) )
2741 					{
2742 						sal_uInt16 nMasterNum = GetMasterPageIndex( nAktPageNum, eAktPageKind );
2743 						if ( nMasterNum < pPageList2->Count() )
2744 							pMasterPersist = (*pPageList2)[ nMasterNum ];
2745 					}
2746 				}
2747 				if ( pMasterPersist )
2748 				{
2749 					while( ( pMasterPersist && pMasterPersist->aSlideAtom.nFlags & 2 ) // it is possible that a masterpage
2750 						&& pMasterPersist->aSlideAtom.nMasterId ) // itself is following a master colorscheme
2751 					{
2752 						sal_uInt16 nNextMaster = pMasterPages->FindPage( pMasterPersist->aSlideAtom.nMasterId );
2753 						if ( nNextMaster == PPTSLIDEPERSIST_ENTRY_NOTFOUND )
2754 							break;
2755 						else
2756 							pMasterPersist = (*pPageList2)[ nNextMaster ];
2757 					}
2758 					((SdrPowerPointImport*)this)->aPageColors = pMasterPersist->aColorScheme;
2759 				}
2760 			}
2761 		}
2762 		// momentanes Farbschema eintragen
2763 		((SdrPowerPointImport*)this)->nPageColorsNum = nAktPageNum;
2764 		((SdrPowerPointImport*)this)->ePageColorsKind = eAktPageKind;
2765 	}
2766 	rColor = aPageColors.GetColor( nNum );
2767 	return sal_True;
2768 }
2769 
SeekToShape(SvStream & rSt,void * pClientData,sal_uInt32 nId) const2770 sal_Bool SdrPowerPointImport::SeekToShape( SvStream& rSt, void* pClientData, sal_uInt32 nId ) const
2771 {
2772 	sal_Bool bRet = SvxMSDffManager::SeekToShape( rSt, pClientData, nId );
2773 	if ( !bRet )
2774 	{
2775 		ProcessData& rData = *( (ProcessData*)pClientData );
2776 		PptSlidePersistEntry& rPersistEntry = rData.rPersistEntry;
2777 		if ( rPersistEntry.ePageKind == PPT_SLIDEPAGE )
2778 		{
2779 			if ( HasMasterPage( nAktPageNum, eAktPageKind ) )
2780 			{
2781 				sal_uInt16 nMasterNum = GetMasterPageIndex( nAktPageNum, eAktPageKind );
2782 				PptSlidePersistList* pPageList = GetPageList( PPT_MASTERPAGE );
2783 				if ( pPageList && ( nMasterNum < pPageList->Count() ) )
2784 				{
2785 					PptSlidePersistEntry* pPersist = (*pPageList)[ nMasterNum ]; // get the masterpage's persistentry
2786 					if ( pPersist && pPersist->pPresentationObjects )
2787 					{
2788 						sal_uInt32 nCurrent(0L);
2789 						DffRecordList* pCList = maShapeRecords.pCList; // we got a backup of the current position
2790 						if ( pCList )
2791 							nCurrent = pCList->nCurrent;
2792 						if ( ((SdrEscherImport*)this )->maShapeRecords.SeekToContent( rSt, DFF_msofbtClientData, SEEK_FROM_CURRENT_AND_RESTART ) )
2793 						{
2794 							sal_uInt32 nStreamPos = rSt.Tell();
2795 							PPTTextObj aTextObj( rSt, (SdrPowerPointImport&)*this, rPersistEntry, NULL );
2796 							if ( aTextObj.Count() || aTextObj.GetOEPlaceHolderAtom() )
2797 							{
2798 								sal_uInt32 nShapePos = 0;
2799 								switch ( aTextObj.GetInstance() )
2800 								{
2801 									case TSS_TYPE_TITLE	:
2802 										nShapePos = pPersist->pPresentationObjects[ TSS_TYPE_PAGETITLE ];
2803 									break;
2804 									case TSS_TYPE_PAGETITLE	:
2805 										nShapePos = pPersist->pPresentationObjects[ TSS_TYPE_PAGETITLE ];
2806 									break;
2807 									case TSS_TYPE_SUBTITLE :
2808 									case TSS_TYPE_HALFBODY :
2809 									case TSS_TYPE_QUARTERBODY :
2810 									case TSS_TYPE_BODY :
2811 										nShapePos = pPersist->pPresentationObjects[ TSS_TYPE_BODY ];
2812 									break;
2813 //									case TSS_TYPE_NOTES	:
2814 //									case TSS_TYPE_UNUSED :
2815 //									case TSS_TYPE_TEXT_IN_SHAPE	:
2816 								}
2817 								if ( nShapePos )
2818 								{
2819 									rSt.Seek( nShapePos );
2820 									bRet = sal_True;
2821 								}
2822 							}
2823 							if ( !bRet )
2824 								rSt.Seek( nStreamPos );
2825 						}
2826 						if ( pCList )												// restoring
2827 							pCList->nCurrent = nCurrent;
2828 						((SdrEscherImport*)this )->maShapeRecords.pCList = pCList;
2829 					}
2830 				}
2831 			}
2832 		}
2833 	}
2834 	return bRet;
2835 }
2836 
MakeBlancPage(sal_Bool bMaster) const2837 SdrPage* SdrPowerPointImport::MakeBlancPage( sal_Bool bMaster ) const
2838 {
2839 	SdrPage* pRet = pSdrModel->AllocPage( bMaster );
2840 	pRet->SetSize( GetPageSize() );
2841 
2842 /*
2843 	SJ (21.08.00) : since bug #77576# i decided not to set a border size.
2844 
2845 	Size aPageSize( aDocAtom.GetSlidesPageSize() ); // PageSize in 576DPI-Units
2846 	long nHMarg = aPageSize.Width() - aDocAtom.aSlidesPageSize.Width();
2847 	long nVMarg = aPageSize.Height() - aDocAtom.aSlidesPageSize.Height();
2848 	if ( nHMarg > 0 )
2849 	{
2850 		Scale( nHMarg );
2851 		pRet->SetLftBorder( nHMarg / 2 );
2852 		pRet->SetRgtBorder( nHMarg - nHMarg / 2 );
2853 	}
2854 	if ( nVMarg > 0 )
2855 	{
2856 		Scale( nVMarg );
2857 		pRet->SetUppBorder( nVMarg / 2 );
2858 		pRet->SetLwrBorder( nVMarg - nVMarg / 2 );
2859 	}
2860 */
2861 	return pRet;
2862 }
2863 
ImportComment10(SvxMSDffManager & rMan,SvStream & rStCtrl,SdrPage * pPage,DffRecordHeader & rComment10Hd)2864 void ImportComment10( SvxMSDffManager& rMan, SvStream& rStCtrl, SdrPage* pPage, DffRecordHeader& rComment10Hd )
2865 {
2866 	rtl::OUString	sAuthor;
2867 	rtl::OUString	sText;
2868 	rtl::OUString	sInitials;
2869 
2870 	sal_Int32		nIndex = 0;
2871 	util::DateTime	aDateTime;
2872 	sal_Int32		nPosX = 0;
2873 	sal_Int32		nPosY = 0;
2874 
2875 	while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < rComment10Hd.GetRecEndFilePos() ) )
2876 	{
2877 		DffRecordHeader aCommentHd;
2878 		rStCtrl >> aCommentHd;
2879 		switch( aCommentHd.nRecType )
2880 		{
2881 			case PPT_PST_CString :
2882 			{
2883 				String aString;
2884 				SvxMSDffManager::MSDFFReadZString( rStCtrl, aString, aCommentHd.nRecLen, sal_True );
2885 				switch ( aCommentHd.nRecInstance )
2886 				{
2887 					case 0 : sAuthor = aString;		break;
2888 					case 1 : sText = aString;		break;
2889 					case 2 : sInitials = aString;	break;
2890 				}
2891 			}
2892 			break;
2893 
2894 			case PPT_PST_CommentAtom10 :
2895 			{
2896 				rStCtrl >> nIndex
2897 						>> aDateTime.Year
2898 						>> aDateTime.Month
2899 						>> aDateTime.Day // DayOfWeek
2900 						>> aDateTime.Day
2901 						>> aDateTime.Hours
2902 						>> aDateTime.Minutes
2903 						>> aDateTime.Seconds
2904 						>> aDateTime.HundredthSeconds
2905 						>> nPosX
2906 						>> nPosY;
2907 
2908 				aDateTime.HundredthSeconds /= 10;
2909 			}
2910 			break;
2911 		}
2912 		aCommentHd.SeekToEndOfRecord( rStCtrl );
2913 	}
2914 	Point aPosition( nPosX, nPosY );
2915 	rMan.Scale( aPosition );
2916 
2917 	try
2918 	{
2919 		uno::Reference< office::XAnnotationAccess > xAnnotationAccess( pPage->getUnoPage(), UNO_QUERY_THROW );
2920 		uno::Reference< office::XAnnotation > xAnnotation( xAnnotationAccess->createAndInsertAnnotation() );
2921 		xAnnotation->setPosition( geometry::RealPoint2D( aPosition.X() / 100.0, aPosition.Y() / 100.0 ) );
2922 		xAnnotation->setAuthor( sAuthor );
2923 		xAnnotation->setDateTime( aDateTime );
2924 		uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
2925 		xText->setString( sText );
2926 	}
2927 	catch( uno::Exception& )
2928 	{
2929 
2930 	}
2931 }
2932 
2933 
2934 // be sure not to import masterpages with this method
ImportPage(SdrPage * pRet,const PptSlidePersistEntry * pMasterPersist)2935 void SdrPowerPointImport::ImportPage( SdrPage* pRet, const PptSlidePersistEntry* pMasterPersist )
2936 {
2937 	sal_uInt32 nMerk = rStCtrl.Tell();
2938 	PptSlidePersistList* pList = GetPageList( eAktPageKind );
2939 	if ( ( !pList ) || ( pList->Count() <= nAktPageNum ) )
2940 		return;
2941 	PptSlidePersistEntry& rSlidePersist = *(*pList)[ nAktPageNum ];
2942 	if ( rSlidePersist.bStarDrawFiller )
2943 		return;
2944 
2945 	DffRecordHeader aPageHd;
2946 	if ( SeekToAktPage( &aPageHd ) )
2947 	{
2948 		if ( mbTracing )
2949 			mpTracer->AddAttribute( eAktPageKind == PPT_SLIDEPAGE
2950 									? rtl::OUString::createFromAscii( "Page" )
2951 									: rtl::OUString::createFromAscii( "NotesPage" ),
2952 									rtl::OUString::valueOf( (sal_Int32)nAktPageNum + 1 ) );
2953 
2954 		rSlidePersist.pHeaderFooterEntry = new HeaderFooterEntry( pMasterPersist );
2955 		ProcessData aProcessData( rSlidePersist, (SdPage*)pRet );
2956 		sal_Size nLastPosition;
2957 		while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < aPageHd.GetRecEndFilePos() ) )
2958 		{
2959 			nLastPosition = rStCtrl.Tell();
2960 			DffRecordHeader aHd;
2961 			rStCtrl >> aHd;
2962 			switch ( aHd.nRecType )
2963 			{
2964 				case PPT_PST_HeadersFooters :
2965 				{
2966 					ImportHeaderFooterContainer( aHd, *rSlidePersist.pHeaderFooterEntry );
2967 				}
2968 				break;
2969 
2970 				case PPT_PST_ProgTags :
2971 				{
2972 					DffRecordHeader aContentDataHd;
2973 					if ( SeekToContentOfProgTag( 10, rStCtrl, aHd, aContentDataHd ) )
2974 					{
2975 						DffRecordHeader aComment10Hd;
2976 						while( ( rStCtrl.GetError() == 0 ) && SeekToRec( rStCtrl, PPT_PST_Comment10, aContentDataHd.GetRecEndFilePos(), &aComment10Hd ) )
2977 						{
2978 							ImportComment10( *this, rStCtrl, pRet, aComment10Hd );
2979 							aComment10Hd.SeekToEndOfRecord( rStCtrl );
2980 						}
2981 					}
2982 				}
2983 				break;
2984 
2985 				case PPT_PST_PPDrawing :
2986 				{
2987 					DffRecordHeader aPPDrawHd;
2988 					if ( SeekToRec( rStCtrl, DFF_msofbtDgContainer, aHd.GetRecEndFilePos(), &aPPDrawHd ) )
2989 					{
2990 						sal_uInt32 nPPDrawOfs = rStCtrl.Tell();
2991 
2992 						// importing the background object before importing the page
2993 						while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < aPPDrawHd.GetRecEndFilePos() ) )
2994 						{
2995 							DffRecordHeader aEscherObjListHd;
2996 							rStCtrl >> aEscherObjListHd;
2997 							switch ( aEscherObjListHd.nRecType )
2998 							{
2999 								case DFF_msofbtSpContainer :
3000 								{
3001 									Rectangle aPageSize( Point(), pRet->GetSize() );
3002 									if ( rSlidePersist.aSlideAtom.nFlags & 4 ) // follow master background ?
3003 									{
3004 										if ( HasMasterPage( nAktPageNum, eAktPageKind ) )
3005 										{
3006 											sal_uInt16 nMasterNum = GetMasterPageIndex( nAktPageNum, eAktPageKind );
3007 											PptSlidePersistList* pPageList = GetPageList( PPT_MASTERPAGE );
3008 											PptSlidePersistEntry* pE = (*pPageList)[ nMasterNum ];
3009 											while( ( pE->aSlideAtom.nFlags & 4 ) && pE->aSlideAtom.nMasterId )
3010 											{
3011 												sal_uInt16 nNextMaster = pMasterPages->FindPage( pE->aSlideAtom.nMasterId );
3012 												if ( nNextMaster == PPTSLIDEPERSIST_ENTRY_NOTFOUND )
3013 													break;
3014 												else
3015 													pE = (*pPageList)[ nNextMaster ];
3016 											}
3017 											if ( pE->nBackgroundOffset )
3018 											{
3019 												// do not follow master colorscheme ?
3020 												sal_Bool bTemporary = ( rSlidePersist.aSlideAtom.nFlags & 2 ) != 0;
3021 												sal_uInt32 nPos = rStCtrl.Tell();
3022 												rStCtrl.Seek( pE->nBackgroundOffset );
3023 												rSlidePersist.pBObj = ImportObj( rStCtrl, (void*)&aProcessData, aPageSize, aPageSize );
3024 												rSlidePersist.bBObjIsTemporary = bTemporary;
3025 												rStCtrl.Seek( nPos );
3026 											}
3027 										}
3028 									}
3029 									else
3030 									{
3031 										DffRecordHeader aShapeHd;
3032 										rStCtrl >> aShapeHd;
3033 										if ( aShapeHd.nRecType == DFF_msofbtSp )
3034 										{
3035 											sal_uInt32 nSpFlags;
3036 											rStCtrl >> nSpFlags >> nSpFlags;
3037 											if ( nSpFlags & SP_FBACKGROUND )
3038 											{
3039 												aEscherObjListHd.SeekToBegOfRecord( rStCtrl );
3040 												rSlidePersist.pBObj = ImportObj( rStCtrl, (void*)&aProcessData, aPageSize, aPageSize );
3041 												rSlidePersist.bBObjIsTemporary = sal_False;
3042 											}
3043 										}
3044 									}
3045 								}
3046 								break;
3047 							}
3048 							if ( aEscherObjListHd.nRecType == DFF_msofbtSpContainer )
3049 								break;
3050 							aEscherObjListHd.SeekToEndOfRecord( rStCtrl );
3051 						}
3052 
3053 						// now importing page
3054 						rStCtrl.Seek( nPPDrawOfs );
3055 						while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < aPPDrawHd.GetRecEndFilePos() ) )
3056 						{
3057 							DffRecordHeader aEscherObjListHd;
3058 							rStCtrl >> aEscherObjListHd;
3059 							switch ( aEscherObjListHd.nRecType )
3060 							{
3061 								case DFF_msofbtSpgrContainer :
3062 								{
3063 									DffRecordHeader aShapeHd;
3064 									if ( SeekToRec( rStCtrl, DFF_msofbtSpContainer, aEscherObjListHd.GetRecEndFilePos(), &aShapeHd ) )
3065 									{
3066 										sal_Size nShapeLastPosition;
3067 										aShapeHd.SeekToEndOfRecord( rStCtrl );
3068 										while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < aEscherObjListHd.GetRecEndFilePos() ) )
3069 										{
3070 											nShapeLastPosition = rStCtrl.Tell();
3071 											rStCtrl >> aShapeHd;
3072 											if ( ( aShapeHd.nRecType == DFF_msofbtSpContainer ) || ( aShapeHd.nRecType == DFF_msofbtSpgrContainer ) )
3073 											{
3074 												Rectangle aEmpty;
3075 												aShapeHd.SeekToBegOfRecord( rStCtrl );
3076 												sal_Int32 nShapeId;
3077 												aProcessData.pTableRowProperties = NULL;
3078 												SdrObject* pObj = ImportObj( rStCtrl, (void*)&aProcessData, aEmpty, aEmpty, 0, &nShapeId );
3079 												if ( pObj )
3080 												{
3081 													if ( aProcessData.pTableRowProperties )
3082 														pObj = CreateTable( pObj, aProcessData.pTableRowProperties, aProcessData.rPersistEntry.pSolverContainer );
3083 
3084 													pRet->NbcInsertObject( pObj );
3085 
3086 													if( nShapeId )
3087 														insertShapeId( nShapeId, pObj );
3088 												}
3089 											}
3090 											aShapeHd.SeekToEndOfRecord( rStCtrl );
3091 											if (rStCtrl.Tell() == nShapeLastPosition) {
3092 												// We are inside an endless loop
3093 												break;
3094 											}
3095 										}
3096 									}
3097 								}
3098 								break;
3099 							}
3100 							if ( aEscherObjListHd.nRecType == DFF_msofbtSpgrContainer )
3101 								break;
3102 							aEscherObjListHd.SeekToEndOfRecord( rStCtrl );
3103 						}
3104 
3105 						/* There are a lot of Shapes who are dependent to
3106 						   the current background color */
3107 						if ( rSlidePersist.ePageKind == PPT_SLIDEPAGE )
3108 						{
3109 							List* pList2 = aProcessData.pBackgroundColoredObjects;
3110 							if ( pList2 )
3111 							{
3112 								if ( rSlidePersist.pBObj )
3113 								{
3114 									void* pPtr;
3115 									const SfxPoolItem* pPoolItem = NULL;
3116 									const SfxItemSet& rObjectItemSet = rSlidePersist.pBObj->GetMergedItemSet();
3117 
3118 									//SfxItemState eState = rObjectItemSet.GetItemState( XATTR_FILLCOLOR, sal_False, &pPoolItem );
3119 									if ( pPoolItem )
3120 									{
3121 										SfxItemSet aNewSet(*rObjectItemSet.GetPool());
3122 										aNewSet.Put(*pPoolItem);
3123 										aNewSet.Put(XFillStyleItem( XFILL_SOLID ));
3124 
3125 										for ( pPtr = pList2->First(); pPtr; pPtr = pList2->Next() )
3126 										{
3127 											((SdrObject*)pPtr)->SetMergedItemSet(aNewSet);
3128 										}
3129 									}
3130 								}
3131 							}
3132 						}
3133 						if ( rSlidePersist.pBObj )
3134 						{
3135 							// #i99386# transfer the attributes from the temporary BackgroundObject
3136 							// to the Page and delete it. Maybe rSlidePersist.bBObjIsTemporary is
3137 							// obsolete here, too.
3138 							pRet->getSdrPageProperties().ClearItem();
3139 							pRet->getSdrPageProperties().PutItemSet(rSlidePersist.pBObj->GetMergedItemSet());
3140 							SdrObject::Free( rSlidePersist.pBObj );
3141 						}
3142 					}
3143 				}
3144 				break;
3145 			}
3146 			aHd.SeekToEndOfRecord( rStCtrl );
3147 			if (rStCtrl.Tell() == nLastPosition) {
3148 				// We are inside an endless loop
3149 				break;
3150 			}
3151 		}
3152 		if ( rSlidePersist.pSolverContainer )
3153 			SolveSolver( *rSlidePersist.pSolverContainer );
3154 		if ( mbTracing )
3155 			mpTracer->RemoveAttribute( eAktPageKind == PPT_SLIDEPAGE
3156 										? rtl::OUString::createFromAscii( "Page" )
3157 										: rtl::OUString::createFromAscii( "NotesPage" ) );
3158 	}
3159 	rStCtrl.Seek( nMerk );
3160 }
3161 
GetSlideLayoutAtom() const3162 const PptSlideLayoutAtom* SdrPowerPointImport::GetSlideLayoutAtom() const
3163 {
3164 	PptSlidePersistList* pPageList = GetPageList( eAktPageKind );
3165 	if ( pPageList && nAktPageNum < pPageList->Count() )
3166 	{
3167 		PptSlidePersistEntry* pE = (*pPageList)[ nAktPageNum ];
3168 		if ( pE )
3169 			return &pE->aSlideAtom.aLayout;
3170 	}
3171 	return NULL;
3172 }
3173 
IsNoteOrHandout(sal_uInt16 nPageNum,PptPageKind) const3174 sal_Bool SdrPowerPointImport::IsNoteOrHandout( sal_uInt16 nPageNum, PptPageKind /*ePageKind*/) const
3175 {
3176     sal_Bool bNote = eAktPageKind == PPT_NOTEPAGE;
3177     if ( eAktPageKind == PPT_MASTERPAGE )
3178 		bNote = ( nPageNum & 1 ) == 0;
3179     return bNote;
3180 }
3181 
GetMasterPageId(sal_uInt16 nPageNum,PptPageKind ePageKind) const3182 sal_uInt32 SdrPowerPointImport::GetMasterPageId( sal_uInt16 nPageNum, PptPageKind ePageKind ) const
3183 {
3184     PptSlidePersistList* pPageList = GetPageList( ePageKind );
3185     if ( pPageList && nPageNum < pPageList->Count() )
3186         return (*pPageList)[ nPageNum ]->aSlideAtom.nMasterId;
3187    return 0;
3188 }
3189 
GetNotesPageId(sal_uInt16 nPageNum) const3190 sal_uInt32 SdrPowerPointImport::GetNotesPageId( sal_uInt16 nPageNum ) const
3191 {
3192     PptSlidePersistList* pPageList=GetPageList( PPT_SLIDEPAGE );
3193     if ( pPageList && nPageNum < pPageList->Count() )
3194         return (*pPageList)[ nPageNum ]->aSlideAtom.nNotesId;
3195    return 0;
3196 }
3197 
HasMasterPage(sal_uInt16 nPageNum,PptPageKind ePageKind) const3198 sal_Bool SdrPowerPointImport::HasMasterPage( sal_uInt16 nPageNum, PptPageKind ePageKind ) const
3199 {
3200     if ( ePageKind == PPT_NOTEPAGE )
3201 		return aDocAtom.nNotesMasterPersist != 0;
3202     if ( ePageKind == PPT_MASTERPAGE )
3203 		return sal_False;
3204     return GetMasterPageId( nPageNum, ePageKind ) != 0;
3205 }
3206 
GetMasterPageIndex(sal_uInt16 nPageNum,PptPageKind ePageKind) const3207 sal_uInt16 SdrPowerPointImport::GetMasterPageIndex( sal_uInt16 nPageNum, PptPageKind ePageKind ) const
3208 {
3209     sal_uInt16 nIdx = 0;
3210     if ( ePageKind == PPT_NOTEPAGE )
3211 		return 2;
3212     sal_uInt32 nId = GetMasterPageId( nPageNum, ePageKind );
3213     if ( nId && pMasterPages )
3214 	{
3215         nIdx = pMasterPages->FindPage( nId );
3216         if ( nIdx == PPTSLIDEPERSIST_ENTRY_NOTFOUND )
3217 			nIdx = 0;
3218     }
3219     return nIdx;
3220 }
3221 
ImportPageBackgroundObject(const SdrPage & rPage,sal_uInt32 & nBgFileOffset,sal_Bool bForce)3222 SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage, sal_uInt32& nBgFileOffset, sal_Bool bForce )
3223 {
3224     SdrObject* pRet = NULL;
3225     sal_Bool bCreateObj = bForce;
3226     SfxItemSet* pSet = NULL;
3227     sal_uLong nFPosMerk = rStCtrl.Tell(); // FilePos merken fuer spaetere Restauration
3228     DffRecordHeader aPageHd;
3229     if ( SeekToAktPage( &aPageHd ) )
3230 	{	// und nun die Hintergrundattribute der Page suchen
3231         sal_uLong nPageRecEnd = aPageHd.GetRecEndFilePos();
3232         DffRecordHeader aPPDrawHd;
3233         if ( SeekToRec( rStCtrl, PPT_PST_PPDrawing, nPageRecEnd, &aPPDrawHd ) )
3234 		{
3235             sal_uLong nPPDrawEnd = aPPDrawHd.GetRecEndFilePos();
3236             DffRecordHeader aEscherF002Hd;
3237             if ( SeekToRec( rStCtrl, DFF_msofbtDgContainer, nPPDrawEnd, &aEscherF002Hd ) )
3238 			{
3239                 sal_uLong nEscherF002End = aEscherF002Hd.GetRecEndFilePos();
3240                 DffRecordHeader aEscherObjectHd;
3241                 if ( SeekToRec( rStCtrl, DFF_msofbtSpContainer, nEscherF002End, &aEscherObjectHd ) )
3242 				{
3243 					nBgFileOffset = aEscherObjectHd.GetRecBegFilePos();
3244                     //sal_uLong nEscherObjectEnd = aEscherObjectHd.GetRecEndFilePos();
3245                     //DffRecordHeader aEscherPropertiesHd;
3246                     if ( SeekToRec( rStCtrl, DFF_msofbtOPT,nEscherF002End ) )
3247 					{
3248 						rStCtrl >> (DffPropertyReader&)*this;
3249 						mnFix16Angle = Fix16ToAngle( GetPropertyValue( DFF_Prop_Rotation, 0 ) );
3250                         sal_uInt32 nColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff );
3251                         pSet = new SfxItemSet( pSdrModel->GetItemPool() );
3252                         DffObjData aObjData( aEscherObjectHd, Rectangle( 0, 0, 28000, 21000 ), 0 );
3253 						ApplyAttributes( rStCtrl, *pSet, aObjData );
3254                         Color aColor( MSO_CLR_ToColor( nColor ) );
3255 				        pSet->Put( XFillColorItem( String(), aColor ) );
3256                     }
3257                 }
3258             }
3259         }
3260     }
3261     rStCtrl.Seek( nFPosMerk ); // FilePos restaurieren
3262     if ( bCreateObj )
3263 	{
3264         if ( !pSet )
3265 		{
3266             pSet = new SfxItemSet( pSdrModel->GetItemPool() );
3267             pSet->Put( XFillStyleItem( XFILL_NONE ) );
3268         }
3269         pSet->Put( XLineStyleItem( XLINE_NONE ) );
3270         Rectangle aRect( rPage.GetLftBorder(), rPage.GetUppBorder(), rPage.GetWdt()-rPage.GetRgtBorder(), rPage.GetHgt()-rPage.GetLwrBorder() );
3271         pRet = new SdrRectObj( aRect );
3272         pRet->SetModel( pSdrModel );
3273 
3274         pRet->SetMergedItemSet(*pSet);
3275 
3276         pRet->SetMarkProtect( sal_True );
3277         pRet->SetMoveProtect( sal_True );
3278         pRet->SetResizeProtect( sal_True );
3279     }
3280     delete pSet;
3281     return pRet;
3282 }
3283 
3284 ////////////////////////////////////////////////////////////////////////////////////////////////////
3285 
HeaderFooterEntry(const PptSlidePersistEntry * pMPE)3286 HeaderFooterEntry::HeaderFooterEntry( const PptSlidePersistEntry* pMPE ) :
3287 	pMasterPersist	( pMPE ),
3288 	nAtom			( 0 )
3289 {
3290 	if ( pMPE )
3291 	{
3292 		HeaderFooterEntry* pMHFE = pMPE->pHeaderFooterEntry;
3293 		if ( pMHFE )
3294 		{
3295 			nAtom = pMPE->pHeaderFooterEntry->nAtom;
3296 			pPlaceholder[ 0 ] = pMHFE->pPlaceholder[ 0 ];
3297 			pPlaceholder[ 1 ] = pMHFE->pPlaceholder[ 1 ];
3298 			pPlaceholder[ 2 ] = pMHFE->pPlaceholder[ 2 ];
3299 			pPlaceholder[ 3 ] = pMHFE->pPlaceholder[ 3 ];
3300 		}
3301 	}
3302 }
3303 
~HeaderFooterEntry()3304 HeaderFooterEntry::~HeaderFooterEntry()
3305 {
3306 }
3307 
GetMaskForInstance(sal_uInt32 nInstance)3308 sal_uInt32 HeaderFooterEntry::GetMaskForInstance( sal_uInt32 nInstance )
3309 {
3310 	sal_uInt32 nRet = 0;
3311 	switch ( nInstance )
3312 	{
3313 		case 0 : nRet = 0x07ffff; break;
3314 		case 1 : nRet = 0x100000; break;
3315 		case 2 : nRet = 0x200000; break;
3316 		case 3 : nRet = 0x080000; break;
3317 	}
3318 	return nRet;
3319 }
3320 
IsToDisplay(sal_uInt32 nInstance)3321 sal_uInt32 HeaderFooterEntry::IsToDisplay( sal_uInt32 nInstance )
3322 {
3323 	sal_uInt32 nMask = 0;
3324 	switch ( nInstance )
3325 	{
3326 		case 0 : nMask = 0x010000; break;
3327 		case 1 : nMask = 0x100000; break;
3328 		case 2 : nMask = 0x200000; break;
3329 		case 3 : nMask = 0x080000; break;
3330 	}
3331 	return ( nAtom & nMask );
3332 }
3333 
3334 // The following method checks if the slide is using a different colorscheme than
3335 // its master, if this is the fact, then the HeaderFooter must probably be
3336 // imported as real sdrobject. In this case, the return value is the offset to the
3337 // master header footer object, so it can be re-loaded with a different color set
NeedToImportInstance(const sal_uInt32 nInstance,const PptSlidePersistEntry & rSlidePersist)3338 sal_uInt32 HeaderFooterEntry::NeedToImportInstance( const sal_uInt32 nInstance, const PptSlidePersistEntry& rSlidePersist )
3339 {
3340 	sal_uInt32 nRet = 0;
3341 	if ( pMasterPersist )
3342 	{
3343 		if ( !( rSlidePersist.aSlideAtom.nFlags & 2 ) )
3344 		{	// not following the master persist, so we have to check if the colors are changed
3345 			if ( memcmp( &rSlidePersist.aColorScheme, &pMasterPersist->aColorScheme, 32 ) )
3346 			{
3347 				nRet = pMasterPersist->HeaderFooterOfs[ nInstance ];
3348 			}
3349 		}
3350 	}
3351 	return nRet;
3352 }
3353 
ImportHeaderFooterContainer(DffRecordHeader & rHd,HeaderFooterEntry & rE)3354 void SdrEscherImport::ImportHeaderFooterContainer( DffRecordHeader& rHd, HeaderFooterEntry& rE )
3355 {
3356 	rHd.SeekToContent( rStCtrl );
3357 	while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < rHd.GetRecEndFilePos() ) )
3358 	{
3359 		DffRecordHeader aHd;
3360 		rStCtrl >> aHd;
3361 		switch ( aHd.nRecType )
3362 		{
3363 			case PPT_PST_HeadersFootersAtom :
3364 				rStCtrl >> rE.nAtom;
3365 			break;
3366 
3367 			case PPT_PST_CString :
3368 			{
3369 				if ( aHd.nRecInstance < 4 )
3370 					MSDFFReadZString( rStCtrl, rE.pPlaceholder[ aHd.nRecInstance ], aHd.nRecLen, sal_True );
3371 			}
3372 			break;
3373 		}
3374 		aHd.SeekToEndOfRecord( rStCtrl );
3375 	}
3376 }
3377 
3378 //static sal_Unicode PPTExportMapper( sal_Unicode nUni, sal_Bool& bNeedsStarBats )
3379 //{
3380 //	bNeedsStarBats = sal_False;
3381 //
3382 //	sal_Unicode cLo, cReplace;
3383 //	cLo = cReplace = 0;
3384 //	switch ( nUni )
3385 //	{
3386 //		case 132 : cLo = 175; break;
3387 //		case 147 : cLo = 174; break;
3388 //		// Currency
3389 //		case 0x00A2:	cReplace = 224; break;
3390 //		case 0x00A4:	cReplace = 225; break;
3391 //		case 0x00A5:	cReplace = 226; break;
3392 //		case 0x20A1:	cReplace = 228; break;
3393 //		case 0x20A2:	cReplace = 229; break;
3394 //		case 0x20A3:	cReplace = 230; break;
3395 //		case 0x20A4:	cReplace = 231; break;
3396 //		case 0x20A7:	cReplace = 227; break;
3397 //		case 0x20A8:	cReplace = 234; break;
3398 //		case 0x20A9:	cReplace = 232; break;
3399 //		case 0x20AB:	cReplace = 233; break;
3400 //		case 0x20AC:	cReplace = 128; break;
3401 //		// Punctuation and other
3402 //		case 0x201A:	cReplace = 130; break;		// SINGLE LOW-9 QUOTATION MARK
3403 //		case 0x0192:	cReplace = 131; break;		// LATIN SMALL LETTER F WITH HOOK
3404 //		case 0x201E:								// DOUBLE LOW-9 QUOTATION MARK
3405 //		case 0x301F:								// LOW DOUBLE PRIME QUOTATION MARK
3406 //						cReplace = 132; break;
3407 //		case 0x2026:	cReplace = 133; break;		// HORIZONTAL ELLIPSES
3408 //		case 0x2020:	cReplace = 134; break;		// DAGGER
3409 //		case 0x2021:	cReplace = 135; break;		// DOUBLE DAGGER
3410 //		case 0x02C6:	cReplace = 136; break;		// MODIFIER LETTER CIRCUMFLEX ACCENT
3411 //		case 0x2030:	cReplace = 137; break;		// PER MILLE SIGN
3412 //		case 0x0160:	cReplace = 138; break;		// LATIN CAPITAL LETTER S WITH CARON
3413 //		case 0x2039:	cReplace = 139; break;		// SINGLE LEFT-POINTING ANGLE QUOTATION MARK
3414 //		case 0x0152:	cReplace = 140; break;		// LATIN CAPITAL LIGATURE OE
3415 //		case 0x017D:	cReplace = 142; break;		// LATIN CAPITAL LETTER Z WITH CARON
3416 //		case 0x2018:								// LEFT SINGLE QUOTATION MARK
3417 //		case 0x02BB:								// MODIFIER LETTER TURNED COMMA
3418 //						cReplace = 145; break;
3419 //		case 0x2019:								// RIGHT SINGLE QUOTATION MARK
3420 //		case 0x02BC:								// MODIFIER LETTER APOSTROPHE
3421 //						cReplace = 146; break;
3422 //		case 0x201C:								// LEFT DOUBLE QUOTATION MARK
3423 //		case 0x301D:								// REVERSED DOUBLE PRIME QUOTATION MARK
3424 //						cReplace = 147; break;
3425 //		case 0x201D:								// RIGHT DOUBLE QUOTATION MARK
3426 //		case 0x301E:								// REVERSED DOUBLE PRIME QUOTATION MARK
3427 //						cReplace = 148; break;
3428 //		case 0x2022:	cReplace = 149; break;		// BULLET
3429 //		case 0x2013:	cReplace = 150; break;		// EN DASH
3430 //		case 0x2014:	cReplace = 151; break;		// EM DASH
3431 //		case 0x02DC:	cReplace = 152; break;		// SMALL TILDE
3432 //		case 0x2122:	cReplace = 153; break;		// TRADE MARK SIGN
3433 //		case 0x0161:	cReplace = 154; break;		// LATIN SMALL LETTER S WITH CARON
3434 //		case 0x203A:	cReplace = 155; break;		// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
3435 //		case 0x0153:	cReplace = 156; break;		// LATIN SMALL LIGATURE OE
3436 //		case 0x017E:	cReplace = 158; break;		// LATIN SMALL LETTER Z WITH CARON
3437 //		case 0x0178:	cReplace = 159; break;		// LATIN CAPITAL LETTER Y WITH DIAERESIS
3438 //		case 0x00B6:	cReplace = 222; break;		// PILCROW SIGN / PARAGRAPH SIGN
3439 //	}
3440 //	if ( cReplace )
3441 //	{
3442 //		bNeedsStarBats = sal_True;
3443 //		return cReplace;
3444 //	}
3445 //	else
3446 //		return cLo;
3447 //}
3448 
3449 // no longer needed
PPTSubstitute(sal_uInt16,sal_Unicode,sal_uInt32 &,Font &,char) const3450 sal_Unicode SdrPowerPointImport::PPTSubstitute( sal_uInt16 /*nFont*/, sal_Unicode /*nChar*/,
3451 										sal_uInt32& /*nMappedFontId*/, Font& /*rFont*/, char /*nDefault*/) const
3452 {
3453     return 0;
3454 }
3455 
3456 ////////////////////////////////////////////////////////////////////////////////////////////////////
3457 
PPTBuGraEntry(Graphic & rGraphic,sal_uInt32 nInst)3458 PPTBuGraEntry::PPTBuGraEntry( Graphic& rGraphic, sal_uInt32 nInst ) :
3459 	nInstance		( nInst ),
3460 	aBuGra			( rGraphic )  {}
3461 
PPTExtParaLevel()3462 PPTExtParaLevel::PPTExtParaLevel()
3463 : mnExtParagraphMask( 0 )
3464 , mnBuBlip( 0xffff )
3465 , mnHasAnm( 0 )
3466 , mnAnmScheme( 0 )
3467 , mpfPP10Ext( 0 )
3468 , mnExtCharacterMask( 0 )
3469 , mcfPP10Ext( 0 )
3470 , mbSet( sal_False )
3471 {}
3472 
operator >>(SvStream & rIn,PPTExtParaLevel & rLevel)3473 SvStream& operator>>( SvStream& rIn, PPTExtParaLevel& rLevel )
3474 {
3475 	rLevel.mbSet = sal_True;
3476 	rIn >> rLevel.mnExtParagraphMask;
3477 	if ( rLevel.mnExtParagraphMask & 0x00800000 )
3478 		rIn >> rLevel.mnBuBlip;
3479 	if ( rLevel.mnExtParagraphMask & 0x02000000 )
3480 		rIn >> rLevel.mnHasAnm;
3481 	if ( rLevel.mnExtParagraphMask & 0x01000000 )
3482 		rIn >> rLevel.mnAnmScheme;
3483 	if ( rLevel.mnExtParagraphMask & 0x04000000 )
3484 		rIn >> rLevel.mpfPP10Ext;
3485 	rIn >> rLevel.mnExtCharacterMask;
3486 	if ( rLevel.mnExtCharacterMask & 0x100000 )
3487 		rIn >> rLevel.mcfPP10Ext;
3488 	return rIn;
3489 }
3490 
GetGraphic(sal_uInt32 nInstance,Graphic & rGraph) const3491 sal_Bool PPTExtParaProv::GetGraphic( sal_uInt32 nInstance, Graphic& rGraph ) const
3492 {
3493 	sal_Bool bRetValue = sal_False;
3494 	PPTBuGraEntry* pPtr = NULL;
3495 	if ( nInstance < aBuGraList.Count() )
3496 	{
3497 		pPtr = (PPTBuGraEntry*)aBuGraList.GetObject( nInstance );
3498 		if ( pPtr->nInstance == nInstance )
3499 			bRetValue = sal_True;
3500 	}
3501 	if ( !bRetValue )
3502 	{
3503         sal_uInt32 i;
3504 		for ( i = 0; i < aBuGraList.Count(); i++ )
3505 		{
3506             pPtr = (PPTBuGraEntry*)aBuGraList.GetObject( i );
3507 			if ( pPtr->nInstance == nInstance )
3508 			{
3509 				bRetValue = sal_True;
3510 				break;
3511 			}
3512 		}
3513 	}
3514 	if ( bRetValue )
3515 		rGraph = pPtr->aBuGra;
3516 	return bRetValue;
3517 }
3518 
PPTExtParaProv(SdrPowerPointImport & rMan,SvStream & rSt,const DffRecordHeader * pHd)3519 PPTExtParaProv::PPTExtParaProv( SdrPowerPointImport& rMan, SvStream& rSt, const DffRecordHeader* pHd ) :
3520 	bStyles			( sal_False ),
3521 	bGraphics		( sal_False )
3522 {
3523 	sal_uInt32 nOldPos = rSt.Tell();
3524 
3525 	// here we have to get the graphical bullets...
3526 
3527 	DffRecordHeader	aHd;
3528 	DffRecordHeader aContentDataHd;
3529 
3530 	const DffRecordHeader* pListHd = rMan.aDocRecManager.GetRecordHeader( PPT_PST_List, SEEK_FROM_BEGINNING );
3531 	while( pListHd )
3532 	{
3533 		pListHd->SeekToContent( rSt );
3534         if ( !rMan.SeekToContentOfProgTag( 9, rSt, *pListHd, aContentDataHd ) )
3535             break;
3536 		while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aContentDataHd.GetRecEndFilePos() ) )
3537 		{
3538 			rSt >> aHd;
3539 			switch ( aHd.nRecType )
3540 			{
3541 				case PPT_PST_ExtendedBuGraContainer :
3542 				{
3543 					while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aHd.GetRecEndFilePos() ) )
3544 					{
3545 						sal_uInt16 nType;
3546 						DffRecordHeader aBuGraAtomHd;
3547 						rSt >> aBuGraAtomHd;
3548 						if ( aBuGraAtomHd.nRecType == PPT_PST_ExtendedBuGraAtom )
3549 						{
3550 							rSt >> nType;
3551 							Graphic aGraphic;
3552 							if ( rMan.GetBLIPDirect( rSt, aGraphic, NULL ) )
3553 							{
3554 								sal_uInt32 nInstance = aBuGraAtomHd.nRecInstance;
3555 								PPTBuGraEntry* pBuGra = new PPTBuGraEntry( aGraphic, nInstance );
3556 								sal_uInt32 n = 0;
3557 								sal_uInt32 nBuGraCount = aBuGraList.Count();
3558 								if ( nBuGraCount )
3559 								{
3560 									if ( ( (PPTBuGraEntry*)aBuGraList.GetObject( nBuGraCount - 1 ) )->nInstance < nInstance )
3561 										n = nBuGraCount;
3562 									else
3563 									{	// maybe the instances are not sorted, we sort it
3564 										for ( n = 0; n < nBuGraCount; n++ )
3565 										{	// sorting fields ( hi >> lo )
3566 											if ( ( (PPTBuGraEntry*)aBuGraList.GetObject( n ) )->nInstance < nInstance )
3567 												break;
3568 										}
3569 									}
3570 								}
3571 								aBuGraList.Insert( pBuGra, (sal_uInt32)n );
3572 							}
3573 #ifdef DBG_UTIL
3574 							else DBG_ERROR( "PPTExParaProv::PPTExParaProv - bullet graphic is not valid (SJ)" );
3575 #endif
3576 						}
3577 #ifdef DBG_UTIL
3578 						else DBG_ERROR( "PPTExParaProv::PPTExParaProv - unknown atom interpreting the PPT_PST_ExtendedBuGraContainer (SJ)" );
3579 #endif
3580 						aBuGraAtomHd.SeekToEndOfRecord( rSt );
3581 					}
3582 					if ( aBuGraList.Count() )
3583 						bGraphics = sal_True;
3584 				}
3585 				break;
3586 
3587 				case PPT_PST_ExtendedPresRuleContainer :
3588 					aExtendedPresRules.Consume( rSt, sal_False, aHd.GetRecEndFilePos() );
3589 				break;
3590 #ifdef DBG_UTIL
3591 				default :
3592 					DBG_ERROR( "PPTExParaProv::PPTExParaProv - unknown atom reading ppt2000 num rules (SJ)" );
3593 				case PPT_PST_MasterText :	// first seen in: ms-tt02.ppt
3594 				case PPT_PST_SrKinsoku :
3595                 case PPT_PST_NewlyAddedAtom4016 :
3596 				case PPT_PST_NewlyAddedAtomByPPT2000_6010 :
3597 				case PPT_PST_NewlyAddedAtomByPPT2000_6011 :
3598                 case PPT_PST_NewlyAddedAtomByXP1037 :
3599                 case PPT_PST_NewlyAddedAtomByXP12004 :
3600                 case PPT_PST_NewlyAddedAtomByXP14001 :
3601 				break;
3602 #endif
3603 			}
3604 			aHd.SeekToEndOfRecord( rSt );
3605 		}
3606 		break;
3607 	}
3608 
3609 	while( pHd )
3610 	{   // get the extended paragraph styles on mainmaster ( graphical bullets, num ruling ... )
3611         if ( !rMan.SeekToContentOfProgTag( 9, rSt, *pHd, aContentDataHd ) )
3612             break;
3613 		while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aContentDataHd.GetRecEndFilePos() ) )
3614 		{
3615 			rSt >> aHd;
3616             switch ( aHd.nRecType )
3617             {
3618 			    case PPT_PST_ExtendedParagraphMasterAtom :
3619 			    {
3620 				    if ( aHd.nRecInstance < PPT_STYLESHEETENTRYS )
3621 				    {
3622 					    sal_uInt16 nDepth, i = 0;
3623 					    rSt >> nDepth;
3624 					    if ( i <= 5 )
3625 					    {
3626 
3627 						    while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aHd.GetRecEndFilePos() ) && ( i < nDepth ) )
3628 						    {
3629 							    bStyles = sal_True;
3630 							    rSt >> aExtParaSheet[ aHd.nRecInstance ].aExtParaLevel[ i++ ];
3631 						    }
3632 #ifdef DBG_UTIL
3633 						    if ( rSt.Tell() != aHd.GetRecEndFilePos() )
3634 							    DBG_ERROR( "PPTExParaProv::PPTExParaProv - error reading PPT_PST_ExtendedParagraphMasterAtom (SJ)" );
3635 #endif
3636 					    }
3637 #ifdef DBG_UTIL
3638 					    else DBG_ERROR( "PPTExParaProv::PPTExParaProv - depth is greater than 5 (SJ)" );
3639 #endif
3640 				    }
3641 #ifdef DBG_UTIL
3642 				    else DBG_ERROR( "PPTExParaProv::PPTExParaProv - instance out of range (SJ)" );
3643 #endif
3644     			}
3645                 break;
3646                 default :
3647                     DBG_ERROR( "PPTExParaProv::PPTExParaProv - unknown atom, assuming PPT_PST_ExtendedParagraphMasterAtom (SJ)" );
3648                 case PPT_PST_NewlyAddedAtomByXP11008 :
3649                 case PPT_PST_NewlyAddedAtomByXP11010 :
3650                 case PPT_PST_NewlyAddedAtomByXP12010 :
3651                 case PPT_PST_NewlyAddedAtomByXP12011 :
3652                 case 0xf144 :
3653                 break;
3654             }
3655 			aHd.SeekToEndOfRecord( rSt );
3656 		}
3657 		break;
3658 	}
3659 	rSt.Seek( nOldPos );
3660 }
3661 
~PPTExtParaProv()3662 PPTExtParaProv::~PPTExtParaProv()
3663 {
3664 	void* pPtr;
3665 	for ( pPtr = aBuGraList.First(); pPtr; pPtr = aBuGraList.Next() )
3666 		delete (PPTBuGraEntry*)pPtr;
3667 }
3668 
3669 ////////////////////////////////////////////////////////////////////////////////////////////////////
3670 
PPTNumberFormatCreator(PPTExtParaProv * pParaProv)3671 PPTNumberFormatCreator::PPTNumberFormatCreator( PPTExtParaProv* pParaProv ) :
3672     pExtParaProv ( pParaProv )
3673 {
3674 }
3675 
~PPTNumberFormatCreator()3676 PPTNumberFormatCreator::~PPTNumberFormatCreator()
3677 {
3678     delete pExtParaProv;
3679 }
3680 
ImplGetExtNumberFormat(SdrPowerPointImport & rManager,SvxNumberFormat & rNumberFormat,sal_uInt32 nLevel,sal_uInt32 nInstance,sal_uInt32 nDestinationInstance,boost::optional<sal_Int16> & rStartNumbering,sal_uInt32 nFontHeight,PPTParagraphObj * pPara)3681 sal_Bool PPTNumberFormatCreator::ImplGetExtNumberFormat( SdrPowerPointImport& rManager,
3682 	SvxNumberFormat& rNumberFormat, sal_uInt32 nLevel, sal_uInt32 nInstance, sal_uInt32 nDestinationInstance,
3683 		boost::optional< sal_Int16 >& rStartNumbering, sal_uInt32 nFontHeight,	PPTParagraphObj* pPara )
3684 {
3685 	sal_Bool bHardAttribute = ( nDestinationInstance == 0xffffffff );
3686 
3687 	sal_uInt32	nBuFlags = 0;
3688 	sal_uInt16	nHasAnm = 0;
3689 	sal_uInt32	nAnmScheme = 0x10003;
3690 	sal_uInt16	nBuBlip = 0xffff;
3691 
3692     const PPTExtParaProv* pParaProv = pExtParaProv;
3693     if ( !pExtParaProv )
3694         pParaProv = ( pPara ) ? pPara->mrStyleSheet.pExtParaProv
3695                               : rManager.pPPTStyleSheet->pExtParaProv;
3696 	if ( pPara )
3697 	{
3698 		nBuFlags = pPara->pParaSet->mnExtParagraphMask;
3699 		if ( nBuFlags )
3700 		{
3701 			if ( nBuFlags & 0x00800000 )
3702 				nBuBlip = pPara->pParaSet->mnBuBlip;
3703 			if ( nBuFlags & 0x01000000 )
3704 				nAnmScheme = pPara->pParaSet->mnAnmScheme;
3705 			if ( nBuFlags & 0x02000000 )
3706 				nHasAnm = pPara->pParaSet->mnHasAnm;
3707 			bHardAttribute = sal_True;
3708 		}
3709 	}
3710 
3711 	if ( ( nBuFlags & 0x03800000 ) != 0x03800000 )	// merge style sheet
3712 	{	// we have to read the master attributes
3713 		if ( pParaProv && ( nLevel < 5 ) )
3714 		{
3715 			if ( pParaProv->bStyles )
3716 			{
3717 				const PPTExtParaLevel& rLev = pParaProv->aExtParaSheet[ nInstance ].aExtParaLevel[ nLevel ];
3718 				if ( rLev.mbSet )
3719 				{
3720 					sal_uInt32 nMaBuFlags = rLev.mnExtParagraphMask;
3721 
3722 					if ( (!( nBuFlags & 0x00800000)) && ( nMaBuFlags & 0x00800000 ) )
3723 					{
3724 						if (!( nBuFlags & 0x02000000))			// if there is a BuStart without BuInstance,
3725 							nBuBlip = rLev.mnBuBlip;		// then there is no graphical Bullet possible
3726 					}
3727 					if ( (!( nBuFlags & 0x01000000)) && ( nMaBuFlags & 0x01000000 ) )
3728 						nAnmScheme = rLev.mnAnmScheme;
3729 					if ( (!( nBuFlags & 0x02000000)) && ( nMaBuFlags & 0x02000000 ) )
3730 						nHasAnm = rLev.mnHasAnm;
3731 					nBuFlags |= nMaBuFlags;
3732 				}
3733 			}
3734 		}
3735 	}
3736 	if ( nBuBlip != 0xffff )		// set graphical bullet
3737 	{
3738 		Graphic aGraphic;
3739 		if ( pParaProv->GetGraphic( nBuBlip, aGraphic ) )
3740 		{
3741             SvxBrushItem aBrush( aGraphic, GPOS_MM, SID_ATTR_BRUSH );
3742 			rNumberFormat.SetGraphicBrush( &aBrush );
3743 			sal_uInt32 nHeight = (sal_uInt32)( (double)nFontHeight * 0.2540 * nBulletHeight + 0.5 );
3744 			Size aPrefSize( aGraphic.GetPrefSize() );
3745 			sal_uInt32 nWidth = ( nHeight * aPrefSize.Width() ) / aPrefSize.Height();
3746 			rNumberFormat.SetGraphicSize( Size( nWidth, nHeight ) );
3747 			rNumberFormat.SetNumberingType ( SVX_NUM_BITMAP );
3748 		}
3749 	}
3750 	else if ( nHasAnm )
3751 	{
3752 		switch( static_cast< sal_uInt16 >( nAnmScheme ) )
3753 		{
3754 			default :
3755 			case 0 :
3756 			{
3757 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_LOWER_LETTER );
3758 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3759 			}
3760 			break;
3761 			case 1 :
3762 			{
3763 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_UPPER_LETTER );
3764 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3765 			}
3766 			break;
3767 			case 2 :
3768 			{
3769 				rNumberFormat.SetNumberingType( SVX_NUM_ARABIC );
3770 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3771 			}
3772 			break;
3773 			case 3 :
3774 			{
3775 				rNumberFormat.SetNumberingType( SVX_NUM_ARABIC );
3776 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3777 			}
3778 			break;
3779 			case 4 :
3780 			{
3781 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_LOWER );
3782 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3783 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3784 			}
3785 			break;
3786 			case 5 :
3787 			{
3788 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_LOWER );
3789 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3790 			}
3791 			break;
3792 			case 6 :
3793 			{
3794 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_LOWER );
3795 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3796 			}
3797 			break;
3798 			case 7 :
3799 			{
3800 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_UPPER );
3801 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3802 			}
3803 			break;
3804 			case 8 :
3805 			{
3806 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_LOWER_LETTER );
3807 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3808 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3809 			}
3810 			break;
3811 			case 9 :
3812 			{
3813 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_LOWER_LETTER );
3814 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3815 			}
3816 			break;
3817 			case 10 :
3818 			{
3819 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_UPPER_LETTER );
3820 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3821 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3822 			}
3823 			break;
3824 			case 11 :
3825 			{
3826 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_UPPER_LETTER );
3827 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3828 			}
3829 			break;
3830 			case 12 :
3831 			{
3832 				rNumberFormat.SetNumberingType( SVX_NUM_ARABIC );
3833 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3834 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3835 			}
3836 			break;
3837 			case 13 :
3838 			{
3839 				rNumberFormat.SetNumberingType( SVX_NUM_ARABIC );
3840 			}
3841 			break;
3842 			case 14 :
3843 			{
3844 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_UPPER );
3845 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3846 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3847 			}
3848 			break;
3849 			case 15 :
3850 			{
3851 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_UPPER );
3852 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3853 			}
3854 			break;
3855 			case 16: // Simplified Chinese.
3856 			{
3857 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_UPPER_ZH );
3858 			}
3859 			break;
3860 			case 17: // Simplified Chinese with single-byte period.
3861 			{
3862 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_UPPER_ZH );
3863 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3864 			}
3865 			break;
3866 			case 18: // Double byte circle numbers.
3867 			case 19: // Wingdings white circle numbers.
3868 			case 20: // Wingdings black circle numbers.
3869 			{
3870 				rNumberFormat.SetNumberingType( SVX_NUM_CIRCLE_NUMBER );
3871 			}
3872 			break;
3873 			case 21: // Traditional Chinese.
3874 			{
3875 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_UPPER_ZH_TW );
3876 			}
3877 			break;
3878 			case 22: // Traditional Chinese with single-byte period.
3879 			{
3880 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_UPPER_ZH_TW );
3881 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3882 			}
3883 			break;
3884 			case 26: // Japanese/Korean.
3885 			{
3886 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_LOWER_ZH );
3887 			}
3888 			break;
3889 			case 27: // Japanese/Korean with single-byte period.
3890 			{
3891 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_LOWER_ZH );
3892 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3893 			}
3894 			break;
3895 			case 28: // Double-byte Arabic numbers.
3896 			{
3897 				rNumberFormat.SetNumberingType( SVX_NUM_FULL_WIDTH_ARABIC );
3898 			}
3899 			break;
3900 			case 29: // Double-byte Arabic numbers with double-byte period.
3901 			{
3902 				rNumberFormat.SetNumberingType( SVX_NUM_FULL_WIDTH_ARABIC );
3903 				rNumberFormat.SetSuffix( String( sal_Unicode(0xff0e) ) );
3904 			}
3905 			break;
3906 			case 38: // Japanese with double-byte period.
3907 			{
3908 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_LOWER_ZH ); // No such type. Instead with Lower Chinese Number
3909 				rNumberFormat.SetSuffix( String( sal_Unicode(0xff0e) ) );
3910 			}
3911 			break;
3912 		}
3913 		rStartNumbering = boost::optional< sal_Int16 >( nAnmScheme >> 16 );
3914 		sal_Int16 nBuStart = *rStartNumbering;
3915 		//The Seventh bit of nBuFlags that specifies whether fBulletHasAutoNumber exists,
3916 		//and fBulletHasAutoNumber that specifies whether this paragraph has an automatic numbering scheme.
3917 		if ( ( nBuFlags & 0x02000000 ) && ( nBuStart != 1 ))
3918 		{
3919 			rNumberFormat.SetStart( static_cast<sal_uInt16>(nBuStart) );
3920 		}
3921 	}
3922 	return bHardAttribute;
3923 }
3924 
GetNumberFormat(SdrPowerPointImport & rManager,SvxNumberFormat & rNumberFormat,sal_uInt32 nLevel,const PPTParaLevel & rParaLevel,const PPTCharLevel & rCharLevel,sal_uInt32 nInstance)3925 void PPTNumberFormatCreator::GetNumberFormat( SdrPowerPointImport& rManager, SvxNumberFormat& rNumberFormat, sal_uInt32 nLevel, const PPTParaLevel& rParaLevel, const PPTCharLevel& rCharLevel, sal_uInt32 nInstance )
3926 {
3927 	nIsBullet = ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BulletOn ) ) != 0 ? 1 : 0;
3928 	nBulletChar = rParaLevel.mnBulletChar;
3929 
3930 	sal_Bool bBuHardFont;
3931 	bBuHardFont = ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BuHardFont ) ) != 0;
3932 	if ( bBuHardFont )
3933 		nBulletFont = rParaLevel.mnBulletFont;
3934 	else
3935 		nBulletFont = rCharLevel.mnFont;
3936 	nBulletHeight = rParaLevel.mnBulletHeight;
3937     nBulletColor = rParaLevel.mnBulletColor;
3938     nTextOfs = rParaLevel.mnTextOfs;
3939 	nBulletOfs = rParaLevel.mnBulletOfs;
3940 
3941 	boost::optional< sal_Int16 > oStartNumbering;
3942 	ImplGetExtNumberFormat( rManager, rNumberFormat, nLevel, nInstance, 0xffffffff, oStartNumbering, rCharLevel.mnFontHeight, NULL );
3943 	if ( ( rNumberFormat.GetNumberingType() != SVX_NUM_BITMAP ) && ( nBulletHeight > 0x7fff ) )
3944 		nBulletHeight = rCharLevel.mnFontHeight ? ((-((sal_Int16)nBulletHeight)) * 100 ) / rCharLevel.mnFontHeight : 100;
3945 	ImplGetNumberFormat( rManager, rNumberFormat, nLevel );
3946 	switch ( rNumberFormat.GetNumberingType() )
3947 	{
3948 		case SVX_NUM_CHARS_UPPER_LETTER :
3949 		case SVX_NUM_CHARS_LOWER_LETTER :
3950 		case SVX_NUM_ROMAN_UPPER :
3951 		case SVX_NUM_ROMAN_LOWER :
3952 		case SVX_NUM_ARABIC :
3953 		case SVX_NUM_CHARS_UPPER_LETTER_N :
3954 		case SVX_NUM_CHARS_LOWER_LETTER_N :
3955 		{
3956 			sal_uInt32 nFont = rCharLevel.mnFont;
3957 			PptFontEntityAtom* pFontEnityAtom = rManager.GetFontEnityAtom( nFont );
3958 			if ( pFontEnityAtom )
3959 			{
3960 				Font aFont;
3961 				aFont.SetCharSet( pFontEnityAtom->eCharSet );
3962 				aFont.SetName( pFontEnityAtom->aName );
3963 				aFont.SetFamily( pFontEnityAtom->eFamily );
3964 				aFont.SetPitch( pFontEnityAtom->ePitch );
3965 				rNumberFormat.SetBulletFont( &aFont );
3966 			}
3967 		}
3968 		break;
3969 	}
3970 }
3971 
GetNumberFormat(SdrPowerPointImport & rManager,SvxNumberFormat & rNumberFormat,PPTParagraphObj * pParaObj,sal_uInt32 nDestinationInstance,boost::optional<sal_Int16> & rStartNumbering)3972 sal_Bool PPTNumberFormatCreator::GetNumberFormat( SdrPowerPointImport& rManager, SvxNumberFormat& rNumberFormat, PPTParagraphObj* pParaObj,
3973 												sal_uInt32 nDestinationInstance, boost::optional< sal_Int16 >& rStartNumbering )
3974 {
3975 	sal_uInt32 nHardCount = 0;
3976 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletOn, nIsBullet, nDestinationInstance );
3977 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletChar, nBulletChar, nDestinationInstance );
3978 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletFont, nBulletFont, nDestinationInstance );
3979 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletHeight, nBulletHeight, nDestinationInstance );
3980 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletColor, nBulletColor, nDestinationInstance );
3981 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_TextOfs, nTextOfs, nDestinationInstance );
3982 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletOfs, nBulletOfs, nDestinationInstance );
3983 
3984 	if ( nIsBullet )
3985 		rNumberFormat.SetNumberingType( SVX_NUM_CHAR_SPECIAL );
3986 
3987 	sal_uInt32 nFontHeight = 24;
3988 	PPTPortionObj* pPtr = pParaObj->First();
3989 	if ( pPtr )
3990 		pPtr->GetAttrib( PPT_CharAttr_FontHeight, nFontHeight, nDestinationInstance );
3991 	if ( nIsBullet )
3992 		nHardCount += ImplGetExtNumberFormat( rManager, rNumberFormat, pParaObj->pParaSet->mnDepth,
3993 													pParaObj->mnInstance, nDestinationInstance, rStartNumbering, nFontHeight, pParaObj );
3994 
3995 	if ( rNumberFormat.GetNumberingType() != SVX_NUM_BITMAP )
3996 		pParaObj->UpdateBulletRelSize( nBulletHeight );
3997 	if ( nHardCount )
3998 		ImplGetNumberFormat( rManager, rNumberFormat, pParaObj->pParaSet->mnDepth );
3999 
4000 	if ( nHardCount )
4001 	{
4002 		switch ( rNumberFormat.GetNumberingType() )
4003 		{
4004 			case SVX_NUM_CHARS_UPPER_LETTER :
4005 			case SVX_NUM_CHARS_LOWER_LETTER :
4006 			case SVX_NUM_ROMAN_UPPER :
4007 			case SVX_NUM_ROMAN_LOWER :
4008 			case SVX_NUM_ARABIC :
4009 			case SVX_NUM_CHARS_UPPER_LETTER_N :
4010 			case SVX_NUM_CHARS_LOWER_LETTER_N :
4011 			{
4012 				if ( pPtr )
4013 				{
4014 					sal_uInt32 nFont;
4015 					pPtr->GetAttrib( PPT_CharAttr_Font, nFont, nDestinationInstance );
4016 					PptFontEntityAtom* pFontEnityAtom = rManager.GetFontEnityAtom( nFont );
4017 					if ( pFontEnityAtom )
4018 					{
4019 						Font aFont;
4020 						aFont.SetCharSet( pFontEnityAtom->eCharSet );
4021 						aFont.SetName( pFontEnityAtom->aName );
4022 						aFont.SetFamily( pFontEnityAtom->eFamily );
4023 						aFont.SetPitch( pFontEnityAtom->ePitch );
4024 						rNumberFormat.SetBulletFont( &aFont );
4025 					}
4026 				}
4027 			}
4028 			break;
4029 		}
4030 	}
4031 	return ( nHardCount ) ? sal_True : sal_False;
4032 }
4033 
ImplGetNumberFormat(SdrPowerPointImport & rManager,SvxNumberFormat & rNumberFormat,sal_uInt32)4034 void PPTNumberFormatCreator::ImplGetNumberFormat( SdrPowerPointImport& rManager, SvxNumberFormat& rNumberFormat, sal_uInt32 /*nLevel*/)
4035 {
4036 	Font aFont;
4037 	PptFontEntityAtom* pAtom = rManager.GetFontEnityAtom( nBulletFont );
4038     if ( pAtom )
4039     {
4040 		CharSet eCharSet( pAtom->eCharSet );
4041 		aFont.SetName( pAtom->aName );
4042 		aFont.SetCharSet( eCharSet );
4043 		aFont.SetFamily( pAtom->eFamily );
4044 		aFont.SetPitch( pAtom->ePitch );
4045     }
4046 	Color aCol( rManager.MSO_TEXT_CLR_ToColor( nBulletColor ) );
4047 	aFont.SetColor( aCol );
4048 
4049     sal_uInt16 nBuChar = (sal_uInt16)nBulletChar;
4050     if ( aFont.GetCharSet() == RTL_TEXTENCODING_SYMBOL )
4051     {
4052 		nBuChar &= 0x00ff;
4053 		nBuChar |= 0xf000;
4054     }
4055 	rNumberFormat.SetBulletFont( &aFont );
4056 	rNumberFormat.SetBulletChar( nBuChar );
4057 	rNumberFormat.SetBulletRelSize( (sal_uInt16)nBulletHeight );
4058 	rNumberFormat.SetBulletColor( aCol );
4059 	sal_uInt16 nAbsLSpace = (sal_uInt16)( ( (sal_uInt32)nTextOfs * 2540 ) / 576 );
4060 	sal_uInt16 nFirstLineOffset = nAbsLSpace - (sal_uInt16)( ( (sal_uInt32)nBulletOfs * 2540 ) / 576 );
4061 	rNumberFormat.SetAbsLSpace( nAbsLSpace );
4062 	rNumberFormat.SetFirstLineOffset( -nFirstLineOffset );
4063 }
4064 
4065 ////////////////////////////////////////////////////////////////////////////////////////////////////
4066 
PPTCharSheet(sal_uInt32 nInstance)4067 PPTCharSheet::PPTCharSheet( sal_uInt32 nInstance )
4068 {
4069 	sal_uInt32 nColor = PPT_COLSCHEME_TEXT_UND_ZEILEN;
4070 	sal_uInt16 nFontHeight(0);
4071 	switch ( nInstance )
4072 	{
4073 		case TSS_TYPE_PAGETITLE :
4074 		case TSS_TYPE_TITLE :
4075 		{
4076 			nColor = PPT_COLSCHEME_TITELTEXT;
4077 			nFontHeight = 44;
4078 		}
4079 		break;
4080 		case TSS_TYPE_BODY :
4081 		case TSS_TYPE_SUBTITLE :
4082 		case TSS_TYPE_HALFBODY :
4083 		case TSS_TYPE_QUARTERBODY :
4084 			nFontHeight = 32;
4085 		break;
4086 		case TSS_TYPE_NOTES :
4087 			nFontHeight = 12;
4088 		break;
4089 		case TSS_TYPE_UNUSED :
4090 		case TSS_TYPE_TEXT_IN_SHAPE :
4091 			nFontHeight = 24;
4092 		break;
4093 	}
4094 	for ( sal_uInt32 nDepth = 0; nDepth < 5; nDepth++ )
4095 	{
4096 		maCharLevel[ nDepth ].mnFlags = 0;
4097 		maCharLevel[ nDepth ].mnFont = 0;
4098 		maCharLevel[ nDepth ].mnAsianOrComplexFont = 0xffff;
4099 		maCharLevel[ nDepth ].mnFontHeight = nFontHeight;
4100 		maCharLevel[ nDepth ].mnFontColor = nColor;
4101 		maCharLevel[ nDepth ].mnFontColorInStyleSheet = Color( (sal_uInt8)nColor, (sal_uInt8)( nColor >> 8 ), (sal_uInt8)( nColor >> 16 ) );
4102 		maCharLevel[ nDepth ].mnEscapement = 0;
4103 	}
4104 }
4105 
PPTCharSheet(const PPTCharSheet & rAttr)4106 PPTCharSheet::PPTCharSheet( const PPTCharSheet& rAttr )
4107 {
4108 	*this = rAttr;
4109 }
4110 
Read(SvStream & rIn,sal_Bool,sal_uInt32 nLevel,sal_Bool)4111 void PPTCharSheet::Read( SvStream& rIn, sal_Bool /*bMasterStyle*/, sal_uInt32 nLevel, sal_Bool /*bFirst*/)
4112 {
4113     // Zeichenattribute
4114     sal_uInt32 nCMask;
4115 	sal_uInt16 nVal16;
4116 	rIn >> nCMask;
4117 
4118 	if ( nCMask & 0x0000FFFF )
4119 	{
4120         sal_uInt16 nBitAttr;
4121 		maCharLevel[ nLevel ].mnFlags &= ~( (sal_uInt16)nCMask );
4122 		rIn >> nBitAttr; // Bit-Attribute (Fett, Unterstrichen, ...)
4123 		maCharLevel[ nLevel ].mnFlags |= nBitAttr;
4124     }
4125 	if ( nCMask & ( 1 << PPT_CharAttr_Font ) )					// 0x00010000
4126 		rIn >> maCharLevel[ nLevel ].mnFont;
4127 	if ( nCMask & ( 1 << PPT_CharAttr_AsianOrComplexFont ) )	// 0x00200000
4128 		rIn >> maCharLevel[ nLevel ].mnAsianOrComplexFont;
4129 	if ( nCMask & ( 1 << PPT_CharAttr_ANSITypeface ) )			// 0x00400000
4130 		rIn >> nVal16;
4131 	if ( nCMask & ( 1 << PPT_CharAttr_Symbol ) )				// 0x00800000
4132 		rIn >> nVal16;
4133 	if ( nCMask & ( 1 << PPT_CharAttr_FontHeight ) )			// 0x00020000
4134 		rIn >> maCharLevel[ nLevel ].mnFontHeight;
4135 	if ( nCMask & ( 1 << PPT_CharAttr_FontColor ) )				// 0x00040000
4136 	{
4137 		rIn >> maCharLevel[ nLevel ].mnFontColor;
4138 		if( ! (maCharLevel[ nLevel ].mnFontColor & 0xff000000 ) )
4139 			maCharLevel[ nLevel ].mnFontColor = PPT_COLSCHEME_HINTERGRUND;
4140 	}
4141 	if ( nCMask & ( 1 << PPT_CharAttr_Escapement ) )			// 0x00080000
4142 		rIn >> maCharLevel[ nLevel ].mnEscapement;
4143 	if ( nCMask & 0x00100000 )									// 0x00100000
4144 		rIn >> nVal16;
4145 
4146 	nCMask >>= 24;
4147     while( nCMask )
4148 	{
4149 		if ( nCMask & 1 )
4150 		{
4151 		    DBG_ERROR( "PPTCharSheet::Read - unknown attribute, send me this document (SJ)" );
4152 			rIn >> nVal16;
4153 		}
4154 		nCMask >>= 1;
4155 	}
4156 }
4157 
PPTParaSheet(sal_uInt32 nInstance)4158 PPTParaSheet::PPTParaSheet( sal_uInt32 nInstance )
4159 {
4160 	sal_uInt16 nBuFlags = 0;
4161 	sal_uInt32 nBulletColor = 0x8000000;
4162 	sal_uInt16 nUpperDist = 0;
4163 
4164 	switch ( nInstance )
4165 	{
4166 		case TSS_TYPE_PAGETITLE :
4167 		case TSS_TYPE_TITLE :
4168 			nBulletColor = PPT_COLSCHEME_TITELTEXT;
4169 		break;
4170 		case TSS_TYPE_BODY :
4171 		case TSS_TYPE_SUBTITLE :
4172 		case TSS_TYPE_HALFBODY :
4173 		case TSS_TYPE_QUARTERBODY :
4174 		{
4175 			nBuFlags = 1;
4176 			nUpperDist = 0x14;
4177 		}
4178 		break;
4179 		case TSS_TYPE_NOTES :
4180 			nUpperDist = 0x1e;
4181 		break;
4182 /*
4183 		default :
4184 		case TSS_TYPE_UNUSED :
4185 		case TSS_TYPE_TEXT_IN_SHAPE :
4186 		break;
4187 */
4188 	}
4189 	for ( sal_uInt32 i = 0; i < 5; i++ )
4190 	{
4191 		maParaLevel[ i ].mnBuFlags = nBuFlags;
4192 		maParaLevel[ i ].mnBulletChar = 0x2022;
4193 		maParaLevel[ i ].mnBulletFont = 0;
4194 		maParaLevel[ i ].mnBulletHeight = 100;
4195 		maParaLevel[ i ].mnBulletColor = nBulletColor;
4196 		maParaLevel[ i ].mnAdjust = 0;
4197 		maParaLevel[ i ].mnLineFeed = 100;
4198 		maParaLevel[ i ].mnLowerDist = 0;
4199 		maParaLevel[ i ].mnUpperDist = nUpperDist;
4200 		maParaLevel[ i ].mnTextOfs = 0;
4201 		maParaLevel[ i ].mnBulletOfs = 0;
4202 		maParaLevel[ i ].mnDefaultTab = 0x240;
4203         maParaLevel[ i ].mnAsianLineBreak = 0;
4204 		maParaLevel[ i ].mnBiDi = 0;
4205 	}
4206 }
4207 
PPTParaSheet(const PPTParaSheet & rSheet)4208 PPTParaSheet::PPTParaSheet( const PPTParaSheet& rSheet )
4209 {
4210 	*this = rSheet;
4211 }
4212 
Read(SdrPowerPointImport & rManager,SvStream & rIn,sal_Bool,sal_uInt32 nLevel,sal_Bool bFirst)4213 void PPTParaSheet::Read( SdrPowerPointImport&
4214 #ifdef DBG_UTIL
4215 					rManager
4216 #endif
4217 					, SvStream& rIn, sal_Bool /*bMasterStyle*/,
4218                     sal_uInt32 nLevel, sal_Bool bFirst )
4219 {
4220     // Absatzattribute
4221 	sal_uInt16  nVal16, i, nMask16;
4222     sal_uInt32  nVal32, nPMask;
4223 	rIn >> nPMask;
4224 
4225     nMask16 = (sal_uInt16)nPMask & 0xf;
4226 	if ( nMask16 )
4227 	{
4228 		rIn >> nVal16;
4229 		maParaLevel[ nLevel ].mnBuFlags &=~ nMask16;
4230         nVal16 &= nMask16;
4231         maParaLevel[ nLevel ].mnBuFlags |= nVal16;
4232 	}
4233 	if ( nPMask & 0x0080 )
4234         rIn >> maParaLevel[ nLevel ].mnBulletChar;
4235 	if ( nPMask & 0x0010 )
4236         rIn >> maParaLevel[ nLevel ].mnBulletFont;
4237 	if ( nPMask & 0x0040 )
4238 	{
4239 		rIn >> nVal16;
4240 		maParaLevel[ nLevel ].mnBulletHeight = nVal16;
4241 	}
4242 	if ( nPMask & 0x0020 )
4243 	{
4244 		rIn >> nVal32;
4245 		maParaLevel[ nLevel ].mnBulletColor = nVal32;
4246 	}
4247 	if ( bFirst )
4248 	{
4249 		if ( nPMask & 0xF00 )
4250 		{	// AbsJust!
4251 			rIn >> nVal16;
4252 			maParaLevel[ nLevel ].mnAdjust = nVal16 & 3;
4253 		}
4254 		if ( nPMask & 0x1000 )
4255 			rIn >> maParaLevel[ nLevel ].mnLineFeed;
4256 		if ( nPMask & 0x2000 )
4257 			rIn >> maParaLevel[ nLevel ].mnUpperDist;
4258 		if ( nPMask & 0x4000 )
4259 			rIn >> maParaLevel[ nLevel ].mnLowerDist;
4260 		if ( nPMask & 0x8000 )
4261 			rIn >> maParaLevel[ nLevel ].mnTextOfs;
4262 		if ( nPMask & 0x10000 )
4263 			rIn >> maParaLevel[ nLevel ].mnBulletOfs;
4264 		if ( nPMask & 0x20000 )
4265 			rIn >> maParaLevel[ nLevel ].mnDefaultTab;
4266 		if ( nPMask & 0x200000 )
4267 		{
4268 			// number of tabulators
4269 			rIn >> nVal16;
4270 			for ( i = 0; i < nVal16; i++ )
4271 				rIn >> nVal32;		// reading the tabulators
4272 		}
4273 		if ( nPMask & 0x40000 )
4274 			rIn >> nVal16;
4275 		if ( nPMask & 0x80000 )
4276 			rIn >> maParaLevel[ nLevel ].mnAsianLineBreak;
4277 		if ( nPMask & 0x100000 )
4278 			rIn >> maParaLevel[ nLevel ].mnBiDi;
4279 	}
4280 	else
4281 	{
4282 		if ( nPMask & 0x800 )
4283 		{
4284 			rIn >> nVal16;
4285 			maParaLevel[ nLevel ].mnAdjust = nVal16 & 3;
4286 		}
4287 		if ( nPMask & 0x1000 )
4288 			rIn >> maParaLevel[ nLevel ].mnLineFeed;
4289 		if ( nPMask & 0x2000 )
4290 			rIn >> maParaLevel[ nLevel ].mnUpperDist;
4291 		if ( nPMask & 0x4000 )
4292 			rIn >> maParaLevel[ nLevel ].mnLowerDist;
4293 		if ( nPMask & 0x8000 )
4294 			rIn >> nVal16;
4295 		if ( nPMask & 0x100 )
4296 			rIn >> maParaLevel[ nLevel ].mnTextOfs;
4297 		if ( nPMask & 0x200 )
4298 			rIn >> nVal16;
4299 		if ( nPMask & 0x400 )
4300 			rIn >> maParaLevel[ nLevel ].mnBulletOfs;
4301 		if ( nPMask & 0x10000 )
4302 			rIn >> nVal16;
4303         if ( nPMask & 0xe0000 )
4304         {
4305             sal_uInt16 nFlagsToModifyMask = (sal_uInt16)( ( nPMask >> 17 ) & 7 );
4306             rIn >> nVal16;
4307             // bits that are not involved to zero
4308             nVal16 &= nFlagsToModifyMask;
4309             // bits that are to change to zero
4310             maParaLevel[ nLevel ].mnAsianLineBreak &=~nFlagsToModifyMask;
4311             // now set the corresponding bits
4312             maParaLevel[ nLevel ].mnAsianLineBreak |= nVal16;
4313         }
4314 		if ( nPMask & 0x100000 )
4315 		{
4316 			// number of tabulators
4317 			rIn >> nVal16;
4318 			for ( i = 0; i < nVal16; i++ )
4319 				rIn >> nVal32;		// reading the tabulators
4320 		}
4321         if ( nPMask & 0x200000 )
4322             rIn >> maParaLevel[ nLevel ].mnBiDi;		// #88602#
4323 	}
4324 
4325     nPMask >>= 22;
4326     while( nPMask )
4327 	{
4328 		if ( nPMask & 1 )
4329 		{
4330 #ifdef DBG_UTIL
4331             if (!(rManager.rImportParam.nImportFlags & PPT_IMPORTFLAGS_NO_TEXT_ASSERT))
4332             {
4333 		    	DBG_ERROR( "PPTParaSheet::Read - unknown attribute, send me this document (SJ)" );
4334             }
4335 #endif
4336 			rIn >> nVal16;
4337 		}
4338 		nPMask >>= 1;
4339 	}
4340 }
4341 
UpdateBulletRelSize(sal_uInt32 nLevel,sal_uInt16 nFontHeight)4342 void PPTParaSheet::UpdateBulletRelSize(  sal_uInt32 nLevel, sal_uInt16 nFontHeight )
4343 {
4344 	if ( maParaLevel[ nLevel ].mnBulletHeight > 0x7fff ) // a negative value is the absolute bullet height
4345 	{
4346 		sal_Int16  nBulletRelSize = ( sal_Int16 )maParaLevel[ nLevel ].mnBulletHeight;
4347 		nBulletRelSize = nFontHeight ? ((-nBulletRelSize) * 100 ) / nFontHeight : 100;
4348 		if ( nBulletRelSize < 0 ) //bullet size over flow
4349 			nBulletRelSize = 100;
4350 		maParaLevel[ nLevel ].mnBulletHeight = nBulletRelSize;
4351 	}
4352 }
4353 
PPTStyleSheet(const DffRecordHeader & rSlideHd,SvStream & rIn,SdrPowerPointImport & rManager,const PPTTextCharacterStyleAtomInterpreter &,const PPTTextParagraphStyleAtomInterpreter & rTxPFStyle,const PPTTextSpecInfo & rTextSpecInfo)4354 PPTStyleSheet::PPTStyleSheet( const DffRecordHeader& rSlideHd, SvStream& rIn, SdrPowerPointImport& rManager,
4355                                 const PPTTextCharacterStyleAtomInterpreter& /*rTxCFStyle*/, const PPTTextParagraphStyleAtomInterpreter& rTxPFStyle,
4356 									const PPTTextSpecInfo& rTextSpecInfo ) :
4357 
4358 	PPTNumberFormatCreator  ( new PPTExtParaProv( rManager, rIn, &rSlideHd ) ),
4359 	maTxSI	                ( rTextSpecInfo )
4360 {
4361 	sal_uInt32 i;
4362 	sal_uInt32 nOldFilePos = rIn.Tell();
4363 
4364 	// default stylesheets
4365 	mpCharSheet[ TSS_TYPE_PAGETITLE ] = new PPTCharSheet( TSS_TYPE_PAGETITLE );
4366 	mpCharSheet[ TSS_TYPE_BODY ] = new PPTCharSheet( TSS_TYPE_BODY );
4367 	mpCharSheet[ TSS_TYPE_NOTES ] = new PPTCharSheet(  TSS_TYPE_NOTES );
4368 	mpCharSheet[ TSS_TYPE_UNUSED ] = new PPTCharSheet( TSS_TYPE_UNUSED );	// this entry is not used by ppt
4369 	mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ] = new PPTCharSheet( TSS_TYPE_TEXT_IN_SHAPE );
4370 	mpParaSheet[ TSS_TYPE_PAGETITLE ] = new PPTParaSheet( TSS_TYPE_PAGETITLE );
4371 	mpParaSheet[ TSS_TYPE_BODY ] = new PPTParaSheet( TSS_TYPE_BODY );
4372 	mpParaSheet[ TSS_TYPE_NOTES ] = new PPTParaSheet( TSS_TYPE_NOTES );
4373 	mpParaSheet[ TSS_TYPE_UNUSED ] = new PPTParaSheet( TSS_TYPE_UNUSED );
4374 	mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ] = new PPTParaSheet( TSS_TYPE_TEXT_IN_SHAPE );
4375 	mpCharSheet[ TSS_TYPE_QUARTERBODY ] = mpCharSheet[ TSS_TYPE_HALFBODY ] = mpCharSheet[ TSS_TYPE_TITLE ] = mpCharSheet[ TSS_TYPE_SUBTITLE ] = NULL;
4376 	mpParaSheet[ TSS_TYPE_QUARTERBODY ] = mpParaSheet[ TSS_TYPE_HALFBODY ] = mpParaSheet[ TSS_TYPE_TITLE ] = mpParaSheet[ TSS_TYPE_SUBTITLE ] = NULL;
4377 
4378 	/* SJ: try to locate the txMasterStyleAtom in the Environment
4379 
4380 	   it seems that the environment TextStyle is having a higher priority
4381 	   than the TextStyle that can be found within the master page
4382 	*/
4383 	sal_Bool bFoundTxMasterStyleAtom04 = sal_False;
4384 	DffRecordHeader* pEnvHeader = rManager.aDocRecManager.GetRecordHeader( PPT_PST_Environment );
4385 	if ( pEnvHeader )
4386 	{
4387 		pEnvHeader->SeekToContent( rIn );
4388 		DffRecordHeader aTxMasterStyleHd;
4389 		while ( rIn.Tell() < pEnvHeader->GetRecEndFilePos() )
4390 		{
4391 			rIn >> aTxMasterStyleHd;
4392 			if ( aTxMasterStyleHd.nRecType == PPT_PST_TxMasterStyleAtom )
4393 			{
4394 				sal_uInt16 nLevelAnz;
4395 				rIn >> nLevelAnz;
4396 
4397 				if (nLevelAnz > 5)
4398 				{
4399 					throw std::range_error("Bad input file, Too many stylesheet levels");
4400 				}
4401 
4402 				sal_uInt16 nLev = 0;
4403 				sal_Bool bFirst = sal_True;
4404 				bFoundTxMasterStyleAtom04 = sal_True;
4405 				while ( rIn.GetError() == 0 && rIn.Tell() < aTxMasterStyleHd.GetRecEndFilePos() && nLev < nLevelAnz )
4406 				{
4407 					if ( nLev )
4408 					{
4409 						mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ nLev ] = mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ nLev - 1 ];
4410 						mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev ] = mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev - 1 ];
4411 					}
4412 					mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->Read( rManager, rIn, sal_True, nLev, bFirst );
4413                     if ( !nLev )
4414                     {
4415                         // set paragraph defaults for instance 4 (TSS_TYPE_TEXT_IN_SHAPE)
4416                         if ( rTxPFStyle.bValid )
4417                         {
4418                             PPTParaLevel& rParaLevel = mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ 0 ];
4419                             rParaLevel.mnAsianLineBreak = 0;
4420                             if ( rTxPFStyle.bForbiddenRules )
4421                                 rParaLevel.mnAsianLineBreak |= 1;
4422                             if ( !rTxPFStyle.bLatinTextWrap )
4423                                 rParaLevel.mnAsianLineBreak |= 2;
4424                             if ( rTxPFStyle.bHangingPunctuation )
4425                                 rParaLevel.mnAsianLineBreak |= 4;
4426                         }
4427                     }
4428 					mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->Read( rIn, sal_True, nLev, bFirst );
4429 					mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->UpdateBulletRelSize(  nLev, mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev ].mnFontHeight );
4430 					bFirst = sal_False;
4431 					nLev++;
4432 				}
4433 				break;
4434 			}
4435 			else
4436 				aTxMasterStyleHd.SeekToEndOfRecord( rIn );
4437 		}
4438 	}
4439 
4440 	rSlideHd.SeekToContent( rIn );
4441 	DffRecordHeader aTxMasterStyleHd;
4442 	while ( rIn.Tell() < rSlideHd.GetRecEndFilePos() )
4443 	{
4444 		rIn >> aTxMasterStyleHd;
4445 		if ( aTxMasterStyleHd.nRecType == PPT_PST_TxMasterStyleAtom )
4446 			break;
4447 		else
4448 			aTxMasterStyleHd.SeekToEndOfRecord( rIn );
4449 	}
4450 	while ( ( aTxMasterStyleHd.nRecType == PPT_PST_TxMasterStyleAtom ) && ( rIn.Tell() < rSlideHd.GetRecEndFilePos() ) ) //TODO: aTxMasterStyleHd may be used without having been properly initialized
4451 	{
4452 		sal_uInt32 nInstance = aTxMasterStyleHd.nRecInstance;
4453 		if ( ( nInstance < PPT_STYLESHEETENTRYS ) &&
4454 			( ( nInstance != TSS_TYPE_TEXT_IN_SHAPE ) || ( bFoundTxMasterStyleAtom04 == sal_False ) ) )
4455 		{
4456 			if ( nInstance > 4 )
4457 			{
4458 				delete mpCharSheet[ nInstance ];	// be sure to delete the old one if this instance comes twice
4459 				delete mpParaSheet[ nInstance ];
4460 
4461 				switch ( nInstance )
4462 				{
4463 					case TSS_TYPE_SUBTITLE :
4464 					{
4465 						mpCharSheet[ TSS_TYPE_SUBTITLE ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4466 						mpParaSheet[ TSS_TYPE_SUBTITLE ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4467 					}
4468 					break;
4469 					case TSS_TYPE_TITLE :
4470 					{
4471 						mpCharSheet[ TSS_TYPE_TITLE ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_PAGETITLE ] ) );
4472 						mpParaSheet[ TSS_TYPE_TITLE ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_PAGETITLE ] ) );
4473 					}
4474 					break;
4475 					case TSS_TYPE_HALFBODY :
4476 					{
4477 						mpCharSheet[ TSS_TYPE_HALFBODY ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4478 						mpParaSheet[ TSS_TYPE_HALFBODY ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4479 					}
4480 					break;
4481 
4482 					case TSS_TYPE_QUARTERBODY :
4483 					{
4484 						mpCharSheet[ TSS_TYPE_QUARTERBODY ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4485 						mpParaSheet[ TSS_TYPE_QUARTERBODY ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4486 					}
4487 					break;
4488 				}
4489 			}
4490 			sal_uInt16 nLevelAnz;
4491 			rIn >> nLevelAnz;
4492 			if ( nLevelAnz > 5 )
4493 			{
4494 				DBG_ERROR( "PPTStyleSheet::Ppt-TextStylesheet hat mehr als 5 Ebenen! (SJ)" );
4495 				nLevelAnz = 5;
4496 			}
4497 			sal_uInt16	nLev = 0;
4498 			sal_Bool	bFirst = sal_True;
4499 
4500 			while ( rIn.GetError() == 0 && rIn.Tell() < aTxMasterStyleHd.GetRecEndFilePos() && nLev < nLevelAnz )
4501 			{
4502 				if ( nLev && ( nInstance < 5 ) )
4503 				{
4504 					mpParaSheet[ nInstance ]->maParaLevel[ nLev ] = mpParaSheet[ nInstance ]->maParaLevel[ nLev - 1 ];
4505 					mpCharSheet[ nInstance ]->maCharLevel[ nLev ] = mpCharSheet[ nInstance ]->maCharLevel[ nLev - 1 ];
4506 				}
4507 
4508 				// Ausnahme: Vorlage 5, 6 (MasterTitle Titel und SubTitel)
4509 				if ( nInstance >= TSS_TYPE_SUBTITLE )
4510 				{
4511 					bFirst = sal_False;
4512 
4513 					sal_uInt16 nDontKnow;
4514 					rIn >> nDontKnow;
4515 				}
4516 				mpParaSheet[ nInstance ]->Read( rManager, rIn, sal_True, nLev, bFirst );
4517 				mpCharSheet[ nInstance ]->Read( rIn, sal_True, nLev, bFirst );
4518 				mpParaSheet[ nInstance ]->UpdateBulletRelSize(  nLev, mpCharSheet[ nInstance ]->maCharLevel[ nLev ].mnFontHeight );
4519 				bFirst = sal_False;
4520 				nLev++;
4521 			}
4522 #ifdef DBG_UTIL
4523             if (!(rManager.rImportParam.nImportFlags & PPT_IMPORTFLAGS_NO_TEXT_ASSERT))
4524             {
4525 			    if ( rIn.GetError() == 0 )
4526 			    {
4527 				    ByteString aMsg;
4528 				    if ( rIn.Tell() > aTxMasterStyleHd.GetRecEndFilePos() )
4529 				    {
4530 					    aMsg += "\n  ";
4531 					    aMsg += "reading too many bytes:";
4532 					    aMsg += ByteString::CreateFromInt32( rIn.Tell() - aTxMasterStyleHd.GetRecEndFilePos() );
4533 				    }
4534 				    if ( rIn.Tell() < aTxMasterStyleHd.GetRecEndFilePos() )
4535 				    {
4536 					    aMsg += "\n  ";
4537 					    aMsg += "reading too less bytes:";
4538 					    aMsg += ByteString::CreateFromInt32( aTxMasterStyleHd.GetRecEndFilePos() - rIn.Tell() );
4539 				    }
4540 				    if ( aMsg.Len() != 0 )
4541 				    {
4542 					    aMsg.Insert( "]:", 0 );
4543 					    aMsg.Insert( "PptStyleSheet::operator>>[", 0 );
4544 					    DBG_ERROR(aMsg.GetBuffer());
4545 				    }
4546 			    }
4547 			    if ( rIn.Tell() != aTxMasterStyleHd.GetRecEndFilePos() )
4548 				    DBG_ASSERT(0, "SJ: Falsche Anzahl von Bytes gelesen beim Import der PPT-Formatvorlagen");
4549             }
4550 #endif
4551 		}
4552 		aTxMasterStyleHd.SeekToEndOfRecord( rIn );
4553 		rIn >> aTxMasterStyleHd;
4554 	}
4555 	if ( !mpCharSheet[ TSS_TYPE_SUBTITLE ] )
4556 	{
4557 		mpCharSheet[ TSS_TYPE_SUBTITLE ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4558 		mpParaSheet[ TSS_TYPE_SUBTITLE ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4559 	}
4560 	if ( !mpCharSheet[ TSS_TYPE_TITLE ] )
4561 	{
4562 		mpCharSheet[ TSS_TYPE_TITLE ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_PAGETITLE ] ) );
4563 		mpParaSheet[ TSS_TYPE_TITLE ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_PAGETITLE ] ) );
4564 	}
4565 	if ( !mpCharSheet[ TSS_TYPE_HALFBODY ] )
4566 	{
4567 		mpCharSheet[ TSS_TYPE_HALFBODY ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4568 		mpParaSheet[ TSS_TYPE_HALFBODY ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4569 	}
4570 	if ( !mpCharSheet[ TSS_TYPE_QUARTERBODY ] )
4571 	{
4572 		mpCharSheet[ TSS_TYPE_QUARTERBODY ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4573 		mpParaSheet[ TSS_TYPE_QUARTERBODY ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4574 	}
4575 	if ( !bFoundTxMasterStyleAtom04 )
4576 	{	// try to locate the txMasterStyleAtom in the Environment
4577 		DffRecordHeader* pEnvHeader2 = rManager.aDocRecManager.GetRecordHeader( PPT_PST_Environment );
4578 		if ( pEnvHeader2 )
4579 		{
4580 			pEnvHeader2->SeekToContent( rIn );
4581 			DffRecordHeader aTxMasterStyleHd2;
4582 			while ( rIn.Tell() < pEnvHeader2->GetRecEndFilePos() )
4583 			{
4584 				rIn >> aTxMasterStyleHd2;
4585 				if ( aTxMasterStyleHd2.nRecType == PPT_PST_TxMasterStyleAtom )
4586 				{
4587 					sal_uInt16 nLevelAnz;
4588 					rIn >> nLevelAnz;
4589 
4590 					sal_uInt16 nLev = 0;
4591 					sal_Bool bFirst = sal_True;
4592 					while ( rIn.GetError() == 0 && rIn.Tell() < aTxMasterStyleHd2.GetRecEndFilePos() && nLev < nLevelAnz )
4593 					{
4594 						if ( nLev )
4595 						{
4596 							mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ nLev ] = mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ nLev - 1 ];
4597 							mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev ] = mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev - 1 ];
4598 						}
4599 						mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->Read( rManager, rIn, sal_True, nLev, bFirst );
4600                         if ( !nLev )
4601                         {
4602                             // set paragraph defaults for instance 4 (TSS_TYPE_TEXT_IN_SHAPE)
4603                             if ( rTxPFStyle.bValid )
4604                             {
4605                                 PPTParaLevel& rParaLevel = mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ 0 ];
4606                                 rParaLevel.mnAsianLineBreak = 0;
4607                                 if ( rTxPFStyle.bForbiddenRules )
4608                                     rParaLevel.mnAsianLineBreak |= 1;
4609                                 if ( !rTxPFStyle.bLatinTextWrap )
4610                                     rParaLevel.mnAsianLineBreak |= 2;
4611                                 if ( rTxPFStyle.bHangingPunctuation )
4612                                     rParaLevel.mnAsianLineBreak |= 4;
4613                             }
4614                         }
4615 						mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->Read( rIn, sal_True, nLev, bFirst );
4616 						mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->UpdateBulletRelSize(  nLev, mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev ].mnFontHeight );
4617 						bFirst = sal_False;
4618 						nLev++;
4619 					}
4620 					break;
4621 				}
4622 				else
4623 					aTxMasterStyleHd2.SeekToEndOfRecord( rIn );
4624 			}
4625 		}
4626 	}
4627 	rIn.Seek( nOldFilePos );
4628 
4629 	// will will create the default numbulletitem for each instance
4630 	for ( i = 0; i < PPT_STYLESHEETENTRYS; i++ )
4631 	{
4632 		sal_uInt16			nLevels, nDepth = 0;
4633 		SvxNumRuleType	eNumRuleType;
4634 
4635 		switch ( i )
4636 		{
4637 			case TSS_TYPE_PAGETITLE :
4638 			case TSS_TYPE_TITLE :
4639 				nLevels = 1;
4640 				eNumRuleType = SVX_RULETYPE_NUMBERING;
4641 			break;
4642 			case TSS_TYPE_SUBTITLE :
4643 				nLevels = 10;
4644 				eNumRuleType = SVX_RULETYPE_NUMBERING;
4645 			break;
4646 			case TSS_TYPE_BODY :
4647 			case TSS_TYPE_HALFBODY :
4648 			case TSS_TYPE_QUARTERBODY :
4649 				nLevels = 10;
4650 				eNumRuleType = SVX_RULETYPE_PRESENTATION_NUMBERING;
4651 			break;
4652 			default :
4653 			case TSS_TYPE_NOTES :
4654 			case TSS_TYPE_UNUSED :
4655 			case TSS_TYPE_TEXT_IN_SHAPE :
4656 				nLevels = 10;
4657 				eNumRuleType = SVX_RULETYPE_NUMBERING;
4658 			break;
4659 		}
4660 		SvxNumRule aRule( NUM_BULLET_REL_SIZE | NUM_BULLET_COLOR |
4661 						NUM_CHAR_TEXT_DISTANCE | NUM_SYMBOL_ALIGNMENT,
4662 						nLevels, sal_False, eNumRuleType );
4663 		for ( sal_uInt16 nCount = 0; nDepth < nLevels; nCount++ )
4664 		{
4665 			const PPTParaLevel& rParaLevel = mpParaSheet[ i ]->maParaLevel[ nCount ];
4666 			const PPTCharLevel& rCharLevel = mpCharSheet[ i ]->maCharLevel[ nCount ];
4667 			SvxNumberFormat aNumberFormat( SVX_NUM_CHAR_SPECIAL );
4668 			aNumberFormat.SetBulletChar( ' ' );
4669 			GetNumberFormat( rManager, aNumberFormat, nCount, rParaLevel, rCharLevel, i );
4670 			aRule.SetLevel( nDepth++, aNumberFormat );
4671 			if ( nCount >= 4 )
4672 			{
4673 				for ( ;nDepth < nLevels; nDepth++ )
4674 					aRule.SetLevel( nDepth, aNumberFormat );
4675 				if ( eNumRuleType == SVX_RULETYPE_PRESENTATION_NUMBERING )
4676 					aRule.SetLevel( 0, aNumberFormat );
4677 			}
4678 		}
4679 		mpNumBulletItem[ i ] = new SvxNumBulletItem( aRule, EE_PARA_NUMBULLET );
4680 	}
4681 }
4682 
~PPTStyleSheet()4683 PPTStyleSheet::~PPTStyleSheet()
4684 {
4685 	for ( sal_uInt32 i = 0; i < PPT_STYLESHEETENTRYS; i++ )
4686 	{
4687 		delete mpCharSheet[ i ];
4688 		delete mpParaSheet[ i ];
4689 		delete mpNumBulletItem[ i ];
4690 	}
4691 }
4692 
4693 ////////////////////////////////////////////////////////////////////////////////////////////////////
4694 
PPTParaPropSet()4695 PPTParaPropSet::PPTParaPropSet() :
4696 	pParaSet( new ImplPPTParaPropSet )
4697 {
4698     pParaSet->mnHasAnm = 1;
4699 }
4700 
PPTParaPropSet(PPTParaPropSet & rParaPropSet)4701 PPTParaPropSet::PPTParaPropSet( PPTParaPropSet& rParaPropSet )
4702 {
4703 	pParaSet = rParaPropSet.pParaSet;
4704 	pParaSet->mnRefCount++;
4705 
4706 	mnOriginalTextPos = rParaPropSet.mnOriginalTextPos;
4707 }
4708 
~PPTParaPropSet()4709 PPTParaPropSet::~PPTParaPropSet()
4710 {
4711 	if ( ! ( --pParaSet->mnRefCount ) )
4712 		delete pParaSet;
4713 }
4714 
operator =(PPTParaPropSet & rParaPropSet)4715 PPTParaPropSet& PPTParaPropSet::operator=( PPTParaPropSet& rParaPropSet )
4716 {
4717 	if ( this != &rParaPropSet )
4718 	{
4719 		if ( ! ( --pParaSet->mnRefCount ) )
4720 			delete pParaSet;
4721 		pParaSet = rParaPropSet.pParaSet;
4722 		pParaSet->mnRefCount++;
4723 
4724 		mnOriginalTextPos = rParaPropSet.mnOriginalTextPos;
4725 	}
4726 	return *this;
4727 }
4728 
PPTCharPropSet(sal_uInt32 nParagraph)4729 PPTCharPropSet::PPTCharPropSet( sal_uInt32 nParagraph ) :
4730 	mnParagraph		( nParagraph ),
4731 	mpFieldItem		( NULL ),
4732 	pCharSet		( new ImplPPTCharPropSet )
4733 {
4734 	mnHylinkOrigColor = 0;
4735 	mbIsHyperlink = sal_False;
4736 	mbHardHylinkOrigColor = sal_False;
4737 	mnLanguage[ 0 ] = mnLanguage[ 1 ] = mnLanguage[ 2 ] = 0;
4738 }
4739 
PPTCharPropSet(PPTCharPropSet & rCharPropSet)4740 PPTCharPropSet::PPTCharPropSet( PPTCharPropSet& rCharPropSet )
4741 {
4742 	mnHylinkOrigColor = rCharPropSet.mnHylinkOrigColor;
4743 	mbIsHyperlink = rCharPropSet.mbIsHyperlink;
4744 	mbHardHylinkOrigColor = rCharPropSet.mbHardHylinkOrigColor;
4745 	pCharSet = rCharPropSet.pCharSet;
4746 	pCharSet->mnRefCount++;
4747 
4748 	mnParagraph = rCharPropSet.mnParagraph;
4749 	mnOriginalTextPos = rCharPropSet.mnOriginalTextPos;
4750 	maString = rCharPropSet.maString;
4751 	mpFieldItem = ( rCharPropSet.mpFieldItem ) ? new SvxFieldItem( *rCharPropSet.mpFieldItem ) : NULL;
4752 	mnLanguage[ 0 ] = rCharPropSet.mnLanguage[ 0 ];
4753 	mnLanguage[ 1 ] = rCharPropSet.mnLanguage[ 1 ];
4754 	mnLanguage[ 2 ] = rCharPropSet.mnLanguage[ 2 ];
4755 }
4756 
PPTCharPropSet(PPTCharPropSet & rCharPropSet,sal_uInt32 nParagraph)4757 PPTCharPropSet::PPTCharPropSet( PPTCharPropSet& rCharPropSet, sal_uInt32 nParagraph )
4758 {
4759 	pCharSet = rCharPropSet.pCharSet;
4760 	pCharSet->mnRefCount++;
4761 
4762 	mnHylinkOrigColor = rCharPropSet.mnHylinkOrigColor;
4763 	mbIsHyperlink = rCharPropSet.mbIsHyperlink;
4764 	mbHardHylinkOrigColor = rCharPropSet.mbHardHylinkOrigColor;
4765 
4766 	mnParagraph = nParagraph;
4767 	mnOriginalTextPos = rCharPropSet.mnOriginalTextPos;
4768 	maString = rCharPropSet.maString;
4769 	mpFieldItem = ( rCharPropSet.mpFieldItem ) ? new SvxFieldItem( *rCharPropSet.mpFieldItem ) : NULL;
4770 	mnLanguage[ 0 ] = mnLanguage[ 1 ] = mnLanguage[ 2 ] = 0;
4771 }
4772 
~PPTCharPropSet()4773 PPTCharPropSet::~PPTCharPropSet()
4774 {
4775 	if ( ! ( --pCharSet->mnRefCount ) )
4776 		delete pCharSet;
4777 	delete mpFieldItem;
4778 }
4779 
operator =(PPTCharPropSet & rCharPropSet)4780 PPTCharPropSet& PPTCharPropSet::operator=( PPTCharPropSet& rCharPropSet )
4781 {
4782 	if ( this != &rCharPropSet )
4783 	{
4784 		if ( ! ( --pCharSet->mnRefCount ) )
4785 			delete pCharSet;
4786 		pCharSet = rCharPropSet.pCharSet;
4787 		pCharSet->mnRefCount++;
4788 
4789 		mnOriginalTextPos = rCharPropSet.mnOriginalTextPos;
4790 		mnParagraph = rCharPropSet.mnParagraph;
4791 		maString = rCharPropSet.maString;
4792 		mpFieldItem = ( rCharPropSet.mpFieldItem ) ? new SvxFieldItem( *rCharPropSet.mpFieldItem ) : NULL;
4793 	}
4794 	return *this;
4795 }
4796 
ImplMakeUnique()4797 void PPTCharPropSet::ImplMakeUnique()
4798 {
4799 	if ( pCharSet->mnRefCount > 1 )
4800 	{
4801 		ImplPPTCharPropSet& rOld = *pCharSet;
4802 		rOld.mnRefCount--;
4803 		pCharSet = new ImplPPTCharPropSet( rOld );
4804 		pCharSet->mnRefCount = 1;
4805 	}
4806 }
4807 
SetFont(sal_uInt16 nFont)4808 void PPTCharPropSet::SetFont( sal_uInt16 nFont )
4809 {
4810 	sal_uInt32	nMask = 1 << PPT_CharAttr_Font;
4811 	sal_uInt32	bDoNotMake = pCharSet->mnAttrSet & nMask;
4812 
4813 	if ( bDoNotMake )
4814 		bDoNotMake = nFont == pCharSet->mnFont;
4815 
4816 	if ( !bDoNotMake )
4817 	{
4818 		ImplMakeUnique();
4819 		pCharSet->mnFont = nFont;
4820 		pCharSet->mnAttrSet |= nMask;
4821 	}
4822 }
4823 
SetColor(sal_uInt32 nColor)4824 void PPTCharPropSet::SetColor( sal_uInt32 nColor )
4825 {
4826 	ImplMakeUnique();
4827 	pCharSet->mnColor = nColor;
4828 	pCharSet->mnAttrSet |= 1 << PPT_CharAttr_FontColor;
4829 }
4830 
4831 ////////////////////////////////////////////////////////////////////////////////////////////////////
4832 
PPTRuler()4833 PPTRuler::PPTRuler() :
4834 	nRefCount	( 1 ),
4835 	nFlags		( 0 ),
4836 	pTab		( NULL ),
4837 	nTabCount	( 0 )
4838 {
4839 }
4840 
~PPTRuler()4841 PPTRuler::~PPTRuler()
4842 {
4843 	delete[] pTab;
4844 };
4845 
4846 
PPTTextRulerInterpreter()4847 PPTTextRulerInterpreter::PPTTextRulerInterpreter() :
4848 	mpImplRuler ( new PPTRuler() )
4849 {
4850 }
4851 
PPTTextRulerInterpreter(PPTTextRulerInterpreter & rRuler)4852 PPTTextRulerInterpreter::PPTTextRulerInterpreter( PPTTextRulerInterpreter& rRuler )
4853 {
4854 	mpImplRuler = rRuler.mpImplRuler;
4855 	mpImplRuler->nRefCount++;
4856 }
4857 
PPTTextRulerInterpreter(sal_uInt32 nFileOfs,SdrPowerPointImport & rMan,DffRecordHeader & rHeader,SvStream & rIn)4858 PPTTextRulerInterpreter::PPTTextRulerInterpreter( sal_uInt32 nFileOfs, SdrPowerPointImport& rMan, DffRecordHeader& rHeader, SvStream& rIn ) :
4859 	mpImplRuler	( new PPTRuler() )
4860 {
4861 	if ( nFileOfs != 0xffffffff )
4862 	{
4863 		sal_uInt32 nOldPos = rIn.Tell();
4864 		DffRecordHeader rHd;
4865 		if ( nFileOfs )
4866 		{
4867 			rIn.Seek( nFileOfs );
4868 			rIn >> rHd;
4869 		}
4870 		else
4871 		{
4872 			rHeader.SeekToContent( rIn );
4873 			if ( rMan.SeekToRec( rIn, PPT_PST_TextRulerAtom, rHeader.GetRecEndFilePos(), &rHd ) )
4874 				nFileOfs++;
4875 		}
4876 		if ( nFileOfs )
4877 		{
4878 			sal_Int16	nTCount;
4879 			sal_Int32	i;
4880 			rIn >> mpImplRuler->nFlags;
4881 			if ( mpImplRuler->nFlags & 1 )
4882 				rIn >> mpImplRuler->nDefaultTab;
4883 			if ( mpImplRuler->nFlags & 4 )
4884 			{
4885 				rIn >> nTCount;
4886 				if ( nTCount )
4887 				{
4888 					mpImplRuler->nTabCount = (sal_uInt16)nTCount;
4889 					mpImplRuler->pTab = new PPTTabEntry[ mpImplRuler->nTabCount ];
4890 					for ( i = 0; i < nTCount; i++ )
4891 					{
4892 						rIn >> mpImplRuler->pTab[ i ].nOffset
4893 							>> mpImplRuler->pTab[ i ].nStyle;
4894 					}
4895 				}
4896 			}
4897 			for ( i = 0; i < 5; i++ )
4898 			{
4899 				if ( mpImplRuler->nFlags & ( 8 << i ) )
4900 					rIn >> mpImplRuler->nTextOfs[ i ];
4901 				if ( mpImplRuler->nFlags & ( 256 << i ) )
4902 					rIn >> mpImplRuler->nBulletOfs[ i ];
4903 			}
4904 		}
4905 		rIn.Seek( nOldPos );
4906 	}
4907 }
4908 
GetDefaultTab(sal_uInt32,sal_uInt16 & nValue) const4909 sal_Bool PPTTextRulerInterpreter::GetDefaultTab( sal_uInt32 /*nLevel*/, sal_uInt16& nValue ) const
4910 {
4911 	if ( ! ( mpImplRuler->nFlags & 1 ) )
4912 		return sal_False;
4913 	nValue = mpImplRuler->nDefaultTab;
4914 	return sal_True;
4915 }
4916 
GetTextOfs(sal_uInt32 nLevel,sal_uInt16 & nValue) const4917 sal_Bool PPTTextRulerInterpreter::GetTextOfs( sal_uInt32 nLevel, sal_uInt16& nValue ) const
4918 {
4919 	if ( ! ( ( nLevel < 5 ) && ( mpImplRuler->nFlags & ( 8 << nLevel ) ) ) )
4920 		return sal_False;
4921 	nValue = mpImplRuler->nTextOfs[ nLevel ];
4922 	return sal_True;
4923 }
4924 
GetBulletOfs(sal_uInt32 nLevel,sal_uInt16 & nValue) const4925 sal_Bool PPTTextRulerInterpreter::GetBulletOfs( sal_uInt32 nLevel, sal_uInt16& nValue ) const
4926 {
4927 	if ( ! ( ( nLevel < 5 ) && ( mpImplRuler->nFlags & ( 256 << nLevel ) ) ) )
4928 		return sal_False;
4929 	nValue = mpImplRuler->nBulletOfs[ nLevel ];
4930 	return sal_True;
4931 }
4932 
operator =(PPTTextRulerInterpreter & rRuler)4933 PPTTextRulerInterpreter& PPTTextRulerInterpreter::operator=( PPTTextRulerInterpreter& rRuler )
4934 {
4935 	if ( this != &rRuler )
4936 	{
4937 		if ( ! ( --mpImplRuler->nRefCount ) )
4938 			delete mpImplRuler;
4939 		mpImplRuler = rRuler.mpImplRuler;
4940 		mpImplRuler->nRefCount++;
4941 	}
4942 	return *this;
4943 }
4944 
~PPTTextRulerInterpreter()4945 PPTTextRulerInterpreter::~PPTTextRulerInterpreter()
4946 {
4947 	if ( ! ( --mpImplRuler->nRefCount ) )
4948 		delete mpImplRuler;
4949 }
4950 
4951 ////////////////////////////////////////////////////////////////////////////////////////////////////
4952 
PPTTextCharacterStyleAtomInterpreter()4953 PPTTextCharacterStyleAtomInterpreter::PPTTextCharacterStyleAtomInterpreter() :
4954 	nFlags1	( 0 ),
4955 	nFlags2 ( 0 ),
4956 	nFlags3 ( 0 )
4957 {
4958 }
4959 
Read(SvStream & rIn,const DffRecordHeader & rRecHd)4960 sal_Bool PPTTextCharacterStyleAtomInterpreter::Read( SvStream& rIn, const DffRecordHeader& rRecHd )
4961 {
4962     rRecHd.SeekToContent( rIn );
4963 
4964     rIn >> nFlags1
4965 		>> nFlags2
4966 		>> nFlags3
4967 		>> n1
4968 		>> nFontHeight
4969 		>> nFontColor;
4970 
4971 	return sal_True;
4972 }
4973 
~PPTTextCharacterStyleAtomInterpreter()4974 PPTTextCharacterStyleAtomInterpreter::~PPTTextCharacterStyleAtomInterpreter()
4975 {
4976 }
4977 
4978 ////////////////////////////////////////////////////////////////////////////////////////////////////
PPTTextParagraphStyleAtomInterpreter()4979 PPTTextParagraphStyleAtomInterpreter::PPTTextParagraphStyleAtomInterpreter() :
4980     bValid              ( sal_False ),
4981     bForbiddenRules     ( sal_False ),
4982     bHangingPunctuation ( sal_False ),
4983     bLatinTextWrap      ( sal_False )
4984 {
4985 }
4986 
Read(SvStream & rIn,const DffRecordHeader & rRecHd)4987 sal_Bool PPTTextParagraphStyleAtomInterpreter::Read( SvStream& rIn, const DffRecordHeader& rRecHd )
4988 {
4989     bValid = sal_False;
4990     rRecHd.SeekToContent( rIn );
4991     sal_uInt32 nDummy32, nFlags, nRecEndPos = rRecHd.GetRecEndFilePos();
4992     sal_uInt16 nDummy16;
4993 
4994     rIn >> nDummy16
4995         >> nFlags;
4996 
4997     if ( nFlags & 0xf && ( rIn.Tell() < nRecEndPos ) )
4998         rIn >> nDummy16;    // BuFlags
4999     if ( nFlags & 0x80 && ( rIn.Tell() < nRecEndPos ) )
5000 		rIn >> nDummy16;    // BuChar
5001     if ( nFlags & 0x10 && ( rIn.Tell() < nRecEndPos ) )
5002 	    rIn >> nDummy16;    // nBuFont;
5003     if ( nFlags & 0x40 && ( rIn.Tell() < nRecEndPos ) )
5004         rIn >> nDummy16;    // nBuHeight;
5005 	if ( nFlags & 0x0020 && ( rIn.Tell() < nRecEndPos ) )
5006         rIn >> nDummy32;    // nBuColor;
5007 	if ( nFlags & 0x800 && ( rIn.Tell() < nRecEndPos ) )
5008 		rIn >> nDummy16;    // AbsJust!
5009 	if ( nFlags & 0x400 && ( rIn.Tell() < nRecEndPos ) )
5010 		rIn >> nDummy16;
5011 	if ( nFlags & 0x200 && ( rIn.Tell() < nRecEndPos ) )
5012 		rIn >> nDummy16;
5013 	if ( nFlags & 0x100 && ( rIn.Tell() < nRecEndPos ) )
5014 		rIn >> nDummy16;
5015 	if ( nFlags & 0x1000 && ( rIn.Tell() < nRecEndPos ) )
5016 		rIn >> nDummy16;    // LineFeed
5017 	if ( nFlags & 0x2000 && ( rIn.Tell() < nRecEndPos ) )
5018 		rIn >> nDummy16;    // nUpperDist
5019 	if ( nFlags & 0x4000 && ( rIn.Tell() < nRecEndPos ) )
5020 		rIn >> nDummy16;    // nLowerDist
5021 	if ( nFlags & 0x8000 && ( rIn.Tell() < nRecEndPos ) )
5022 		rIn >> nDummy16;
5023 	if ( nFlags & 0x10000 && ( rIn.Tell() < nRecEndPos ) )
5024 		rIn >> nDummy16;
5025 	if ( nFlags & 0xe0000 && ( rIn.Tell() < nRecEndPos ) )
5026     {
5027         rIn >> nDummy16;
5028         if ( nFlags & 0x20000 )
5029             bForbiddenRules = ( nDummy16 & 1 ) == 1;
5030         if ( nFlags & 0x40000 )
5031             bLatinTextWrap = ( nDummy16 & 2 ) == 0;
5032         if ( nFlags & 0x80000 )
5033             bHangingPunctuation = ( nDummy16 & 4 ) == 4;
5034     }
5035     nFlags &=~ 0xfffff;
5036     sal_uInt32 nMask = 0x100000;
5037     while ( nFlags && nMask && ( rIn.Tell() < nRecEndPos ) )
5038     {
5039         if ( nFlags & nMask )
5040         {
5041             rIn >> nDummy16;
5042             nFlags ^= nMask;
5043         }
5044         nMask <<= 1;
5045     }
5046     bValid = rIn.Tell() == nRecEndPos;
5047     return bValid;
5048 }
5049 
~PPTTextParagraphStyleAtomInterpreter()5050 PPTTextParagraphStyleAtomInterpreter::~PPTTextParagraphStyleAtomInterpreter()
5051 {
5052 
5053 }
5054 
5055 ////////////////////////////////////////////////////////////////////////////////////////////////////
5056 
PPTTextSpecInfo(sal_uInt32 _nCharIdx)5057 PPTTextSpecInfo::PPTTextSpecInfo( sal_uInt32 _nCharIdx ) :
5058 	nCharIdx		( _nCharIdx ),
5059 	nDontKnow		( 1 )
5060 {
5061 	nLanguage[ 0 ] = 0x400;
5062 	nLanguage[ 1 ] = 0;
5063 	nLanguage[ 2 ] = 0;
5064 }
5065 
~PPTTextSpecInfo()5066 PPTTextSpecInfo::~PPTTextSpecInfo()
5067 {
5068 }
5069 
PPTTextSpecInfoAtomInterpreter()5070 PPTTextSpecInfoAtomInterpreter::PPTTextSpecInfoAtomInterpreter() :
5071 	bValid	( sal_False )
5072 {
5073 }
5074 
Read(SvStream & rIn,const DffRecordHeader & rRecHd,sal_uInt16 nRecordType,const PPTTextSpecInfo * pTextSpecDefault)5075 sal_Bool PPTTextSpecInfoAtomInterpreter::Read( SvStream& rIn, const DffRecordHeader& rRecHd,
5076 	sal_uInt16 nRecordType, const PPTTextSpecInfo* pTextSpecDefault )
5077 {
5078 	bValid = sal_False;
5079 	sal_uInt32	nCharIdx = 0;
5080 	rRecHd.SeekToContent( rIn );
5081 
5082 	while ( rIn.Tell() < rRecHd.GetRecEndFilePos() )
5083 	{
5084 		sal_uInt32	nCharCount,
5085 					nFlags, i;
5086 
5087 		if ( nRecordType == PPT_PST_TextSpecInfoAtom )
5088 		{
5089 			rIn >> nCharCount;
5090 			nCharIdx += nCharCount;
5091 		}
5092 		rIn >> nFlags;
5093 
5094 		PPTTextSpecInfo* pEntry = new PPTTextSpecInfo( nCharIdx );
5095 		if ( pTextSpecDefault )
5096 		{
5097 			pEntry->nDontKnow = pTextSpecDefault->nDontKnow;
5098 			pEntry->nLanguage[ 0 ] = pTextSpecDefault->nLanguage[ 0 ];
5099 			pEntry->nLanguage[ 1 ] = pTextSpecDefault->nLanguage[ 1 ];
5100 			pEntry->nLanguage[ 2 ] = pTextSpecDefault->nLanguage[ 2 ];
5101 		}
5102 		for ( i = 1; nFlags && i ; i <<= 1 )
5103 		{
5104 			sal_uInt16 nLang = 0;
5105 			switch( nFlags & i )
5106 			{
5107 				case 0 : break;
5108 				case 1 : rIn >> pEntry->nDontKnow; break;
5109 				case 2 : rIn >> nLang; break;
5110 				case 4 : rIn >> nLang; break;
5111 				default :
5112 				{
5113 					rIn.SeekRel( 2 );
5114 				}
5115 			}
5116 			if ( nLang )
5117 			{
5118 // bug119985 2012.06.14
5119 				if (i == 2)
5120 				{
5121 					pEntry->nLanguage[ 0 ] = pEntry->nLanguage[ 1 ] = pEntry->nLanguage[ 2 ] = nLang;
5122 				}
5123 			}
5124 			nFlags &= ~i;
5125 		}
5126 		aList.Insert( pEntry, LIST_APPEND );
5127 	}
5128 	bValid = rIn.Tell() == rRecHd.GetRecEndFilePos();
5129 	return bValid;
5130 }
5131 
~PPTTextSpecInfoAtomInterpreter()5132 PPTTextSpecInfoAtomInterpreter::~PPTTextSpecInfoAtomInterpreter()
5133 {
5134 	void *pPtr;
5135 	for ( pPtr = aList.First(); pPtr; pPtr = aList.Next() )
5136 		delete (PPTTextSpecInfo*)pPtr;
5137 }
5138 
5139 ////////////////////////////////////////////////////////////////////////////////////////////////////
5140 
Read(SvStream & rIn)5141 void StyleTextProp9::Read( SvStream& rIn )
5142 {
5143 	rIn >> mnExtParagraphMask;
5144 	if ( mnExtParagraphMask & 0x800000 )
5145 		rIn >> mnBuBlip;
5146 	if ( mnExtParagraphMask & 0x2000000 )
5147 		rIn >> mnHasAnm;
5148 	if ( mnExtParagraphMask & 0x1000000 )
5149 		rIn >> mnAnmScheme;
5150 	if ( mnExtParagraphMask & 0x4000000 )
5151 		rIn >> mpfPP10Ext;
5152 	rIn >> mnExtCharacterMask;
5153 	if ( mnExtCharacterMask & 0x100000 )
5154 		rIn >> mncfPP10Ext;
5155 	rIn >> mnSpecialInfoMask;
5156 	if ( mnSpecialInfoMask & 0x20 )
5157 		rIn >> mnPP10Ext;
5158 	if ( mnSpecialInfoMask & 0x40 )
5159 		rIn >> mfBidi;
5160 }
5161 
PPTStyleTextPropReader(SvStream & rIn,SdrPowerPointImport & rMan,const DffRecordHeader & rTextHeader,PPTTextRulerInterpreter & rRuler,const DffRecordHeader & rExtParaHd,sal_uInt32 nInstance)5162 PPTStyleTextPropReader::PPTStyleTextPropReader( SvStream& rIn, SdrPowerPointImport& rMan, const DffRecordHeader& rTextHeader,
5163 														PPTTextRulerInterpreter& rRuler, const DffRecordHeader& rExtParaHd, sal_uInt32 nInstance )
5164 {
5165     Init(rIn, rMan, rTextHeader, rRuler, rExtParaHd, nInstance);
5166 }
5167 
ReadParaProps(SvStream & rIn,SdrPowerPointImport & rMan,const DffRecordHeader & rTextHeader,const String & aString,PPTTextRulerInterpreter & rRuler,sal_uInt32 & nCharCount,sal_Bool & bTextPropAtom)5168 void PPTStyleTextPropReader::ReadParaProps( SvStream& rIn, SdrPowerPointImport& rMan, const DffRecordHeader& rTextHeader,
5169                                             const String& aString, PPTTextRulerInterpreter& rRuler,
5170                                             sal_uInt32& nCharCount, sal_Bool& bTextPropAtom )
5171 {
5172     sal_uInt32  nMask = 0; //TODO: nMask initialized here to suppress warning for now, see corresponding TODO below
5173     sal_uInt32  nCharAnzRead = 0;
5174     sal_uInt16  nDummy16;
5175 
5176     sal_uInt16 nStringLen = aString.Len();
5177 
5178     DffRecordHeader aTextHd2;
5179     rTextHeader.SeekToContent( rIn );
5180     if ( rMan.SeekToRec( rIn, PPT_PST_StyleTextPropAtom, rTextHeader.GetRecEndFilePos(), &aTextHd2 ) )
5181         bTextPropAtom = sal_True;
5182     while ( nCharAnzRead <= nStringLen )
5183     {
5184         PPTParaPropSet aParaPropSet;
5185         ImplPPTParaPropSet& aSet = *aParaPropSet.pParaSet;
5186         if ( bTextPropAtom )
5187         {
5188             rIn >> nCharCount
5189                 >> aParaPropSet.pParaSet->mnDepth;	// Einruecktiefe
5190 
5191 			aParaPropSet.pParaSet->mnDepth =		// taking care of about using not more than 9 outliner levels
5192 				std::min(sal_uInt16(8),
5193 					aParaPropSet.pParaSet->mnDepth);
5194 
5195             nCharCount--;
5196 
5197             rIn >> nMask;
5198             aSet.mnAttrSet = nMask & 0x207df7;
5199             sal_uInt16 nBulFlg = 0;
5200             if ( nMask & 0xF )
5201                 rIn >> nBulFlg; // Bullet-HardAttr-Flags
5202             aSet.mpArry[ PPT_ParaAttr_BulletOn    ] = ( nBulFlg & 1 ) ? 1 : 0;
5203             aSet.mpArry[ PPT_ParaAttr_BuHardFont  ] = ( nBulFlg & 2 ) ? 1 : 0;
5204             aSet.mpArry[ PPT_ParaAttr_BuHardColor ] = ( nBulFlg & 4 ) ? 1 : 0;
5205 
5206             if ( nMask & 0x0080 )	// buChar
5207                 rIn >> aSet.mpArry[ PPT_ParaAttr_BulletChar ];
5208             if ( nMask & 0x0010 )	// buTypeface
5209                 rIn >> aSet.mpArry[ PPT_ParaAttr_BulletFont ];
5210             if ( nMask & 0x0040 )	// buSize
5211             {
5212                 rIn >> aSet.mpArry[ PPT_ParaAttr_BulletHeight ];
5213                 if ( ! ( ( nMask & ( 1 << PPT_ParaAttr_BuHardHeight ) )
5214                          && ( nBulFlg & ( 1 << PPT_ParaAttr_BuHardHeight ) ) ) )
5215                     aSet.mnAttrSet ^= 0x40;
5216             }
5217             if ( nMask & 0x0020 )	// buColor
5218             {
5219                 sal_uInt32 nVal32, nHiByte;
5220                 rIn >> nVal32;
5221                 nHiByte = nVal32 >> 24;
5222                 if ( nHiByte <= 8 )
5223                     nVal32 = nHiByte | PPT_COLSCHEME;
5224                 aSet.mnBulletColor = nVal32;
5225             }
5226             if ( nMask & 0x0800 )	// pfAlignment
5227             {
5228                 rIn >> nDummy16;
5229                 aSet.mpArry[ PPT_ParaAttr_Adjust ] = nDummy16 & 3;
5230             }
5231             if ( nMask & 0x1000 )	// pfLineSpacing
5232                 rIn >> aSet.mpArry[ PPT_ParaAttr_LineFeed ];
5233             if ( nMask & 0x2000 )	// pfSpaceBefore
5234                 rIn >> aSet.mpArry[ PPT_ParaAttr_UpperDist ];
5235             if ( nMask & 0x4000 )	// pfSpaceAfter
5236                 rIn >> aSet.mpArry[ PPT_ParaAttr_LowerDist ];
5237             if ( nMask & 0x100 )	// pfLeftMargin
5238             {
5239                 rIn >> aSet.mpArry[ PPT_ParaAttr_TextOfs ];
5240                 aSet.mnAttrSet |= 1 << PPT_ParaAttr_TextOfs;
5241             }
5242             if ( nMask & 0x400 )	// pfIndent
5243             {
5244                 rIn >> aSet.mpArry[ PPT_ParaAttr_BulletOfs ];
5245                 aSet.mnAttrSet |= 1 << PPT_ParaAttr_BulletOfs;
5246             }
5247             if ( nMask & 0x8000 )	// pfDefaultTabSize
5248                 rIn >> nDummy16;
5249             if ( nMask & 0x100000 )	// pfTabStops
5250             {
5251                 sal_uInt16 i, nDistance, nAlignment, nNumberOfTabStops = 0;
5252                 rIn >> nNumberOfTabStops;
5253                 for ( i = 0; i < nNumberOfTabStops; i++ )
5254                 {
5255                     rIn >> nDistance
5256                         >> nAlignment;
5257                 }
5258             }
5259             if ( nMask & 0x10000 )	// pfBaseLine
5260                 rIn >> nDummy16;
5261             if ( nMask & 0xe0000 )	// pfCharWrap, pfWordWrap, pfOverflow
5262             {
5263                 rIn >> nDummy16;
5264                 if ( nMask & 0x20000 )
5265                     aSet.mpArry[ PPT_ParaAttr_AsianLB_1 ] = nDummy16 & 1;
5266                 if ( nMask & 0x40000 )
5267                     aSet.mpArry[ PPT_ParaAttr_AsianLB_2 ] = ( nDummy16 >> 1 ) & 1;
5268                 if ( nMask & 0x80000 )
5269                     aSet.mpArry[ PPT_ParaAttr_AsianLB_3 ] = ( nDummy16 >> 2 ) & 1;
5270                 aSet.mnAttrSet |= ( ( nMask >> 17 ) & 7 ) << PPT_ParaAttr_AsianLB_1;
5271             }
5272             if ( nMask & 0x200000 )	// pfTextDirection
5273                 rIn >> aSet.mpArry[ PPT_ParaAttr_BiDi ];
5274         }
5275         else
5276             nCharCount = nStringLen;
5277 
5278         //if the textofs attr has been read at above, need not to reset.
5279         if ( ( !( aSet.mnAttrSet & 1 << PPT_ParaAttr_TextOfs ) ) && rRuler.GetTextOfs( aParaPropSet.pParaSet->mnDepth, aSet.mpArry[ PPT_ParaAttr_TextOfs ] ) )
5280             aSet.mnAttrSet |= 1 << PPT_ParaAttr_TextOfs;
5281         if ( ( !( aSet.mnAttrSet & 1 << PPT_ParaAttr_BulletOfs ) ) && rRuler.GetBulletOfs( aParaPropSet.pParaSet->mnDepth, aSet.mpArry[ PPT_ParaAttr_BulletOfs ] ) )
5282             aSet.mnAttrSet |= 1 << PPT_ParaAttr_BulletOfs;
5283         if ( rRuler.GetDefaultTab( aParaPropSet.pParaSet->mnDepth, aSet.mpArry[ PPT_ParaAttr_DefaultTab ] ) )
5284             aSet.mnAttrSet |= 1 << PPT_ParaAttr_DefaultTab;
5285 
5286         if ( ( nCharCount > nStringLen ) || ( nStringLen < nCharAnzRead + nCharCount ) )
5287         {
5288             bTextPropAtom = sal_False;
5289             nCharCount = nStringLen - nCharAnzRead;
5290             // please fix the right hand side of
5291             // PPTParaPropSet& PPTParaPropSet::operator=(PPTParaPropSet&),
5292             // it should be a const reference
5293             PPTParaPropSet aTmpPPTParaPropSet;
5294             aParaPropSet = aTmpPPTParaPropSet;
5295             DBG_ERROR( "SJ:PPTStyleTextPropReader::could not get this PPT_PST_StyleTextPropAtom by reading the paragraph attributes" );
5296         }
5297         PPTParaPropSet* pPara = new PPTParaPropSet( aParaPropSet );
5298         pPara->mnOriginalTextPos = nCharAnzRead;
5299         aParaPropList.Insert( pPara, LIST_APPEND );
5300         if ( nCharCount )
5301         {
5302             sal_uInt32	 nCount;
5303             const sal_Unicode* pDat = aString.GetBuffer() + nCharAnzRead;
5304             for ( nCount = 0; nCount < nCharCount; nCount++ )
5305             {
5306                 if ( pDat[ nCount ] == 0xd )
5307                 {
5308                     pPara = new PPTParaPropSet( aParaPropSet );
5309                     pPara->mnOriginalTextPos = nCharAnzRead + nCount + 1;
5310                     aParaPropList.Insert( pPara, LIST_APPEND );
5311                 }
5312             }
5313         }
5314         nCharAnzRead += nCharCount + 1;
5315     }
5316 }
5317 
ReadCharProps(SvStream & rIn,PPTCharPropSet & aCharPropSet,const String & aString,sal_uInt32 & nCharCount,sal_uInt32 nCharAnzRead,sal_Bool & bTextPropAtom,sal_uInt32 nExtParaPos,const std::vector<StyleTextProp9> & aStyleTextProp9,sal_uInt32 & nExtParaFlags,sal_uInt16 & nBuBlip,sal_uInt16 & nHasAnm,sal_uInt32 & nAnmScheme)5318 void PPTStyleTextPropReader::ReadCharProps( SvStream& rIn, PPTCharPropSet& aCharPropSet, const String& aString,
5319                                             sal_uInt32& nCharCount, sal_uInt32 nCharAnzRead,
5320                                             sal_Bool& bTextPropAtom, sal_uInt32 nExtParaPos,
5321                                             const std::vector< StyleTextProp9 >& aStyleTextProp9,
5322                                             sal_uInt32& nExtParaFlags, sal_uInt16& nBuBlip,
5323                                             sal_uInt16& nHasAnm, sal_uInt32& nAnmScheme )
5324 {
5325     sal_uInt32  nMask = 0; //TODO: nMask initialized here to suppress warning for now, see corresponding TODO below
5326     sal_uInt16  nDummy16;
5327     sal_Int32   nCharsToRead;
5328     sal_uInt32  nExtParaNibble = 0;
5329 
5330     sal_uInt16 nStringLen = aString.Len();
5331 
5332     rIn >> nDummy16;
5333     nCharCount = nDummy16;
5334     rIn >> nDummy16;
5335     nCharsToRead = nStringLen - ( nCharAnzRead + nCharCount );
5336     if ( nCharsToRead < 0 )
5337     {
5338         nCharCount = nStringLen - nCharAnzRead;
5339         if ( nCharsToRead < -1 )
5340         {
5341             bTextPropAtom = sal_False;
5342             DBG_ERROR( "SJ:PPTStyleTextPropReader::could not get this PPT_PST_StyleTextPropAtom by reading the character attributes" );
5343         }
5344     }
5345     ImplPPTCharPropSet& aSet = *aCharPropSet.pCharSet;
5346 
5347     // character attributes
5348     rIn >> nMask;
5349     if ( (sal_uInt16)nMask )
5350     {
5351         aSet.mnAttrSet |= (sal_uInt16)nMask;
5352         rIn >> aSet.mnFlags;
5353     }
5354     if ( nMask & 0x10000 )	// cfTypeface
5355     {
5356         rIn >> aSet.mnFont;
5357         aSet.mnAttrSet |= 1 << PPT_CharAttr_Font;
5358     }
5359     if ( nMask & 0x200000 )	// cfFEOldTypeface
5360     {
5361         rIn >> aSet.mnAsianOrComplexFont;
5362         aSet.mnAttrSet |= 1 << PPT_CharAttr_AsianOrComplexFont;
5363     }
5364     if ( nMask & 0x400000 )	// cfANSITypeface
5365     {
5366         rIn >> aSet.mnANSITypeface;
5367         aSet.mnAttrSet |= 1 << PPT_CharAttr_ANSITypeface;
5368     }
5369     if ( nMask & 0x800000 )	// cfSymbolTypeface
5370     {
5371         rIn >> aSet.mnSymbolFont;
5372         aSet.mnAttrSet |= 1 << PPT_CharAttr_Symbol;
5373     }
5374     if ( nMask & 0x20000 )	// cfSize
5375     {
5376         rIn >> aSet.mnFontHeight;
5377         aSet.mnAttrSet |= 1 << PPT_CharAttr_FontHeight;
5378     }
5379     if ( nMask & 0x40000 )	// cfColor
5380     {
5381         sal_uInt32 nVal;
5382         rIn >> nVal;
5383         if ( !( nVal & 0xff000000 ) )
5384             nVal = PPT_COLSCHEME_HINTERGRUND;
5385         aSet.mnColor = nVal;
5386         aSet.mnAttrSet |= 1 << PPT_CharAttr_FontColor;
5387     }
5388     if ( nMask & 0x80000 )	// cfPosition
5389     {
5390         rIn >> aSet.mnEscapement;
5391         aSet.mnAttrSet |= 1 << PPT_CharAttr_Escapement;
5392     }
5393     if ( nExtParaPos )
5394     {
5395         sal_uInt32 nExtBuInd = nMask & 0x3c00;
5396         if ( nExtBuInd )
5397             nExtBuInd = ( aSet.mnFlags & 0x3c00 ) >> 10;
5398         if ( nExtBuInd < aStyleTextProp9.size() )
5399         {
5400             if ( nExtParaNibble && ( ( nExtBuInd + nExtParaNibble ) < aStyleTextProp9.size() ) )
5401                 nExtBuInd += nExtParaNibble;
5402 
5403             nExtParaFlags = aStyleTextProp9[ nExtBuInd ].mnExtParagraphMask;
5404             nBuBlip = aStyleTextProp9[ nExtBuInd ].mnBuBlip;
5405             nHasAnm = aStyleTextProp9[ nExtBuInd ].mnHasAnm;
5406             nAnmScheme = aStyleTextProp9[ nExtBuInd ].mnAnmScheme;
5407         }
5408         if ( ( nExtBuInd & 0xf ) == 0xf )
5409             nExtParaNibble += 16;
5410     }
5411 }
5412 
Init(SvStream & rIn,SdrPowerPointImport & rMan,const DffRecordHeader & rTextHeader,PPTTextRulerInterpreter & rRuler,const DffRecordHeader & rExtParaHd,sal_uInt32 nInstance)5413 void PPTStyleTextPropReader::Init( SvStream& rIn, SdrPowerPointImport& rMan, const DffRecordHeader& rTextHeader,
5414                                    PPTTextRulerInterpreter& rRuler, const DffRecordHeader& rExtParaHd, sal_uInt32 nInstance )
5415 {
5416 	sal_uInt32 nMerk = rIn.Tell();
5417 	sal_uInt32 nExtParaPos = ( rExtParaHd.nRecType == PPT_PST_ExtendedParagraphAtom ) ? rExtParaHd.nFilePos + 8 : 0;
5418 
5419 	std::vector< StyleTextProp9 > aStyleTextProp9;
5420 	if ( rExtParaHd.nRecType == PPT_PST_ExtendedParagraphAtom  )
5421 	{
5422 		rIn.Seek( rExtParaHd.nFilePos + 8 );
5423 		while( ( rIn.GetError() == 0 ) && ( rIn.Tell() < rExtParaHd.GetRecEndFilePos() ) )
5424 		{
5425 			aStyleTextProp9.resize( aStyleTextProp9.size() + 1 );
5426 			aStyleTextProp9.back().Read( rIn );
5427 		}
5428 		rIn.Seek( nMerk );
5429 	}
5430 
5431 	String aString;
5432 	DffRecordHeader aTextHd;
5433 	rIn >> aTextHd;
5434 	sal_uInt32 nMaxLen = aTextHd.nRecLen;
5435 	if ( nMaxLen >= 0xFFFF )
5436 		nMaxLen = 0xFFFE;
5437 
5438 	if( aTextHd.nRecType == PPT_PST_TextCharsAtom )
5439 	{
5440 		sal_uInt32 i;
5441 		sal_Unicode nChar,*pBuf = new sal_Unicode[ ( nMaxLen >> 1 ) + 1 ];
5442 		rIn.Read( pBuf, nMaxLen );
5443 		nMaxLen >>= 1;
5444 		pBuf[ nMaxLen ] = 0;
5445 		sal_Unicode* pPtr = pBuf;
5446 #ifdef OSL_BIGENDIAN
5447 		sal_Unicode nTemp;
5448 		for ( i = 0; i < nMaxLen; i++ )
5449 		{
5450 			nTemp = *pPtr;
5451 			*pPtr++ = ( nTemp << 8 ) | ( nTemp >> 8 );
5452 		}
5453 		pPtr = pBuf;
5454 #endif
5455 
5456 		for ( i = 0; i < nMaxLen; pPtr++, i++ )
5457 		{
5458 			nChar = *pPtr;
5459 			if ( !nChar )
5460 				break;
5461 			if ( ( nChar & 0xff00 ) == 0xf000 )			// in this special case we got a symbol
5462 				aSpecMarkerList.Insert( (void*)( i | PPT_SPEC_SYMBOL ), LIST_APPEND );
5463 			else if ( nChar == 0xd )
5464 			{
5465 				if ( nInstance == TSS_TYPE_PAGETITLE )
5466 					*pPtr = 0xb;
5467 				else
5468 					aSpecMarkerList.Insert( (void*)( i | PPT_SPEC_NEWLINE ), LIST_APPEND );
5469 			}
5470 		}
5471 		if ( i )
5472 			aString = String( pBuf, (sal_uInt16)i );
5473 		delete[] pBuf;
5474 	}
5475 	else if( aTextHd.nRecType == PPT_PST_TextBytesAtom )
5476 	{
5477 		sal_Char *pBuf = new sal_Char[ nMaxLen + 1 ];
5478 		pBuf[ nMaxLen ] = 0;
5479 		rIn.Read( pBuf, nMaxLen );
5480 		sal_Char* pPtr = pBuf;
5481 		for (;;)
5482 		{
5483             sal_Char cLo = *pPtr;
5484             if ( cLo == 0 )
5485                 break;
5486 			if ( cLo == 0xd )
5487 			{
5488 				if ( nInstance == TSS_TYPE_PAGETITLE )
5489 					*pPtr = 0xb;
5490 				else
5491 					aSpecMarkerList.Insert( (void*)( (pPtr - pBuf) | PPT_SPEC_NEWLINE ), LIST_APPEND );
5492 			}
5493 			pPtr++;
5494 		}
5495 		xub_StrLen nLen = sal::static_int_cast< xub_StrLen >( pPtr - pBuf );
5496 		if ( nLen )
5497 			aString = String( pBuf, nLen, RTL_TEXTENCODING_MS_1252 );
5498 		delete[] pBuf;
5499 	}
5500     else
5501     {
5502         // no chars, but potentially char/para props?
5503 		sal_uInt32  nCharCount;
5504 		sal_Bool    bTextPropAtom = sal_False;
5505         ReadParaProps( rIn, rMan, rTextHeader, aString, rRuler, nCharCount, bTextPropAtom );
5506 
5507         if ( bTextPropAtom )
5508         {
5509             // yeah, StyleTextProp is there, read it all & push to
5510             // aParaPropList
5511             PPTCharPropSet aCharPropSet(0);
5512             aCharPropSet.mnOriginalTextPos = 0;
5513 
5514             sal_uInt32 nCharAnzRead = 0;
5515 			sal_uInt32 nExtParaFlags = 0, nAnmScheme = 0;
5516 			sal_uInt16 nBuBlip = 0xffff, nHasAnm = 0;
5517             ReadCharProps( rIn, aCharPropSet, aString, nCharCount, nCharAnzRead,
5518                            bTextPropAtom, nExtParaPos, aStyleTextProp9, nExtParaFlags,
5519                            nBuBlip, nHasAnm, nAnmScheme );
5520 
5521             aCharPropList.Insert(
5522                 new PPTCharPropSet( aCharPropSet, 0 ), LIST_APPEND );
5523         }
5524     }
5525 
5526 	if ( aString.Len() )
5527 	{
5528 		sal_uInt32  nCharCount;
5529 		sal_Bool    bTextPropAtom = sal_False;
5530 
5531         ReadParaProps( rIn, rMan, rTextHeader, aString, rRuler, nCharCount, bTextPropAtom );
5532 
5533 		sal_Bool bEmptyParaPossible = sal_True;
5534 		sal_uInt32 nCharAnzRead = 0;
5535 		sal_uInt32 nCurrentPara = 0;
5536 		sal_uInt32 nCurrentSpecMarker = (sal_uInt32)(sal_uIntPtr)aSpecMarkerList.First();
5537 		sal_uInt16 nStringLen = aString.Len();
5538 
5539 		while ( nCharAnzRead < nStringLen )
5540 		{
5541 			sal_uInt32 nExtParaFlags = 0, nLatestParaUpdate = 0xffffffff, nAnmScheme = 0;
5542 			sal_uInt16 nBuBlip = 0xffff, nHasAnm = 0;
5543 
5544 			PPTCharPropSet aCharPropSet( nCurrentPara );
5545 			if ( bTextPropAtom )
5546                 ReadCharProps( rIn, aCharPropSet, aString, nCharCount, nCharAnzRead,
5547                                bTextPropAtom, nExtParaPos, aStyleTextProp9, nExtParaFlags,
5548                                nBuBlip, nHasAnm, nAnmScheme );
5549 			else
5550 				nCharCount = nStringLen;
5551 
5552 			sal_uInt32 nLen;
5553 			while( nCharCount )
5554 			{
5555 				if ( nExtParaPos && ( nLatestParaUpdate != nCurrentPara ) && ( nCurrentPara < aParaPropList.Count() ) )
5556 				{
5557 					PPTParaPropSet* pPropSet = (PPTParaPropSet*)aParaPropList.GetObject( nCurrentPara );
5558 					pPropSet->pParaSet->mnExtParagraphMask = nExtParaFlags;
5559 					if ( nExtParaFlags & 0x800000 )
5560 						pPropSet->pParaSet->mnBuBlip = nBuBlip;
5561 					if ( nExtParaFlags & 0x01000000 )
5562 						pPropSet->pParaSet->mnAnmScheme = nAnmScheme;
5563 					if ( nExtParaFlags & 0x02000000 )
5564 						pPropSet->pParaSet->mnHasAnm = nHasAnm;
5565 					nLatestParaUpdate = nCurrentPara;
5566 				}
5567 				aCharPropSet.mnOriginalTextPos = nCharAnzRead;
5568 				if ( nCurrentSpecMarker &&  ( ( nCurrentSpecMarker & 0xffff ) < ( nCharAnzRead + nCharCount ) ) )
5569 				{
5570 					if ( nCurrentSpecMarker & PPT_SPEC_NEWLINE )
5571 					{
5572 						nLen = ( nCurrentSpecMarker & 0xffff ) - nCharAnzRead;
5573 						if ( nLen )
5574 							aCharPropSet.maString = String( aString, (sal_uInt16)nCharAnzRead, (sal_uInt16)nLen );
5575 						else if ( bEmptyParaPossible )
5576 							aCharPropSet.maString = String();
5577 						if ( nLen || bEmptyParaPossible )
5578 							aCharPropList.Insert( new PPTCharPropSet( aCharPropSet, nCurrentPara ), LIST_APPEND );
5579 						nCurrentPara++;
5580 						nLen++;
5581 						nCharAnzRead += nLen;
5582 						nCharCount -= nLen;
5583 						bEmptyParaPossible = sal_True;
5584 					}
5585 					else if ( nCurrentSpecMarker & PPT_SPEC_SYMBOL )
5586 					{
5587 						if ( ( nCurrentSpecMarker & 0xffff ) != nCharAnzRead )
5588 						{
5589 							nLen = ( nCurrentSpecMarker & 0xffff ) - nCharAnzRead;
5590 							aCharPropSet.maString = String( aString, (sal_uInt16)nCharAnzRead, (sal_uInt16)nLen );
5591 							aCharPropList.Insert( new PPTCharPropSet( aCharPropSet, nCurrentPara ), LIST_APPEND );
5592 							nCharCount -= nLen;
5593 							nCharAnzRead += nLen;
5594 						}
5595 						PPTCharPropSet* pCPropSet = new PPTCharPropSet( aCharPropSet, nCurrentPara );
5596 						pCPropSet->maString = aString.GetChar( (sal_uInt16)nCharAnzRead );
5597                         if ( aCharPropSet.pCharSet->mnAttrSet & ( 1 << PPT_CharAttr_Symbol ) )
5598 						    pCPropSet->SetFont( aCharPropSet.pCharSet->mnSymbolFont );
5599 						aCharPropList.Insert( pCPropSet, LIST_APPEND );
5600 						nCharCount--;
5601 						nCharAnzRead++;
5602 						bEmptyParaPossible = sal_False;
5603 					}
5604 					nCurrentSpecMarker = (sal_uInt32)(sal_uIntPtr)aSpecMarkerList.Next();
5605 				}
5606 				else
5607 				{
5608 					aCharPropSet.maString = String( aString, (sal_uInt16)nCharAnzRead, (sal_uInt16)nCharCount );
5609 					aCharPropList.Insert( new PPTCharPropSet( aCharPropSet, nCurrentPara ), LIST_APPEND );
5610 					nCharAnzRead += nCharCount;
5611 					bEmptyParaPossible = sal_False;
5612 					break;
5613 				}
5614 			}
5615  		}
5616 		if ( aCharPropList.Count() && ( ((PPTCharPropSet*)aCharPropList.Last())->mnParagraph != nCurrentPara ) )
5617 		{
5618 			PPTCharPropSet* pCharPropSet = new PPTCharPropSet( *(PPTCharPropSet*)aCharPropList.Last(), nCurrentPara );
5619 			pCharPropSet->maString = String();
5620 			pCharPropSet->mnOriginalTextPos = nStringLen - 1;
5621 			aCharPropList.Insert( pCharPropSet, LIST_APPEND );
5622 		}
5623 	}
5624 	rIn.Seek( nMerk );
5625 }
5626 
~PPTStyleTextPropReader()5627 PPTStyleTextPropReader::~PPTStyleTextPropReader()
5628 {
5629 	void* pTmp;
5630 	for ( pTmp = aParaPropList.First(); pTmp; pTmp = aParaPropList.Next() )
5631 		delete (PPTParaPropSet*)pTmp;
5632 	for ( pTmp = aCharPropList.First(); pTmp; pTmp = aCharPropList.Next() )
5633 		delete (PPTCharPropSet*)pTmp;
5634 }
5635 
5636 ////////////////////////////////////////////////////////////////////////////////////////////////////
5637 
5638 struct FieldEntry
5639 {
5640 	sal_uInt32	nFieldType;
5641 	sal_uInt32	nFieldStartPos;
5642 	sal_uInt32	nFieldEndPos;
5643 	String	aFieldUrl;
5644 
FieldEntryFieldEntry5645 	FieldEntry( sal_uInt32 nType, sal_uInt32 nStart, sal_uInt32 nEnd )
5646 	{
5647 		nFieldType = nType;
5648 		nFieldStartPos = nStart;
5649 		nFieldEndPos = nEnd;
5650 	}
FieldEntryFieldEntry5651 	FieldEntry( FieldEntry& rFieldEntry )
5652 	{
5653 		nFieldType = rFieldEntry.nFieldType;
5654 		nFieldStartPos = rFieldEntry.nFieldStartPos;
5655 		nFieldEndPos = rFieldEntry.nFieldEndPos;
5656 		aFieldUrl = rFieldEntry.aFieldUrl;
5657 	}
5658 };
5659 
5660 
PPTPortionObj(const PPTStyleSheet & rStyleSheet,sal_uInt32 nInstance,sal_uInt32 nDepth)5661 PPTPortionObj::PPTPortionObj( const PPTStyleSheet& rStyleSheet, sal_uInt32 nInstance, sal_uInt32 nDepth ) :
5662 	PPTCharPropSet	( 0 ),
5663 	mrStyleSheet	( rStyleSheet ),
5664 	mnInstance		( nInstance ),
5665 	mnDepth			( ( nDepth > 4 ) ? 4 : nDepth )
5666 {
5667 }
5668 
PPTPortionObj(PPTCharPropSet & rCharPropSet,const PPTStyleSheet & rStyleSheet,sal_uInt32 nInstance,sal_uInt32 nDepth)5669 PPTPortionObj::PPTPortionObj( PPTCharPropSet& rCharPropSet, const PPTStyleSheet& rStyleSheet, sal_uInt32 nInstance, sal_uInt32 nDepth ) :
5670 	PPTCharPropSet	( rCharPropSet ),
5671 	mrStyleSheet	( rStyleSheet ),
5672 	mnInstance		( nInstance ),
5673 	mnDepth			( nDepth )
5674 {
5675 }
5676 
PPTPortionObj(PPTPortionObj & rPortionObj)5677 PPTPortionObj::PPTPortionObj( PPTPortionObj& rPortionObj ) :
5678 	PPTCharPropSet		( rPortionObj ),
5679 	mrStyleSheet		( rPortionObj.mrStyleSheet ),
5680 	mnInstance			( rPortionObj.mnInstance ),
5681 	mnDepth				( rPortionObj.mnDepth )
5682 {
5683 }
5684 
~PPTPortionObj()5685 PPTPortionObj::~PPTPortionObj()
5686 {
5687 }
5688 
HasTabulator()5689 sal_Bool PPTPortionObj::HasTabulator()
5690 {
5691 	sal_Bool bRetValue =	sal_False;
5692 	sal_Int32			nCount;
5693 	const sal_Unicode*	pPtr = maString.GetBuffer();
5694 	for ( nCount = 0; nCount < maString.Len(); nCount++ )
5695 	{
5696 		if ( pPtr[ nCount ] == 0x9 )
5697 		{
5698 			bRetValue = sal_True;
5699 			break;
5700 		}
5701 
5702 	}
5703 	return bRetValue;
5704 }
5705 
GetAttrib(sal_uInt32 nAttr,sal_uInt32 & nRetValue,sal_uInt32 nDestinationInstance)5706 sal_Bool PPTPortionObj::GetAttrib( sal_uInt32 nAttr, sal_uInt32& nRetValue, sal_uInt32 nDestinationInstance )
5707 {
5708 	sal_uInt32	nMask = 1 << nAttr;
5709 	nRetValue = 0;
5710 
5711 	sal_uInt32 bIsHardAttribute = ( ( pCharSet->mnAttrSet & nMask ) != 0 ) ? 1 : 0;
5712 
5713 	if ( bIsHardAttribute )
5714 	{
5715 		switch ( nAttr )
5716 		{
5717 			case PPT_CharAttr_Bold :
5718 			case PPT_CharAttr_Italic :
5719 			case PPT_CharAttr_Underline :
5720 			case PPT_CharAttr_Shadow :
5721 			case PPT_CharAttr_Strikeout :
5722 			case PPT_CharAttr_Embossed :
5723 				nRetValue = ( pCharSet->mnFlags & nMask ) ? 1 : 0;
5724 			break;
5725 			case PPT_CharAttr_Font :
5726 				nRetValue = pCharSet->mnFont;
5727 			break;
5728 			case PPT_CharAttr_AsianOrComplexFont :
5729 				nRetValue = pCharSet->mnAsianOrComplexFont;
5730 			break;
5731 			case PPT_CharAttr_FontHeight :
5732 				nRetValue = pCharSet->mnFontHeight;
5733 			break;
5734 			case PPT_CharAttr_FontColor :
5735 				nRetValue = pCharSet->mnColor;
5736 			break;
5737 			case PPT_CharAttr_Escapement :
5738 				nRetValue = pCharSet->mnEscapement;
5739 			break;
5740 			default :
5741 				DBG_ERROR( "SJ:PPTPortionObj::GetAttrib ( hard attribute does not exist )" );
5742 		}
5743 	}
5744 	else
5745 	{
5746 		const PPTCharLevel& rCharLevel = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ mnDepth ];
5747 		PPTCharLevel* pCharLevel = NULL;
5748 		if ( ( nDestinationInstance == 0xffffffff )
5749 				|| ( mnDepth && ( ( mnInstance == TSS_TYPE_SUBTITLE ) || ( mnInstance == TSS_TYPE_TEXT_IN_SHAPE ) ) ) )
5750 			bIsHardAttribute = 1;
5751 		else if ( nDestinationInstance != mnInstance )
5752 			pCharLevel = &mrStyleSheet.mpCharSheet[ nDestinationInstance ]->maCharLevel[ mnDepth ];
5753 		switch( nAttr )
5754 		{
5755 			case PPT_CharAttr_Bold :
5756 			case PPT_CharAttr_Italic :
5757 			case PPT_CharAttr_Underline :
5758 			case PPT_CharAttr_Shadow :
5759 			case PPT_CharAttr_Strikeout :
5760 			case PPT_CharAttr_Embossed :
5761 			{
5762 				nRetValue = ( rCharLevel.mnFlags & nMask ) ? 1 : 0;
5763 				if ( pCharLevel )
5764 				{
5765 					sal_uInt32 nTmp = ( pCharLevel->mnFlags & nMask ) ? 1 : 0;
5766 					if ( nRetValue != nTmp )
5767 						bIsHardAttribute = 1;
5768 				}
5769 			}
5770 			break;
5771 			case PPT_CharAttr_Font :
5772 			{
5773 				nRetValue = rCharLevel.mnFont;
5774 				if ( pCharLevel && ( nRetValue != pCharLevel->mnFont ) )
5775 					bIsHardAttribute = 1;
5776 			}
5777 			break;
5778 			case PPT_CharAttr_AsianOrComplexFont :
5779 			{
5780 				nRetValue = rCharLevel.mnAsianOrComplexFont;
5781 				if ( pCharLevel && ( nRetValue != pCharLevel->mnAsianOrComplexFont ) )
5782 					bIsHardAttribute = 1;
5783 			}
5784 			break;
5785 			case PPT_CharAttr_FontHeight :
5786 			{
5787 				nRetValue = rCharLevel.mnFontHeight;
5788 				if ( pCharLevel && ( nRetValue != pCharLevel->mnFontHeight ) )
5789 					bIsHardAttribute = 1;
5790 			}
5791 			break;
5792 			case PPT_CharAttr_FontColor :
5793 			{
5794 				nRetValue = rCharLevel.mnFontColor;
5795 				if ( pCharLevel && ( nRetValue != pCharLevel->mnFontColor ) )
5796 					bIsHardAttribute = 1;
5797 			}
5798 			break;
5799 			case PPT_CharAttr_Escapement :
5800 			{
5801 				nRetValue = rCharLevel.mnEscapement;
5802 				if ( pCharLevel && ( nRetValue != pCharLevel->mnEscapement ) )
5803 					bIsHardAttribute = 1;
5804 			}
5805 			break;
5806 			default :
5807 				DBG_ERROR( "SJ:PPTPortionObj::GetAttrib ( attribute does not exist )" );
5808 		}
5809 	}
5810 	return (sal_Bool)bIsHardAttribute;
5811 }
5812 
ApplyTo(SfxItemSet & rSet,SdrPowerPointImport & rManager,sal_uInt32 nDestinationInstance)5813 void PPTPortionObj::ApplyTo(  SfxItemSet& rSet, SdrPowerPointImport& rManager, sal_uInt32 nDestinationInstance )
5814 {
5815 	ApplyTo( rSet, rManager, nDestinationInstance, NULL );
5816 }
5817 
ApplyTo(SfxItemSet & rSet,SdrPowerPointImport & rManager,sal_uInt32 nDestinationInstance,const PPTTextObj * pTextObj)5818 void PPTPortionObj::ApplyTo(  SfxItemSet& rSet, SdrPowerPointImport& rManager, sal_uInt32 nDestinationInstance, const PPTTextObj* pTextObj )
5819 {
5820 	sal_uInt32	nVal;
5821 	if ( GetAttrib( PPT_CharAttr_Bold, nVal, nDestinationInstance ) )
5822 	{
5823         rSet.Put( SvxWeightItem( nVal != 0 ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
5824 		rSet.Put( SvxWeightItem( nVal != 0 ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
5825 		rSet.Put( SvxWeightItem( nVal != 0 ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
5826 	}
5827 	if ( GetAttrib( PPT_CharAttr_Italic, nVal, nDestinationInstance ) )
5828 	{
5829         rSet.Put( SvxPostureItem( nVal != 0 ? ITALIC_NORMAL : ITALIC_NONE, EE_CHAR_ITALIC ) );
5830 		rSet.Put( SvxPostureItem( nVal != 0 ? ITALIC_NORMAL : ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
5831 		rSet.Put( SvxPostureItem( nVal != 0 ? ITALIC_NORMAL : ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
5832 	}
5833 	if ( GetAttrib( PPT_CharAttr_Underline, nVal, nDestinationInstance ) )
5834         rSet.Put( SvxUnderlineItem( nVal != 0 ? UNDERLINE_SINGLE : UNDERLINE_NONE, EE_CHAR_UNDERLINE ) );
5835 
5836 	if ( GetAttrib( PPT_CharAttr_Shadow, nVal, nDestinationInstance ) )
5837         rSet.Put( SvxShadowedItem( nVal != 0, EE_CHAR_SHADOW ) );
5838 
5839 	if ( GetAttrib( PPT_CharAttr_Strikeout, nVal, nDestinationInstance ) )
5840         rSet.Put( SvxCrossedOutItem( nVal != 0 ? STRIKEOUT_SINGLE : STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ) );
5841 
5842 	sal_uInt32	nAsianFontId = 0xffff;
5843 	if ( GetAttrib( PPT_CharAttr_AsianOrComplexFont, nAsianFontId, nDestinationInstance ) )
5844 	{
5845 		if ( nAsianFontId != 0xffff )
5846 		{
5847 			PptFontEntityAtom* pFontEnityAtom = rManager.GetFontEnityAtom( nAsianFontId );
5848 			if ( pFontEnityAtom )
5849 			{
5850 				rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName,
5851 							String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO_CJK ) );
5852 				rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName,
5853 							String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO_CTL ) );
5854 			}
5855 		}
5856 	}
5857 	if ( GetAttrib( PPT_CharAttr_Font, nVal, nDestinationInstance ) )
5858 	{
5859 		PptFontEntityAtom* pFontEnityAtom = rManager.GetFontEnityAtom( nVal );
5860 		if ( pFontEnityAtom )
5861 		{
5862 			rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName, String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO ) );
5863 
5864             // #119475# bullet font info for CJK and CTL
5865             if ( RTL_TEXTENCODING_SYMBOL ==  pFontEnityAtom->eCharSet )
5866 			{
5867 				rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName, String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO_CJK ) );
5868 				rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName, String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO_CTL ) );
5869 			}
5870 		}
5871 	}
5872 	if ( GetAttrib( PPT_CharAttr_FontHeight, nVal, nDestinationInstance ) )	// Schriftgrad in Point
5873 	{
5874 		sal_uInt32 nHeight = rManager.ScalePoint( nVal );
5875 		rSet.Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
5876 		rSet.Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
5877 		rSet.Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CTL ) );
5878 	}
5879 
5880 	if ( GetAttrib( PPT_CharAttr_Embossed, nVal, nDestinationInstance ) )
5881 		rSet.Put( SvxCharReliefItem( nVal != 0 ? RELIEF_EMBOSSED : RELIEF_NONE, EE_CHAR_RELIEF ) );
5882 	if ( nVal )	/* if Embossed is set, the font color depends to the fillstyle/color of the object,
5883 				   if the object has no fillstyle, the font color depends to fillstyle of the background */
5884 	{
5885 		Color aDefColor( COL_BLACK );
5886 		MSO_FillType eFillType = mso_fillSolid;
5887 		if ( rManager.GetPropertyValue( DFF_Prop_fNoFillHitTest ) & 0x10 )
5888 			eFillType = (MSO_FillType)rManager.GetPropertyValue( DFF_Prop_fillType, mso_fillSolid );
5889 		else
5890 			eFillType = mso_fillBackground;
5891 		switch( eFillType )
5892 		{
5893 			case mso_fillShade :
5894 			case mso_fillShadeCenter :
5895 			case mso_fillShadeShape :
5896 			case mso_fillShadeScale :
5897 			case mso_fillShadeTitle :
5898 			case mso_fillSolid :
5899 				aDefColor = rManager.MSO_CLR_ToColor( rManager.GetPropertyValue( DFF_Prop_fillColor ) );
5900 			break;
5901 			case mso_fillPattern :
5902 				aDefColor = rManager.MSO_CLR_ToColor( rManager.GetPropertyValue( DFF_Prop_fillBackColor ) );
5903 			break;
5904 			case mso_fillTexture :
5905 			{
5906 				Graphic aGraf;
5907 				if ( rManager.GetBLIP( rManager.GetPropertyValue( DFF_Prop_fillBlip ), aGraf, NULL ) )
5908 				{
5909 					Bitmap aBmp( aGraf.GetBitmap() );
5910 					Size aSize( aBmp.GetSizePixel() );
5911 					if ( aSize.Width() && aSize.Height() )
5912 					{
5913 						if ( aSize.Width () > 64 )
5914 							aSize.Width () = 64;
5915 						if ( aSize.Height() > 64 )
5916 							aSize.Height() = 64;
5917 
5918 						sal_uLong nRt = 0, nGn = 0, nBl = 0;
5919 						BitmapReadAccess*	pAcc = aBmp.AcquireReadAccess();
5920 						if( pAcc )
5921 						{
5922 							const long nWidth = aSize.Width();
5923 							const long nHeight = aSize.Height();
5924 
5925 							if( pAcc->HasPalette() )
5926 							{
5927 								for( long nY = 0L; nY < nHeight; nY++ )
5928 								{
5929 									for( long nX = 0L; nX < nWidth; nX++ )
5930 									{
5931 										const BitmapColor& rCol = pAcc->GetPaletteColor( pAcc->GetPixelIndex( nY, nX ) );
5932 										nRt+=rCol.GetRed(); nGn+=rCol.GetGreen(); nBl+=rCol.GetBlue();
5933 									}
5934 								}
5935 							}
5936 							else
5937 							{
5938 								for( long nY = 0L; nY < nHeight; nY++ )
5939 								{
5940 									for( long nX = 0L; nX < nWidth; nX++ )
5941 									{
5942 										const BitmapColor aCol( pAcc->GetPixel( nY, nX ) );
5943 										nRt+=aCol.GetRed(); nGn+=aCol.GetGreen(); nBl+=aCol.GetBlue();
5944 									}
5945 								}
5946 							}
5947 							aBmp.ReleaseAccess( pAcc );
5948 							sal_uInt32 nC = ( aSize.Width() * aSize.Height() );
5949 							nRt /= nC;
5950 							nGn /= nC;
5951 							nBl /= nC;
5952 							aDefColor = Color(sal_uInt8( nRt ), sal_uInt8( nGn ),sal_uInt8( nBl ) );
5953 						}
5954 					}
5955 				}
5956 			}
5957 			break;
5958 			case mso_fillBackground	:
5959 			{
5960 				if ( pTextObj )	// the textobject is needed
5961 				{
5962 					const SfxItemSet* pItemSet = pTextObj->GetBackground();
5963 					if ( pItemSet )
5964 					{
5965 						const SfxPoolItem* pFillStyleItem = NULL;
5966 						pItemSet->GetItemState( XATTR_FILLSTYLE, sal_False, &pFillStyleItem );
5967 						if ( pFillStyleItem )
5968 						{
5969 							XFillStyle eFillStyle = ((XFillStyleItem*)pFillStyleItem)->GetValue();
5970 							switch( eFillStyle )
5971 							{
5972 								case XFILL_SOLID :
5973 								{
5974 									const SfxPoolItem* pFillColorItem = NULL;
5975 									pItemSet->GetItemState( XATTR_FILLCOLOR, sal_False, &pFillColorItem );
5976 									if ( pFillColorItem )
5977 										aDefColor = ((XColorItem*)pFillColorItem)->GetColorValue();
5978 								}
5979 								break;
5980 								case XFILL_GRADIENT :
5981 								{
5982 									const SfxPoolItem* pGradientItem = NULL;
5983 									pItemSet->GetItemState( XATTR_FILLGRADIENT, sal_False, &pGradientItem );
5984 									if ( pGradientItem )
5985 										aDefColor = ((XFillGradientItem*)pGradientItem)->GetGradientValue().GetStartColor();
5986 								}
5987 								break;
5988 								case XFILL_HATCH :
5989 								case XFILL_BITMAP :
5990 									aDefColor = Color( COL_WHITE );
5991 								break;
5992 								default: break;
5993 							}
5994 						}
5995 					}
5996 				}
5997 			}
5998 			break;
5999 //			case mso_fillPicture :
6000 			default: break;
6001 		}
6002 		rSet.Put( SvxColorItem( aDefColor, EE_CHAR_COLOR ) );
6003 	}
6004 	else
6005 	{
6006 		if ( GetAttrib( PPT_CharAttr_FontColor, nVal, nDestinationInstance ) )	// Textfarbe (4Byte-Arg)
6007 		{
6008 			Color aCol( rManager.MSO_TEXT_CLR_ToColor( nVal ) );
6009 			rSet.Put( SvxColorItem( aCol, EE_CHAR_COLOR ) );
6010 			if ( nDestinationInstance == 0xffffffff )
6011 				mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ mnDepth ].mnFontColorInStyleSheet = aCol;
6012 		}
6013 		else if ( nVal & 0x0f000000 )	// this is not a hard attribute, but maybe the page has a different colerscheme,
6014 		{								// so that in this case we must use a hard color attribute
6015 			Color	aCol( rManager.MSO_TEXT_CLR_ToColor( nVal ) );
6016 			Color&	aColorInSheet = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ mnDepth ].mnFontColorInStyleSheet;
6017 			if ( aColorInSheet != aCol )
6018 				rSet.Put( SvxColorItem( aCol, EE_CHAR_COLOR ) );
6019 		}
6020 	}
6021 
6022 	if ( GetAttrib( PPT_CharAttr_Escapement, nVal, nDestinationInstance ) )	// Hoch/Tiefstellung in %
6023 	{
6024 		sal_uInt16	nEsc = 0;
6025 		sal_uInt8	nProp = 100;
6026 
6027 		if ( nVal )
6028 		{
6029 			nEsc = (sal_Int16)nVal;
6030 			nProp = DFLT_ESC_PROP;
6031 		}
6032         SvxEscapementItem aItem( nEsc, nProp, EE_CHAR_ESCAPEMENT );
6033 		rSet.Put( aItem );
6034 	}
6035 	if ( mnLanguage[ 0 ] )
6036 		rSet.Put( SvxLanguageItem( mnLanguage[ 0 ], EE_CHAR_LANGUAGE ) );
6037 	if ( mnLanguage[ 1 ] )
6038 		rSet.Put( SvxLanguageItem( mnLanguage[ 1 ], EE_CHAR_LANGUAGE_CJK ) );
6039 	if ( mnLanguage[ 2 ] )
6040 		rSet.Put( SvxLanguageItem( mnLanguage[ 2 ], EE_CHAR_LANGUAGE_CTL ) );
6041 }
6042 
GetTextField()6043 SvxFieldItem* PPTPortionObj::GetTextField()
6044 {
6045 	if ( mpFieldItem )
6046 		return new SvxFieldItem( *mpFieldItem );
6047 	return NULL;
6048 }
6049 
6050 //	-----------------------------------------------------------------------
6051 
PPTParagraphObj(const PPTStyleSheet & rStyleSheet,sal_uInt32 nInstance,sal_uInt16 nDepth)6052 PPTParagraphObj::PPTParagraphObj( const PPTStyleSheet& rStyleSheet, sal_uInt32 nInstance, sal_uInt16 nDepth ) :
6053     PPTNumberFormatCreator  ( NULL ),
6054 	mrStyleSheet		    ( rStyleSheet ),
6055 	mnInstance			    ( nInstance ),
6056 	mbTab				    ( sal_True ),		// style sheets always have to get the right tabulator setting
6057 	mnPortionCount		    ( 0 ),
6058 	mpPortionList		    ( NULL )
6059 {
6060 	if ( nDepth > 4 )
6061 		nDepth = 4;
6062 	pParaSet->mnDepth = nDepth;
6063 }
6064 
PPTParagraphObj(PPTStyleTextPropReader & rPropReader,const PPTStyleSheet & rStyleSheet,sal_uInt32 nInstance,PPTTextRulerInterpreter & rRuler)6065 PPTParagraphObj::PPTParagraphObj( PPTStyleTextPropReader& rPropReader, const PPTStyleSheet& rStyleSheet,
6066 									sal_uInt32 nInstance, PPTTextRulerInterpreter& rRuler ) :
6067 	PPTParaPropSet			( *( (PPTParaPropSet*)rPropReader.aParaPropList.GetCurObject() ) ),
6068     PPTNumberFormatCreator  ( NULL ),
6069 	PPTTextRulerInterpreter	( rRuler ),
6070 	mrStyleSheet			( rStyleSheet ),
6071 	mnInstance				( nInstance ),
6072 	mbTab					( sal_False ),
6073 	mnCurrentObject			( 0 ),
6074 	mnPortionCount			( 0 ),
6075     mpPortionList			( NULL )
6076 {
6077 	sal_uInt32 nCurPos = rPropReader.aCharPropList.GetCurPos();
6078 	PPTCharPropSet* pCharPropSet = (PPTCharPropSet*)rPropReader.aCharPropList.GetCurObject();
6079 	if ( pCharPropSet )
6080 	{
6081 		sal_uInt32 nCurrentParagraph = pCharPropSet->mnParagraph;
6082 		for ( ; pCharPropSet && ( pCharPropSet->mnParagraph == nCurrentParagraph ); pCharPropSet = (PPTCharPropSet*)rPropReader.aCharPropList.Next() )
6083 			mnPortionCount++;	// counting number of portions that are part of this paragraph
6084 		pCharPropSet = (PPTCharPropSet*)rPropReader.aCharPropList.Seek( nCurPos );
6085 
6086 		mpPortionList = new PPTPortionObj*[ mnPortionCount ];
6087 		for ( sal_uInt32 i = 0; i < mnPortionCount; i++ )
6088 		{
6089 			if ( pCharPropSet )
6090 			{
6091                 PPTPortionObj* pPPTPortion = new PPTPortionObj( *pCharPropSet, rStyleSheet, nInstance, pParaSet->mnDepth );
6092 				mpPortionList[ i ] = pPPTPortion;
6093 				if ( !mbTab )
6094 					mbTab = mpPortionList[ i ]->HasTabulator();
6095 			}
6096 			else
6097 			{
6098 				DBG_ERROR( "SJ:PPTParagraphObj::It seems that there are missing some textportions" );
6099 				mpPortionList[ i ] = NULL;
6100 			}
6101 			pCharPropSet = (PPTCharPropSet*)rPropReader.aCharPropList.Next();
6102 		}
6103 	}
6104 }
6105 
~PPTParagraphObj()6106 PPTParagraphObj::~PPTParagraphObj()
6107 {
6108 	ImplClear();
6109 }
6110 
AppendPortion(PPTPortionObj & rPPTPortion)6111 void PPTParagraphObj::AppendPortion( PPTPortionObj& rPPTPortion )
6112 {
6113 	sal_uInt32 i;
6114 	PPTPortionObj** mpOldPortionList = mpPortionList;
6115 	mpPortionList = new PPTPortionObj*[ ++mnPortionCount ];
6116 	for ( i = 0; i < mnPortionCount - 1; i++ )
6117 		mpPortionList[ i ] = mpOldPortionList[ i ];
6118 	delete[] mpOldPortionList;
6119 	mpPortionList[ mnPortionCount - 1 ] = new PPTPortionObj( rPPTPortion );
6120 	if ( !mbTab )
6121 		mbTab = mpPortionList[ mnPortionCount - 1 ]->HasTabulator();
6122 }
6123 
UpdateBulletRelSize(sal_uInt32 & nBulletRelSize) const6124 void PPTParagraphObj::UpdateBulletRelSize( sal_uInt32& nBulletRelSize ) const
6125 {
6126 	if ( nBulletRelSize > 0x7fff )		// a negative value is the absolute bullet height
6127 	{
6128 		sal_uInt16 nFontHeight = 0;
6129 		if ( mpPortionList )
6130 		{
6131 			PPTPortionObj* pPortion = mpPortionList[ 0 ];
6132 			if ( pPortion && ( pPortion->pCharSet->mnAttrSet & ( 1 << PPT_CharAttr_FontHeight ) ) )
6133 				nFontHeight = pPortion->pCharSet->mnFontHeight;
6134 		}
6135 		// if we do not have a hard attributed fontheight, the fontheight is taken from the style
6136 		if ( !nFontHeight )
6137 			nFontHeight = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFontHeight;
6138 		nBulletRelSize = nFontHeight ? ((-((sal_Int16)nBulletRelSize)) * 100 ) / nFontHeight : 100;
6139 	}
6140 }
6141 
GetAttrib(sal_uInt32 nAttr,sal_uInt32 & nRetValue,sal_uInt32 nDestinationInstance)6142 sal_Bool PPTParagraphObj::GetAttrib( sal_uInt32 nAttr, sal_uInt32& nRetValue, sal_uInt32 nDestinationInstance )
6143 {
6144 	sal_uInt32	nMask = 1 << nAttr;
6145 	nRetValue = 0;
6146 
6147 	if ( nAttr > 21 )
6148 	{
6149 		DBG_ERROR( "SJ:PPTParagraphObj::GetAttrib - attribute does not exist" );
6150 		return sal_False;
6151 	}
6152 
6153 	sal_uInt32 bIsHardAttribute = ( ( pParaSet->mnAttrSet & nMask ) != 0 ) ? 1 : 0;
6154 
6155 	if ( bIsHardAttribute )
6156 	{
6157 		if ( nAttr == PPT_ParaAttr_BulletColor )
6158 		{
6159             sal_Bool bHardBulletColor;
6160             if ( pParaSet->mnAttrSet & ( 1 << PPT_ParaAttr_BuHardColor ) )
6161 			    bHardBulletColor = pParaSet->mpArry[ PPT_ParaAttr_BuHardColor ] != 0;
6162             else
6163                 bHardBulletColor = ( mrStyleSheet.mpParaSheet[ mnInstance ]->maParaLevel[ pParaSet->mnDepth ].mnBuFlags
6164                                         & ( 1 << PPT_ParaAttr_BuHardColor ) ) != 0;
6165             if ( bHardBulletColor )
6166 			    nRetValue = pParaSet->mnBulletColor;
6167             else
6168             {
6169 				nRetValue = PPT_COLSCHEME_TEXT_UND_ZEILEN;
6170 				if ( ( nDestinationInstance != 0xffffffff ) && mnPortionCount )
6171 				{
6172 					PPTPortionObj* pPortion = mpPortionList[ 0 ];
6173 					if ( pPortion )
6174 					{
6175 						if ( pPortion->pCharSet->mnAttrSet & ( 1 << PPT_CharAttr_FontColor ) )
6176 							nRetValue = pPortion->pCharSet->mnColor;
6177 						else
6178 							nRetValue = mrStyleSheet.mpCharSheet[ nDestinationInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFontColor;
6179 					}
6180 				}
6181             }
6182 		}
6183 		else if ( nAttr == PPT_ParaAttr_BulletFont )
6184 		{
6185 			sal_Bool bHardBuFont;
6186 			if ( pParaSet->mnAttrSet & ( 1 << PPT_ParaAttr_BuHardFont ) )
6187 				bHardBuFont = pParaSet->mpArry[ PPT_ParaAttr_BuHardFont ] != 0;
6188 			else
6189 				bHardBuFont = ( mrStyleSheet.mpParaSheet[ mnInstance ]->maParaLevel[ pParaSet->mnDepth ].mnBuFlags
6190                                         & ( 1 << PPT_ParaAttr_BuHardFont ) ) != 0;
6191 			if ( bHardBuFont )
6192 				nRetValue = pParaSet->mpArry[ PPT_ParaAttr_BulletFont ];
6193 			else
6194 			{
6195 				// it is the font used which assigned to the first character of the following text
6196 				nRetValue = 0;
6197 				if ( ( nDestinationInstance != 0xffffffff ) && mnPortionCount )
6198 				{
6199 					PPTPortionObj* pPortion = mpPortionList[ 0 ];
6200 					if ( pPortion )
6201 					{
6202 						if ( pPortion->pCharSet->mnAttrSet & ( 1 << PPT_CharAttr_Font ) )
6203 							nRetValue = pPortion->pCharSet->mnFont;
6204 						else
6205 							nRetValue = mrStyleSheet.mpCharSheet[ nDestinationInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFont;
6206 					}
6207 				}
6208 			}
6209 		}
6210 		else
6211 			nRetValue = pParaSet->mpArry[ nAttr ];
6212 	}
6213 	else
6214 	{
6215 		const PPTParaLevel& rParaLevel = mrStyleSheet.mpParaSheet[ mnInstance ]->maParaLevel[ pParaSet->mnDepth ];
6216 
6217 		PPTParaLevel* pParaLevel = NULL;
6218 		if ( ( nDestinationInstance == 0xffffffff )
6219 			|| ( pParaSet->mnDepth && ( ( mnInstance == TSS_TYPE_SUBTITLE ) || ( mnInstance == TSS_TYPE_TEXT_IN_SHAPE ) ) ) )
6220 			bIsHardAttribute = 1;
6221 		else if ( nDestinationInstance != mnInstance )
6222 			pParaLevel = &mrStyleSheet.mpParaSheet[ nDestinationInstance ]->maParaLevel[ pParaSet->mnDepth ];
6223 		switch ( nAttr )
6224 		{
6225 			case PPT_ParaAttr_BulletOn :
6226 			{
6227 				nRetValue = rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BulletOn );
6228 				if ( pParaLevel )
6229 				{
6230 					if ( nRetValue != ( (sal_uInt32)pParaLevel->mnBuFlags & ( 1 << PPT_ParaAttr_BulletOn ) ) )
6231 						bIsHardAttribute = 1;
6232 				}
6233 			}
6234 			break;
6235 			case PPT_ParaAttr_BuHardFont :
6236 			case PPT_ParaAttr_BuHardColor :
6237 			case PPT_ParaAttr_BuHardHeight :
6238 				DBG_ERROR( "SJ:PPTParagraphObj::GetAttrib - this attribute does not make sense" );
6239 			break;
6240 			case PPT_ParaAttr_BulletChar :
6241 			{
6242 				nRetValue = rParaLevel.mnBulletChar;
6243 				if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletChar ) )
6244 					bIsHardAttribute = 1;
6245 			}
6246 			break;
6247 			case PPT_ParaAttr_BulletFont :
6248 			{
6249 				sal_Bool bHardBuFont;
6250 				if ( pParaSet->mnAttrSet & ( 1 << PPT_ParaAttr_BuHardFont ) )
6251 					bHardBuFont = pParaSet->mpArry[ PPT_ParaAttr_BuHardFont ] != 0;
6252 				else
6253                     bHardBuFont = ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BuHardFont ) ) != 0;
6254 				if ( bHardBuFont )
6255 				{
6256 					nRetValue = rParaLevel.mnBulletFont;
6257 					if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletFont ) )
6258 						bIsHardAttribute = 1;
6259 				}
6260 				else
6261 				{
6262 					if ( mnPortionCount )
6263 					{
6264 						PPTPortionObj* pPortion = mpPortionList[ 0 ];
6265 						if ( pPortion )
6266 							bIsHardAttribute = pPortion->GetAttrib( PPT_CharAttr_Font, nRetValue, nDestinationInstance );
6267 					}
6268 					else
6269 					{
6270 						nRetValue = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFont;
6271 						bIsHardAttribute = 1;
6272 					}
6273 				}
6274 			}
6275 			break;
6276 			case PPT_ParaAttr_BulletHeight :
6277 			{
6278 				nRetValue = rParaLevel.mnBulletHeight;
6279 				if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletHeight ) )
6280 					bIsHardAttribute = 1;
6281 			}
6282 			break;
6283 			case PPT_ParaAttr_BulletColor :
6284 			{
6285                 sal_Bool bHardBulletColor;
6286                 if ( pParaSet->mnAttrSet & ( 1 << PPT_ParaAttr_BuHardColor ) )
6287 				    bHardBulletColor = pParaSet->mpArry[ PPT_ParaAttr_BuHardColor ] != 0;
6288                 else
6289                     bHardBulletColor = ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BuHardColor ) ) != 0;
6290                 if ( bHardBulletColor )
6291                 {
6292                     nRetValue = rParaLevel.mnBulletColor;
6293 				    if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletColor ) )
6294 					    bIsHardAttribute = 1;
6295                 }
6296                 else
6297                 {
6298 					if ( mnPortionCount )
6299 					{
6300 						PPTPortionObj* pPortion = mpPortionList[ 0 ];
6301 						if ( pPortion )
6302 						{
6303 							if (pPortion->mbIsHyperlink )
6304 							{
6305 								if( pPortion->mbHardHylinkOrigColor )
6306 									nRetValue = pPortion->mnHylinkOrigColor;
6307 								else
6308 									nRetValue = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFontColor;
6309 								bIsHardAttribute = sal_True;
6310 							}
6311 							else
6312 							{
6313 								bIsHardAttribute = pPortion->GetAttrib( PPT_CharAttr_FontColor, nRetValue, nDestinationInstance );
6314 							}
6315 						}
6316 					}
6317 					else
6318 					{
6319 						nRetValue = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFontColor;
6320 						bIsHardAttribute = 1;
6321 					}
6322                 }
6323 			}
6324 			break;
6325 			case PPT_ParaAttr_Adjust :
6326 			{
6327 				nRetValue = rParaLevel.mnAdjust;
6328 				if ( pParaLevel && ( nRetValue != pParaLevel->mnAdjust ) )
6329 					bIsHardAttribute = 1;
6330 			}
6331 			break;
6332 			case PPT_ParaAttr_LineFeed :
6333 			{
6334 				nRetValue = rParaLevel.mnLineFeed;
6335 				if ( pParaLevel && ( nRetValue != pParaLevel->mnLineFeed ) )
6336 					bIsHardAttribute = 1;
6337 			}
6338 			break;
6339 			case PPT_ParaAttr_UpperDist :
6340 			{
6341 				nRetValue = rParaLevel.mnUpperDist;
6342 				if ( pParaLevel && ( nRetValue != pParaLevel->mnUpperDist ) )
6343 					bIsHardAttribute = 1;
6344 			}
6345 			break;
6346 			case PPT_ParaAttr_LowerDist :
6347 			{
6348 				nRetValue = rParaLevel.mnLowerDist;
6349 				if ( pParaLevel && ( nRetValue != pParaLevel->mnLowerDist ) )
6350 					bIsHardAttribute = 1;
6351 			}
6352 			break;
6353 			case PPT_ParaAttr_TextOfs :
6354 			{
6355 				nRetValue = rParaLevel.mnTextOfs;
6356 				if ( pParaLevel && ( nRetValue != pParaLevel->mnTextOfs ) )
6357 					bIsHardAttribute = 1;
6358 			}
6359 			break;
6360 			case PPT_ParaAttr_BulletOfs :
6361 			{
6362 				nRetValue = rParaLevel.mnBulletOfs;
6363 				if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletOfs ) )
6364 					bIsHardAttribute = 1;
6365 			}
6366 			break;
6367 			case PPT_ParaAttr_DefaultTab :
6368 			{
6369 				nRetValue = rParaLevel.mnDefaultTab;
6370 				if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletOfs ) )
6371 					bIsHardAttribute = 1;
6372 			}
6373             break;
6374             case PPT_ParaAttr_AsianLB_1 :
6375             {
6376                 nRetValue = rParaLevel.mnAsianLineBreak & 1;
6377                 if ( pParaLevel && ( nRetValue != ( (sal_uInt32)pParaLevel->mnAsianLineBreak & 1 ) ) )
6378                     bIsHardAttribute = 1;
6379             }
6380             break;
6381             case PPT_ParaAttr_AsianLB_2 :
6382             {
6383                 nRetValue = ( rParaLevel.mnAsianLineBreak >> 1 ) & 1;
6384                 if ( pParaLevel && ( nRetValue != ( ( (sal_uInt32)pParaLevel->mnAsianLineBreak >> 1 ) & 1 ) ) )
6385                     bIsHardAttribute = 1;
6386             }
6387             break;
6388             case PPT_ParaAttr_AsianLB_3 :
6389             {
6390                 nRetValue = ( rParaLevel.mnAsianLineBreak >> 2 ) & 1;
6391                 if ( pParaLevel && ( nRetValue != ( ( (sal_uInt32)pParaLevel->mnAsianLineBreak >> 2 ) & 1 ) ) )
6392                     bIsHardAttribute = 1;
6393             }
6394             break;
6395 			case PPT_ParaAttr_BiDi :
6396 			{
6397                 nRetValue = rParaLevel.mnBiDi;
6398                 if ( pParaLevel && ( nRetValue != pParaLevel->mnBiDi ) )
6399                     bIsHardAttribute = 1;
6400 			}
6401 			break;
6402 		}
6403 	}
6404 	return (sal_Bool)bIsHardAttribute;
6405 }
6406 
ApplyTo(SfxItemSet & rSet,boost::optional<sal_Int16> & rStartNumbering,SdrPowerPointImport & rManager,sal_uInt32 nDestinationInstance,const PPTParagraphObj *)6407 void PPTParagraphObj::ApplyTo( SfxItemSet& rSet,  boost::optional< sal_Int16 >& rStartNumbering, SdrPowerPointImport& rManager, sal_uInt32 nDestinationInstance, const PPTParagraphObj* /*pPrev*/)
6408 {
6409 	sal_Int16	nVal2;
6410 	sal_uInt32	nVal, nUpperDist, nLowerDist;
6411 	sal_uInt32	nInstance = nDestinationInstance != 0xffffffff ? nDestinationInstance : mnInstance;
6412 
6413 	if ( ( nDestinationInstance != 0xffffffff ) || ( pParaSet->mnDepth <= 1 ) )
6414 	{
6415 		SvxNumBulletItem* pNumBulletItem = mrStyleSheet.mpNumBulletItem[ nInstance ];
6416 		if ( pNumBulletItem )
6417 		{
6418 			SvxNumberFormat aNumberFormat( SVX_NUM_NUMBER_NONE );
6419 			if ( GetNumberFormat( rManager, aNumberFormat, this, nDestinationInstance, rStartNumbering ) )
6420 			{
6421 				if ( aNumberFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE )
6422 				{
6423 					aNumberFormat.SetLSpace( 0 );
6424 					aNumberFormat.SetAbsLSpace( 0 );
6425 					aNumberFormat.SetFirstLineOffset( 0 );
6426 					aNumberFormat.SetCharTextDistance( 0 );
6427 					aNumberFormat.SetFirstLineIndent( 0 );
6428 					aNumberFormat.SetIndentAt( 0 );
6429 				}
6430 				SvxNumBulletItem aNewNumBulletItem( *pNumBulletItem );
6431 				SvxNumRule* pRule = aNewNumBulletItem.GetNumRule();
6432 				if ( pRule )
6433 				{
6434 					pRule->SetLevel( pParaSet->mnDepth, aNumberFormat );
6435 					sal_uInt16 i, n;
6436 					for ( i = 0; i < pRule->GetLevelCount(); i++ )
6437 					{
6438 						if ( i != pParaSet->mnDepth )
6439 						{
6440 							n = i > 4 ? 4 : i;
6441 
6442 							SvxNumberFormat aNumberFormat2( pRule->GetLevel( i ) );
6443 							const PPTParaLevel& rParaLevel = mrStyleSheet.mpParaSheet[ nInstance ]->maParaLevel[ n ];
6444 							const PPTCharLevel& rCharLevel = mrStyleSheet.mpCharSheet[ nInstance ]->maCharLevel[ n ];
6445 							sal_uInt32 nColor;
6446 							if ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BuHardColor ) )
6447 								nColor = rParaLevel.mnBulletColor;
6448 							else
6449 								nColor = rCharLevel.mnFontColor;
6450 							aNumberFormat2.SetBulletColor( rManager.MSO_TEXT_CLR_ToColor( nColor ) );
6451 							pRule->SetLevel( i, aNumberFormat2 );
6452 						}
6453 					}
6454 					rSet.Put( aNewNumBulletItem );
6455 				}
6456 			}
6457 		}
6458 	}
6459 
6460 	sal_uInt32 nIsBullet2, _nTextOfs, _nBulletOfs, nHardAttribute = 0;
6461 	GetAttrib( PPT_ParaAttr_BulletOn, nIsBullet2, nDestinationInstance );
6462 	nHardAttribute += GetAttrib( PPT_ParaAttr_TextOfs, _nTextOfs, nDestinationInstance );
6463 	nHardAttribute += GetAttrib( PPT_ParaAttr_BulletOfs, _nBulletOfs, nDestinationInstance );
6464 	if ( !nIsBullet2 )
6465 	{
6466         SvxLRSpaceItem aLRSpaceItem( EE_PARA_LRSPACE );
6467 		sal_uInt16 nAbsLSpace = (sal_uInt16)( ( (sal_uInt32)_nTextOfs * 2540 ) / 576 );
6468 		sal_uInt16 nFirstLineOffset = nAbsLSpace - (sal_uInt16)( ( (sal_uInt32)_nBulletOfs * 2540 ) / 576 );
6469 		aLRSpaceItem.SetLeft( nAbsLSpace );
6470 		aLRSpaceItem.SetTxtFirstLineOfstValue( -nFirstLineOffset );
6471 		rSet.Put( aLRSpaceItem );
6472 	}
6473 	else
6474 	{
6475         SvxLRSpaceItem aLRSpaceItem( EE_PARA_LRSPACE );
6476 		aLRSpaceItem.SetLeft( 0 );
6477 		aLRSpaceItem.SetTxtFirstLineOfstValue( 0 );
6478 		rSet.Put( aLRSpaceItem );
6479 	}
6480 	if ( GetAttrib( PPT_ParaAttr_Adjust, nVal, nDestinationInstance ) )
6481 	{
6482 		if ( nVal <= 3 )
6483 		{	// Absatzausrichtung
6484 			static SvxAdjust __READONLY_DATA aAdj[ 4 ] = { SVX_ADJUST_LEFT, SVX_ADJUST_CENTER, SVX_ADJUST_RIGHT, SVX_ADJUST_BLOCK };
6485             rSet.Put( SvxAdjustItem( aAdj[ nVal ], EE_PARA_JUST ) );
6486 		}
6487 	}
6488 
6489     if ( GetAttrib( PPT_ParaAttr_AsianLB_1, nVal, nDestinationInstance ) )
6490         rSet.Put( SfxBoolItem( EE_PARA_FORBIDDENRULES, nVal != 0 ) );
6491     if ( GetAttrib( PPT_ParaAttr_AsianLB_3, nVal, nDestinationInstance ) )
6492         rSet.Put( SfxBoolItem( EE_PARA_HANGINGPUNCTUATION, nVal != 0 ) );
6493 
6494 	if ( GetAttrib( PPT_ParaAttr_BiDi, nVal, nDestinationInstance ) )
6495 		rSet.Put( SvxFrameDirectionItem( nVal == 1 ? FRMDIR_HORI_RIGHT_TOP : FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
6496 
6497 	// LineSpacing
6498 	PPTPortionObj* pPortion = First();
6499 	sal_Bool bIsHardAttribute = GetAttrib( PPT_ParaAttr_LineFeed, nVal, nDestinationInstance );
6500 	nVal2 = (sal_Int16)nVal;
6501     sal_uInt32 nFont = sal_uInt32();
6502     if ( pPortion && pPortion->GetAttrib( PPT_CharAttr_Font, nFont, nDestinationInstance ) )
6503         bIsHardAttribute = sal_True;
6504 
6505 	if ( bIsHardAttribute )
6506 	{
6507 		if ( pPortion && ( nVal2 > 200 ) )
6508 		{
6509 			sal_uInt32 nFontHeight;
6510 			pPortion->GetAttrib( PPT_CharAttr_FontHeight, nFontHeight, nDestinationInstance );
6511 			nVal2 = -(sal_Int16)( ( nFontHeight * nVal * 8 ) / 100 );
6512 		}
6513 		rSet.Put( SdrTextFixedCellHeightItem( sal_True ), SDRATTR_TEXT_USEFIXEDCELLHEIGHT );
6514 		SvxLineSpacingItem aItem( 200, EE_PARA_SBL );
6515 		if ( nVal2 <= 0 )
6516 		{
6517 			aItem.SetLineHeight( (sal_uInt16)( rManager.ScalePoint( -nVal2 ) / 8 ) );
6518 			aItem.GetLineSpaceRule() = SVX_LINE_SPACE_FIX;
6519 		}
6520 		else
6521 		{
6522             sal_uInt8 nPropLineSpace = (sal_uInt8)nVal2;
6523 			aItem.SetPropLineSpace( nPropLineSpace );
6524 			aItem.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
6525 		}
6526 		rSet.Put( aItem );
6527 	}
6528 
6529 	// Paragraph Spacing
6530 	sal_uInt32 nFontHeight = 0;
6531 	bIsHardAttribute = ( (sal_uInt32)GetAttrib( PPT_ParaAttr_UpperDist, nUpperDist, nDestinationInstance ) +
6532 		(sal_uInt32)GetAttrib( PPT_ParaAttr_LowerDist, nLowerDist, nDestinationInstance ) ) != 0;
6533 	if ( ( nUpperDist > 0 ) || ( nLowerDist > 0 ) )
6534 	{
6535 		if ( mnPortionCount )
6536 		{
6537 			mpPortionList[ mnPortionCount - 1 ]->GetAttrib( PPT_CharAttr_FontHeight, nFontHeight, nDestinationInstance );
6538 			if ( ((sal_Int16)nUpperDist) > 0 )
6539 				nUpperDist = - (sal_Int16)( ( nFontHeight * nUpperDist * 100 ) / 1000 );
6540 			if ( ((sal_Int16)nLowerDist) > 0 )
6541 				nLowerDist = - (sal_Int16)( ( nFontHeight * nLowerDist * 100 ) / 1000 );
6542 		}
6543 		bIsHardAttribute = sal_True;
6544 	}
6545 	if ( bIsHardAttribute )
6546 	{
6547         SvxULSpaceItem aULSpaceItem( EE_PARA_ULSPACE );
6548 		nVal2 = (sal_Int16)nUpperDist;
6549 		if ( nVal2 <= 0 )
6550 			aULSpaceItem.SetUpper( (sal_uInt16)(((sal_uInt32) - nVal2 * 2540 ) / ( 72 * 8 ) ) );
6551 		else
6552 		{
6553 			aULSpaceItem.SetUpperValue( 0 );
6554 			aULSpaceItem.SetPropUpper( (sal_uInt16)nUpperDist == 100 ? 101 : (sal_uInt16)nUpperDist );
6555 		}
6556 		nVal2 = (sal_Int16)nLowerDist;
6557 		if ( nVal2 <= 0 )
6558 			aULSpaceItem.SetLower( (sal_uInt16)(((sal_uInt32) - nVal2 * 2540 ) / ( 72 * 8 ) ) );
6559 		else
6560 		{
6561 			aULSpaceItem.SetLowerValue( 0 );
6562 			aULSpaceItem.SetPropLower( (sal_uInt16)nLowerDist == 100 ? 101 : (sal_uInt16)nLowerDist );
6563 		}
6564 		rSet.Put( aULSpaceItem );
6565 	}
6566 
6567 	if ( mbTab )	// makes it sense to apply tabsettings
6568 	{
6569 		sal_uInt32 i, nDefaultTab, nTab, nTextOfs2 = 0;
6570 		sal_uInt32 nLatestManTab = 0;
6571 		GetAttrib( PPT_ParaAttr_TextOfs, nTextOfs2, nDestinationInstance );
6572 		GetAttrib( PPT_ParaAttr_BulletOfs, nTab, nDestinationInstance );
6573 		GetAttrib( PPT_ParaAttr_BulletOn, i, nDestinationInstance );
6574 		GetAttrib( PPT_ParaAttr_DefaultTab, nDefaultTab, nDestinationInstance );
6575         SvxTabStopItem aTabItem( 0, 0, SVX_TAB_ADJUST_DEFAULT, EE_PARA_TABS );
6576 		if ( GetTabCount() )
6577 		{
6578 			// paragraph offset = MIN(first_line_offset, hanging_offset)
6579 			sal_uInt32 nParaOffset = Min( nTextOfs2, nTab );
6580 			for ( i = 0; i < GetTabCount(); i++ )
6581 			{
6582 				SvxTabAdjust eTabAdjust;
6583 				nTab = GetTabOffsetByIndex( (sal_uInt16)i );
6584 				switch( GetTabStyleByIndex( (sal_uInt16)i ) )
6585 				{
6586 					case 1 :	eTabAdjust = SVX_TAB_ADJUST_CENTER; break;
6587 					case 2 :	eTabAdjust = SVX_TAB_ADJUST_RIGHT; break;
6588 					case 3 :	eTabAdjust = SVX_TAB_ADJUST_DECIMAL; break;
6589 					default :	eTabAdjust = SVX_TAB_ADJUST_LEFT;
6590 				}
6591 				if ( nTab > nParaOffset ) // If tab stop greater than paragraph offset
6592 					aTabItem.Insert( SvxTabStop( ( ( (long( nTab - nTextOfs2 )) * 2540 ) / 576 ), eTabAdjust ) );
6593 			}
6594 			nLatestManTab = nTab;
6595 		}
6596 		if ( nIsBullet2 == 0 )
6597 			aTabItem.Insert( SvxTabStop( (sal_uInt16)0 ) );
6598 		if ( nDefaultTab )
6599 		{
6600 			nTab = ( nTextOfs2 > nLatestManTab ) ? nTextOfs2 : nLatestManTab;
6601 			nTab /= nDefaultTab;
6602 			nTab = nDefaultTab * ( 1 + nTab );
6603 			for ( i = 0; ( i < 20 ) && ( nTab < 0x1b00 ); i++ )
6604 			{
6605 				aTabItem.Insert( SvxTabStop( (sal_uInt16)( ( ( nTab - nTextOfs2 ) * 2540 ) / 576 ) ) );
6606 				nTab += nDefaultTab;
6607 			}
6608 		}
6609 		rSet.Put( aTabItem );
6610 	}
6611 }
6612 
GetTextSize()6613 sal_uInt32 PPTParagraphObj::GetTextSize()
6614 {
6615 	sal_uInt32 nCount, nRetValue = 0;
6616 	for ( sal_uInt32 i = 0; i < mnPortionCount; i++ )
6617 	{
6618 		PPTPortionObj* pPortionObj = mpPortionList[ i ];
6619 		nCount = pPortionObj->Count();
6620 		if ( ( !nCount ) && pPortionObj->mpFieldItem )
6621 			nCount++;
6622 		nRetValue += nCount;
6623 	}
6624 	return nRetValue;
6625 }
6626 
First()6627 PPTPortionObj* PPTParagraphObj::First()
6628 {
6629 	mnCurrentObject = 0;
6630 	if ( !mnPortionCount )
6631 		return NULL;
6632 	return mpPortionList[ 0 ];
6633 }
6634 
Next()6635 PPTPortionObj* PPTParagraphObj::Next()
6636 {
6637 	sal_uInt32 i = mnCurrentObject + 1;
6638 	if ( i >= mnPortionCount )
6639 		return NULL;
6640 	mnCurrentObject++;
6641 	return mpPortionList[ i ];
6642 }
6643 
ImplClear()6644 void PPTParagraphObj::ImplClear()
6645 {
6646 	for ( void* pPtr = First(); pPtr; pPtr = Next() )
6647 		delete (PPTPortionObj*)pPtr;
6648 	delete[] mpPortionList;
6649 }
6650 
~PPTFieldEntry()6651 PPTFieldEntry::~PPTFieldEntry()
6652 {
6653 	delete pField1;
6654 	delete pField2;
6655 	delete pString;
6656 };
6657 
GetDateTime(const sal_uInt32 nVal,SvxDateFormat & eDateFormat,SvxTimeFormat & eTimeFormat)6658 void PPTFieldEntry::GetDateTime( const sal_uInt32 nVal, SvxDateFormat& eDateFormat, SvxTimeFormat& eTimeFormat )
6659 {
6660 	eDateFormat = SVXDATEFORMAT_APPDEFAULT;
6661 	eTimeFormat = SVXTIMEFORMAT_APPDEFAULT;
6662 	// ID auswerten
6663 	switch( nVal )
6664 	{
6665 		case 0:
6666 		case 6:
6667 			eDateFormat = SVXDATEFORMAT_A;
6668 		break;
6669 		case 1:
6670 			eDateFormat = SVXDATEFORMAT_F;
6671 		break;
6672 		case 2:
6673 		case 3:
6674 			eDateFormat = SVXDATEFORMAT_D;
6675 		break;
6676 		case 4:
6677 		case 5:
6678 			eDateFormat = SVXDATEFORMAT_C;
6679 		break;
6680 		case 7:
6681 			eDateFormat = SVXDATEFORMAT_A;
6682 		case 9:
6683 			eTimeFormat = SVXTIMEFORMAT_24_HM;
6684 		break;
6685 		case 8:
6686 			eDateFormat = SVXDATEFORMAT_A;
6687 		case 11:
6688 			eTimeFormat = SVXTIMEFORMAT_12_HM;
6689 		break;
6690 		case 10:
6691 			eTimeFormat = SVXTIMEFORMAT_24_HMS;
6692 		break;
6693 		case 12:
6694 			eTimeFormat = SVXTIMEFORMAT_12_HMS;
6695 		break;
6696 	}
6697 }
6698 
SetDateTime(sal_uInt32 nVal)6699 void PPTFieldEntry::SetDateTime( sal_uInt32 nVal )
6700 {
6701 	SvxDateFormat eDateFormat;
6702 	SvxTimeFormat eTimeFormat;
6703 	GetDateTime( nVal, eDateFormat, eTimeFormat );
6704 	if ( eDateFormat != SVXDATEFORMAT_APPDEFAULT )
6705         pField1 = new SvxFieldItem( SvxDateField( Date(), SVXDATETYPE_VAR, eDateFormat ), EE_FEATURE_FIELD );
6706 	if ( eTimeFormat != SVXTIMEFORMAT_APPDEFAULT )
6707 	{
6708         SvxFieldItem* pFieldItem = new SvxFieldItem( SvxExtTimeField( Time(), SVXTIMETYPE_VAR, eTimeFormat ), EE_FEATURE_FIELD );
6709 		if ( pField1 )
6710 			pField2 = pFieldItem;
6711 		else
6712 			pField1 = pFieldItem;
6713 	}
6714 }
6715 
6716 //	-----------------------------------------------------------------------
6717 
PPTTextObj(SvStream & rIn,SdrPowerPointImport & rSdrPowerPointImport,PptSlidePersistEntry & rPersistEntry,DffObjData * pObjData)6718 PPTTextObj::PPTTextObj( SvStream& rIn, SdrPowerPointImport& rSdrPowerPointImport, PptSlidePersistEntry& rPersistEntry, DffObjData* pObjData ) :
6719 	mpImplTextObj	( new ImplPPTTextObj( rPersistEntry ) )
6720 {
6721 	mpImplTextObj->mnRefCount = 1;
6722 	mpImplTextObj->mnShapeId = 0;
6723 	mpImplTextObj->mnShapeMaster = 0;
6724 	mpImplTextObj->mpPlaceHolderAtom = NULL;
6725 	mpImplTextObj->mnDestinationInstance = mpImplTextObj->mnInstance = 4;
6726 	mpImplTextObj->mnCurrentObject = 0;
6727 	mpImplTextObj->mnParagraphCount = 0;
6728 	mpImplTextObj->mpParagraphList = NULL;
6729 	mpImplTextObj->mnTextFlags = 0;
6730 	mpImplTextObj->meShapeType = ( pObjData && pObjData->bShapeType ) ? pObjData->eShapeType : mso_sptMin;
6731 
6732 	DffRecordHeader	aExtParaHd;
6733 	aExtParaHd.nRecType = 0;	// set empty
6734 
6735 	sal_uInt32 bStatus = sal_True;
6736 
6737 	DffRecordHeader aShapeContainerHd;
6738 	rIn >> aShapeContainerHd;
6739 
6740 	if ( ( pObjData == NULL ) || ( pObjData->bShapeType ) )
6741 	{
6742         PPTExtParaProv* pExtParaProv = rSdrPowerPointImport.pPPTStyleSheet->pExtParaProv;
6743 		if ( pObjData )
6744 		{
6745 			mpImplTextObj->mnShapeId = pObjData->nShapeId;
6746 			if ( pObjData->nSpFlags & SP_FHAVEMASTER )
6747 				mpImplTextObj->mnShapeMaster = rSdrPowerPointImport.GetPropertyValue( DFF_Prop_hspMaster, 0 );
6748 		}
6749 		////////////////
6750 		// ClientData //
6751 		////////////////
6752 		if ( rSdrPowerPointImport.maShapeRecords.SeekToContent( rIn, DFF_msofbtClientData, SEEK_FROM_CURRENT_AND_RESTART ) )
6753 		{
6754 			sal_uInt32 nOldPos = rIn.Tell();
6755 			DffRecordHeader& aClientDataContainerHd = *rSdrPowerPointImport.maShapeRecords.Current();
6756 			DffRecordHeader aPlaceHolderAtomHd;
6757             if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_OEPlaceholderAtom, aClientDataContainerHd.GetRecEndFilePos(), &aPlaceHolderAtomHd ) )
6758 			{
6759 				mpImplTextObj->mpPlaceHolderAtom = new PptOEPlaceholderAtom;
6760                 rIn >> *( mpImplTextObj->mpPlaceHolderAtom );
6761             }
6762 			rIn.Seek( nOldPos );
6763 			DffRecordHeader aProgTagHd;
6764             if ( rSdrPowerPointImport.SeekToContentOfProgTag( 9, rIn, aClientDataContainerHd, aProgTagHd ) )
6765             {
6766                 rIn >> aExtParaHd;
6767             }
6768 		}
6769 
6770 		///////////////////
6771 		// ClientTextBox //
6772 		///////////////////
6773 		if ( rSdrPowerPointImport.maShapeRecords.SeekToContent( rIn, DFF_msofbtClientTextbox, SEEK_FROM_CURRENT_AND_RESTART ) )
6774 		{
6775 			DffRecordHeader aClientTextBoxHd( *rSdrPowerPointImport.maShapeRecords.Current() );
6776 			sal_uInt32	nTextRulerAtomOfs = 0;	// case of zero -> this atom may be found in aClientDataContainerHd;
6777 											// case of -1 -> ther is no atom of this kind
6778 											// else -> this is the fileofs where we can get it
6779 
6780 			//////////////////////////////////////
6781 			// checkout if this is a referenced //
6782 			// textobj, if so the we will patch //
6783 			// the ClientTextBoxHd for a        //
6784 			// equivalent one					//
6785 			//////////////////////////////////////
6786 			DffRecordHeader aTextHd;
6787 			if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_OutlineTextRefAtom, aClientTextBoxHd.GetRecEndFilePos(), &aTextHd ) )
6788 			{
6789 				sal_uInt32 nRefNum;
6790 				rIn >> nRefNum;
6791 
6792 				if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_TextRulerAtom, aClientTextBoxHd.GetRecEndFilePos() ) )
6793 					nTextRulerAtomOfs = rIn.Tell();
6794 				else
6795 					nTextRulerAtomOfs = 0xffffffff;
6796 
6797 				sal_uInt32 nInstance = 0;
6798 				switch( rSdrPowerPointImport.eAktPageKind )
6799 				{
6800 					case PPT_NOTEPAGE :
6801 						nInstance++;
6802 					case PPT_MASTERPAGE :
6803 						nInstance++;
6804 					case PPT_SLIDEPAGE :
6805 					break;
6806 					default :
6807 						bStatus = sal_False;
6808 				}
6809 				if ( bStatus )
6810 				{
6811 					sal_uInt32 nSlideId = rSdrPowerPointImport.GetAktPageId();
6812 					if ( !nSlideId )
6813 						bStatus = sal_False;
6814 					else
6815 					{
6816 						if ( !aExtParaHd.nRecType )
6817 						{
6818 							sal_uInt32 nOldPos = rIn.Tell();
6819 							// try to locate the referenced ExtendedParaHd
6820 							DffRecordHeader* pHd = pExtParaProv->
6821 														aExtendedPresRules.GetRecordHeader( PPT_PST_ExtendedParagraphHeaderAtom,
6822 																							SEEK_FROM_CURRENT_AND_RESTART );
6823 							DffRecordHeader		aPresRuleHd;
6824 							DffRecordHeader*	pFirst = pHd;
6825 
6826 							sal_uInt32	nTmpSlideId, nTmpRef;
6827 							while ( pHd )
6828 							{
6829 								pHd->SeekToContent( rIn );
6830 								rIn >> nTmpSlideId
6831 									>> nTmpRef;			// this seems to be the instance
6832 
6833 								if ( ( nTmpSlideId == nSlideId ) && ( pHd->nRecInstance == nRefNum ) )
6834 								{
6835 									pHd->SeekToEndOfRecord( rIn );
6836 									rIn >> aPresRuleHd;
6837 									if ( aPresRuleHd.nRecType == PPT_PST_ExtendedParagraphAtom )
6838 									{
6839 										aExtParaHd = aPresRuleHd;
6840 										break;
6841 									}
6842 								}
6843 								pHd = pExtParaProv->
6844 										aExtendedPresRules.GetRecordHeader( PPT_PST_ExtendedParagraphHeaderAtom,
6845 																			SEEK_FROM_CURRENT_AND_RESTART );
6846 								if ( pHd == pFirst )
6847 									break;
6848 							}
6849 							rIn.Seek( nOldPos );
6850 						}
6851 						// now pHd points to the right SlideListWithText Container
6852 						PptSlidePersistList* pPageList = rSdrPowerPointImport.GetPageList( rSdrPowerPointImport.eAktPageKind );
6853 						PptSlidePersistEntry* pE = NULL;
6854 						if ( pPageList && ( rSdrPowerPointImport.nAktPageNum < pPageList->Count() ) )
6855 							pE = (*pPageList)[ rSdrPowerPointImport.nAktPageNum ];
6856 						if ( (!pE) || (!pE->nSlidePersistStartOffset) || ( pE->aPersistAtom.nSlideId != nSlideId ) )
6857 							bStatus = sal_False;
6858 						else
6859 						{
6860 							rIn.Seek( pE->nSlidePersistStartOffset );
6861 							// now we got the right page and are searching for the right
6862 							// TextHeaderAtom
6863 							while ( rIn.Tell() < pE->nSlidePersistEndOffset )
6864 							{
6865 								rIn >> aClientTextBoxHd;
6866 								if ( aClientTextBoxHd.nRecType == PPT_PST_TextHeaderAtom )
6867 								{
6868 									if ( aClientTextBoxHd.nRecInstance == nRefNum )
6869 									{
6870 										aClientTextBoxHd.SeekToEndOfRecord( rIn );
6871 										break;
6872 									}
6873 								}
6874 								aClientTextBoxHd.SeekToEndOfRecord( rIn );
6875 							}
6876 							if ( rIn.Tell() > pE->nSlidePersistEndOffset )
6877 								bStatus = sal_False;
6878 							else
6879 							{	// patching the RecordHeader
6880 								aClientTextBoxHd.nFilePos -= DFF_COMMON_RECORD_HEADER_SIZE;
6881 								aClientTextBoxHd.nRecLen += DFF_COMMON_RECORD_HEADER_SIZE;
6882 								aClientTextBoxHd.nRecType = DFF_msofbtClientTextbox;
6883 								aClientTextBoxHd.nRecVer = DFF_PSFLAG_CONTAINER;
6884 
6885 								// we have to calculate the correct record len
6886 								DffRecordHeader aTmpHd;
6887 								while ( rIn.Tell() < pE->nSlidePersistEndOffset )
6888 								{
6889 									rIn >> aTmpHd;
6890 									if ( ( aTmpHd.nRecType == PPT_PST_SlidePersistAtom ) || ( aTmpHd.nRecType == PPT_PST_TextHeaderAtom ) )
6891 										break;
6892 									aTmpHd.SeekToEndOfRecord( rIn );
6893 									aClientTextBoxHd.nRecLen += aTmpHd.nRecLen + DFF_COMMON_RECORD_HEADER_SIZE;
6894 								}
6895 								aClientTextBoxHd.SeekToContent( rIn );
6896 							}
6897 						}
6898 					}
6899 				}
6900 			}
6901 
6902 			if ( bStatus )
6903 			{
6904 				if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_TextHeaderAtom, aClientTextBoxHd.GetRecEndFilePos(), &aTextHd ) )
6905 				{
6906 					// TextHeaderAtom is always the first Atom
6907 					sal_uInt16 nInstance;
6908 					rIn >> nInstance;	// this number tells us the TxMasterStyleAtom Instance
6909 					if ( nInstance > 8 )
6910 						nInstance = 4;
6911 					aTextHd.SeekToEndOfRecord( rIn );
6912 					mpImplTextObj->mnInstance = nInstance;
6913 
6914 					sal_uInt32 nFilePos = rIn.Tell();
6915 					if ( rSdrPowerPointImport.SeekToRec2( PPT_PST_TextBytesAtom,
6916                                                           PPT_PST_TextCharsAtom,
6917                                                           aClientTextBoxHd.GetRecEndFilePos() )
6918                          || rSdrPowerPointImport.SeekToRec( rIn,
6919                                                             PPT_PST_StyleTextPropAtom,
6920                                                             aClientTextBoxHd.GetRecEndFilePos() ) )
6921 					{
6922 						PPTTextRulerInterpreter aTextRulerInterpreter( nTextRulerAtomOfs, rSdrPowerPointImport,
6923 																		aClientTextBoxHd, rIn );
6924 
6925 						PPTStyleTextPropReader aStyleTextPropReader( rIn, rSdrPowerPointImport,	aClientTextBoxHd,
6926 																		aTextRulerInterpreter, aExtParaHd, nInstance );
6927 						sal_uInt32 nParagraphs = mpImplTextObj->mnParagraphCount = aStyleTextPropReader.aParaPropList.Count();
6928 						if ( nParagraphs )
6929 						{
6930 							// the language settings will be merged into the list of PPTCharPropSet
6931 							DffRecordHeader aTextSpecInfoHd;
6932 							PPTTextSpecInfoAtomInterpreter aTextSpecInfoAtomInterpreter;
6933 							if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_TextSpecInfoAtom,
6934 														aClientTextBoxHd.GetRecEndFilePos(), &aTextSpecInfoHd ) )
6935 							{
6936 								if ( aTextSpecInfoAtomInterpreter.Read( rIn, aTextSpecInfoHd, PPT_PST_TextSpecInfoAtom,
6937 										&(rSdrPowerPointImport.pPPTStyleSheet->maTxSI) ) )
6938 								{
6939 									sal_uInt32	nI = 0;
6940 									PPTTextSpecInfo* pSpecInfo;
6941 									for ( pSpecInfo = (PPTTextSpecInfo*)aTextSpecInfoAtomInterpreter.aList.First();
6942 										pSpecInfo; pSpecInfo =(PPTTextSpecInfo*)aTextSpecInfoAtomInterpreter.aList.Next() )
6943 									{
6944 										sal_uInt32 nCharIdx = pSpecInfo->nCharIdx;
6945 
6946 										// portions and text have to been split in some cases
6947 										for ( ; nI < aStyleTextPropReader.aCharPropList.Count(); )
6948 										{
6949 											PPTCharPropSet* pSet = (PPTCharPropSet*)aStyleTextPropReader.aCharPropList.GetObject( nI );
6950 											if ( pSet->mnOriginalTextPos < nCharIdx )
6951 											{
6952 												pSet->mnLanguage[ 0 ] = pSpecInfo->nLanguage[ 0 ];
6953 												pSet->mnLanguage[ 1 ] = pSpecInfo->nLanguage[ 1 ];
6954 												pSet->mnLanguage[ 2 ] = pSpecInfo->nLanguage[ 2 ];
6955 												// test if the current portion needs to be split
6956 												if ( pSet->maString.Len() > 1 )
6957 												{
6958 													sal_Int32 nIndexOfNextPortion = pSet->maString.Len() + pSet->mnOriginalTextPos;
6959 													sal_Int32 nNewLen = nIndexOfNextPortion - nCharIdx;
6960 													sal_Int32 nOldLen = pSet->maString.Len() - nNewLen;
6961 
6962 													if ( ( nNewLen > 0 ) && ( nOldLen > 0 ) )
6963 													{
6964 														String aString( pSet->maString );
6965 														PPTCharPropSet* pNew = new PPTCharPropSet( *pSet );
6966 														pSet->maString = String( aString, 0, (sal_uInt16)nOldLen );
6967 														pNew->maString = String( aString, (sal_uInt16)nOldLen, (sal_uInt16)nNewLen );
6968 														pNew->mnOriginalTextPos += nOldLen;
6969 														aStyleTextPropReader.aCharPropList.Insert( pNew, nI + 1 );
6970 													}
6971 												}
6972 											}
6973 											else
6974 												break;
6975 											nI++;
6976 										}
6977 									}
6978 								}
6979 #ifdef DBG_UTIL
6980                                 else
6981                                 {
6982                                     if (!(rSdrPowerPointImport.rImportParam.nImportFlags & PPT_IMPORTFLAGS_NO_TEXT_ASSERT))
6983                                     {
6984     		                            DBG_ERROR( "SdrTextSpecInfoAtomInterpreter::Ctor(): parsing error, this document needs to be analysed (SJ)" );
6985                                     }
6986                                 }
6987 #endif
6988 							}
6989 							//
6990 							// now will search for possible textextensions such as date/time fields
6991 							// or ParaTabStops and append them on this textobj
6992 							//
6993 							rIn.Seek( nFilePos );
6994 							List* pFieldList = NULL;
6995 							while ( rIn.Tell() < aClientTextBoxHd.GetRecEndFilePos() )
6996 							{
6997 								rIn >> aTextHd;
6998 								sal_uInt16 nVal = 0;
6999 								PPTFieldEntry* pEntry = NULL;
7000 								switch ( aTextHd.nRecType )
7001 								{
7002 									case PPT_PST_DateTimeMCAtom :
7003 									{
7004 										pEntry = new PPTFieldEntry;
7005 										rIn >> pEntry->nPos
7006 											>> nVal
7007 											>> nVal;
7008 										pEntry->SetDateTime( nVal & 0xff );
7009 									}
7010 									break;
7011 
7012 									case PPT_PST_FooterMCAtom :
7013 									{
7014 										pEntry = new PPTFieldEntry;
7015 										rIn >> pEntry->nPos;
7016                                         pEntry->pField1 = new SvxFieldItem( SvxFooterField(), EE_FEATURE_FIELD );
7017 									}
7018 									break;
7019 
7020 									case PPT_PST_HeaderMCAtom :
7021 									{
7022 										pEntry = new PPTFieldEntry;
7023 										rIn >> pEntry->nPos;
7024                                         pEntry->pField1 = new SvxFieldItem( SvxHeaderField(), EE_FEATURE_FIELD );
7025 									}
7026 									break;
7027 
7028 									case PPT_PST_GenericDateMCAtom :
7029 									{
7030 										pEntry = new PPTFieldEntry;
7031 										rIn >> pEntry->nPos;
7032                                         pEntry->pField1 = new SvxFieldItem( SvxDateTimeField(), EE_FEATURE_FIELD );
7033 										if ( rPersistEntry.pHeaderFooterEntry )	// sj: #i34111# on master pages it is possible
7034 										{										// that there is no HeaderFooterEntry available
7035 											if ( rPersistEntry.pHeaderFooterEntry->nAtom & 0x20000 )	// auto date time
7036 												pEntry->SetDateTime( rPersistEntry.pHeaderFooterEntry->nAtom & 0xff );
7037 											else
7038 												pEntry->pString = new String( rPersistEntry.pHeaderFooterEntry->pPlaceholder[ nVal ] );
7039 										}
7040 									}
7041 									break;
7042 
7043 									case PPT_PST_SlideNumberMCAtom :
7044 									case PPT_PST_RTFDateTimeMCAtom :
7045 									{
7046 										pEntry = new PPTFieldEntry;
7047 										if ( aTextHd.nRecLen >= 4 )
7048 										{
7049 											rIn >> pEntry->nPos
7050 												>> nVal;
7051 
7052 											// ID auswerten
7053 											//SvxFieldItem* pFieldItem = NULL;
7054 											switch( aTextHd.nRecType )
7055 											{
7056 												case PPT_PST_SlideNumberMCAtom:
7057                                                     pEntry->pField1 = new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD );
7058 												break;
7059 
7060 												case PPT_PST_RTFDateTimeMCAtom:
7061 												{
7062 													// Rude workaround for one special case reported
7063 													// by a customer. (#i75203#)
7064 
7065 													// Don't even attempt to handle the general use
7066 													// case for PPT_PST_RTFDateTimeMCAtom (a generic
7067 													// MS style date/time format string). Just handle
7068 													// the special case where the format string
7069 													// contains only one or several possibly empty
7070 													// quoted strings. I.e. something that doesn't
7071 													// expand to any date or time at all, but to a
7072 													// fixed string. How on earth somebody manages to
7073 													// produce such things in PPT slides I have no
7074 													// idea.
7075 													if (nVal == 0)
7076 													{
7077 														sal_Unicode n;
7078 														xub_StrLen nLen;
7079 														String aStr;
7080 														bool inquote = sal_False;
7081 														for (nLen = 0, n = 0; nLen < 64; nLen++)
7082 														{
7083 															rIn >> n;
7084 
7085 															// Collect quoted characters into aStr
7086 															if ( n == '\'')
7087 																inquote = !inquote;
7088 															else if (!n)
7089 															{
7090 																// End of format string
7091 																pEntry->pString = new String( aStr );
7092 																break;
7093 															}
7094 															else if (!inquote)
7095 															{
7096 																// Non-quoted character, i.e. a real
7097 																// format specifier. We don't handle
7098 																// those. Sorry.
7099 																break;
7100 															}
7101 															else
7102 															{
7103 																aStr += n;
7104 															}
7105 														}
7106 													}
7107 													if ( pEntry->pString == NULL )
7108 													{
7109 														// Handle as previously
7110 														pEntry->pField1 = new SvxFieldItem( SvxDateField( Date(), SVXDATETYPE_FIX ), EE_FEATURE_FIELD );
7111 													}
7112 												}
7113 											}
7114 										}
7115 									}
7116 									break;
7117 
7118 									case PPT_PST_InteractiveInfo :
7119 									{
7120 										DffRecordHeader aHdInteractiveInfoAtom;
7121 										if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_InteractiveInfoAtom, aTextHd.GetRecEndFilePos(), &aHdInteractiveInfoAtom ) )
7122 										{
7123 											PptInteractiveInfoAtom aInteractiveInfoAtom;
7124 											rIn >> aInteractiveInfoAtom;
7125 											for ( SdHyperlinkEntry* pHyperlink = (SdHyperlinkEntry*)rSdrPowerPointImport.aHyperList.First();
7126 													pHyperlink; pHyperlink = (SdHyperlinkEntry*)rSdrPowerPointImport.aHyperList.Next() )
7127 											{
7128 												if ( pHyperlink->nIndex == aInteractiveInfoAtom.nExHyperlinkId )
7129 												{
7130 													aTextHd.SeekToEndOfRecord( rIn );
7131 													rIn >> aTextHd;
7132 													if ( aTextHd.nRecType != PPT_PST_TxInteractiveInfoAtom )
7133 													{
7134 														aTextHd.SeekToBegOfRecord( rIn );
7135 														continue;
7136 													}
7137 													else
7138 													{
7139 														sal_uInt32 nStartPos, nEndPos;
7140 														rIn >> nStartPos
7141 															>> nEndPos;
7142 														if ( nEndPos )
7143 														{
7144 															pEntry = new PPTFieldEntry;
7145 															pEntry->nPos = (sal_uInt16)nStartPos;
7146 															pEntry->nTextRangeEnd = (sal_uInt16)nEndPos;
7147                                                             String aTarget( pHyperlink->aTarget );
7148                                                             if ( pHyperlink->aConvSubString.Len() )
7149                                                             {
7150                                                                 aTarget.Append( (sal_Unicode)'#' );
7151                                                                 aTarget.Append( pHyperlink->aConvSubString );
7152                                                             }
7153                                                             pEntry->pField1 = new SvxFieldItem( SvxURLField( aTarget, String(), SVXURLFORMAT_REPR ), EE_FEATURE_FIELD );
7154 														}
7155 													}
7156 													break;
7157 												}
7158 											}
7159 										}
7160 									}
7161 									break;
7162 								}
7163 								aTextHd.SeekToEndOfRecord( rIn );
7164 								if ( pEntry )
7165 								{
7166 									if ( !pFieldList )
7167 										pFieldList = new List;
7168 									sal_uInt32 n;
7169 									for ( n = 0; n < pFieldList->Count(); n++ )
7170 									{	// sorting fields ( hi >> lo )
7171 										if ( ( (PPTFieldEntry*)pFieldList->GetObject( n ) )->nPos < pEntry->nPos )
7172 											break;
7173 									}
7174 									pFieldList->Insert( pEntry, (sal_uInt32)n );
7175 								}
7176 							}
7177 							if ( pFieldList )
7178 							{
7179 								PPTFieldEntry* pFE = (PPTFieldEntry*)pFieldList->First();
7180 								List& aCharPropList = aStyleTextPropReader.aCharPropList;
7181 
7182 								sal_Int32	i = nParagraphs - 1;
7183 								sal_Int32	n = aCharPropList.Count() - 1;
7184 
7185 								// at this point we just have a list of textportions(aCharPropList)
7186 								// the next while loop tries to resolve the list of fields(pFieldList)
7187 								while( pFE && ( n >= 0 ) && ( i >= 0 ) )
7188 								{
7189  									PPTCharPropSet* pSet  = (PPTCharPropSet*)aCharPropList.GetObject( n );
7190 									String aString( pSet->maString );
7191 									sal_uInt32 nCount = aString.Len();
7192 									sal_uInt32 nPos = pSet->mnOriginalTextPos + nCount;
7193 									while ( pFE && nCount-- )
7194 									{
7195 										nPos--;
7196 										while ( pFE && ( pFE->nPos > nPos ) )
7197 											pFE = (PPTFieldEntry*)pFieldList->Next();
7198 										if ( !pFE )
7199 											break;
7200 
7201 										if ( pFE->nPos == nPos )
7202 										{
7203 											if ( aString.GetChar( (sal_uInt16)nCount ) == 0x2a )
7204 											{
7205 												sal_uInt32 nBehind = aString.Len() - ( nCount + 1 );
7206 												pSet->maString = String();
7207 												if ( nBehind )
7208 												{
7209 													PPTCharPropSet* pNewCPS = new PPTCharPropSet( *pSet );
7210 													pNewCPS->maString = String( aString, (sal_uInt16)nCount + 1, (sal_uInt16)nBehind );
7211 													aCharPropList.Insert( pNewCPS, n + 1 );
7212 												}
7213 												if ( pFE->pField2 )
7214 												{
7215 													PPTCharPropSet* pNewCPS = new PPTCharPropSet( *pSet );
7216 													pNewCPS->mpFieldItem = pFE->pField2, pFE->pField2 = NULL;
7217 													aCharPropList.Insert( pNewCPS, n + 1 );
7218 
7219 													pNewCPS = new PPTCharPropSet( *pSet );
7220 													pNewCPS->maString = String( String( RTL_CONSTASCII_USTRINGPARAM( " " ) ) );
7221 													aCharPropList.Insert( pNewCPS, n + 1 );
7222 												}
7223 												if ( nCount )
7224 												{
7225 													PPTCharPropSet* pNewCPS = new PPTCharPropSet( *pSet );
7226 													pNewCPS->maString = String( aString, (sal_uInt16)0, (sal_uInt16)nCount );
7227 													aCharPropList.Insert( pNewCPS, n++ );
7228 												}
7229 												if ( pFE->pField1 )
7230                                                 {
7231 													pSet->mpFieldItem = pFE->pField1, pFE->pField1 = NULL;
7232                                                 }
7233 												else if ( pFE->pString )
7234                                                     pSet->maString = *pFE->pString;
7235 											}
7236 											else
7237 											{
7238 												if ( pFE->nTextRangeEnd ) // text range hyperlink
7239 												{
7240 													sal_uInt32 nHyperLen = pFE->nTextRangeEnd - nPos;
7241 													if ( nHyperLen )
7242 													{
7243 														PPTCharPropSet* pBefCPS = NULL;
7244 														if ( nCount )
7245 														{
7246 															pBefCPS = new PPTCharPropSet( *pSet );
7247 															pSet->maString = String( pSet->maString, (sal_uInt16)nCount, (sal_uInt16)( pSet->maString.Len() - nCount ) );
7248 														}
7249 														sal_uInt32	nIdx = n;
7250 														sal_Int32	nHyperLenLeft = nHyperLen;
7251 
7252 														while ( ( aCharPropList.Count() > nIdx ) && nHyperLenLeft )
7253 														{
7254 															// the textrange hyperlink can take more than 1 paragraph
7255 															// the solution here is to clone the hyperlink...
7256 
7257 															PPTCharPropSet* pCurrent = (PPTCharPropSet*)aCharPropList.GetObject( nIdx );
7258 															sal_Int32		nNextStringLen = pCurrent->maString.Len();
7259 
7260 															DBG_ASSERT( pFE->pField1, "missing field!" );
7261 															if (!pFE->pField1)
7262 															    break;
7263 
7264 															const SvxURLField* pField = (const SvxURLField*)pFE->pField1->GetField();
7265 
7266 															pCurrent->mbIsHyperlink=sal_True;
7267                                                             pCurrent->mnHylinkOrigColor=pCurrent->pCharSet->mnColor;
7268 															pCurrent->mbHardHylinkOrigColor= ( ( pCurrent->pCharSet->mnAttrSet >>PPT_CharAttr_FontColor ) & 1)>0;
7269 
7270 															if ( pCurrent->mpFieldItem )
7271 															{
7272 																pCurrent->SetColor( PPT_COLSCHEME_A_UND_HYPERLINK );
7273 																if ( pCurrent->mpFieldItem->GetField()->ISA( SvxURLField ) )
7274 																	break;
7275 																nHyperLenLeft--;
7276 															}
7277 															else if ( nNextStringLen )
7278 															{
7279 																if ( nNextStringLen <= nHyperLenLeft )
7280 																{
7281                                                                     pCurrent->mpFieldItem = new SvxFieldItem( SvxURLField( pField->GetURL(), pCurrent->maString, SVXURLFORMAT_REPR ), EE_FEATURE_FIELD );
7282 																	nHyperLenLeft -= nNextStringLen;
7283 
7284 																	if ( nHyperLenLeft )
7285 																	{
7286 																		// if the next portion is in a higher paragraph,
7287 																		// the textrange is to decrease (because of the LineBreak character)
7288 																		if ( aCharPropList.Count() > ( nIdx + 1 ) )
7289 																		{
7290 																			PPTCharPropSet* pNext = (PPTCharPropSet*)aCharPropList.GetObject( nIdx + 1 );
7291 																			if ( pNext->mnParagraph > pCurrent->mnParagraph )
7292 																				nHyperLenLeft--;
7293 																		}
7294 																	}
7295 																}
7296 																else
7297 																{
7298 																	PPTCharPropSet* pNewCPS = new PPTCharPropSet( *pCurrent );
7299 																	pNewCPS->maString = String( pCurrent->maString, (sal_uInt16)nHyperLenLeft, (sal_uInt16)( nNextStringLen - nHyperLenLeft ) );
7300 																	aCharPropList.Insert( pNewCPS, nIdx + 1 );
7301 																	String aRepresentation( pCurrent->maString, 0, (sal_uInt16)nHyperLenLeft );
7302                                                                     pCurrent->mpFieldItem = new SvxFieldItem( SvxURLField( pField->GetURL(), aRepresentation, SVXURLFORMAT_REPR ), EE_FEATURE_FIELD );
7303 																	nHyperLenLeft = 0;
7304 																}
7305 																pCurrent->maString = String();
7306 																pCurrent->SetColor( PPT_COLSCHEME_A_UND_HYPERLINK );
7307 															}
7308 															nIdx++;
7309 														}
7310 														delete pFE->pField1, pFE->pField1 = NULL;
7311 
7312 														if ( pBefCPS )
7313 														{
7314 															pBefCPS->maString = String( aString, (sal_uInt16)0, (sal_uInt16)nCount );
7315 															aCharPropList.Insert( pBefCPS, n++ );
7316 
7317 														}
7318 													}
7319 												}
7320 											}
7321 											break;
7322 										}
7323 									}
7324 									n--;
7325 								}
7326 								for ( void* pPtr = pFieldList->First(); pPtr; pPtr = pFieldList->Next() )
7327 									delete (PPTFieldEntry*)pPtr;
7328 								delete pFieldList;
7329 							}
7330 							mpImplTextObj->mpParagraphList = new PPTParagraphObj*[ nParagraphs ];
7331 							aStyleTextPropReader.aCharPropList.First();
7332 							sal_uInt32 nCount = 0;
7333 							for ( void* pPtr = aStyleTextPropReader.aParaPropList.First();
7334 										pPtr;
7335 										pPtr = aStyleTextPropReader.aParaPropList.Next() )
7336 							{
7337                                 PPTParagraphObj* pPara = new PPTParagraphObj( aStyleTextPropReader, *rSdrPowerPointImport.pPPTStyleSheet, nInstance, aTextRulerInterpreter );
7338 								mpImplTextObj->mpParagraphList[ nCount++ ] = pPara;
7339 
7340                                 sal_uInt32 nParaAdjust, nFlags = 0;
7341 	                            pPara->GetAttrib( PPT_ParaAttr_Adjust, nParaAdjust, GetInstance() );
7342 
7343                                 switch ( nParaAdjust )
7344                                 {
7345                                     case 0 : nFlags = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT;   break;
7346                                     case 1 : nFlags = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER; break;
7347                                     case 2 : nFlags = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT;  break;
7348                                     case 3 : nFlags = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK;  break;
7349                                 }
7350                                 mpImplTextObj->mnTextFlags |= nFlags;
7351 							}
7352 						}
7353 					}
7354 				}
7355 			}
7356 		}
7357 	}
7358 }
7359 
PPTTextObj(PPTTextObj & rTextObj)7360 PPTTextObj::PPTTextObj( PPTTextObj& rTextObj )
7361 {
7362 	mpImplTextObj = rTextObj.mpImplTextObj;
7363 	mpImplTextObj->mnRefCount++;
7364 }
7365 
~PPTTextObj()7366 PPTTextObj::~PPTTextObj()
7367 {
7368 	ImplClear();
7369 }
7370 
First()7371 PPTParagraphObj* PPTTextObj::First()
7372 {
7373 	mpImplTextObj->mnCurrentObject = 0;
7374 	if ( !mpImplTextObj->mnParagraphCount )
7375 		return NULL;
7376 	return mpImplTextObj->mpParagraphList[ 0 ];
7377 }
7378 
Next()7379 PPTParagraphObj* PPTTextObj::Next()
7380 {
7381 	sal_uInt32 i = mpImplTextObj->mnCurrentObject + 1;
7382 	if ( i >= mpImplTextObj->mnParagraphCount )
7383 		return NULL;
7384 	mpImplTextObj->mnCurrentObject++;
7385 	return mpImplTextObj->mpParagraphList[ i ];
7386 }
7387 
GetBackground() const7388 const SfxItemSet* PPTTextObj::GetBackground() const
7389 {
7390 	if ( mpImplTextObj->mrPersistEntry.pBObj )
7391 		return &mpImplTextObj->mrPersistEntry.pBObj->GetMergedItemSet();
7392 	else
7393 		return NULL;
7394 }
7395 
ImplClear()7396 void PPTTextObj::ImplClear()
7397 {
7398 	if ( ! ( --mpImplTextObj->mnRefCount ) )
7399 	{
7400 		for ( PPTParagraphObj* pPtr = First(); pPtr; pPtr = Next() )
7401 			delete pPtr;
7402 		delete[] mpImplTextObj->mpParagraphList;
7403 		delete mpImplTextObj->mpPlaceHolderAtom;
7404 		delete mpImplTextObj;
7405 	}
7406 }
7407 
operator =(PPTTextObj & rTextObj)7408 PPTTextObj& PPTTextObj::operator=( PPTTextObj& rTextObj )
7409 {
7410 	if ( this != &rTextObj )
7411 	{
7412 		ImplClear();
7413 		mpImplTextObj = rTextObj.mpImplTextObj;
7414 		mpImplTextObj->mnRefCount++;
7415 	}
7416 	return *this;
7417 }
7418 
IsLine(const SdrObject * pObj)7419 sal_Bool IsLine( const SdrObject* pObj )
7420 {
7421 	return pObj->ISA( SdrPathObj ) && ((SdrPathObj*)pObj)->IsLine() && (((SdrPathObj*)pObj)->GetPointCount() == 2 );
7422 }
7423 
GetCellPosition(const SdrObject * pObj,const std::set<sal_Int32> & rRows,const std::set<sal_Int32> & rColumns,sal_Int32 & nTableIndex,sal_Int32 & nRow,sal_Int32 & nRowCount,sal_Int32 & nColumn,sal_Int32 & nColumnCount)7424 sal_Bool GetCellPosition( const SdrObject* pObj, const std::set< sal_Int32 >& rRows, const std::set< sal_Int32 >& rColumns,
7425 							sal_Int32& nTableIndex, sal_Int32& nRow, sal_Int32& nRowCount, sal_Int32& nColumn, sal_Int32& nColumnCount )
7426 {
7427 	Rectangle aSnapRect( pObj->GetSnapRect() );
7428 	sal_Bool bCellObject = ( aSnapRect.GetWidth() > 1 ) && ( aSnapRect.GetHeight() > 1 );
7429 	if ( bCellObject )
7430 	{
7431 		std::set< sal_Int32 >::const_iterator aRowIter( rRows.find( aSnapRect.Top() ) );
7432 		std::set< sal_Int32 >::const_iterator aColumnIter( rColumns.find( aSnapRect.Left() ) );
7433 		if ( ( aRowIter == rRows.end() ) || ( aColumnIter == rColumns.end() ) )
7434 			bCellObject = sal_False;
7435 		else
7436 		{
7437 			nRowCount = 1;
7438 			nRow = std::distance( rRows.begin(), aRowIter );
7439 			while( ++aRowIter != rRows.end() )
7440 			{
7441 				if ( *aRowIter >= aSnapRect.Bottom() )
7442 					break;
7443 				nRowCount++;
7444 			}
7445 			nColumnCount = 1;
7446 			nColumn = std::distance( rColumns.begin(), aColumnIter );
7447 			while( ++aColumnIter != rColumns.end() )
7448 			{
7449 				if ( *aColumnIter >= aSnapRect.Right() )
7450 					break;
7451 				nColumnCount++;
7452 			}
7453 			nTableIndex = nRow * rColumns.size() + nColumn;
7454 		}
7455 	}
7456 	return bCellObject;
7457 }
7458 
7459 #define LinePositionLeft	0x01000000
7460 #define LinePositionTop		0x02000000
7461 #define LinePositionRight	0x04000000
7462 #define LinePositionBottom	0x08000000
7463 #define LinePositionTLBR	0x10000000
7464 #define LinePositionBLTR	0x20000000
7465 
7466 
GetRowPositions(const Rectangle & rSnapRect,const std::set<sal_Int32> & rRows,const std::set<sal_Int32> & rColumns,std::vector<sal_Int32> & rPositions,sal_Int32 nColumn,sal_Int32 nFlags)7467 void GetRowPositions( const Rectangle& rSnapRect, const std::set< sal_Int32 >& rRows,
7468 						const std::set< sal_Int32 >& rColumns, std::vector< sal_Int32 >& rPositions, sal_Int32 nColumn, sal_Int32 nFlags )
7469 {
7470 	std::set< sal_Int32 >::const_iterator aRow( rRows.find( rSnapRect.Top() ) );
7471 	if ( aRow != rRows.end() )
7472 	{
7473 		sal_Int32 nRow = std::distance( rRows.begin(), aRow );
7474 		while( ( aRow != rRows.end() ) && ((*aRow) < rSnapRect.Bottom() ) )
7475 		{
7476 			if ( nFlags & LinePositionLeft )
7477 				rPositions.push_back( ( ( nRow * rColumns.size() ) + nColumn ) | LinePositionLeft );
7478 			if ( nFlags & LinePositionRight )
7479 				rPositions.push_back( ( ( nRow * rColumns.size() ) + ( nColumn - 1 ) ) | LinePositionRight );
7480 
7481 			nRow++;
7482 			aRow++;
7483 		}
7484 	}
7485 }
7486 
7487 
GetColumnPositions(const Rectangle & rSnapRect,const std::set<sal_Int32> &,const std::set<sal_Int32> & rColumns,std::vector<sal_Int32> & rPositions,sal_Int32 nRow,sal_Int32 nFlags)7488 void GetColumnPositions( const Rectangle& rSnapRect, const std::set< sal_Int32 >& /* rRows */,
7489 						const std::set< sal_Int32 >& rColumns, std::vector< sal_Int32 >& rPositions, sal_Int32 nRow, sal_Int32 nFlags )
7490 {
7491 	std::set< sal_Int32 >::const_iterator aColumn( rColumns.find( rSnapRect.Left() ) );
7492 	if ( aColumn != rColumns.end() )
7493 	{
7494 		sal_Int32 nColumn = std::distance( rColumns.begin(), aColumn );
7495 		while( ( aColumn != rColumns.end() ) && ((*aColumn) < rSnapRect.Right() ) )
7496 		{
7497 			if ( nFlags & LinePositionTop )
7498 				rPositions.push_back( ( ( nRow * rColumns.size() ) + nColumn ) | LinePositionTop );
7499 			if ( nFlags & LinePositionBottom )
7500 				rPositions.push_back( ( ( ( nRow - 1 ) * rColumns.size() ) + nColumn ) | LinePositionBottom );
7501 
7502 			nColumn++;
7503 			aColumn++;
7504 		}
7505 	}
7506 }
7507 
GetLinePositions(const SdrObject * pObj,const std::set<sal_Int32> & rRows,const std::set<sal_Int32> & rColumns,std::vector<sal_Int32> & rPositions,const Rectangle & rGroupSnap)7508 void GetLinePositions( const SdrObject* pObj, const std::set< sal_Int32 >& rRows, const std::set< sal_Int32 >& rColumns,
7509 						std::vector< sal_Int32 >& rPositions, const Rectangle& rGroupSnap )
7510 {
7511 	Rectangle aSnapRect( pObj->GetSnapRect() );
7512 	if ( aSnapRect.Left() == aSnapRect.Right() )
7513 	{
7514 		std::set< sal_Int32 >::const_iterator aColumn( rColumns.find( aSnapRect.Left() ) );
7515 		if ( ( aColumn != rColumns.end() ) || ( aSnapRect.Left() == rGroupSnap.Right() ) )
7516 		{
7517 			sal_Int32 nColumn, nFlags;
7518 			if ( aColumn != rColumns.end() )
7519 			{
7520 				nColumn = std::distance( rColumns.begin(), aColumn );
7521 				nFlags = LinePositionLeft;
7522 				if ( aColumn != rColumns.begin() )
7523 					nFlags |= LinePositionRight;
7524 			}
7525 			else
7526 			{
7527 				nColumn = rColumns.size();
7528 				nFlags = LinePositionRight;
7529 			}
7530 			GetRowPositions( aSnapRect, rRows, rColumns, rPositions, nColumn, nFlags );
7531 		}
7532 	}
7533 	else if ( aSnapRect.Top() == aSnapRect.Bottom() )
7534 	{
7535 		std::set< sal_Int32 >::const_iterator aRow( rRows.find( aSnapRect.Top() ) );
7536 		if ( ( aRow != rRows.end() ) || ( aSnapRect.Top() == rGroupSnap.Bottom() ) )
7537 		{
7538 			sal_Int32 nRow, nFlags;
7539 			if ( aRow != rRows.end() )
7540 			{
7541 				nRow = std::distance( rRows.begin(), aRow );
7542 				nFlags = LinePositionTop;
7543 				if ( aRow != rRows.begin() )
7544 					nFlags |= LinePositionBottom;
7545 			}
7546 			else
7547 			{
7548 				nRow = rRows.size();
7549 				nFlags = LinePositionBottom;
7550 			}
7551 			GetColumnPositions( aSnapRect, rRows, rColumns, rPositions, nRow, nFlags );
7552 		}
7553 	}
7554 	else
7555 	{
7556 		sal_uInt32 nPosition = 0;
7557 		Point aPt1( ((SdrPathObj*)pObj)->GetPoint( 0 ) );
7558 		Point aPt2( ((SdrPathObj*)pObj)->GetPoint( 1 ) );
7559 		if ( aPt1.X() < aPt2.X() )
7560 			nPosition |= aPt1.Y() < aPt2.Y() ? LinePositionTLBR : LinePositionBLTR;
7561 		else
7562 			nPosition |= aPt1.Y() < aPt2.Y() ? LinePositionBLTR : LinePositionTLBR;
7563 
7564 		std::set< sal_Int32 >::const_iterator aRow( rRows.find( aPt1.Y() < aPt2.Y() ? aPt1.Y() : aPt2.Y() ) );
7565 		std::set< sal_Int32 >::const_iterator aColumn( rColumns.find( aPt1.X() < aPt2.X() ? aPt1.X() : aPt2.X() ) );
7566 		if ( ( aRow != rRows.end() ) && ( aColumn != rColumns.end() ) )
7567 		{
7568 			nPosition |= ( std::distance( rRows.begin(), aRow ) * rColumns.size() ) + std::distance( rColumns.begin(), aColumn );
7569 			rPositions.push_back( nPosition );
7570 		}
7571 	}
7572 }
7573 
CreateTableRows(Reference<XTableRows> xTableRows,const std::set<sal_Int32> & rRows,sal_Int32 nTableBottom)7574 void CreateTableRows( Reference< XTableRows > xTableRows, const std::set< sal_Int32 >& rRows, sal_Int32 nTableBottom )
7575 {
7576 	if ( rRows.size() > 1 )
7577 		xTableRows->insertByIndex( 0, rRows.size() - 1 );
7578 
7579 	std::set< sal_Int32 >::const_iterator aIter( rRows.begin() );
7580 	sal_Int32 nLastPosition( *aIter );
7581 	Reference< XIndexAccess > xIndexAccess( xTableRows, UNO_QUERY_THROW );
7582 	for ( sal_Int32 n = 0; n < xIndexAccess->getCount(); n++ )
7583 	{
7584 		sal_Int32 nHeight;
7585 		if ( ++aIter != rRows.end() )
7586 		{
7587 			nHeight = *aIter - nLastPosition;
7588 			nLastPosition = *aIter;
7589 		}
7590 		else
7591 			nHeight = nTableBottom - nLastPosition;
7592 
7593 		static const rtl::OUString	sWidth( RTL_CONSTASCII_USTRINGPARAM ( "Height" ) );
7594 		Reference< XPropertySet > xPropSet( xIndexAccess->getByIndex( n ), UNO_QUERY_THROW );
7595 		xPropSet->setPropertyValue( sWidth, Any( nHeight ) );
7596 	}
7597 }
7598 
CreateTableColumns(Reference<XTableColumns> xTableColumns,const std::set<sal_Int32> & rColumns,sal_Int32 nTableRight)7599 void CreateTableColumns( Reference< XTableColumns > xTableColumns, const std::set< sal_Int32 >& rColumns, sal_Int32 nTableRight )
7600 {
7601 	if ( rColumns.size() > 1 )
7602 		xTableColumns->insertByIndex( 0, rColumns.size() - 1 );
7603 
7604 	std::set< sal_Int32 >::const_iterator aIter( rColumns.begin() );
7605 	sal_Int32 nLastPosition( *aIter );
7606 	Reference< XIndexAccess > xIndexAccess( xTableColumns, UNO_QUERY_THROW );
7607 	for ( sal_Int32 n = 0; n < xIndexAccess->getCount(); n++ )
7608 	{
7609 		sal_Int32 nWidth;
7610 		if ( ++aIter != rColumns.end() )
7611 		{
7612 			nWidth = *aIter - nLastPosition;
7613 			nLastPosition = *aIter;
7614 		}
7615 		else
7616 			nWidth = nTableRight - nLastPosition;
7617 
7618 		static const rtl::OUString	sWidth( RTL_CONSTASCII_USTRINGPARAM ( "Width" ) );
7619 		Reference< XPropertySet > xPropSet( xIndexAccess->getByIndex( n ), UNO_QUERY_THROW );
7620 		xPropSet->setPropertyValue( sWidth, Any( nWidth ) );
7621 	}
7622 }
7623 
MergeCells(const Reference<XTable> & xTable,sal_Int32 nCol,sal_Int32 nRow,sal_Int32 nColSpan,sal_Int32 nRowSpan)7624 void MergeCells( const Reference< XTable >& xTable, sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan )
7625 {
7626 	DBG_ASSERT( (nColSpan > 1) || (nRowSpan > 1), "nonsense parameter!!" );
7627 	DBG_ASSERT( (nCol >= 0) && (nCol < xTable->getColumnCount()) && (nRow >= 0) && (nRow < xTable->getRowCount()), "die zelle gibt es nicht!!" );
7628 	DBG_ASSERT( (nColSpan >= 1) && ((nCol  + nColSpan - 1) < xTable->getColumnCount()), "nColSpan murks!" );
7629 	DBG_ASSERT(  (nRowSpan >= 1) && ((nRow  + nRowSpan - 1) < xTable->getRowCount()), "nRowSpan murks!" );
7630 
7631 	if( xTable.is() ) try
7632 	{
7633 		Reference< XMergeableCellRange > xRange( xTable->createCursorByRange( xTable->getCellRangeByPosition( nCol, nRow,nCol + nColSpan - 1, nRow + nRowSpan - 1 ) ), UNO_QUERY_THROW );
7634 		if( xRange->isMergeable() )
7635 			xRange->merge();
7636 	}
7637 	catch( Exception& )
7638 	{
7639 		DBG_ASSERT( false, "exception caught!" );
7640 	}
7641 }
7642 
ApplyCellAttributes(const SdrObject * pObj,Reference<XCell> & xCell)7643 void ApplyCellAttributes( const SdrObject* pObj, Reference< XCell >& xCell )
7644 {
7645 	try
7646 	{
7647 		Reference< XPropertySet > xPropSet( xCell, UNO_QUERY_THROW );
7648 
7649 		const sal_Int32 nLeftDist(((const SdrTextLeftDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_LEFTDIST)).GetValue());
7650 		const sal_Int32 nRightDist(((const SdrTextRightDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_RIGHTDIST)).GetValue());
7651 		const sal_Int32 nUpperDist(((const SdrTextUpperDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_UPPERDIST)).GetValue());
7652 		const sal_Int32 nLowerDist(((const SdrTextLowerDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_LOWERDIST)).GetValue());
7653 		static const rtl::OUString	sTopBorder( RTL_CONSTASCII_USTRINGPARAM( "TextUpperDistance" ) );
7654 		static const rtl::OUString	sBottomBorder( RTL_CONSTASCII_USTRINGPARAM( "TextLowerDistance" ) );
7655 		static const rtl::OUString	sLeftBorder( RTL_CONSTASCII_USTRINGPARAM( "TextLeftDistance" ) );
7656 		static const rtl::OUString	sRightBorder( RTL_CONSTASCII_USTRINGPARAM( "TextRightDistance" ) );
7657 		xPropSet->setPropertyValue( sTopBorder, Any( nUpperDist ) );
7658 		xPropSet->setPropertyValue( sRightBorder, Any( nRightDist ) );
7659 		xPropSet->setPropertyValue( sLeftBorder, Any( nLeftDist ) );
7660 		xPropSet->setPropertyValue( sBottomBorder, Any( nLowerDist ) );
7661 
7662 		static const rtl::OUString	sTextVerticalAdjust( RTL_CONSTASCII_USTRINGPARAM( "TextVerticalAdjust" ) );
7663 		const SdrTextVertAdjust eTextVertAdjust(((const SdrTextVertAdjustItem&)pObj->GetMergedItem(SDRATTR_TEXT_VERTADJUST)).GetValue());
7664 		drawing::TextVerticalAdjust eVA( drawing::TextVerticalAdjust_TOP );
7665 		if ( eTextVertAdjust == SDRTEXTVERTADJUST_CENTER )
7666 			eVA = drawing::TextVerticalAdjust_CENTER;
7667 		else if ( eTextVertAdjust == SDRTEXTVERTADJUST_BOTTOM )
7668 			eVA = drawing::TextVerticalAdjust_BOTTOM;
7669 		xPropSet->setPropertyValue( sTextVerticalAdjust, Any( eVA ) );
7670 
7671 		//set textHorizontalAdjust and TextWritingMode attr
7672 		const sal_Int32 eHA(((const SdrTextLeftDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_HORZADJUST)).GetValue());
7673 		const SvxFrameDirection eDirection = (const SvxFrameDirection)((( const SvxFrameDirectionItem&)pObj->GetMergedItem(EE_PARA_WRITINGDIR)).GetValue());
7674 		static const rtl::OUString	sHorizontalAdjust( RTL_CONSTASCII_USTRINGPARAM( "TextHorizontalAdjust" ) );
7675 		static const rtl::OUString	sWritingMode( RTL_CONSTASCII_USTRINGPARAM("TextWritingMode") );
7676 		xPropSet->setPropertyValue(  sHorizontalAdjust , Any( eHA ) );
7677 		if ( eDirection == FRMDIR_VERT_TOP_RIGHT )
7678 		{//vertical writing
7679 			xPropSet->setPropertyValue(  sWritingMode , Any( ::com::sun::star::text::WritingMode_TB_RL ) );
7680 		}
7681 		SfxItemSet aSet( pObj->GetMergedItemSet() );
7682 		XFillStyle eFillStyle(((XFillStyleItem&)pObj->GetMergedItem( XATTR_FILLSTYLE )).GetValue());
7683 		::com::sun::star::drawing::FillStyle eFS( com::sun::star::drawing::FillStyle_NONE );
7684 		switch( eFillStyle )
7685 		{
7686 			case XFILL_SOLID :
7687 				{
7688 					static const rtl::OUString sFillColor( String( RTL_CONSTASCII_USTRINGPARAM( "FillColor" ) ) );
7689 					eFS = com::sun::star::drawing::FillStyle_SOLID;
7690 					Color aFillColor( ((XFillColorItem&)pObj->GetMergedItem( XATTR_FILLCOLOR )).GetColorValue() );
7691 					sal_Int32 nFillColor( aFillColor.GetColor() );
7692 					xPropSet->setPropertyValue( sFillColor, Any( nFillColor ) );
7693 				}
7694 				break;
7695 			case XFILL_GRADIENT :
7696 				{
7697 					eFS = com::sun::star::drawing::FillStyle_GRADIENT;
7698 					XGradient aXGradient(((const XFillGradientItem&)pObj->GetMergedItem(XATTR_FILLGRADIENT)).GetGradientValue());
7699 
7700 					com::sun::star::awt::Gradient aGradient;
7701 					aGradient.Style = (awt::GradientStyle) aXGradient.GetGradientStyle();
7702 					aGradient.StartColor = (sal_Int32)aXGradient.GetStartColor().GetColor();
7703 					aGradient.EndColor = (sal_Int32)aXGradient.GetEndColor().GetColor();
7704 					aGradient.Angle = (short)aXGradient.GetAngle();
7705 					aGradient.Border = aXGradient.GetBorder();
7706 					aGradient.XOffset = aXGradient.GetXOffset();
7707 					aGradient.YOffset = aXGradient.GetYOffset();
7708 					aGradient.StartIntensity = aXGradient.GetStartIntens();
7709 					aGradient.EndIntensity = aXGradient.GetEndIntens();
7710 					aGradient.StepCount = aXGradient.GetSteps();
7711 
7712 					static const rtl::OUString sFillGradient( String( RTL_CONSTASCII_USTRINGPARAM( "FillGradient" ) ) );
7713 					xPropSet->setPropertyValue( sFillGradient, Any( aGradient ) );
7714 				}
7715 				break;
7716 			case XFILL_HATCH :
7717 				eFS = com::sun::star::drawing::FillStyle_HATCH;
7718 			break;
7719 			case XFILL_BITMAP :
7720 				{
7721 					eFS = com::sun::star::drawing::FillStyle_BITMAP;
7722 
7723 					const XFillBitmapItem aXFillBitmapItem((const XFillBitmapItem&)pObj->GetMergedItem( XATTR_FILLBITMAP ));
7724 					rtl::OUString aURL( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
7725 					aURL += rtl::OUString::createFromAscii(aXFillBitmapItem.GetGraphicObject().GetUniqueID().GetBuffer());
7726 
7727 					static const rtl::OUString sFillBitmapURL( String( RTL_CONSTASCII_USTRINGPARAM( "FillBitmapURL" ) ) );
7728 					xPropSet->setPropertyValue( sFillBitmapURL, Any( aURL ) );
7729 
7730 					static const rtl::OUString sFillBitmapMode( String( RTL_CONSTASCII_USTRINGPARAM( "FillBitmapMode" ) ) );
7731 					const XFillBmpStretchItem aStretchItem(( const XFillBmpStretchItem&)pObj->GetMergedItem( XATTR_FILLBMP_STRETCH ));
7732 					const XFillBmpTileItem aTileItem(( const XFillBmpTileItem&)pObj->GetMergedItem( XATTR_FILLBMP_TILE ));
7733 					if( aTileItem.GetValue() )
7734 						xPropSet->setPropertyValue( sFillBitmapMode, Any( com::sun::star::drawing::BitmapMode_REPEAT ) );
7735 					else if( aStretchItem.GetValue() )
7736 						xPropSet->setPropertyValue( sFillBitmapMode, Any( com::sun::star::drawing::BitmapMode_STRETCH ) );
7737 					else
7738 						xPropSet->setPropertyValue( sFillBitmapMode, Any( com::sun::star::drawing::BitmapMode_NO_REPEAT ) );
7739 				}
7740 			break;
7741 			case XFILL_NONE :
7742 				eFS = com::sun::star::drawing::FillStyle_NONE;
7743 			break;
7744 
7745 		}
7746 		static const rtl::OUString sFillStyle( String( RTL_CONSTASCII_USTRINGPARAM( "FillStyle" ) ) );
7747 		xPropSet->setPropertyValue( sFillStyle, Any( eFS ) );
7748 		if ( eFillStyle != XFILL_NONE )
7749 		{
7750 			sal_Int16 nFillTransparence( ( (const XFillTransparenceItem&)pObj->GetMergedItem( XATTR_FILLTRANSPARENCE ) ).GetValue() );
7751 			static const rtl::OUString sFillTransparence( String( RTL_CONSTASCII_USTRINGPARAM( "FillTransparence" ) ) );
7752 			xPropSet->setPropertyValue( sFillTransparence, Any( nFillTransparence ) );
7753 		}
7754 	}
7755 	catch( Exception& )
7756 	{
7757 	}
7758 }
7759 
ApplyCellLineAttributes(const SdrObject * pLine,Reference<XTable> & xTable,const std::vector<sal_Int32> vPositions,sal_Int32 nColumns)7760 void ApplyCellLineAttributes( const SdrObject* pLine, Reference< XTable >& xTable, const std::vector< sal_Int32 > vPositions, sal_Int32 nColumns )
7761 {
7762 	try
7763 	{
7764 		SfxItemSet aSet( pLine->GetMergedItemSet() );
7765 		XLineStyle eLineStyle(((XLineStyleItem&)pLine->GetMergedItem( XATTR_LINESTYLE )).GetValue());
7766 		com::sun::star::table::BorderLine aBorderLine;
7767 		switch( eLineStyle )
7768 		{
7769 			case XLINE_DASH :
7770 			case XLINE_SOLID :
7771 				{
7772 					Color aLineColor( ((XLineColorItem&)pLine->GetMergedItem( XATTR_LINECOLOR )).GetColorValue() );
7773 					aBorderLine.Color = aLineColor.GetColor();
7774 					// Avoid width = 0, the min value should be 1.
7775 					aBorderLine.OuterLineWidth = std::max( static_cast< sal_Int16 >( 1 ), static_cast< sal_Int16 >( ((const XLineWidthItem&)(pLine->GetMergedItem(XATTR_LINEWIDTH))).GetValue() / 4) );
7776 					aBorderLine.InnerLineWidth = std::max( static_cast< sal_Int16 >( 1 ), static_cast< sal_Int16 >( ((const XLineWidthItem&)(pLine->GetMergedItem(XATTR_LINEWIDTH))).GetValue() / 4) );
7777 					aBorderLine.LineDistance = 0;
7778 				}
7779 				break;
7780 			case XLINE_NONE :
7781 				{
7782 					aBorderLine.OuterLineWidth = 0;
7783 					aBorderLine.InnerLineWidth = 0;
7784 					aBorderLine.LineDistance = 0;
7785 				}
7786 			break;
7787 		}
7788 		Reference< XCellRange > xCellRange( xTable, UNO_QUERY_THROW );
7789 		std::vector< sal_Int32 >::const_iterator aIter( vPositions.begin() );
7790 		while( aIter != vPositions.end() )
7791 		{
7792 			static const rtl::OUString sTopBorder( String( RTL_CONSTASCII_USTRINGPARAM( "TopBorder" ) ) );
7793 			static const rtl::OUString sBottomBorder( String( RTL_CONSTASCII_USTRINGPARAM( "BottomBorder" ) ) );
7794 			static const rtl::OUString sLeftBorder( String( RTL_CONSTASCII_USTRINGPARAM( "LeftBorder" ) ) );
7795 			static const rtl::OUString sRightBorder( String( RTL_CONSTASCII_USTRINGPARAM( "RightBorder" ) ) );
7796 			static const rtl::OUString	sDiagonalTLBR( RTL_CONSTASCII_USTRINGPARAM ( "DiagonalTLBR" ) );
7797 			static const rtl::OUString	sDiagonalBLTR( RTL_CONSTASCII_USTRINGPARAM ( "DiagonalBLTR" ) );
7798 
7799 			sal_Int32 nPosition = *aIter & 0xffffff;
7800 			sal_Int32 nFlags = *aIter &~0xffffff;
7801 			sal_Int32 nRow = nPosition / nColumns;
7802 			sal_Int32 nColumn = nPosition - ( nRow * nColumns );
7803 			Reference< XCell > xCell( xCellRange->getCellByPosition( nColumn, nRow ) );
7804 			Reference< XPropertySet > xPropSet( xCell, UNO_QUERY_THROW );
7805 
7806 			if ( nFlags & LinePositionLeft )
7807 				xPropSet->setPropertyValue( sLeftBorder, Any( aBorderLine ) );
7808 			if ( nFlags & LinePositionTop )
7809 				xPropSet->setPropertyValue( sTopBorder, Any( aBorderLine ) );
7810 			if ( nFlags & LinePositionRight )
7811 				xPropSet->setPropertyValue( sRightBorder, Any( aBorderLine ) );
7812 			if ( nFlags & LinePositionBottom )
7813 				xPropSet->setPropertyValue( sBottomBorder, Any( aBorderLine ) );
7814 			if ( nFlags & LinePositionTLBR )
7815 				xPropSet->setPropertyValue( sDiagonalTLBR, Any( sal_True ) );
7816 			if ( nFlags & LinePositionBLTR )
7817 				xPropSet->setPropertyValue( sDiagonalBLTR, Any( sal_True ) );
7818 			aIter++;
7819 		}
7820 	}
7821 	catch( Exception& )
7822 	{
7823 	}
7824 }
7825 
CreateTable(SdrObject * pGroup,sal_uInt32 * pTableArry,SvxMSDffSolverContainer * pSolverContainer)7826 SdrObject* SdrPowerPointImport::CreateTable( SdrObject* pGroup, sal_uInt32* pTableArry, SvxMSDffSolverContainer* pSolverContainer )
7827 {
7828 	SdrObject* pRet = pGroup;
7829 	sal_uInt32 nRows = pTableArry[ 1 ];
7830 	if ( nRows && pGroup->ISA( SdrObjGroup ) )
7831 	{
7832 		SdrObjList* pSubList(((SdrObjGroup*)pGroup)->GetSubList());
7833 		if ( pSubList )
7834 		{
7835 			std::set< sal_Int32 > aRows;
7836 			std::set< sal_Int32 > aColumns;
7837 
7838 			SdrObjListIter aGroupIter( *pSubList, IM_DEEPNOGROUPS, sal_False );
7839 			while( aGroupIter.IsMore() )
7840 			{
7841 				const SdrObject* pObj( aGroupIter.Next() );
7842 				if ( !IsLine( pObj ) )
7843 				{
7844 					Rectangle aSnapRect( pObj->GetSnapRect() );
7845 					aRows.insert( aSnapRect.Top() );
7846 					aColumns.insert( aSnapRect.Left() );
7847 				}
7848 			}
7849 			::sdr::table::SdrTableObj* pTable = new ::sdr::table::SdrTableObj( pSdrModel );
7850 			pTable->uno_lock();
7851 			Reference< XTable > xTable( pTable->getTable() );
7852 			try
7853 			{
7854 				Reference< XColumnRowRange > xColumnRowRange( xTable, UNO_QUERY_THROW );
7855 
7856 				CreateTableRows( xColumnRowRange->getRows(), aRows, pGroup->GetSnapRect().Bottom() );
7857 				CreateTableColumns( xColumnRowRange->getColumns(), aColumns, pGroup->GetSnapRect().Right() );
7858 
7859 				sal_Int32 nCellCount = aRows.size() * aColumns.size();
7860 				sal_Int32 *pMergedCellIndexTable = new sal_Int32[ nCellCount ];
7861 				for ( sal_Int32 i = 0; i < nCellCount; i++ )
7862 					pMergedCellIndexTable[ i ] = i;
7863 
7864 				aGroupIter.Reset();
7865 				while( aGroupIter.IsMore() )
7866 				{
7867 					SdrObject* pObj( aGroupIter.Next() );
7868 					if ( !IsLine( pObj ) )
7869 					{
7870 						Rectangle aSnapRect( pObj->GetSnapRect() );
7871 						sal_Int32 nTableIndex = 0;
7872 						sal_Int32 nRow = 0;
7873 						sal_Int32 nRowCount = 0;
7874 						sal_Int32 nColumn = 0;
7875 						sal_Int32 nColumnCount = 0;
7876 						if ( GetCellPosition( pObj, aRows, aColumns, nTableIndex, nRow, nRowCount, nColumn, nColumnCount ) )
7877 						{
7878 							Reference< XCellRange > xCellRange( xTable, UNO_QUERY_THROW );
7879 							Reference< XCell > xCell( xCellRange->getCellByPosition( nColumn, nRow ) );
7880 
7881 							ApplyCellAttributes( pObj, xCell );
7882 
7883 							if ( ( nRowCount > 1 ) || ( nColumnCount > 1 ) )	// cell merging
7884 							{
7885 								MergeCells( xTable, nColumn, nRow, nColumnCount, nRowCount );
7886 								for ( sal_Int32 nRowIter = 0; nRowIter < nRowCount; nRowIter++ )
7887 								{
7888 									for ( sal_Int32 nColumnIter = 0; nColumnIter < nColumnCount; nColumnIter++ )
7889 									{	// now set the correct index for the merged cell
7890 										pMergedCellIndexTable[ ( ( nRow + nRowIter ) * aColumns.size() ) + nColumn + nColumnIter ] = nTableIndex;
7891 									}
7892 								}
7893 							}
7894 
7895 							// applying text
7896 							OutlinerParaObject* pParaObject = pObj->GetOutlinerParaObject();
7897 							if ( pParaObject )
7898 							{
7899 								SdrText* pSdrText = pTable->getText( nTableIndex );
7900 								if ( pSdrText )
7901 									pSdrText->SetOutlinerParaObject(new OutlinerParaObject(*pParaObject) );
7902 							}
7903 						}
7904 					}
7905 				}
7906 				aGroupIter.Reset();
7907 				while( aGroupIter.IsMore() )
7908 				{
7909 					SdrObject* pObj( aGroupIter.Next() );
7910 					if ( IsLine( pObj ) )
7911 					{
7912 						std::vector< sal_Int32 > vPositions;	// containing cell indexes + cell position
7913 						GetLinePositions( pObj, aRows, aColumns, vPositions, pGroup->GetSnapRect() );
7914 
7915 						// correcting merged cell position
7916 						std::vector< sal_Int32 >::iterator aIter( vPositions.begin() );
7917 						while( aIter != vPositions.end() )
7918 						{
7919 							sal_Int32 nOldPosition = *aIter & 0xffff;
7920 							sal_Int32 nOldFlags = *aIter & 0xffff0000;
7921 							sal_Int32 nNewPosition = pMergedCellIndexTable[ nOldPosition ] | nOldFlags;
7922 							*aIter++ = nNewPosition;
7923 						}
7924 						ApplyCellLineAttributes( pObj, xTable, vPositions, aColumns.size() );
7925 					}
7926 				}
7927 				delete[] pMergedCellIndexTable;
7928 
7929 				// we are replacing the whole group object by a single table object, so
7930 				// possibly connections to the group object have to be removed.
7931 				if ( pSolverContainer )
7932 				{
7933 					for ( SvxMSDffConnectorRule* pPtr = (SvxMSDffConnectorRule*)pSolverContainer->aCList.First();
7934 						pPtr; pPtr = (SvxMSDffConnectorRule*)pSolverContainer->aCList.Next() )
7935 					{
7936 						SdrObjListIter aIter( *pGroup, IM_DEEPWITHGROUPS );
7937 						while( aIter.IsMore() )
7938 						{
7939 							SdrObject* pPartObj = aIter.Next();
7940 							if ( pPtr->pAObj == pPartObj )
7941 								pPtr->pAObj = NULL;
7942 							if ( pPtr->pBObj == pPartObj )
7943 								pPtr->pBObj = NULL;
7944 						}
7945 						//I n MS, the one_row_one_col table is made up of five shape,the connector is connected to some part of a table.
7946 						// but in AOO, the connector is connected to the whole group table,so the connector obj is a group table when export by AOO.
7947 						// should process this situation when import.
7948 						if ( pPtr->pAObj == pGroup )
7949 							pPtr->pAObj = pTable;
7950 						if ( pPtr->pBObj == pGroup )
7951 							pPtr->pBObj = pTable;
7952 					}
7953 				}
7954 				pTable->uno_unlock();
7955 				pTable->SetSnapRect( pGroup->GetSnapRect() );
7956 				pRet = pTable;
7957 
7958 				// Remove Objects from shape map
7959 				SdrObjListIter aIter( *pGroup, IM_DEEPWITHGROUPS );
7960 				while( aIter.IsMore() )
7961 				{
7962 					SdrObject* pPartObj = aIter.Next();
7963 					removeShapeId( pPartObj );
7964 				}
7965 
7966 				SdrObject::Free( pGroup );
7967 			}
7968 			catch( Exception& )
7969 			{
7970 				pTable->uno_unlock();
7971 				SdrObject* pObj = pTable;
7972 				SdrObject::Free( pObj );
7973 			}
7974 		}
7975 	}
7976 	return pRet;
7977 }
7978 
7979 
7980 ////////////////////////////////////////////////////////////////////////////////////////////////////
IsVerticalText() const7981 sal_Bool SdrPowerPointImport::IsVerticalText() const
7982 {
7983 	sal_Bool bVerticalText = sal_False;
7984 	if ( IsProperty( DFF_Prop_txflTextFlow ) )
7985 	{
7986 		MSO_TextFlow eTextFlow = (MSO_TextFlow)( GetPropertyValue( DFF_Prop_txflTextFlow ) & 0xFFFF );
7987 		switch( eTextFlow )
7988 		{
7989 		case mso_txflTtoBA :					// Top to Bottom @-font, above -> below
7990 		case mso_txflTtoBN :					// Top to Bottom non-@, above -> below
7991 		case mso_txflVertN :					// Vertical, non-@, above -> below
7992 			bVerticalText = !bVerticalText;
7993 			break;
7994 		default: break;
7995 		}
7996 	}
7997 
7998 	return bVerticalText;
7999 }
8000 
ApplyTextAnchorAttributes(PPTTextObj & rTextObj,SfxItemSet & rSet) const8001 void	SdrPowerPointImport::ApplyTextAnchorAttributes( PPTTextObj& rTextObj, SfxItemSet& rSet ) const
8002 {
8003 	SdrTextVertAdjust eTVA;
8004 	SdrTextHorzAdjust eTHA;
8005 
8006 	sal_uInt32 nTextFlags = rTextObj.GetTextFlags();
8007 
8008 	nTextFlags &= PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT   | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT
8009 		| PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK;
8010 
8011 	if ( IsVerticalText() )
8012 	{
8013 		eTVA = SDRTEXTVERTADJUST_BLOCK;
8014 		eTHA = SDRTEXTHORZADJUST_CENTER;
8015 
8016 		// Textverankerung lesen
8017 		MSO_Anchor eTextAnchor = (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop );
8018 
8019 		switch( eTextAnchor )
8020 		{
8021 		case mso_anchorTop:
8022 		case mso_anchorTopCentered:
8023 			eTHA = SDRTEXTHORZADJUST_RIGHT;
8024 			break;
8025 
8026 		case mso_anchorMiddle :
8027 		case mso_anchorMiddleCentered:
8028 			eTHA = SDRTEXTHORZADJUST_CENTER;
8029 			break;
8030 
8031 		case mso_anchorBottom:
8032 		case mso_anchorBottomCentered:
8033 			eTHA = SDRTEXTHORZADJUST_LEFT;
8034 			break;
8035 
8036 		default:
8037 			break;
8038 		}
8039 		// if there is a 100% use of following attributes, the textbox can been aligned also in vertical direction
8040 		switch ( eTextAnchor )
8041 		{
8042 		case mso_anchorTopCentered :
8043 		case mso_anchorMiddleCentered :
8044 		case mso_anchorBottomCentered :
8045 			{
8046 				// check if it is sensible to use the centered alignment
8047 				sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT;
8048 				if ( ( nTextFlags & nMask ) != nMask )  // if the textobject has left or also right aligned paragraphs
8049 					eTVA = SDRTEXTVERTADJUST_CENTER;    // the text has to be displayed using the full width;
8050 			}
8051 			break;
8052 
8053 		default :
8054 			{
8055 				if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT )
8056 					eTVA = SDRTEXTVERTADJUST_TOP;
8057 				else if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT )
8058 					eTVA = SDRTEXTVERTADJUST_BOTTOM;
8059 			}
8060 			break;
8061 		}
8062 	}
8063 	else
8064 	{
8065 		eTVA = SDRTEXTVERTADJUST_CENTER;
8066 		eTHA = SDRTEXTHORZADJUST_BLOCK;
8067 
8068 		// Textverankerung lesen
8069 		MSO_Anchor eTextAnchor = (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop );
8070 
8071 		switch( eTextAnchor )
8072 		{
8073 		case mso_anchorTop:
8074 		case mso_anchorTopCentered:
8075 			eTVA = SDRTEXTVERTADJUST_TOP;
8076 			break;
8077 
8078 		case mso_anchorMiddle :
8079 		case mso_anchorMiddleCentered:
8080 			eTVA = SDRTEXTVERTADJUST_CENTER;
8081 			break;
8082 
8083 		case mso_anchorBottom:
8084 		case mso_anchorBottomCentered:
8085 			eTVA = SDRTEXTVERTADJUST_BOTTOM;
8086 			break;
8087 
8088 		default:
8089 			break;
8090 		}
8091 		// if there is a 100% usage of following attributes, the textbox can be aligned also in horizontal direction
8092 		switch ( eTextAnchor )
8093 		{
8094 		case mso_anchorTopCentered :
8095 		case mso_anchorMiddleCentered :
8096 		case mso_anchorBottomCentered :
8097 			{
8098 				// check if it is sensible to use the centered alignment
8099 				sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT;
8100 				if ( ( nTextFlags & nMask ) != nMask )  // if the textobject has left or also right aligned paragraphs
8101 					eTHA = SDRTEXTHORZADJUST_CENTER;    // the text has to be displayed using the full width;
8102 			}
8103 			break;
8104 
8105 		default :
8106 			{
8107 				if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT )
8108 					eTHA = SDRTEXTHORZADJUST_LEFT;
8109 				else if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT )
8110 					eTHA = SDRTEXTHORZADJUST_RIGHT;
8111 			}
8112 			break;
8113 		}
8114 	}
8115 	rSet.Put( SdrTextVertAdjustItem( eTVA ) );
8116 	rSet.Put( SdrTextHorzAdjustItem( eTHA ) );
8117 }
8118 
8119 /* vim: set noet sw=4 ts=4: */
8120