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/unohlp.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 hanlde 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 pararagraphs
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 pararagraphs
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 commeht 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_uInt16	nParaIndex = (sal_uInt16)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
2935 // be sure not to import masterpages with this method
ImportPage(SdrPage * pRet,const PptSlidePersistEntry * pMasterPersist)2936 void SdrPowerPointImport::ImportPage( SdrPage* pRet, const PptSlidePersistEntry* pMasterPersist )
2937 {
2938 	sal_uInt32 nMerk = rStCtrl.Tell();
2939     PptSlidePersistList* pList = GetPageList( eAktPageKind );
2940 	if ( ( !pList ) || ( pList->Count() <= nAktPageNum ) )
2941 		return;
2942 	PptSlidePersistEntry& rSlidePersist = *(*pList)[ nAktPageNum ];
2943     if ( rSlidePersist.bStarDrawFiller )
2944 		return;
2945 
2946 	DffRecordHeader aPageHd;
2947     if ( SeekToAktPage( &aPageHd ) )
2948 	{
2949 		if ( mbTracing )
2950 			mpTracer->AddAttribute( eAktPageKind == PPT_SLIDEPAGE
2951 									? rtl::OUString::createFromAscii( "Page" )
2952 									: rtl::OUString::createFromAscii( "NotesPage" ),
2953 									rtl::OUString::valueOf( (sal_Int32)nAktPageNum + 1 ) );
2954 
2955 		rSlidePersist.pHeaderFooterEntry = new HeaderFooterEntry( pMasterPersist );
2956 		ProcessData aProcessData( rSlidePersist, (SdPage*)pRet );
2957 		while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < aPageHd.GetRecEndFilePos() ) )
2958 		{
2959 			DffRecordHeader aHd;
2960 			rStCtrl >> aHd;
2961 			switch ( aHd.nRecType )
2962 			{
2963 				case PPT_PST_HeadersFooters :
2964 				{
2965 					ImportHeaderFooterContainer( aHd, *rSlidePersist.pHeaderFooterEntry );
2966 				}
2967 				break;
2968 
2969 				case PPT_PST_ProgTags :
2970 				{
2971 					DffRecordHeader aContentDataHd;
2972 			        if ( SeekToContentOfProgTag( 10, rStCtrl, aHd, aContentDataHd ) )
2973 					{
2974 						DffRecordHeader aComment10Hd;
2975 						while( ( rStCtrl.GetError() == 0 ) && SeekToRec( rStCtrl, PPT_PST_Comment10, aContentDataHd.GetRecEndFilePos(), &aComment10Hd ) )
2976 						{
2977 							ImportComment10( *this, rStCtrl, pRet, aComment10Hd );
2978 							aComment10Hd.SeekToEndOfRecord( rStCtrl );
2979 						}
2980 					}
2981 				}
2982 				break;
2983 
2984 				case PPT_PST_PPDrawing :
2985 				{
2986 					DffRecordHeader aPPDrawHd;
2987 					if ( SeekToRec( rStCtrl, DFF_msofbtDgContainer, aHd.GetRecEndFilePos(), &aPPDrawHd ) )
2988 					{
2989 						sal_uInt32 nPPDrawOfs = rStCtrl.Tell();
2990 
2991 						// importing the background object before importing the page
2992 						while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < aPPDrawHd.GetRecEndFilePos() ) )
2993 						{
2994 							DffRecordHeader aEscherObjListHd;
2995 							rStCtrl >> aEscherObjListHd;
2996 							switch ( aEscherObjListHd.nRecType )
2997 							{
2998 								case DFF_msofbtSpContainer :
2999 								{
3000 									Rectangle aPageSize( Point(), pRet->GetSize() );
3001 									if ( rSlidePersist.aSlideAtom.nFlags & 4 )			// follow master background ?
3002 									{
3003                                         if ( HasMasterPage( nAktPageNum, eAktPageKind ) )
3004                                         {
3005                                             sal_uInt16 nMasterNum = GetMasterPageIndex( nAktPageNum, eAktPageKind );
3006 											PptSlidePersistList* pPageList = GetPageList( PPT_MASTERPAGE );
3007 											PptSlidePersistEntry* pE = (*pPageList)[ nMasterNum ];
3008                                             while( ( pE->aSlideAtom.nFlags & 4 ) && pE->aSlideAtom.nMasterId )
3009                                             {
3010                                                 sal_uInt16 nNextMaster = pMasterPages->FindPage( pE->aSlideAtom.nMasterId );
3011                                                 if ( nNextMaster == PPTSLIDEPERSIST_ENTRY_NOTFOUND )
3012                                                     break;
3013                                                 else
3014     											    pE = (*pPageList)[ nNextMaster ];
3015                                             }
3016 											if ( pE->nBackgroundOffset )
3017 											{
3018 												// do not follow master colorscheme ?
3019 												sal_Bool bTemporary = ( rSlidePersist.aSlideAtom.nFlags & 2 ) != 0;
3020 												sal_uInt32 nPos = rStCtrl.Tell();
3021 												rStCtrl.Seek( pE->nBackgroundOffset );
3022 												rSlidePersist.pBObj = ImportObj( rStCtrl, (void*)&aProcessData, aPageSize, aPageSize );
3023 												rSlidePersist.bBObjIsTemporary = bTemporary;
3024 												rStCtrl.Seek( nPos );
3025 											}
3026                                         }
3027 									}
3028 									else
3029 									{
3030 										DffRecordHeader aShapeHd;
3031 										rStCtrl >> aShapeHd;
3032 										if ( aShapeHd.nRecType == DFF_msofbtSp )
3033 										{
3034 											sal_uInt32 nSpFlags;
3035 											rStCtrl >> nSpFlags >> nSpFlags;
3036 											if ( nSpFlags & SP_FBACKGROUND )
3037 											{
3038 												aEscherObjListHd.SeekToBegOfRecord( rStCtrl );
3039 												rSlidePersist.pBObj = ImportObj( rStCtrl, (void*)&aProcessData, aPageSize, aPageSize );
3040 												rSlidePersist.bBObjIsTemporary = sal_False;
3041 											}
3042 										}
3043 									}
3044 								}
3045 								break;
3046 							}
3047 							if ( aEscherObjListHd.nRecType == DFF_msofbtSpContainer )
3048 								break;
3049 							aEscherObjListHd.SeekToEndOfRecord( rStCtrl );
3050 						}
3051 
3052 						// now importing page
3053 						rStCtrl.Seek( nPPDrawOfs );
3054 						while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < aPPDrawHd.GetRecEndFilePos() ) )
3055 						{
3056 							DffRecordHeader aEscherObjListHd;
3057 							rStCtrl >> aEscherObjListHd;
3058 							switch ( aEscherObjListHd.nRecType )
3059 							{
3060 								case DFF_msofbtSpgrContainer :
3061 								{
3062 									DffRecordHeader aShapeHd;
3063 									if ( SeekToRec( rStCtrl, DFF_msofbtSpContainer, aEscherObjListHd.GetRecEndFilePos(), &aShapeHd ) )
3064 									{
3065 										aShapeHd.SeekToEndOfRecord( rStCtrl );
3066 										while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < aEscherObjListHd.GetRecEndFilePos() ) )
3067 										{
3068 											rStCtrl >> aShapeHd;
3069 											if ( ( aShapeHd.nRecType == DFF_msofbtSpContainer ) || ( aShapeHd.nRecType == DFF_msofbtSpgrContainer ) )
3070 											{
3071 												Rectangle aEmpty;
3072 												aShapeHd.SeekToBegOfRecord( rStCtrl );
3073 												sal_Int32 nShapeId;
3074 												aProcessData.pTableRowProperties = NULL;
3075 												SdrObject* pObj = ImportObj( rStCtrl, (void*)&aProcessData, aEmpty, aEmpty, 0, &nShapeId );
3076 												if ( pObj )
3077 												{
3078 													if ( aProcessData.pTableRowProperties )
3079 														pObj = CreateTable( pObj, aProcessData.pTableRowProperties, aProcessData.rPersistEntry.pSolverContainer );
3080 
3081 													pRet->NbcInsertObject( pObj );
3082 
3083 													if( nShapeId )
3084 														insertShapeId( nShapeId, pObj );
3085 												}
3086 											}
3087 											aShapeHd.SeekToEndOfRecord( rStCtrl );
3088 										}
3089 									}
3090 								}
3091 								break;
3092 							}
3093 							if ( aEscherObjListHd.nRecType == DFF_msofbtSpgrContainer )
3094 								break;
3095 							aEscherObjListHd.SeekToEndOfRecord( rStCtrl );
3096 						}
3097 
3098 						/* There are a lot of Shapes who are dependent to
3099 						   the current background color */
3100 						if ( rSlidePersist.ePageKind == PPT_SLIDEPAGE )
3101 						{
3102 							List* pList2 = aProcessData.pBackgroundColoredObjects;
3103 							if ( pList2 )
3104 							{
3105 								if ( rSlidePersist.pBObj )
3106 								{
3107 									void* pPtr;
3108 									const SfxPoolItem* pPoolItem = NULL;
3109 									const SfxItemSet& rObjectItemSet = rSlidePersist.pBObj->GetMergedItemSet();
3110 
3111 									//SfxItemState eState = rObjectItemSet.GetItemState( XATTR_FILLCOLOR, sal_False, &pPoolItem );
3112 									if ( pPoolItem )
3113 									{
3114 										SfxItemSet aNewSet(*rObjectItemSet.GetPool());
3115 										aNewSet.Put(*pPoolItem);
3116 										aNewSet.Put(XFillStyleItem( XFILL_SOLID ));
3117 
3118 										for ( pPtr = pList2->First(); pPtr; pPtr = pList2->Next() )
3119 										{
3120 											((SdrObject*)pPtr)->SetMergedItemSet(aNewSet);
3121 										}
3122 									}
3123 								}
3124 							}
3125 						}
3126 						if ( rSlidePersist.pBObj )
3127 						{
3128                             // #i99386# transfer the attributes from the temporary BackgroundObject
3129                             // to the Page and delete it. Maybe rSlidePersist.bBObjIsTemporary is
3130                             // obsolete here, too.
3131                             pRet->getSdrPageProperties().ClearItem();
3132                             pRet->getSdrPageProperties().PutItemSet(rSlidePersist.pBObj->GetMergedItemSet());
3133 							SdrObject::Free( rSlidePersist.pBObj );
3134 						}
3135 					}
3136 				}
3137 				break;
3138 			}
3139 			aHd.SeekToEndOfRecord( rStCtrl );
3140 		}
3141 		if ( rSlidePersist.pSolverContainer )
3142             SolveSolver( *rSlidePersist.pSolverContainer );
3143 		if ( mbTracing )
3144 			mpTracer->RemoveAttribute( eAktPageKind == PPT_SLIDEPAGE
3145 										? rtl::OUString::createFromAscii( "Page" )
3146 										: rtl::OUString::createFromAscii( "NotesPage" ) );
3147 	}
3148 	rStCtrl.Seek( nMerk );
3149 }
3150 
GetSlideLayoutAtom() const3151 const PptSlideLayoutAtom* SdrPowerPointImport::GetSlideLayoutAtom() const
3152 {
3153     PptSlidePersistList* pPageList = GetPageList( eAktPageKind );
3154     if ( pPageList && nAktPageNum < pPageList->Count() )
3155 	{
3156         PptSlidePersistEntry* pE = (*pPageList)[ nAktPageNum ];
3157         if ( pE )
3158             return &pE->aSlideAtom.aLayout;
3159     }
3160     return NULL;
3161 }
3162 
IsNoteOrHandout(sal_uInt16 nPageNum,PptPageKind) const3163 sal_Bool SdrPowerPointImport::IsNoteOrHandout( sal_uInt16 nPageNum, PptPageKind /*ePageKind*/) const
3164 {
3165     sal_Bool bNote = eAktPageKind == PPT_NOTEPAGE;
3166     if ( eAktPageKind == PPT_MASTERPAGE )
3167 		bNote = ( nPageNum & 1 ) == 0;
3168     return bNote;
3169 }
3170 
GetMasterPageId(sal_uInt16 nPageNum,PptPageKind ePageKind) const3171 sal_uInt32 SdrPowerPointImport::GetMasterPageId( sal_uInt16 nPageNum, PptPageKind ePageKind ) const
3172 {
3173     PptSlidePersistList* pPageList = GetPageList( ePageKind );
3174     if ( pPageList && nPageNum < pPageList->Count() )
3175         return (*pPageList)[ nPageNum ]->aSlideAtom.nMasterId;
3176    return 0;
3177 }
3178 
GetNotesPageId(sal_uInt16 nPageNum) const3179 sal_uInt32 SdrPowerPointImport::GetNotesPageId( sal_uInt16 nPageNum ) const
3180 {
3181     PptSlidePersistList* pPageList=GetPageList( PPT_SLIDEPAGE );
3182     if ( pPageList && nPageNum < pPageList->Count() )
3183         return (*pPageList)[ nPageNum ]->aSlideAtom.nNotesId;
3184    return 0;
3185 }
3186 
HasMasterPage(sal_uInt16 nPageNum,PptPageKind ePageKind) const3187 sal_Bool SdrPowerPointImport::HasMasterPage( sal_uInt16 nPageNum, PptPageKind ePageKind ) const
3188 {
3189     if ( ePageKind == PPT_NOTEPAGE )
3190 		return aDocAtom.nNotesMasterPersist != 0;
3191     if ( ePageKind == PPT_MASTERPAGE )
3192 		return sal_False;
3193     return GetMasterPageId( nPageNum, ePageKind ) != 0;
3194 }
3195 
GetMasterPageIndex(sal_uInt16 nPageNum,PptPageKind ePageKind) const3196 sal_uInt16 SdrPowerPointImport::GetMasterPageIndex( sal_uInt16 nPageNum, PptPageKind ePageKind ) const
3197 {
3198     sal_uInt16 nIdx = 0;
3199     if ( ePageKind == PPT_NOTEPAGE )
3200 		return 2;
3201     sal_uInt32 nId = GetMasterPageId( nPageNum, ePageKind );
3202     if ( nId && pMasterPages )
3203 	{
3204         nIdx = pMasterPages->FindPage( nId );
3205         if ( nIdx == PPTSLIDEPERSIST_ENTRY_NOTFOUND )
3206 			nIdx = 0;
3207     }
3208     return nIdx;
3209 }
3210 
ImportPageBackgroundObject(const SdrPage & rPage,sal_uInt32 & nBgFileOffset,sal_Bool bForce)3211 SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage, sal_uInt32& nBgFileOffset, sal_Bool bForce )
3212 {
3213     SdrObject* pRet = NULL;
3214     sal_Bool bCreateObj = bForce;
3215     SfxItemSet* pSet = NULL;
3216     sal_uLong nFPosMerk = rStCtrl.Tell(); // FilePos merken fuer spaetere Restauration
3217     DffRecordHeader aPageHd;
3218     if ( SeekToAktPage( &aPageHd ) )
3219 	{	// und nun die Hintergrundattribute der Page suchen
3220         sal_uLong nPageRecEnd = aPageHd.GetRecEndFilePos();
3221         DffRecordHeader aPPDrawHd;
3222         if ( SeekToRec( rStCtrl, PPT_PST_PPDrawing, nPageRecEnd, &aPPDrawHd ) )
3223 		{
3224             sal_uLong nPPDrawEnd = aPPDrawHd.GetRecEndFilePos();
3225             DffRecordHeader aEscherF002Hd;
3226             if ( SeekToRec( rStCtrl, DFF_msofbtDgContainer, nPPDrawEnd, &aEscherF002Hd ) )
3227 			{
3228                 sal_uLong nEscherF002End = aEscherF002Hd.GetRecEndFilePos();
3229                 DffRecordHeader aEscherObjectHd;
3230                 if ( SeekToRec( rStCtrl, DFF_msofbtSpContainer, nEscherF002End, &aEscherObjectHd ) )
3231 				{
3232 					nBgFileOffset = aEscherObjectHd.GetRecBegFilePos();
3233                     //sal_uLong nEscherObjectEnd = aEscherObjectHd.GetRecEndFilePos();
3234                     //DffRecordHeader aEscherPropertiesHd;
3235                     if ( SeekToRec( rStCtrl, DFF_msofbtOPT,nEscherF002End ) )
3236 					{
3237 						rStCtrl >> (DffPropertyReader&)*this;
3238 						mnFix16Angle = Fix16ToAngle( GetPropertyValue( DFF_Prop_Rotation, 0 ) );
3239                         sal_uInt32 nColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff );
3240                         pSet = new SfxItemSet( pSdrModel->GetItemPool() );
3241                         DffObjData aObjData( aEscherObjectHd, Rectangle( 0, 0, 28000, 21000 ), 0 );
3242 						ApplyAttributes( rStCtrl, *pSet, aObjData );
3243                         Color aColor( MSO_CLR_ToColor( nColor ) );
3244 				        pSet->Put( XFillColorItem( String(), aColor ) );
3245                     }
3246                 }
3247             }
3248         }
3249     }
3250     rStCtrl.Seek( nFPosMerk ); // FilePos restaurieren
3251     if ( bCreateObj )
3252 	{
3253         if ( !pSet )
3254 		{
3255             pSet = new SfxItemSet( pSdrModel->GetItemPool() );
3256             pSet->Put( XFillStyleItem( XFILL_NONE ) );
3257         }
3258         pSet->Put( XLineStyleItem( XLINE_NONE ) );
3259         Rectangle aRect( rPage.GetLftBorder(), rPage.GetUppBorder(), rPage.GetWdt()-rPage.GetRgtBorder(), rPage.GetHgt()-rPage.GetLwrBorder() );
3260         pRet = new SdrRectObj( aRect );
3261         pRet->SetModel( pSdrModel );
3262 
3263         pRet->SetMergedItemSet(*pSet);
3264 
3265         pRet->SetMarkProtect( sal_True );
3266         pRet->SetMoveProtect( sal_True );
3267         pRet->SetResizeProtect( sal_True );
3268     }
3269     delete pSet;
3270     return pRet;
3271 }
3272 
3273 ////////////////////////////////////////////////////////////////////////////////////////////////////
3274 
HeaderFooterEntry(const PptSlidePersistEntry * pMPE)3275 HeaderFooterEntry::HeaderFooterEntry( const PptSlidePersistEntry* pMPE ) :
3276 	pMasterPersist	( pMPE ),
3277 	nAtom			( 0 )
3278 {
3279 	if ( pMPE )
3280 	{
3281 		HeaderFooterEntry* pMHFE = pMPE->pHeaderFooterEntry;
3282 		if ( pMHFE )
3283 		{
3284 			nAtom = pMPE->pHeaderFooterEntry->nAtom;
3285 			pPlaceholder[ 0 ] = pMHFE->pPlaceholder[ 0 ];
3286 			pPlaceholder[ 1 ] = pMHFE->pPlaceholder[ 1 ];
3287 			pPlaceholder[ 2 ] = pMHFE->pPlaceholder[ 2 ];
3288 			pPlaceholder[ 3 ] = pMHFE->pPlaceholder[ 3 ];
3289 		}
3290 	}
3291 }
3292 
~HeaderFooterEntry()3293 HeaderFooterEntry::~HeaderFooterEntry()
3294 {
3295 }
3296 
GetMaskForInstance(sal_uInt32 nInstance)3297 sal_uInt32 HeaderFooterEntry::GetMaskForInstance( sal_uInt32 nInstance )
3298 {
3299 	sal_uInt32 nRet = 0;
3300 	switch ( nInstance )
3301 	{
3302 		case 0 : nRet = 0x07ffff; break;
3303 		case 1 : nRet = 0x100000; break;
3304 		case 2 : nRet = 0x200000; break;
3305 		case 3 : nRet = 0x080000; break;
3306 	}
3307 	return nRet;
3308 }
3309 
IsToDisplay(sal_uInt32 nInstance)3310 sal_uInt32 HeaderFooterEntry::IsToDisplay( sal_uInt32 nInstance )
3311 {
3312 	sal_uInt32 nMask = 0;
3313 	switch ( nInstance )
3314 	{
3315 		case 0 : nMask = 0x010000; break;
3316 		case 1 : nMask = 0x100000; break;
3317 		case 2 : nMask = 0x200000; break;
3318 		case 3 : nMask = 0x080000; break;
3319 	}
3320 	return ( nAtom & nMask );
3321 }
3322 
3323 // The following method checks if the slide is using a different colorscheme than
3324 // its master, if this is the fact, then the HeaderFooter must probably be
3325 // imported as real sdrobject. In this case, the return value is the offset to the
3326 // master header footer object, so it can be re-loaded with a different color set
NeedToImportInstance(const sal_uInt32 nInstance,const PptSlidePersistEntry & rSlidePersist)3327 sal_uInt32 HeaderFooterEntry::NeedToImportInstance( const sal_uInt32 nInstance, const PptSlidePersistEntry& rSlidePersist )
3328 {
3329 	sal_uInt32 nRet = 0;
3330 	if ( pMasterPersist )
3331 	{
3332 		if ( !( rSlidePersist.aSlideAtom.nFlags & 2 ) )
3333 		{	// not following the master persist, so we have to check if the colors are changed
3334 			if ( memcmp( &rSlidePersist.aColorScheme, &pMasterPersist->aColorScheme, 32 ) )
3335 			{
3336 				nRet = pMasterPersist->HeaderFooterOfs[ nInstance ];
3337 			}
3338 		}
3339 	}
3340 	return nRet;
3341 }
3342 
ImportHeaderFooterContainer(DffRecordHeader & rHd,HeaderFooterEntry & rE)3343 void SdrEscherImport::ImportHeaderFooterContainer( DffRecordHeader& rHd, HeaderFooterEntry& rE )
3344 {
3345 	rHd.SeekToContent( rStCtrl );
3346 	while ( ( rStCtrl.GetError() == 0 ) && ( rStCtrl.Tell() < rHd.GetRecEndFilePos() ) )
3347 	{
3348 		DffRecordHeader aHd;
3349 		rStCtrl >> aHd;
3350 		switch ( aHd.nRecType )
3351 		{
3352 			case PPT_PST_HeadersFootersAtom :
3353 				rStCtrl >> rE.nAtom;
3354 			break;
3355 
3356 			case PPT_PST_CString :
3357 			{
3358 				if ( aHd.nRecInstance < 4 )
3359 					MSDFFReadZString( rStCtrl, rE.pPlaceholder[ aHd.nRecInstance ], aHd.nRecLen, sal_True );
3360 			}
3361 			break;
3362 		}
3363 		aHd.SeekToEndOfRecord( rStCtrl );
3364 	}
3365 }
3366 
3367 //static sal_Unicode PPTExportMapper( sal_Unicode nUni, sal_Bool& bNeedsStarBats )
3368 //{
3369 //	bNeedsStarBats = sal_False;
3370 //
3371 //	sal_Unicode cLo, cReplace;
3372 //	cLo = cReplace = 0;
3373 //	switch ( nUni )
3374 //	{
3375 //		case 132 : cLo = 175; break;
3376 //		case 147 : cLo = 174; break;
3377 //		// Currency
3378 //		case 0x00A2:	cReplace = 224; break;
3379 //		case 0x00A4:	cReplace = 225; break;
3380 //		case 0x00A5:	cReplace = 226; break;
3381 //		case 0x20A1:	cReplace = 228; break;
3382 //		case 0x20A2:	cReplace = 229; break;
3383 //		case 0x20A3:	cReplace = 230; break;
3384 //		case 0x20A4:	cReplace = 231; break;
3385 //		case 0x20A7:	cReplace = 227; break;
3386 //		case 0x20A8:	cReplace = 234; break;
3387 //		case 0x20A9:	cReplace = 232; break;
3388 //		case 0x20AB:	cReplace = 233; break;
3389 //		case 0x20AC:	cReplace = 128; break;
3390 //		// Punctuation and other
3391 //		case 0x201A:	cReplace = 130; break;		// SINGLE LOW-9 QUOTATION MARK
3392 //		case 0x0192:	cReplace = 131; break;		// LATIN SMALL LETTER F WITH HOOK
3393 //		case 0x201E:								// DOUBLE LOW-9 QUOTATION MARK
3394 //		case 0x301F:								// LOW DOUBLE PRIME QUOTATION MARK
3395 //						cReplace = 132; break;
3396 //		case 0x2026:	cReplace = 133; break;		// HORIZONTAL ELLIPSES
3397 //		case 0x2020:	cReplace = 134; break;		// DAGGER
3398 //		case 0x2021:	cReplace = 135; break;		// DOUBLE DAGGER
3399 //		case 0x02C6:	cReplace = 136; break;		// MODIFIER LETTER CIRCUMFLEX ACCENT
3400 //		case 0x2030:	cReplace = 137; break;		// PER MILLE SIGN
3401 //		case 0x0160:	cReplace = 138; break;		// LATIN CAPITAL LETTER S WITH CARON
3402 //		case 0x2039:	cReplace = 139; break;		// SINGLE LEFT-POINTING ANGLE QUOTATION MARK
3403 //		case 0x0152:	cReplace = 140; break;		// LATIN CAPITAL LIGATURE OE
3404 //		case 0x017D:	cReplace = 142; break;		// LATIN CAPITAL LETTER Z WITH CARON
3405 //		case 0x2018:								// LEFT SINGLE QUOTATION MARK
3406 //		case 0x02BB:								// MODIFIER LETTER TURNED COMMA
3407 //						cReplace = 145; break;
3408 //		case 0x2019:								// RIGHT SINGLE QUOTATION MARK
3409 //		case 0x02BC:								// MODIFIER LETTER APOSTROPHE
3410 //						cReplace = 146; break;
3411 //		case 0x201C:								// LEFT DOUBLE QUOTATION MARK
3412 //		case 0x301D:								// REVERSED DOUBLE PRIME QUOTATION MARK
3413 //						cReplace = 147; break;
3414 //		case 0x201D:								// RIGHT DOUBLE QUOTATION MARK
3415 //		case 0x301E:								// REVERSED DOUBLE PRIME QUOTATION MARK
3416 //						cReplace = 148; break;
3417 //		case 0x2022:	cReplace = 149; break;		// BULLET
3418 //		case 0x2013:	cReplace = 150; break;		// EN DASH
3419 //		case 0x2014:	cReplace = 151; break;		// EM DASH
3420 //		case 0x02DC:	cReplace = 152; break;		// SMALL TILDE
3421 //		case 0x2122:	cReplace = 153; break;		// TRADE MARK SIGN
3422 //		case 0x0161:	cReplace = 154; break;		// LATIN SMALL LETTER S WITH CARON
3423 //		case 0x203A:	cReplace = 155; break;		// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
3424 //		case 0x0153:	cReplace = 156; break;		// LATIN SMALL LIGATURE OE
3425 //		case 0x017E:	cReplace = 158; break;		// LATIN SMALL LETTER Z WITH CARON
3426 //		case 0x0178:	cReplace = 159; break;		// LATIN CAPITAL LETTER Y WITH DIAERESIS
3427 //		case 0x00B6:	cReplace = 222; break;		// PILCROW SIGN / PARAGRAPH SIGN
3428 //	}
3429 //	if ( cReplace )
3430 //	{
3431 //		bNeedsStarBats = sal_True;
3432 //		return cReplace;
3433 //	}
3434 //	else
3435 //		return cLo;
3436 //}
3437 
3438 // no longer needed
PPTSubstitute(sal_uInt16,sal_Unicode,sal_uInt32 &,Font &,char) const3439 sal_Unicode SdrPowerPointImport::PPTSubstitute( sal_uInt16 /*nFont*/, sal_Unicode /*nChar*/,
3440 										sal_uInt32& /*nMappedFontId*/, Font& /*rFont*/, char /*nDefault*/) const
3441 {
3442     return 0;
3443 }
3444 
3445 ////////////////////////////////////////////////////////////////////////////////////////////////////
3446 
PPTBuGraEntry(Graphic & rGraphic,sal_uInt32 nInst)3447 PPTBuGraEntry::PPTBuGraEntry( Graphic& rGraphic, sal_uInt32 nInst ) :
3448 	nInstance		( nInst ),
3449 	aBuGra			( rGraphic )  {}
3450 
PPTExtParaLevel()3451 PPTExtParaLevel::PPTExtParaLevel()
3452 : mnExtParagraphMask( 0 )
3453 , mnBuBlip( 0xffff )
3454 , mnHasAnm( 0 )
3455 , mnAnmScheme( 0 )
3456 , mpfPP10Ext( 0 )
3457 , mnExtCharacterMask( 0 )
3458 , mcfPP10Ext( 0 )
3459 , mbSet( sal_False )
3460 {}
3461 
operator >>(SvStream & rIn,PPTExtParaLevel & rLevel)3462 SvStream& operator>>( SvStream& rIn, PPTExtParaLevel& rLevel )
3463 {
3464 	rLevel.mbSet = sal_True;
3465 	rIn >> rLevel.mnExtParagraphMask;
3466 	if ( rLevel.mnExtParagraphMask & 0x00800000 )
3467 		rIn >> rLevel.mnBuBlip;
3468 	if ( rLevel.mnExtParagraphMask & 0x02000000 )
3469 		rIn >> rLevel.mnHasAnm;
3470 	if ( rLevel.mnExtParagraphMask & 0x01000000 )
3471 		rIn >> rLevel.mnAnmScheme;
3472 	if ( rLevel.mnExtParagraphMask & 0x04000000 )
3473 		rIn >> rLevel.mpfPP10Ext;
3474 	rIn >> rLevel.mnExtCharacterMask;
3475 	if ( rLevel.mnExtCharacterMask & 0x100000 )
3476 		rIn >> rLevel.mcfPP10Ext;
3477 	return rIn;
3478 }
3479 
GetGraphic(sal_uInt32 nInstance,Graphic & rGraph) const3480 sal_Bool PPTExtParaProv::GetGraphic( sal_uInt32 nInstance, Graphic& rGraph ) const
3481 {
3482 	sal_Bool bRetValue = sal_False;
3483 	PPTBuGraEntry* pPtr = NULL;
3484 	if ( nInstance < aBuGraList.Count() )
3485 	{
3486 		pPtr = (PPTBuGraEntry*)aBuGraList.GetObject( nInstance );
3487 		if ( pPtr->nInstance == nInstance )
3488 			bRetValue = sal_True;
3489 	}
3490 	if ( !bRetValue )
3491 	{
3492         sal_uInt32 i;
3493 		for ( i = 0; i < aBuGraList.Count(); i++ )
3494 		{
3495             pPtr = (PPTBuGraEntry*)aBuGraList.GetObject( i );
3496 			if ( pPtr->nInstance == nInstance )
3497 			{
3498 				bRetValue = sal_True;
3499 				break;
3500 			}
3501 		}
3502 	}
3503 	if ( bRetValue )
3504 		rGraph = pPtr->aBuGra;
3505 	return bRetValue;
3506 }
3507 
PPTExtParaProv(SdrPowerPointImport & rMan,SvStream & rSt,const DffRecordHeader * pHd)3508 PPTExtParaProv::PPTExtParaProv( SdrPowerPointImport& rMan, SvStream& rSt, const DffRecordHeader* pHd ) :
3509 	bStyles			( sal_False ),
3510 	bGraphics		( sal_False )
3511 {
3512 	sal_uInt32 nOldPos = rSt.Tell();
3513 
3514 	// here we have to get the graphical bullets...
3515 
3516 	DffRecordHeader	aHd;
3517 	DffRecordHeader aContentDataHd;
3518 
3519 	const DffRecordHeader* pListHd = rMan.aDocRecManager.GetRecordHeader( PPT_PST_List, SEEK_FROM_BEGINNING );
3520 	while( pListHd )
3521 	{
3522 		pListHd->SeekToContent( rSt );
3523         if ( !rMan.SeekToContentOfProgTag( 9, rSt, *pListHd, aContentDataHd ) )
3524             break;
3525 		while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aContentDataHd.GetRecEndFilePos() ) )
3526 		{
3527 			rSt >> aHd;
3528 			switch ( aHd.nRecType )
3529 			{
3530 				case PPT_PST_ExtendedBuGraContainer :
3531 				{
3532 					while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aHd.GetRecEndFilePos() ) )
3533 					{
3534 						sal_uInt16 nType;
3535 						DffRecordHeader aBuGraAtomHd;
3536 						rSt >> aBuGraAtomHd;
3537 						if ( aBuGraAtomHd.nRecType == PPT_PST_ExtendedBuGraAtom )
3538 						{
3539 							rSt >> nType;
3540 							Graphic aGraphic;
3541 							if ( rMan.GetBLIPDirect( rSt, aGraphic, NULL ) )
3542 							{
3543 								sal_uInt32 nInstance = aBuGraAtomHd.nRecInstance;
3544 								PPTBuGraEntry* pBuGra = new PPTBuGraEntry( aGraphic, nInstance );
3545 								sal_uInt32 n = 0;
3546 								sal_uInt32 nBuGraCount = aBuGraList.Count();
3547 								if ( nBuGraCount )
3548 								{
3549 									if ( ( (PPTBuGraEntry*)aBuGraList.GetObject( nBuGraCount - 1 ) )->nInstance < nInstance )
3550 										n = nBuGraCount;
3551 									else
3552 									{	// maybe the instances are not sorted, we sort it
3553 										for ( n = 0; n < nBuGraCount; n++ )
3554 										{	// sorting fields ( hi >> lo )
3555 											if ( ( (PPTBuGraEntry*)aBuGraList.GetObject( n ) )->nInstance < nInstance )
3556 												break;
3557 										}
3558 									}
3559 								}
3560 								aBuGraList.Insert( pBuGra, (sal_uInt32)n );
3561 							}
3562 #ifdef DBG_UTIL
3563 							else DBG_ERROR( "PPTExParaProv::PPTExParaProv - bullet graphic is not valid (SJ)" );
3564 #endif
3565 						}
3566 #ifdef DBG_UTIL
3567 						else DBG_ERROR( "PPTExParaProv::PPTExParaProv - unknown atom interpreting the PPT_PST_ExtendedBuGraContainer (SJ)" );
3568 #endif
3569 						aBuGraAtomHd.SeekToEndOfRecord( rSt );
3570 					}
3571 					if ( aBuGraList.Count() )
3572 						bGraphics = sal_True;
3573 				}
3574 				break;
3575 
3576 				case PPT_PST_ExtendedPresRuleContainer :
3577 					aExtendedPresRules.Consume( rSt, sal_False, aHd.GetRecEndFilePos() );
3578 				break;
3579 #ifdef DBG_UTIL
3580 				default :
3581 					DBG_ERROR( "PPTExParaProv::PPTExParaProv - unknown atom reading ppt2000 num rules (SJ)" );
3582 				case PPT_PST_MasterText :	// first seen in: ms-tt02.ppt
3583 				case PPT_PST_SrKinsoku :
3584                 case PPT_PST_NewlyAddedAtom4016 :
3585 				case PPT_PST_NewlyAddedAtomByPPT2000_6010 :
3586 				case PPT_PST_NewlyAddedAtomByPPT2000_6011 :
3587                 case PPT_PST_NewlyAddedAtomByXP1037 :
3588                 case PPT_PST_NewlyAddedAtomByXP12004 :
3589                 case PPT_PST_NewlyAddedAtomByXP14001 :
3590 				break;
3591 #endif
3592 			}
3593 			aHd.SeekToEndOfRecord( rSt );
3594 		}
3595 		break;
3596 	}
3597 
3598 	while( pHd )
3599 	{   // get the extended paragraph styles on mainmaster ( graphical bullets, num ruling ... )
3600         if ( !rMan.SeekToContentOfProgTag( 9, rSt, *pHd, aContentDataHd ) )
3601             break;
3602 		while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aContentDataHd.GetRecEndFilePos() ) )
3603 		{
3604 			rSt >> aHd;
3605             switch ( aHd.nRecType )
3606             {
3607 			    case PPT_PST_ExtendedParagraphMasterAtom :
3608 			    {
3609 				    if ( aHd.nRecInstance < PPT_STYLESHEETENTRYS )
3610 				    {
3611 					    sal_uInt16 nDepth, i = 0;
3612 					    rSt >> nDepth;
3613 					    if ( i <= 5 )
3614 					    {
3615 
3616 						    while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aHd.GetRecEndFilePos() ) && ( i < nDepth ) )
3617 						    {
3618 							    bStyles = sal_True;
3619 							    rSt >> aExtParaSheet[ aHd.nRecInstance ].aExtParaLevel[ i++ ];
3620 						    }
3621 #ifdef DBG_UTIL
3622 						    if ( rSt.Tell() != aHd.GetRecEndFilePos() )
3623 							    DBG_ERROR( "PPTExParaProv::PPTExParaProv - error reading PPT_PST_ExtendedParagraphMasterAtom (SJ)" );
3624 #endif
3625 					    }
3626 #ifdef DBG_UTIL
3627 					    else DBG_ERROR( "PPTExParaProv::PPTExParaProv - depth is greater than 5 (SJ)" );
3628 #endif
3629 				    }
3630 #ifdef DBG_UTIL
3631 				    else DBG_ERROR( "PPTExParaProv::PPTExParaProv - instance out of range (SJ)" );
3632 #endif
3633     			}
3634                 break;
3635                 default :
3636                     DBG_ERROR( "PPTExParaProv::PPTExParaProv - unknown atom, assuming PPT_PST_ExtendedParagraphMasterAtom (SJ)" );
3637                 case PPT_PST_NewlyAddedAtomByXP11008 :
3638                 case PPT_PST_NewlyAddedAtomByXP11010 :
3639                 case PPT_PST_NewlyAddedAtomByXP12010 :
3640                 case PPT_PST_NewlyAddedAtomByXP12011 :
3641                 case 0xf144 :
3642                 break;
3643             }
3644 			aHd.SeekToEndOfRecord( rSt );
3645 		}
3646 		break;
3647 	}
3648 	rSt.Seek( nOldPos );
3649 }
3650 
~PPTExtParaProv()3651 PPTExtParaProv::~PPTExtParaProv()
3652 {
3653 	void* pPtr;
3654 	for ( pPtr = aBuGraList.First(); pPtr; pPtr = aBuGraList.Next() )
3655 		delete (PPTBuGraEntry*)pPtr;
3656 }
3657 
3658 ////////////////////////////////////////////////////////////////////////////////////////////////////
3659 
PPTNumberFormatCreator(PPTExtParaProv * pParaProv)3660 PPTNumberFormatCreator::PPTNumberFormatCreator( PPTExtParaProv* pParaProv ) :
3661     pExtParaProv ( pParaProv )
3662 {
3663 }
3664 
~PPTNumberFormatCreator()3665 PPTNumberFormatCreator::~PPTNumberFormatCreator()
3666 {
3667     delete pExtParaProv;
3668 }
3669 
ImplGetExtNumberFormat(SdrPowerPointImport & rManager,SvxNumberFormat & rNumberFormat,sal_uInt32 nLevel,sal_uInt32 nInstance,sal_uInt32 nDestinationInstance,boost::optional<sal_Int16> & rStartNumbering,sal_uInt32 nFontHeight,PPTParagraphObj * pPara)3670 sal_Bool PPTNumberFormatCreator::ImplGetExtNumberFormat( SdrPowerPointImport& rManager,
3671 	SvxNumberFormat& rNumberFormat, sal_uInt32 nLevel, sal_uInt32 nInstance, sal_uInt32 nDestinationInstance,
3672 		boost::optional< sal_Int16 >& rStartNumbering, sal_uInt32 nFontHeight,	PPTParagraphObj* pPara )
3673 {
3674 	sal_Bool bHardAttribute = ( nDestinationInstance == 0xffffffff );
3675 
3676 	sal_uInt32	nBuFlags = 0;
3677 	sal_uInt16	nHasAnm = 0;
3678 	sal_uInt32	nAnmScheme = 0x10003;
3679 	sal_uInt16	nBuBlip = 0xffff;
3680 
3681     const PPTExtParaProv* pParaProv = pExtParaProv;
3682     if ( !pExtParaProv )
3683         pParaProv = ( pPara ) ? pPara->mrStyleSheet.pExtParaProv
3684                               : rManager.pPPTStyleSheet->pExtParaProv;
3685 	if ( pPara )
3686 	{
3687 		nBuFlags = pPara->pParaSet->mnExtParagraphMask;
3688 		if ( nBuFlags )
3689 		{
3690 			if ( nBuFlags & 0x00800000 )
3691 				nBuBlip = pPara->pParaSet->mnBuBlip;
3692 			if ( nBuFlags & 0x01000000 )
3693 				nAnmScheme = pPara->pParaSet->mnAnmScheme;
3694 			if ( nBuFlags & 0x02000000 )
3695 				nHasAnm = pPara->pParaSet->mnHasAnm;
3696 			bHardAttribute = sal_True;
3697 		}
3698 	}
3699 
3700 	if ( ( nBuFlags & 0x03800000 ) != 0x03800000 )	// merge style sheet
3701 	{	// we have to read the master attributes
3702 		if ( pParaProv && ( nLevel < 5 ) )
3703 		{
3704 			if ( pParaProv->bStyles )
3705 			{
3706 				const PPTExtParaLevel& rLev = pParaProv->aExtParaSheet[ nInstance ].aExtParaLevel[ nLevel ];
3707 				if ( rLev.mbSet )
3708 				{
3709 					sal_uInt32 nMaBuFlags = rLev.mnExtParagraphMask;
3710 
3711 					if ( (!( nBuFlags & 0x00800000)) && ( nMaBuFlags & 0x00800000 ) )
3712 					{
3713 						if (!( nBuFlags & 0x02000000))			// if there is a BuStart without BuInstance,
3714 							nBuBlip = rLev.mnBuBlip;		// then there is no graphical Bullet possible
3715 					}
3716 					if ( (!( nBuFlags & 0x01000000)) && ( nMaBuFlags & 0x01000000 ) )
3717 						nAnmScheme = rLev.mnAnmScheme;
3718 					if ( (!( nBuFlags & 0x02000000)) && ( nMaBuFlags & 0x02000000 ) )
3719 						nHasAnm = rLev.mnHasAnm;
3720 					nBuFlags |= nMaBuFlags;
3721 				}
3722 			}
3723 		}
3724 	}
3725 	if ( nBuBlip != 0xffff )		// set graphical bullet
3726 	{
3727 		Graphic aGraphic;
3728 		if ( pParaProv->GetGraphic( nBuBlip, aGraphic ) )
3729 		{
3730             SvxBrushItem aBrush( aGraphic, GPOS_MM, SID_ATTR_BRUSH );
3731 			rNumberFormat.SetGraphicBrush( &aBrush );
3732 			sal_uInt32 nHeight = (sal_uInt32)( (double)nFontHeight * 0.2540 * nBulletHeight + 0.5 );
3733 			Size aPrefSize( aGraphic.GetPrefSize() );
3734 			sal_uInt32 nWidth = ( nHeight * aPrefSize.Width() ) / aPrefSize.Height();
3735 			rNumberFormat.SetGraphicSize( Size( nWidth, nHeight ) );
3736 			rNumberFormat.SetNumberingType ( SVX_NUM_BITMAP );
3737 		}
3738 	}
3739 	else if ( nHasAnm )
3740 	{
3741 		switch( static_cast< sal_uInt16 >( nAnmScheme ) )
3742 		{
3743 			default :
3744 			case 0 :
3745 			{
3746 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_LOWER_LETTER );
3747 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3748 			}
3749 			break;
3750 			case 1 :
3751 			{
3752 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_UPPER_LETTER );
3753 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3754 			}
3755 			break;
3756 			case 2 :
3757 			{
3758 				rNumberFormat.SetNumberingType( SVX_NUM_ARABIC );
3759 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3760 			}
3761 			break;
3762 			case 3 :
3763 			{
3764 				rNumberFormat.SetNumberingType( SVX_NUM_ARABIC );
3765 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3766 			}
3767 			break;
3768 			case 4 :
3769 			{
3770 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_LOWER );
3771 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3772 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3773 			}
3774 			break;
3775 			case 5 :
3776 			{
3777 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_LOWER );
3778 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3779 			}
3780 			break;
3781 			case 6 :
3782 			{
3783 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_LOWER );
3784 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3785 			}
3786 			break;
3787 			case 7 :
3788 			{
3789 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_UPPER );
3790 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3791 			}
3792 			break;
3793 			case 8 :
3794 			{
3795 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_LOWER_LETTER );
3796 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3797 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3798 			}
3799 			break;
3800 			case 9 :
3801 			{
3802 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_LOWER_LETTER );
3803 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3804 			}
3805 			break;
3806 			case 10 :
3807 			{
3808 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_UPPER_LETTER );
3809 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3810 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3811 			}
3812 			break;
3813 			case 11 :
3814 			{
3815 				rNumberFormat.SetNumberingType( SVX_NUM_CHARS_UPPER_LETTER );
3816 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3817 			}
3818 			break;
3819 			case 12 :
3820 			{
3821 				rNumberFormat.SetNumberingType( SVX_NUM_ARABIC );
3822 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3823 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3824 			}
3825 			break;
3826 			case 13 :
3827 			{
3828 				rNumberFormat.SetNumberingType( SVX_NUM_ARABIC );
3829 			}
3830 			break;
3831 			case 14 :
3832 			{
3833 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_UPPER );
3834 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3835 				rNumberFormat.SetPrefix( String( RTL_CONSTASCII_USTRINGPARAM( "(" ) ) );
3836 			}
3837 			break;
3838 			case 15 :
3839 			{
3840 				rNumberFormat.SetNumberingType( SVX_NUM_ROMAN_UPPER );
3841 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ) );
3842 			}
3843 			break;
3844 			case 16: // Simplified Chinese.
3845 			{
3846 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_UPPER_ZH );
3847 			}
3848 			break;
3849 			case 17: // Simplified Chinese with single-byte period.
3850 			{
3851 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_UPPER_ZH );
3852 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3853 			}
3854 			break;
3855 			case 18: // Double byte circle numbers.
3856 			case 19: // Wingdings white circle numbers.
3857 			case 20: // Wingdings black circle numbers.
3858 			{
3859 				rNumberFormat.SetNumberingType( SVX_NUM_CIRCLE_NUMBER );
3860 			}
3861 			break;
3862 			case 21: // Traditional Chinese.
3863 			{
3864 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_UPPER_ZH_TW );
3865 			}
3866 			break;
3867 			case 22: // Traditional Chinese with single-byte period.
3868 			{
3869 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_UPPER_ZH_TW );
3870 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3871 			}
3872 			break;
3873 			case 26: // Japanese/Korean.
3874 			{
3875 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_LOWER_ZH );
3876 			}
3877 			break;
3878 			case 27: // Japanese/Korean with single-byte period.
3879 			{
3880 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_LOWER_ZH );
3881 				rNumberFormat.SetSuffix( String( RTL_CONSTASCII_USTRINGPARAM( "." ) ) );
3882 			}
3883 			break;
3884 			case 28: // Double-byte Arabic numbers.
3885 			{
3886 				rNumberFormat.SetNumberingType( SVX_NUM_FULL_WIDTH_ARABIC );
3887 			}
3888 			break;
3889 			case 29: // Double-byte Arabic numbers with double-byte period.
3890 			{
3891 				rNumberFormat.SetNumberingType( SVX_NUM_FULL_WIDTH_ARABIC );
3892 				rNumberFormat.SetSuffix( String( sal_Unicode(0xff0e) ) );
3893 			}
3894 			break;
3895 			case 38: // Japanese with double-byte period.
3896 			{
3897 				rNumberFormat.SetNumberingType( SVX_NUM_NUMBER_LOWER_ZH ); // No such type. Instead with Lower Chinese Number
3898 				rNumberFormat.SetSuffix( String( sal_Unicode(0xff0e) ) );
3899 			}
3900 			break;
3901 		}
3902 		rStartNumbering = boost::optional< sal_Int16 >( nAnmScheme >> 16 );
3903 		sal_Int16 nBuStart = *rStartNumbering;
3904 		//The Seventh bit of nBuFlags that specifies whether fBulletHasAutoNumber exists,
3905 		//and fBulletHasAutoNumber that specifies whether this paragraph has an automatic numbering scheme.
3906 		if ( ( nBuFlags & 0x02000000 ) && ( nBuStart != 1 ))
3907 		{
3908 			rNumberFormat.SetStart( static_cast<sal_uInt16>(nBuStart) );
3909 		}
3910 	}
3911 	return bHardAttribute;
3912 }
3913 
GetNumberFormat(SdrPowerPointImport & rManager,SvxNumberFormat & rNumberFormat,sal_uInt32 nLevel,const PPTParaLevel & rParaLevel,const PPTCharLevel & rCharLevel,sal_uInt32 nInstance)3914 void PPTNumberFormatCreator::GetNumberFormat( SdrPowerPointImport& rManager, SvxNumberFormat& rNumberFormat, sal_uInt32 nLevel, const PPTParaLevel& rParaLevel, const PPTCharLevel& rCharLevel, sal_uInt32 nInstance )
3915 {
3916 	nIsBullet = ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BulletOn ) ) != 0 ? 1 : 0;
3917 	nBulletChar = rParaLevel.mnBulletChar;
3918 
3919 	sal_Bool bBuHardFont;
3920 	bBuHardFont = ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BuHardFont ) ) != 0;
3921 	if ( bBuHardFont )
3922 		nBulletFont = rParaLevel.mnBulletFont;
3923 	else
3924 		nBulletFont = rCharLevel.mnFont;
3925 	nBulletHeight = rParaLevel.mnBulletHeight;
3926     nBulletColor = rParaLevel.mnBulletColor;
3927     nTextOfs = rParaLevel.mnTextOfs;
3928 	nBulletOfs = rParaLevel.mnBulletOfs;
3929 
3930 	boost::optional< sal_Int16 > oStartNumbering;
3931 	ImplGetExtNumberFormat( rManager, rNumberFormat, nLevel, nInstance, 0xffffffff, oStartNumbering, rCharLevel.mnFontHeight, NULL );
3932 	if ( ( rNumberFormat.GetNumberingType() != SVX_NUM_BITMAP ) && ( nBulletHeight > 0x7fff ) )
3933 		nBulletHeight = rCharLevel.mnFontHeight ? ((-((sal_Int16)nBulletHeight)) * 100 ) / rCharLevel.mnFontHeight : 100;
3934 	ImplGetNumberFormat( rManager, rNumberFormat, nLevel );
3935 	switch ( rNumberFormat.GetNumberingType() )
3936 	{
3937 		case SVX_NUM_CHARS_UPPER_LETTER :
3938 		case SVX_NUM_CHARS_LOWER_LETTER :
3939 		case SVX_NUM_ROMAN_UPPER :
3940 		case SVX_NUM_ROMAN_LOWER :
3941 		case SVX_NUM_ARABIC :
3942 		case SVX_NUM_CHARS_UPPER_LETTER_N :
3943 		case SVX_NUM_CHARS_LOWER_LETTER_N :
3944 		{
3945 			sal_uInt32 nFont = rCharLevel.mnFont;
3946 			PptFontEntityAtom* pFontEnityAtom = rManager.GetFontEnityAtom( nFont );
3947 			if ( pFontEnityAtom )
3948 			{
3949 				Font aFont;
3950 				aFont.SetCharSet( pFontEnityAtom->eCharSet );
3951 				aFont.SetName( pFontEnityAtom->aName );
3952 				aFont.SetFamily( pFontEnityAtom->eFamily );
3953 				aFont.SetPitch( pFontEnityAtom->ePitch );
3954 				rNumberFormat.SetBulletFont( &aFont );
3955 			}
3956 		}
3957 		break;
3958 	}
3959 }
3960 
GetNumberFormat(SdrPowerPointImport & rManager,SvxNumberFormat & rNumberFormat,PPTParagraphObj * pParaObj,sal_uInt32 nDestinationInstance,boost::optional<sal_Int16> & rStartNumbering)3961 sal_Bool PPTNumberFormatCreator::GetNumberFormat( SdrPowerPointImport& rManager, SvxNumberFormat& rNumberFormat, PPTParagraphObj* pParaObj,
3962 												sal_uInt32 nDestinationInstance, boost::optional< sal_Int16 >& rStartNumbering )
3963 {
3964 	sal_uInt32 nHardCount = 0;
3965 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletOn, nIsBullet, nDestinationInstance );
3966 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletChar, nBulletChar, nDestinationInstance );
3967 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletFont, nBulletFont, nDestinationInstance );
3968 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletHeight, nBulletHeight, nDestinationInstance );
3969 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletColor, nBulletColor, nDestinationInstance );
3970 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_TextOfs, nTextOfs, nDestinationInstance );
3971 	nHardCount += pParaObj->GetAttrib( PPT_ParaAttr_BulletOfs, nBulletOfs, nDestinationInstance );
3972 
3973 	if ( nIsBullet )
3974 		rNumberFormat.SetNumberingType( SVX_NUM_CHAR_SPECIAL );
3975 
3976 	sal_uInt32 nFontHeight = 24;
3977 	PPTPortionObj* pPtr = pParaObj->First();
3978 	if ( pPtr )
3979 		pPtr->GetAttrib( PPT_CharAttr_FontHeight, nFontHeight, nDestinationInstance );
3980 	if ( nIsBullet )
3981 		nHardCount += ImplGetExtNumberFormat( rManager, rNumberFormat, pParaObj->pParaSet->mnDepth,
3982 													pParaObj->mnInstance, nDestinationInstance, rStartNumbering, nFontHeight, pParaObj );
3983 
3984 	if ( rNumberFormat.GetNumberingType() != SVX_NUM_BITMAP )
3985 		pParaObj->UpdateBulletRelSize( nBulletHeight );
3986 	if ( nHardCount )
3987 		ImplGetNumberFormat( rManager, rNumberFormat, pParaObj->pParaSet->mnDepth );
3988 
3989 	if ( nHardCount )
3990 	{
3991 		switch ( rNumberFormat.GetNumberingType() )
3992 		{
3993 			case SVX_NUM_CHARS_UPPER_LETTER :
3994 			case SVX_NUM_CHARS_LOWER_LETTER :
3995 			case SVX_NUM_ROMAN_UPPER :
3996 			case SVX_NUM_ROMAN_LOWER :
3997 			case SVX_NUM_ARABIC :
3998 			case SVX_NUM_CHARS_UPPER_LETTER_N :
3999 			case SVX_NUM_CHARS_LOWER_LETTER_N :
4000 			{
4001 				if ( pPtr )
4002 				{
4003 					sal_uInt32 nFont;
4004 					pPtr->GetAttrib( PPT_CharAttr_Font, nFont, nDestinationInstance );
4005 					PptFontEntityAtom* pFontEnityAtom = rManager.GetFontEnityAtom( nFont );
4006 					if ( pFontEnityAtom )
4007 					{
4008 						Font aFont;
4009 						aFont.SetCharSet( pFontEnityAtom->eCharSet );
4010 						aFont.SetName( pFontEnityAtom->aName );
4011 						aFont.SetFamily( pFontEnityAtom->eFamily );
4012 						aFont.SetPitch( pFontEnityAtom->ePitch );
4013 						rNumberFormat.SetBulletFont( &aFont );
4014 					}
4015 				}
4016 			}
4017 			break;
4018 		}
4019 	}
4020 	return ( nHardCount ) ? sal_True : sal_False;
4021 }
4022 
ImplGetNumberFormat(SdrPowerPointImport & rManager,SvxNumberFormat & rNumberFormat,sal_uInt32)4023 void PPTNumberFormatCreator::ImplGetNumberFormat( SdrPowerPointImport& rManager, SvxNumberFormat& rNumberFormat, sal_uInt32 /*nLevel*/)
4024 {
4025 	Font aFont;
4026 	PptFontEntityAtom* pAtom = rManager.GetFontEnityAtom( nBulletFont );
4027     if ( pAtom )
4028     {
4029 		CharSet eCharSet( pAtom->eCharSet );
4030 		aFont.SetName( pAtom->aName );
4031 		aFont.SetCharSet( eCharSet );
4032 		aFont.SetFamily( pAtom->eFamily );
4033 		aFont.SetPitch( pAtom->ePitch );
4034     }
4035 	Color aCol( rManager.MSO_TEXT_CLR_ToColor( nBulletColor ) );
4036 	aFont.SetColor( aCol );
4037 
4038     sal_uInt16 nBuChar = (sal_uInt16)nBulletChar;
4039     if ( aFont.GetCharSet() == RTL_TEXTENCODING_SYMBOL )
4040     {
4041 		nBuChar &= 0x00ff;
4042 		nBuChar |= 0xf000;
4043     }
4044 	rNumberFormat.SetBulletFont( &aFont );
4045 	rNumberFormat.SetBulletChar( nBuChar );
4046 	rNumberFormat.SetBulletRelSize( (sal_uInt16)nBulletHeight );
4047 	rNumberFormat.SetBulletColor( aCol );
4048 	sal_uInt16 nAbsLSpace = (sal_uInt16)( ( (sal_uInt32)nTextOfs * 2540 ) / 576 );
4049 	sal_uInt16 nFirstLineOffset = nAbsLSpace - (sal_uInt16)( ( (sal_uInt32)nBulletOfs * 2540 ) / 576 );
4050 	rNumberFormat.SetAbsLSpace( nAbsLSpace );
4051 	rNumberFormat.SetFirstLineOffset( -nFirstLineOffset );
4052 }
4053 
4054 ////////////////////////////////////////////////////////////////////////////////////////////////////
4055 
PPTCharSheet(sal_uInt32 nInstance)4056 PPTCharSheet::PPTCharSheet( sal_uInt32 nInstance )
4057 {
4058 	sal_uInt32 nColor = PPT_COLSCHEME_TEXT_UND_ZEILEN;
4059 	sal_uInt16 nFontHeight(0);
4060 	switch ( nInstance )
4061 	{
4062 		case TSS_TYPE_PAGETITLE :
4063 		case TSS_TYPE_TITLE :
4064 		{
4065 			nColor = PPT_COLSCHEME_TITELTEXT;
4066 			nFontHeight = 44;
4067 		}
4068 		break;
4069 		case TSS_TYPE_BODY :
4070 		case TSS_TYPE_SUBTITLE :
4071 		case TSS_TYPE_HALFBODY :
4072 		case TSS_TYPE_QUARTERBODY :
4073 			nFontHeight = 32;
4074 		break;
4075 		case TSS_TYPE_NOTES :
4076 			nFontHeight = 12;
4077 		break;
4078 		case TSS_TYPE_UNUSED :
4079 		case TSS_TYPE_TEXT_IN_SHAPE :
4080 			nFontHeight = 24;
4081 		break;
4082 	}
4083 	for ( sal_uInt32 nDepth = 0; nDepth < 5; nDepth++ )
4084 	{
4085 		maCharLevel[ nDepth ].mnFlags = 0;
4086 		maCharLevel[ nDepth ].mnFont = 0;
4087 		maCharLevel[ nDepth ].mnAsianOrComplexFont = 0xffff;
4088 		maCharLevel[ nDepth ].mnFontHeight = nFontHeight;
4089 		maCharLevel[ nDepth ].mnFontColor = nColor;
4090 		maCharLevel[ nDepth ].mnFontColorInStyleSheet = Color( (sal_uInt8)nColor, (sal_uInt8)( nColor >> 8 ), (sal_uInt8)( nColor >> 16 ) );
4091 		maCharLevel[ nDepth ].mnEscapement = 0;
4092 	}
4093 }
4094 
PPTCharSheet(const PPTCharSheet & rAttr)4095 PPTCharSheet::PPTCharSheet( const PPTCharSheet& rAttr )
4096 {
4097 	*this = rAttr;
4098 }
4099 
Read(SvStream & rIn,sal_Bool,sal_uInt32 nLevel,sal_Bool)4100 void PPTCharSheet::Read( SvStream& rIn, sal_Bool /*bMasterStyle*/, sal_uInt32 nLevel, sal_Bool /*bFirst*/)
4101 {
4102     // Zeichenattribute
4103     sal_uInt32 nCMask;
4104 	sal_uInt16 nVal16;
4105 	rIn >> nCMask;
4106 
4107 	if ( nCMask & 0x0000FFFF )
4108 	{
4109         sal_uInt16 nBitAttr;
4110 		maCharLevel[ nLevel ].mnFlags &= ~( (sal_uInt16)nCMask );
4111 		rIn >> nBitAttr; // Bit-Attribute (Fett, Unterstrichen, ...)
4112 		maCharLevel[ nLevel ].mnFlags |= nBitAttr;
4113     }
4114 	if ( nCMask & ( 1 << PPT_CharAttr_Font ) )					// 0x00010000
4115 		rIn >> maCharLevel[ nLevel ].mnFont;
4116 	if ( nCMask & ( 1 << PPT_CharAttr_AsianOrComplexFont ) )	// 0x00200000
4117 		rIn >> maCharLevel[ nLevel ].mnAsianOrComplexFont;
4118 	if ( nCMask & ( 1 << PPT_CharAttr_ANSITypeface ) )			// 0x00400000
4119 		rIn >> nVal16;
4120 	if ( nCMask & ( 1 << PPT_CharAttr_Symbol ) )				// 0x00800000
4121 		rIn >> nVal16;
4122 	if ( nCMask & ( 1 << PPT_CharAttr_FontHeight ) )			// 0x00020000
4123 		rIn >> maCharLevel[ nLevel ].mnFontHeight;
4124 	if ( nCMask & ( 1 << PPT_CharAttr_FontColor ) )				// 0x00040000
4125 	{
4126 		rIn >> maCharLevel[ nLevel ].mnFontColor;
4127 		if( ! (maCharLevel[ nLevel ].mnFontColor & 0xff000000 ) )
4128 			maCharLevel[ nLevel ].mnFontColor = PPT_COLSCHEME_HINTERGRUND;
4129 	}
4130 	if ( nCMask & ( 1 << PPT_CharAttr_Escapement ) )			// 0x00080000
4131 		rIn >> maCharLevel[ nLevel ].mnEscapement;
4132 	if ( nCMask & 0x00100000 )									// 0x00100000
4133 		rIn >> nVal16;
4134 
4135 	nCMask >>= 24;
4136     while( nCMask )
4137 	{
4138 		if ( nCMask & 1 )
4139 		{
4140 		    DBG_ERROR( "PPTCharSheet::Read - unknown attribute, send me this document (SJ)" );
4141 			rIn >> nVal16;
4142 		}
4143 		nCMask >>= 1;
4144 	}
4145 }
4146 
PPTParaSheet(sal_uInt32 nInstance)4147 PPTParaSheet::PPTParaSheet( sal_uInt32 nInstance )
4148 {
4149 	sal_uInt16 nBuFlags = 0;
4150 	sal_uInt32 nBulletColor = 0x8000000;
4151 	sal_uInt16 nUpperDist = 0;
4152 
4153 	switch ( nInstance )
4154 	{
4155 		case TSS_TYPE_PAGETITLE :
4156 		case TSS_TYPE_TITLE :
4157 			nBulletColor = PPT_COLSCHEME_TITELTEXT;
4158 		break;
4159 		case TSS_TYPE_BODY :
4160 		case TSS_TYPE_SUBTITLE :
4161 		case TSS_TYPE_HALFBODY :
4162 		case TSS_TYPE_QUARTERBODY :
4163 		{
4164 			nBuFlags = 1;
4165 			nUpperDist = 0x14;
4166 		}
4167 		break;
4168 		case TSS_TYPE_NOTES :
4169 			nUpperDist = 0x1e;
4170 		break;
4171 /*
4172 		default :
4173 		case TSS_TYPE_UNUSED :
4174 		case TSS_TYPE_TEXT_IN_SHAPE :
4175 		break;
4176 */
4177 	}
4178 	for ( sal_uInt32 i = 0; i < 5; i++ )
4179 	{
4180 		maParaLevel[ i ].mnBuFlags = nBuFlags;
4181 		maParaLevel[ i ].mnBulletChar = 0x2022;
4182 		maParaLevel[ i ].mnBulletFont = 0;
4183 		maParaLevel[ i ].mnBulletHeight = 100;
4184 		maParaLevel[ i ].mnBulletColor = nBulletColor;
4185 		maParaLevel[ i ].mnAdjust = 0;
4186 		maParaLevel[ i ].mnLineFeed = 100;
4187 		maParaLevel[ i ].mnLowerDist = 0;
4188 		maParaLevel[ i ].mnUpperDist = nUpperDist;
4189 		maParaLevel[ i ].mnTextOfs = 0;
4190 		maParaLevel[ i ].mnBulletOfs = 0;
4191 		maParaLevel[ i ].mnDefaultTab = 0x240;
4192         maParaLevel[ i ].mnAsianLineBreak = 0;
4193 		maParaLevel[ i ].mnBiDi = 0;
4194 	}
4195 }
4196 
PPTParaSheet(const PPTParaSheet & rSheet)4197 PPTParaSheet::PPTParaSheet( const PPTParaSheet& rSheet )
4198 {
4199 	*this = rSheet;
4200 }
4201 
Read(SdrPowerPointImport & rManager,SvStream & rIn,sal_Bool,sal_uInt32 nLevel,sal_Bool bFirst)4202 void PPTParaSheet::Read( SdrPowerPointImport&
4203 #ifdef DBG_UTIL
4204 					rManager
4205 #endif
4206 					, SvStream& rIn, sal_Bool /*bMasterStyle*/,
4207                     sal_uInt32 nLevel, sal_Bool bFirst )
4208 {
4209     // Absatzattribute
4210 	sal_uInt16  nVal16, i, nMask16;
4211     sal_uInt32  nVal32, nPMask;
4212 	rIn >> nPMask;
4213 
4214     nMask16 = (sal_uInt16)nPMask & 0xf;
4215 	if ( nMask16 )
4216 	{
4217 		rIn >> nVal16;
4218 		maParaLevel[ nLevel ].mnBuFlags &=~ nMask16;
4219         nVal16 &= nMask16;
4220         maParaLevel[ nLevel ].mnBuFlags |= nVal16;
4221 	}
4222 	if ( nPMask & 0x0080 )
4223         rIn >> maParaLevel[ nLevel ].mnBulletChar;
4224 	if ( nPMask & 0x0010 )
4225         rIn >> maParaLevel[ nLevel ].mnBulletFont;
4226 	if ( nPMask & 0x0040 )
4227 	{
4228 		rIn >> nVal16;
4229 		maParaLevel[ nLevel ].mnBulletHeight = nVal16;
4230 	}
4231 	if ( nPMask & 0x0020 )
4232 	{
4233 		rIn >> nVal32;
4234 		maParaLevel[ nLevel ].mnBulletColor = nVal32;
4235 	}
4236 	if ( bFirst )
4237 	{
4238 		if ( nPMask & 0xF00 )
4239 		{	// AbsJust!
4240 			rIn >> nVal16;
4241 			maParaLevel[ nLevel ].mnAdjust = nVal16 & 3;
4242 		}
4243 		if ( nPMask & 0x1000 )
4244 			rIn >> maParaLevel[ nLevel ].mnLineFeed;
4245 		if ( nPMask & 0x2000 )
4246 			rIn >> maParaLevel[ nLevel ].mnUpperDist;
4247 		if ( nPMask & 0x4000 )
4248 			rIn >> maParaLevel[ nLevel ].mnLowerDist;
4249 		if ( nPMask & 0x8000 )
4250 			rIn >> maParaLevel[ nLevel ].mnTextOfs;
4251 		if ( nPMask & 0x10000 )
4252 			rIn >> maParaLevel[ nLevel ].mnBulletOfs;
4253 		if ( nPMask & 0x20000 )
4254 			rIn >> maParaLevel[ nLevel ].mnDefaultTab;
4255 		if ( nPMask & 0x200000 )
4256 		{
4257 			// number of tabulators
4258 			rIn >> nVal16;
4259 			for ( i = 0; i < nVal16; i++ )
4260 				rIn >> nVal32;		// reading the tabulators
4261 		}
4262 		if ( nPMask & 0x40000 )
4263 			rIn >> nVal16;
4264 		if ( nPMask & 0x80000 )
4265 			rIn >> maParaLevel[ nLevel ].mnAsianLineBreak;
4266 		if ( nPMask & 0x100000 )
4267 			rIn >> maParaLevel[ nLevel ].mnBiDi;
4268 	}
4269 	else
4270 	{
4271 		if ( nPMask & 0x800 )
4272 		{
4273 			rIn >> nVal16;
4274 			maParaLevel[ nLevel ].mnAdjust = nVal16 & 3;
4275 		}
4276 		if ( nPMask & 0x1000 )
4277 			rIn >> maParaLevel[ nLevel ].mnLineFeed;
4278 		if ( nPMask & 0x2000 )
4279 			rIn >> maParaLevel[ nLevel ].mnUpperDist;
4280 		if ( nPMask & 0x4000 )
4281 			rIn >> maParaLevel[ nLevel ].mnLowerDist;
4282 		if ( nPMask & 0x8000 )
4283 			rIn >> nVal16;
4284 		if ( nPMask & 0x100 )
4285 			rIn >> maParaLevel[ nLevel ].mnTextOfs;
4286 		if ( nPMask & 0x200 )
4287 			rIn >> nVal16;
4288 		if ( nPMask & 0x400 )
4289 			rIn >> maParaLevel[ nLevel ].mnBulletOfs;
4290 		if ( nPMask & 0x10000 )
4291 			rIn >> nVal16;
4292         if ( nPMask & 0xe0000 )
4293         {
4294             sal_uInt16 nFlagsToModifyMask = (sal_uInt16)( ( nPMask >> 17 ) & 7 );
4295             rIn >> nVal16;
4296             // bits that are not involved to zero
4297             nVal16 &= nFlagsToModifyMask;
4298             // bits that are to change to zero
4299             maParaLevel[ nLevel ].mnAsianLineBreak &=~nFlagsToModifyMask;
4300             // now set the corresponding bits
4301             maParaLevel[ nLevel ].mnAsianLineBreak |= nVal16;
4302         }
4303 		if ( nPMask & 0x100000 )
4304 		{
4305 			// number of tabulators
4306 			rIn >> nVal16;
4307 			for ( i = 0; i < nVal16; i++ )
4308 				rIn >> nVal32;		// reading the tabulators
4309 		}
4310         if ( nPMask & 0x200000 )
4311             rIn >> maParaLevel[ nLevel ].mnBiDi;		// #88602#
4312 	}
4313 
4314     nPMask >>= 22;
4315     while( nPMask )
4316 	{
4317 		if ( nPMask & 1 )
4318 		{
4319 #ifdef DBG_UTIL
4320             if (!(rManager.rImportParam.nImportFlags & PPT_IMPORTFLAGS_NO_TEXT_ASSERT))
4321             {
4322 		    	DBG_ERROR( "PPTParaSheet::Read - unknown attribute, send me this document (SJ)" );
4323             }
4324 #endif
4325 			rIn >> nVal16;
4326 		}
4327 		nPMask >>= 1;
4328 	}
4329 }
4330 
UpdateBulletRelSize(sal_uInt32 nLevel,sal_uInt16 nFontHeight)4331 void PPTParaSheet::UpdateBulletRelSize(  sal_uInt32 nLevel, sal_uInt16 nFontHeight )
4332 {
4333 	if ( maParaLevel[ nLevel ].mnBulletHeight > 0x7fff ) // a negative value is the absolute bullet height
4334 	{
4335 		sal_Int16  nBulletRelSize = ( sal_Int16 )maParaLevel[ nLevel ].mnBulletHeight;
4336 		nBulletRelSize = nFontHeight ? ((-nBulletRelSize) * 100 ) / nFontHeight : 100;
4337 		if ( nBulletRelSize < 0 ) //bullet size over flow
4338 			nBulletRelSize = 100;
4339 		maParaLevel[ nLevel ].mnBulletHeight = nBulletRelSize;
4340 	}
4341 }
4342 
PPTStyleSheet(const DffRecordHeader & rSlideHd,SvStream & rIn,SdrPowerPointImport & rManager,const PPTTextCharacterStyleAtomInterpreter &,const PPTTextParagraphStyleAtomInterpreter & rTxPFStyle,const PPTTextSpecInfo & rTextSpecInfo)4343 PPTStyleSheet::PPTStyleSheet( const DffRecordHeader& rSlideHd, SvStream& rIn, SdrPowerPointImport& rManager,
4344                                 const PPTTextCharacterStyleAtomInterpreter& /*rTxCFStyle*/, const PPTTextParagraphStyleAtomInterpreter& rTxPFStyle,
4345 									const PPTTextSpecInfo& rTextSpecInfo ) :
4346 
4347 	PPTNumberFormatCreator  ( new PPTExtParaProv( rManager, rIn, &rSlideHd ) ),
4348 	maTxSI	                ( rTextSpecInfo )
4349 {
4350 	sal_uInt32 i;
4351 	sal_uInt32 nOldFilePos = rIn.Tell();
4352 
4353 	// default stylesheets
4354 	mpCharSheet[ TSS_TYPE_PAGETITLE ] = new PPTCharSheet( TSS_TYPE_PAGETITLE );
4355 	mpCharSheet[ TSS_TYPE_BODY ] = new PPTCharSheet( TSS_TYPE_BODY );
4356 	mpCharSheet[ TSS_TYPE_NOTES ] = new PPTCharSheet(  TSS_TYPE_NOTES );
4357 	mpCharSheet[ TSS_TYPE_UNUSED ] = new PPTCharSheet( TSS_TYPE_UNUSED );	// this entry is not used by ppt
4358 	mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ] = new PPTCharSheet( TSS_TYPE_TEXT_IN_SHAPE );
4359 	mpParaSheet[ TSS_TYPE_PAGETITLE ] = new PPTParaSheet( TSS_TYPE_PAGETITLE );
4360 	mpParaSheet[ TSS_TYPE_BODY ] = new PPTParaSheet( TSS_TYPE_BODY );
4361 	mpParaSheet[ TSS_TYPE_NOTES ] = new PPTParaSheet( TSS_TYPE_NOTES );
4362 	mpParaSheet[ TSS_TYPE_UNUSED ] = new PPTParaSheet( TSS_TYPE_UNUSED );
4363 	mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ] = new PPTParaSheet( TSS_TYPE_TEXT_IN_SHAPE );
4364 	mpCharSheet[ TSS_TYPE_QUARTERBODY ] = mpCharSheet[ TSS_TYPE_HALFBODY ] = mpCharSheet[ TSS_TYPE_TITLE ] = mpCharSheet[ TSS_TYPE_SUBTITLE ] = NULL;
4365 	mpParaSheet[ TSS_TYPE_QUARTERBODY ] = mpParaSheet[ TSS_TYPE_HALFBODY ] = mpParaSheet[ TSS_TYPE_TITLE ] = mpParaSheet[ TSS_TYPE_SUBTITLE ] = NULL;
4366 
4367 	/* SJ: try to locate the txMasterStyleAtom in the Environment
4368 
4369 	   it seems that the environment TextStyle is having a higher priority
4370 	   than the TextStyle that can be found within the master page
4371 	*/
4372 	sal_Bool bFoundTxMasterStyleAtom04 = sal_False;
4373 	DffRecordHeader* pEnvHeader = rManager.aDocRecManager.GetRecordHeader( PPT_PST_Environment );
4374 	if ( pEnvHeader )
4375 	{
4376 		pEnvHeader->SeekToContent( rIn );
4377 		DffRecordHeader aTxMasterStyleHd;
4378 		while ( rIn.Tell() < pEnvHeader->GetRecEndFilePos() )
4379 		{
4380 			rIn >> aTxMasterStyleHd;
4381 			if ( aTxMasterStyleHd.nRecType == PPT_PST_TxMasterStyleAtom )
4382 			{
4383 				sal_uInt16 nLevelAnz;
4384 				rIn >> nLevelAnz;
4385 
4386 				if (nLevelAnz > 5)
4387 				{
4388 					throw std::range_error("Bad input file, Too many stylesheet levels");
4389 				}
4390 
4391 				sal_uInt16 nLev = 0;
4392 				sal_Bool bFirst = sal_True;
4393 				bFoundTxMasterStyleAtom04 = sal_True;
4394 				while ( rIn.GetError() == 0 && rIn.Tell() < aTxMasterStyleHd.GetRecEndFilePos() && nLev < nLevelAnz )
4395 				{
4396 					if ( nLev )
4397 					{
4398 						mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ nLev ] = mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ nLev - 1 ];
4399 						mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev ] = mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev - 1 ];
4400 					}
4401 					mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->Read( rManager, rIn, sal_True, nLev, bFirst );
4402                     if ( !nLev )
4403                     {
4404                         // set paragraph defaults for instance 4 (TSS_TYPE_TEXT_IN_SHAPE)
4405                         if ( rTxPFStyle.bValid )
4406                         {
4407                             PPTParaLevel& rParaLevel = mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ 0 ];
4408                             rParaLevel.mnAsianLineBreak = 0;
4409                             if ( rTxPFStyle.bForbiddenRules )
4410                                 rParaLevel.mnAsianLineBreak |= 1;
4411                             if ( !rTxPFStyle.bLatinTextWrap )
4412                                 rParaLevel.mnAsianLineBreak |= 2;
4413                             if ( rTxPFStyle.bHangingPunctuation )
4414                                 rParaLevel.mnAsianLineBreak |= 4;
4415                         }
4416                     }
4417 					mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->Read( rIn, sal_True, nLev, bFirst );
4418 					mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->UpdateBulletRelSize(  nLev, mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev ].mnFontHeight );
4419 					bFirst = sal_False;
4420 					nLev++;
4421 				}
4422 				break;
4423 			}
4424 			else
4425 				aTxMasterStyleHd.SeekToEndOfRecord( rIn );
4426 		}
4427 	}
4428 
4429 	rSlideHd.SeekToContent( rIn );
4430 	DffRecordHeader aTxMasterStyleHd;
4431 	while ( rIn.Tell() < rSlideHd.GetRecEndFilePos() )
4432 	{
4433 		rIn >> aTxMasterStyleHd;
4434 		if ( aTxMasterStyleHd.nRecType == PPT_PST_TxMasterStyleAtom )
4435 			break;
4436 		else
4437 			aTxMasterStyleHd.SeekToEndOfRecord( rIn );
4438 	}
4439 	while ( ( aTxMasterStyleHd.nRecType == PPT_PST_TxMasterStyleAtom ) && ( rIn.Tell() < rSlideHd.GetRecEndFilePos() ) ) //TODO: aTxMasterStyleHd may be used without having been properly initialized
4440 	{
4441 		sal_uInt32 nInstance = aTxMasterStyleHd.nRecInstance;
4442 		if ( ( nInstance < PPT_STYLESHEETENTRYS ) &&
4443 			( ( nInstance != TSS_TYPE_TEXT_IN_SHAPE ) || ( bFoundTxMasterStyleAtom04 == sal_False ) ) )
4444 		{
4445 			if ( nInstance > 4 )
4446 			{
4447 				delete mpCharSheet[ nInstance ];	// be sure to delete the old one if this instance comes twice
4448 				delete mpParaSheet[ nInstance ];
4449 
4450 				switch ( nInstance )
4451 				{
4452 					case TSS_TYPE_SUBTITLE :
4453 					{
4454 						mpCharSheet[ TSS_TYPE_SUBTITLE ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4455 						mpParaSheet[ TSS_TYPE_SUBTITLE ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4456 					}
4457 					break;
4458 					case TSS_TYPE_TITLE :
4459 					{
4460 						mpCharSheet[ TSS_TYPE_TITLE ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_PAGETITLE ] ) );
4461 						mpParaSheet[ TSS_TYPE_TITLE ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_PAGETITLE ] ) );
4462 					}
4463 					break;
4464 					case TSS_TYPE_HALFBODY :
4465 					{
4466 						mpCharSheet[ TSS_TYPE_HALFBODY ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4467 						mpParaSheet[ TSS_TYPE_HALFBODY ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4468 					}
4469 					break;
4470 
4471 					case TSS_TYPE_QUARTERBODY :
4472 					{
4473 						mpCharSheet[ TSS_TYPE_QUARTERBODY ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4474 						mpParaSheet[ TSS_TYPE_QUARTERBODY ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4475 					}
4476 					break;
4477 				}
4478 			}
4479 			sal_uInt16 nLevelAnz;
4480 			rIn >> nLevelAnz;
4481 			if ( nLevelAnz > 5 )
4482 			{
4483 				DBG_ERROR( "PPTStyleSheet::Ppt-TextStylesheet hat mehr als 5 Ebenen! (SJ)" );
4484 				nLevelAnz = 5;
4485 			}
4486 			sal_uInt16	nLev = 0;
4487 			sal_Bool	bFirst = sal_True;
4488 
4489 			while ( rIn.GetError() == 0 && rIn.Tell() < aTxMasterStyleHd.GetRecEndFilePos() && nLev < nLevelAnz )
4490 			{
4491 				if ( nLev && ( nInstance < 5 ) )
4492 				{
4493 					mpParaSheet[ nInstance ]->maParaLevel[ nLev ] = mpParaSheet[ nInstance ]->maParaLevel[ nLev - 1 ];
4494 					mpCharSheet[ nInstance ]->maCharLevel[ nLev ] = mpCharSheet[ nInstance ]->maCharLevel[ nLev - 1 ];
4495 				}
4496 
4497 				// Ausnahme: Vorlage 5, 6 (MasterTitle Titel und SubTitel)
4498 				if ( nInstance >= TSS_TYPE_SUBTITLE )
4499 				{
4500 					bFirst = sal_False;
4501 
4502 					sal_uInt16 nDontKnow;
4503 					rIn >> nDontKnow;
4504 				}
4505 				mpParaSheet[ nInstance ]->Read( rManager, rIn, sal_True, nLev, bFirst );
4506 				mpCharSheet[ nInstance ]->Read( rIn, sal_True, nLev, bFirst );
4507 				mpParaSheet[ nInstance ]->UpdateBulletRelSize(  nLev, mpCharSheet[ nInstance ]->maCharLevel[ nLev ].mnFontHeight );
4508 				bFirst = sal_False;
4509 				nLev++;
4510 			}
4511 #ifdef DBG_UTIL
4512             if (!(rManager.rImportParam.nImportFlags & PPT_IMPORTFLAGS_NO_TEXT_ASSERT))
4513             {
4514 			    if ( rIn.GetError() == 0 )
4515 			    {
4516 				    ByteString aMsg;
4517 				    if ( rIn.Tell() > aTxMasterStyleHd.GetRecEndFilePos() )
4518 				    {
4519 					    aMsg += "\n  ";
4520 					    aMsg += "reading too many bytes:";
4521 					    aMsg += ByteString::CreateFromInt32( rIn.Tell() - aTxMasterStyleHd.GetRecEndFilePos() );
4522 				    }
4523 				    if ( rIn.Tell() < aTxMasterStyleHd.GetRecEndFilePos() )
4524 				    {
4525 					    aMsg += "\n  ";
4526 					    aMsg += "reading too less bytes:";
4527 					    aMsg += ByteString::CreateFromInt32( aTxMasterStyleHd.GetRecEndFilePos() - rIn.Tell() );
4528 				    }
4529 				    if ( aMsg.Len() != 0 )
4530 				    {
4531 					    aMsg.Insert( "]:", 0 );
4532 					    aMsg.Insert( "PptStyleSheet::operator>>[", 0 );
4533 					    DBG_ERROR(aMsg.GetBuffer());
4534 				    }
4535 			    }
4536 			    if ( rIn.Tell() != aTxMasterStyleHd.GetRecEndFilePos() )
4537 				    DBG_ASSERT(0, "SJ: Falsche Anzahl von Bytes gelesen beim Import der PPT-Formatvorlagen");
4538             }
4539 #endif
4540 		}
4541 		aTxMasterStyleHd.SeekToEndOfRecord( rIn );
4542 		rIn >> aTxMasterStyleHd;
4543 	}
4544 	if ( !mpCharSheet[ TSS_TYPE_SUBTITLE ] )
4545 	{
4546 		mpCharSheet[ TSS_TYPE_SUBTITLE ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4547 		mpParaSheet[ TSS_TYPE_SUBTITLE ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4548 	}
4549 	if ( !mpCharSheet[ TSS_TYPE_TITLE ] )
4550 	{
4551 		mpCharSheet[ TSS_TYPE_TITLE ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_PAGETITLE ] ) );
4552 		mpParaSheet[ TSS_TYPE_TITLE ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_PAGETITLE ] ) );
4553 	}
4554 	if ( !mpCharSheet[ TSS_TYPE_HALFBODY ] )
4555 	{
4556 		mpCharSheet[ TSS_TYPE_HALFBODY ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4557 		mpParaSheet[ TSS_TYPE_HALFBODY ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4558 	}
4559 	if ( !mpCharSheet[ TSS_TYPE_QUARTERBODY ] )
4560 	{
4561 		mpCharSheet[ TSS_TYPE_QUARTERBODY ] = new PPTCharSheet( *( mpCharSheet[ TSS_TYPE_BODY ] ) );
4562 		mpParaSheet[ TSS_TYPE_QUARTERBODY ] = new PPTParaSheet( *( mpParaSheet[ TSS_TYPE_BODY ] ) );
4563 	}
4564 	if ( !bFoundTxMasterStyleAtom04 )
4565 	{	// try to locate the txMasterStyleAtom in the Environment
4566 		DffRecordHeader* pEnvHeader2 = rManager.aDocRecManager.GetRecordHeader( PPT_PST_Environment );
4567 		if ( pEnvHeader2 )
4568 		{
4569 			pEnvHeader2->SeekToContent( rIn );
4570 			DffRecordHeader aTxMasterStyleHd2;
4571 			while ( rIn.Tell() < pEnvHeader2->GetRecEndFilePos() )
4572 			{
4573 				rIn >> aTxMasterStyleHd2;
4574 				if ( aTxMasterStyleHd2.nRecType == PPT_PST_TxMasterStyleAtom )
4575 				{
4576 					sal_uInt16 nLevelAnz;
4577 					rIn >> nLevelAnz;
4578 
4579 					sal_uInt16 nLev = 0;
4580 					sal_Bool bFirst = sal_True;
4581 					while ( rIn.GetError() == 0 && rIn.Tell() < aTxMasterStyleHd2.GetRecEndFilePos() && nLev < nLevelAnz )
4582 					{
4583 						if ( nLev )
4584 						{
4585 							mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ nLev ] = mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ nLev - 1 ];
4586 							mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev ] = mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev - 1 ];
4587 						}
4588 						mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->Read( rManager, rIn, sal_True, nLev, bFirst );
4589                         if ( !nLev )
4590                         {
4591                             // set paragraph defaults for instance 4 (TSS_TYPE_TEXT_IN_SHAPE)
4592                             if ( rTxPFStyle.bValid )
4593                             {
4594                                 PPTParaLevel& rParaLevel = mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maParaLevel[ 0 ];
4595                                 rParaLevel.mnAsianLineBreak = 0;
4596                                 if ( rTxPFStyle.bForbiddenRules )
4597                                     rParaLevel.mnAsianLineBreak |= 1;
4598                                 if ( !rTxPFStyle.bLatinTextWrap )
4599                                     rParaLevel.mnAsianLineBreak |= 2;
4600                                 if ( rTxPFStyle.bHangingPunctuation )
4601                                     rParaLevel.mnAsianLineBreak |= 4;
4602                             }
4603                         }
4604 						mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->Read( rIn, sal_True, nLev, bFirst );
4605 						mpParaSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->UpdateBulletRelSize(  nLev, mpCharSheet[ TSS_TYPE_TEXT_IN_SHAPE ]->maCharLevel[ nLev ].mnFontHeight );
4606 						bFirst = sal_False;
4607 						nLev++;
4608 					}
4609 					break;
4610 				}
4611 				else
4612 					aTxMasterStyleHd2.SeekToEndOfRecord( rIn );
4613 			}
4614 		}
4615 	}
4616 	rIn.Seek( nOldFilePos );
4617 
4618 	// will will create the default numbulletitem for each instance
4619 	for ( i = 0; i < PPT_STYLESHEETENTRYS; i++ )
4620 	{
4621 		sal_uInt16			nLevels, nDepth = 0;
4622 		SvxNumRuleType	eNumRuleType;
4623 
4624 		switch ( i )
4625 		{
4626 			case TSS_TYPE_PAGETITLE :
4627 			case TSS_TYPE_TITLE :
4628 				nLevels = 1;
4629 				eNumRuleType = SVX_RULETYPE_NUMBERING;
4630 			break;
4631 			case TSS_TYPE_SUBTITLE :
4632 				nLevels = 10;
4633 				eNumRuleType = SVX_RULETYPE_NUMBERING;
4634 			break;
4635 			case TSS_TYPE_BODY :
4636 			case TSS_TYPE_HALFBODY :
4637 			case TSS_TYPE_QUARTERBODY :
4638 				nLevels = 10;
4639 				eNumRuleType = SVX_RULETYPE_PRESENTATION_NUMBERING;
4640 			break;
4641 			default :
4642 			case TSS_TYPE_NOTES :
4643 			case TSS_TYPE_UNUSED :
4644 			case TSS_TYPE_TEXT_IN_SHAPE :
4645 				nLevels = 10;
4646 				eNumRuleType = SVX_RULETYPE_NUMBERING;
4647 			break;
4648 		}
4649 		SvxNumRule aRule( NUM_BULLET_REL_SIZE | NUM_BULLET_COLOR |
4650 						NUM_CHAR_TEXT_DISTANCE | NUM_SYMBOL_ALIGNMENT,
4651 						nLevels, sal_False, eNumRuleType );
4652 		for ( sal_uInt16 nCount = 0; nDepth < nLevels; nCount++ )
4653 		{
4654 			const PPTParaLevel& rParaLevel = mpParaSheet[ i ]->maParaLevel[ nCount ];
4655 			const PPTCharLevel& rCharLevel = mpCharSheet[ i ]->maCharLevel[ nCount ];
4656 			SvxNumberFormat aNumberFormat( SVX_NUM_CHAR_SPECIAL );
4657 			aNumberFormat.SetBulletChar( ' ' );
4658 			GetNumberFormat( rManager, aNumberFormat, nCount, rParaLevel, rCharLevel, i );
4659 			aRule.SetLevel( nDepth++, aNumberFormat );
4660 			if ( nCount >= 4 )
4661 			{
4662 				for ( ;nDepth < nLevels; nDepth++ )
4663 					aRule.SetLevel( nDepth, aNumberFormat );
4664 				if ( eNumRuleType == SVX_RULETYPE_PRESENTATION_NUMBERING )
4665 					aRule.SetLevel( 0, aNumberFormat );
4666 			}
4667 		}
4668 		mpNumBulletItem[ i ] = new SvxNumBulletItem( aRule, EE_PARA_NUMBULLET );
4669 	}
4670 }
4671 
~PPTStyleSheet()4672 PPTStyleSheet::~PPTStyleSheet()
4673 {
4674 	for ( sal_uInt32 i = 0; i < PPT_STYLESHEETENTRYS; i++ )
4675 	{
4676 		delete mpCharSheet[ i ];
4677 		delete mpParaSheet[ i ];
4678 		delete mpNumBulletItem[ i ];
4679 	}
4680 }
4681 
4682 ////////////////////////////////////////////////////////////////////////////////////////////////////
4683 
PPTParaPropSet()4684 PPTParaPropSet::PPTParaPropSet() :
4685 	pParaSet( new ImplPPTParaPropSet )
4686 {
4687     pParaSet->mnHasAnm = 1;
4688 }
4689 
PPTParaPropSet(PPTParaPropSet & rParaPropSet)4690 PPTParaPropSet::PPTParaPropSet( PPTParaPropSet& rParaPropSet )
4691 {
4692 	pParaSet = rParaPropSet.pParaSet;
4693 	pParaSet->mnRefCount++;
4694 
4695 	mnOriginalTextPos = rParaPropSet.mnOriginalTextPos;
4696 }
4697 
~PPTParaPropSet()4698 PPTParaPropSet::~PPTParaPropSet()
4699 {
4700 	if ( ! ( --pParaSet->mnRefCount ) )
4701 		delete pParaSet;
4702 }
4703 
operator =(PPTParaPropSet & rParaPropSet)4704 PPTParaPropSet& PPTParaPropSet::operator=( PPTParaPropSet& rParaPropSet )
4705 {
4706 	if ( this != &rParaPropSet )
4707 	{
4708 		if ( ! ( --pParaSet->mnRefCount ) )
4709 			delete pParaSet;
4710 		pParaSet = rParaPropSet.pParaSet;
4711 		pParaSet->mnRefCount++;
4712 
4713 		mnOriginalTextPos = rParaPropSet.mnOriginalTextPos;
4714 	}
4715 	return *this;
4716 }
4717 
PPTCharPropSet(sal_uInt32 nParagraph)4718 PPTCharPropSet::PPTCharPropSet( sal_uInt32 nParagraph ) :
4719 	mnParagraph		( nParagraph ),
4720 	mpFieldItem		( NULL ),
4721 	pCharSet		( new ImplPPTCharPropSet )
4722 {
4723 	mnHylinkOrigColor = 0;
4724 	mbIsHyperlink = sal_False;
4725 	mbHardHylinkOrigColor = sal_False;
4726 	mnLanguage[ 0 ] = mnLanguage[ 1 ] = mnLanguage[ 2 ] = 0;
4727 }
4728 
PPTCharPropSet(PPTCharPropSet & rCharPropSet)4729 PPTCharPropSet::PPTCharPropSet( PPTCharPropSet& rCharPropSet )
4730 {
4731 	mnHylinkOrigColor = rCharPropSet.mnHylinkOrigColor;
4732 	mbIsHyperlink = rCharPropSet.mbIsHyperlink;
4733 	mbHardHylinkOrigColor = rCharPropSet.mbHardHylinkOrigColor;
4734 	pCharSet = rCharPropSet.pCharSet;
4735 	pCharSet->mnRefCount++;
4736 
4737 	mnParagraph = rCharPropSet.mnParagraph;
4738 	mnOriginalTextPos = rCharPropSet.mnOriginalTextPos;
4739 	maString = rCharPropSet.maString;
4740 	mpFieldItem = ( rCharPropSet.mpFieldItem ) ? new SvxFieldItem( *rCharPropSet.mpFieldItem ) : NULL;
4741 	mnLanguage[ 0 ] = rCharPropSet.mnLanguage[ 0 ];
4742 	mnLanguage[ 1 ] = rCharPropSet.mnLanguage[ 1 ];
4743 	mnLanguage[ 2 ] = rCharPropSet.mnLanguage[ 2 ];
4744 }
4745 
PPTCharPropSet(PPTCharPropSet & rCharPropSet,sal_uInt32 nParagraph)4746 PPTCharPropSet::PPTCharPropSet( PPTCharPropSet& rCharPropSet, sal_uInt32 nParagraph )
4747 {
4748 	pCharSet = rCharPropSet.pCharSet;
4749 	pCharSet->mnRefCount++;
4750 
4751 	mnHylinkOrigColor = rCharPropSet.mnHylinkOrigColor;
4752 	mbIsHyperlink = rCharPropSet.mbIsHyperlink;
4753 	mbHardHylinkOrigColor = rCharPropSet.mbHardHylinkOrigColor;
4754 
4755 	mnParagraph = nParagraph;
4756 	mnOriginalTextPos = rCharPropSet.mnOriginalTextPos;
4757 	maString = rCharPropSet.maString;
4758 	mpFieldItem = ( rCharPropSet.mpFieldItem ) ? new SvxFieldItem( *rCharPropSet.mpFieldItem ) : NULL;
4759 	mnLanguage[ 0 ] = mnLanguage[ 1 ] = mnLanguage[ 2 ] = 0;
4760 }
4761 
~PPTCharPropSet()4762 PPTCharPropSet::~PPTCharPropSet()
4763 {
4764 	if ( ! ( --pCharSet->mnRefCount ) )
4765 		delete pCharSet;
4766 	delete mpFieldItem;
4767 }
4768 
operator =(PPTCharPropSet & rCharPropSet)4769 PPTCharPropSet& PPTCharPropSet::operator=( PPTCharPropSet& rCharPropSet )
4770 {
4771 	if ( this != &rCharPropSet )
4772 	{
4773 		if ( ! ( --pCharSet->mnRefCount ) )
4774 			delete pCharSet;
4775 		pCharSet = rCharPropSet.pCharSet;
4776 		pCharSet->mnRefCount++;
4777 
4778 		mnOriginalTextPos = rCharPropSet.mnOriginalTextPos;
4779 		mnParagraph = rCharPropSet.mnParagraph;
4780 		maString = rCharPropSet.maString;
4781 		mpFieldItem = ( rCharPropSet.mpFieldItem ) ? new SvxFieldItem( *rCharPropSet.mpFieldItem ) : NULL;
4782 	}
4783 	return *this;
4784 }
4785 
ImplMakeUnique()4786 void PPTCharPropSet::ImplMakeUnique()
4787 {
4788 	if ( pCharSet->mnRefCount > 1 )
4789 	{
4790 		ImplPPTCharPropSet& rOld = *pCharSet;
4791 		rOld.mnRefCount--;
4792 		pCharSet = new ImplPPTCharPropSet( rOld );
4793 		pCharSet->mnRefCount = 1;
4794 	}
4795 }
4796 
SetFont(sal_uInt16 nFont)4797 void PPTCharPropSet::SetFont( sal_uInt16 nFont )
4798 {
4799 	sal_uInt32	nMask = 1 << PPT_CharAttr_Font;
4800 	sal_uInt32	bDoNotMake = pCharSet->mnAttrSet & nMask;
4801 
4802 	if ( bDoNotMake )
4803 		bDoNotMake = nFont == pCharSet->mnFont;
4804 
4805 	if ( !bDoNotMake )
4806 	{
4807 		ImplMakeUnique();
4808 		pCharSet->mnFont = nFont;
4809 		pCharSet->mnAttrSet |= nMask;
4810 	}
4811 }
4812 
SetColor(sal_uInt32 nColor)4813 void PPTCharPropSet::SetColor( sal_uInt32 nColor )
4814 {
4815 	ImplMakeUnique();
4816 	pCharSet->mnColor = nColor;
4817 	pCharSet->mnAttrSet |= 1 << PPT_CharAttr_FontColor;
4818 }
4819 
4820 ////////////////////////////////////////////////////////////////////////////////////////////////////
4821 
PPTRuler()4822 PPTRuler::PPTRuler() :
4823 	nRefCount	( 1 ),
4824 	nFlags		( 0 ),
4825 	pTab		( NULL ),
4826 	nTabCount	( 0 )
4827 {
4828 }
4829 
~PPTRuler()4830 PPTRuler::~PPTRuler()
4831 {
4832 	delete[] pTab;
4833 };
4834 
4835 
PPTTextRulerInterpreter()4836 PPTTextRulerInterpreter::PPTTextRulerInterpreter() :
4837 	mpImplRuler ( new PPTRuler() )
4838 {
4839 }
4840 
PPTTextRulerInterpreter(PPTTextRulerInterpreter & rRuler)4841 PPTTextRulerInterpreter::PPTTextRulerInterpreter( PPTTextRulerInterpreter& rRuler )
4842 {
4843 	mpImplRuler = rRuler.mpImplRuler;
4844 	mpImplRuler->nRefCount++;
4845 }
4846 
PPTTextRulerInterpreter(sal_uInt32 nFileOfs,SdrPowerPointImport & rMan,DffRecordHeader & rHeader,SvStream & rIn)4847 PPTTextRulerInterpreter::PPTTextRulerInterpreter( sal_uInt32 nFileOfs, SdrPowerPointImport& rMan, DffRecordHeader& rHeader, SvStream& rIn ) :
4848 	mpImplRuler	( new PPTRuler() )
4849 {
4850 	if ( nFileOfs != 0xffffffff )
4851 	{
4852 		sal_uInt32 nOldPos = rIn.Tell();
4853 		DffRecordHeader rHd;
4854 		if ( nFileOfs )
4855 		{
4856 			rIn.Seek( nFileOfs );
4857 			rIn >> rHd;
4858 		}
4859 		else
4860 		{
4861 			rHeader.SeekToContent( rIn );
4862 			if ( rMan.SeekToRec( rIn, PPT_PST_TextRulerAtom, rHeader.GetRecEndFilePos(), &rHd ) )
4863 				nFileOfs++;
4864 		}
4865 		if ( nFileOfs )
4866 		{
4867 			sal_Int16	nTCount;
4868 			sal_Int32	i;
4869 			rIn >> mpImplRuler->nFlags;
4870 			if ( mpImplRuler->nFlags & 1 )
4871 				rIn >> mpImplRuler->nDefaultTab;
4872 			if ( mpImplRuler->nFlags & 4 )
4873 			{
4874 				rIn >> nTCount;
4875 				if ( nTCount )
4876 				{
4877 					mpImplRuler->nTabCount = (sal_uInt16)nTCount;
4878 					mpImplRuler->pTab = new PPTTabEntry[ mpImplRuler->nTabCount ];
4879 					for ( i = 0; i < nTCount; i++ )
4880 					{
4881 						rIn >> mpImplRuler->pTab[ i ].nOffset
4882 							>> mpImplRuler->pTab[ i ].nStyle;
4883 					}
4884 				}
4885 			}
4886 			for ( i = 0; i < 5; i++ )
4887 			{
4888 				if ( mpImplRuler->nFlags & ( 8 << i ) )
4889 					rIn >> mpImplRuler->nTextOfs[ i ];
4890 				if ( mpImplRuler->nFlags & ( 256 << i ) )
4891 					rIn >> mpImplRuler->nBulletOfs[ i ];
4892 			}
4893 		}
4894 		rIn.Seek( nOldPos );
4895 	}
4896 }
4897 
GetDefaultTab(sal_uInt32,sal_uInt16 & nValue) const4898 sal_Bool PPTTextRulerInterpreter::GetDefaultTab( sal_uInt32 /*nLevel*/, sal_uInt16& nValue ) const
4899 {
4900 	if ( ! ( mpImplRuler->nFlags & 1 ) )
4901 		return sal_False;
4902 	nValue = mpImplRuler->nDefaultTab;
4903 	return sal_True;
4904 }
4905 
GetTextOfs(sal_uInt32 nLevel,sal_uInt16 & nValue) const4906 sal_Bool PPTTextRulerInterpreter::GetTextOfs( sal_uInt32 nLevel, sal_uInt16& nValue ) const
4907 {
4908 	if ( ! ( ( nLevel < 5 ) && ( mpImplRuler->nFlags & ( 8 << nLevel ) ) ) )
4909 		return sal_False;
4910 	nValue = mpImplRuler->nTextOfs[ nLevel ];
4911 	return sal_True;
4912 }
4913 
GetBulletOfs(sal_uInt32 nLevel,sal_uInt16 & nValue) const4914 sal_Bool PPTTextRulerInterpreter::GetBulletOfs( sal_uInt32 nLevel, sal_uInt16& nValue ) const
4915 {
4916 	if ( ! ( ( nLevel < 5 ) && ( mpImplRuler->nFlags & ( 256 << nLevel ) ) ) )
4917 		return sal_False;
4918 	nValue = mpImplRuler->nBulletOfs[ nLevel ];
4919 	return sal_True;
4920 }
4921 
operator =(PPTTextRulerInterpreter & rRuler)4922 PPTTextRulerInterpreter& PPTTextRulerInterpreter::operator=( PPTTextRulerInterpreter& rRuler )
4923 {
4924 	if ( this != &rRuler )
4925 	{
4926 		if ( ! ( --mpImplRuler->nRefCount ) )
4927 			delete mpImplRuler;
4928 		mpImplRuler = rRuler.mpImplRuler;
4929 		mpImplRuler->nRefCount++;
4930 	}
4931 	return *this;
4932 }
4933 
~PPTTextRulerInterpreter()4934 PPTTextRulerInterpreter::~PPTTextRulerInterpreter()
4935 {
4936 	if ( ! ( --mpImplRuler->nRefCount ) )
4937 		delete mpImplRuler;
4938 }
4939 
4940 ////////////////////////////////////////////////////////////////////////////////////////////////////
4941 
PPTTextCharacterStyleAtomInterpreter()4942 PPTTextCharacterStyleAtomInterpreter::PPTTextCharacterStyleAtomInterpreter() :
4943 	nFlags1	( 0 ),
4944 	nFlags2 ( 0 ),
4945 	nFlags3 ( 0 )
4946 {
4947 }
4948 
Read(SvStream & rIn,const DffRecordHeader & rRecHd)4949 sal_Bool PPTTextCharacterStyleAtomInterpreter::Read( SvStream& rIn, const DffRecordHeader& rRecHd )
4950 {
4951     rRecHd.SeekToContent( rIn );
4952 
4953     rIn >> nFlags1
4954 		>> nFlags2
4955 		>> nFlags3
4956 		>> n1
4957 		>> nFontHeight
4958 		>> nFontColor;
4959 
4960 	return sal_True;
4961 }
4962 
~PPTTextCharacterStyleAtomInterpreter()4963 PPTTextCharacterStyleAtomInterpreter::~PPTTextCharacterStyleAtomInterpreter()
4964 {
4965 }
4966 
4967 ////////////////////////////////////////////////////////////////////////////////////////////////////
PPTTextParagraphStyleAtomInterpreter()4968 PPTTextParagraphStyleAtomInterpreter::PPTTextParagraphStyleAtomInterpreter() :
4969     bValid              ( sal_False ),
4970     bForbiddenRules     ( sal_False ),
4971     bHangingPunctuation ( sal_False ),
4972     bLatinTextWrap      ( sal_False )
4973 {
4974 }
4975 
Read(SvStream & rIn,const DffRecordHeader & rRecHd)4976 sal_Bool PPTTextParagraphStyleAtomInterpreter::Read( SvStream& rIn, const DffRecordHeader& rRecHd )
4977 {
4978     bValid = sal_False;
4979     rRecHd.SeekToContent( rIn );
4980     sal_uInt32 nDummy32, nFlags, nRecEndPos = rRecHd.GetRecEndFilePos();
4981     sal_uInt16 nDummy16;
4982 
4983     rIn >> nDummy16
4984         >> nFlags;
4985 
4986     if ( nFlags & 0xf && ( rIn.Tell() < nRecEndPos ) )
4987         rIn >> nDummy16;    // BuFlags
4988     if ( nFlags & 0x80 && ( rIn.Tell() < nRecEndPos ) )
4989 		rIn >> nDummy16;    // BuChar
4990     if ( nFlags & 0x10 && ( rIn.Tell() < nRecEndPos ) )
4991 	    rIn >> nDummy16;    // nBuFont;
4992     if ( nFlags & 0x40 && ( rIn.Tell() < nRecEndPos ) )
4993         rIn >> nDummy16;    // nBuHeight;
4994 	if ( nFlags & 0x0020 && ( rIn.Tell() < nRecEndPos ) )
4995         rIn >> nDummy32;    // nBuColor;
4996 	if ( nFlags & 0x800 && ( rIn.Tell() < nRecEndPos ) )
4997 		rIn >> nDummy16;    // AbsJust!
4998 	if ( nFlags & 0x400 && ( rIn.Tell() < nRecEndPos ) )
4999 		rIn >> nDummy16;
5000 	if ( nFlags & 0x200 && ( rIn.Tell() < nRecEndPos ) )
5001 		rIn >> nDummy16;
5002 	if ( nFlags & 0x100 && ( rIn.Tell() < nRecEndPos ) )
5003 		rIn >> nDummy16;
5004 	if ( nFlags & 0x1000 && ( rIn.Tell() < nRecEndPos ) )
5005 		rIn >> nDummy16;    // LineFeed
5006 	if ( nFlags & 0x2000 && ( rIn.Tell() < nRecEndPos ) )
5007 		rIn >> nDummy16;    // nUpperDist
5008 	if ( nFlags & 0x4000 && ( rIn.Tell() < nRecEndPos ) )
5009 		rIn >> nDummy16;    // nLowerDist
5010 	if ( nFlags & 0x8000 && ( rIn.Tell() < nRecEndPos ) )
5011 		rIn >> nDummy16;
5012 	if ( nFlags & 0x10000 && ( rIn.Tell() < nRecEndPos ) )
5013 		rIn >> nDummy16;
5014 	if ( nFlags & 0xe0000 && ( rIn.Tell() < nRecEndPos ) )
5015     {
5016         rIn >> nDummy16;
5017         if ( nFlags & 0x20000 )
5018             bForbiddenRules = ( nDummy16 & 1 ) == 1;
5019         if ( nFlags & 0x40000 )
5020             bLatinTextWrap = ( nDummy16 & 2 ) == 0;
5021         if ( nFlags & 0x80000 )
5022             bHangingPunctuation = ( nDummy16 & 4 ) == 4;
5023     }
5024     nFlags &=~ 0xfffff;
5025     sal_uInt32 nMask = 0x100000;
5026     while ( nFlags && nMask && ( rIn.Tell() < nRecEndPos ) )
5027     {
5028         if ( nFlags & nMask )
5029         {
5030             rIn >> nDummy16;
5031             nFlags ^= nMask;
5032         }
5033         nMask <<= 1;
5034     }
5035     bValid = rIn.Tell() == nRecEndPos;
5036     return bValid;
5037 }
5038 
~PPTTextParagraphStyleAtomInterpreter()5039 PPTTextParagraphStyleAtomInterpreter::~PPTTextParagraphStyleAtomInterpreter()
5040 {
5041 
5042 }
5043 
5044 ////////////////////////////////////////////////////////////////////////////////////////////////////
5045 
PPTTextSpecInfo(sal_uInt32 _nCharIdx)5046 PPTTextSpecInfo::PPTTextSpecInfo( sal_uInt32 _nCharIdx ) :
5047 	nCharIdx		( _nCharIdx ),
5048 	nDontKnow		( 1 )
5049 {
5050 	nLanguage[ 0 ] = 0x400;
5051 	nLanguage[ 1 ] = 0;
5052 	nLanguage[ 2 ] = 0;
5053 }
5054 
~PPTTextSpecInfo()5055 PPTTextSpecInfo::~PPTTextSpecInfo()
5056 {
5057 }
5058 
PPTTextSpecInfoAtomInterpreter()5059 PPTTextSpecInfoAtomInterpreter::PPTTextSpecInfoAtomInterpreter() :
5060 	bValid	( sal_False )
5061 {
5062 }
5063 
Read(SvStream & rIn,const DffRecordHeader & rRecHd,sal_uInt16 nRecordType,const PPTTextSpecInfo * pTextSpecDefault)5064 sal_Bool PPTTextSpecInfoAtomInterpreter::Read( SvStream& rIn, const DffRecordHeader& rRecHd,
5065 	sal_uInt16 nRecordType, const PPTTextSpecInfo* pTextSpecDefault )
5066 {
5067 	bValid = sal_False;
5068 	sal_uInt32	nCharIdx = 0;
5069 	rRecHd.SeekToContent( rIn );
5070 
5071 	while ( rIn.Tell() < rRecHd.GetRecEndFilePos() )
5072 	{
5073 		sal_uInt32	nCharCount,
5074 					nFlags, i;
5075 
5076 		if ( nRecordType == PPT_PST_TextSpecInfoAtom )
5077 		{
5078 			rIn >> nCharCount;
5079 			nCharIdx += nCharCount;
5080 		}
5081 		rIn >> nFlags;
5082 
5083 		PPTTextSpecInfo* pEntry = new PPTTextSpecInfo( nCharIdx );
5084 		if ( pTextSpecDefault )
5085 		{
5086 			pEntry->nDontKnow = pTextSpecDefault->nDontKnow;
5087 			pEntry->nLanguage[ 0 ] = pTextSpecDefault->nLanguage[ 0 ];
5088 			pEntry->nLanguage[ 1 ] = pTextSpecDefault->nLanguage[ 1 ];
5089 			pEntry->nLanguage[ 2 ] = pTextSpecDefault->nLanguage[ 2 ];
5090 		}
5091 		for ( i = 1; nFlags && i ; i <<= 1 )
5092 		{
5093 			sal_uInt16 nLang = 0;
5094 			switch( nFlags & i )
5095 			{
5096 				case 0 : break;
5097 				case 1 : rIn >> pEntry->nDontKnow; break;
5098 				case 2 : rIn >> nLang; break;
5099 				case 4 : rIn >> nLang; break;
5100 				default :
5101 				{
5102 					rIn.SeekRel( 2 );
5103 				}
5104 			}
5105 			if ( nLang )
5106 			{
5107 // bug119985 2012.06.14
5108 				if (i == 2)
5109 				{
5110 					pEntry->nLanguage[ 0 ] = pEntry->nLanguage[ 1 ] = pEntry->nLanguage[ 2 ] = nLang;
5111 				}
5112 			}
5113 			nFlags &= ~i;
5114 		}
5115 		aList.Insert( pEntry, LIST_APPEND );
5116 	}
5117 	bValid = rIn.Tell() == rRecHd.GetRecEndFilePos();
5118 	return bValid;
5119 }
5120 
~PPTTextSpecInfoAtomInterpreter()5121 PPTTextSpecInfoAtomInterpreter::~PPTTextSpecInfoAtomInterpreter()
5122 {
5123 	void *pPtr;
5124 	for ( pPtr = aList.First(); pPtr; pPtr = aList.Next() )
5125 		delete (PPTTextSpecInfo*)pPtr;
5126 }
5127 
5128 ////////////////////////////////////////////////////////////////////////////////////////////////////
5129 
Read(SvStream & rIn)5130 void StyleTextProp9::Read( SvStream& rIn )
5131 {
5132 	rIn >> mnExtParagraphMask;
5133 	if ( mnExtParagraphMask & 0x800000 )
5134 		rIn >> mnBuBlip;
5135 	if ( mnExtParagraphMask & 0x2000000 )
5136 		rIn >> mnHasAnm;
5137 	if ( mnExtParagraphMask & 0x1000000 )
5138 		rIn >> mnAnmScheme;
5139 	if ( mnExtParagraphMask & 0x4000000 )
5140 		rIn >> mpfPP10Ext;
5141 	rIn >> mnExtCharacterMask;
5142 	if ( mnExtCharacterMask & 0x100000 )
5143 		rIn >> mncfPP10Ext;
5144 	rIn >> mnSpecialInfoMask;
5145 	if ( mnSpecialInfoMask & 0x20 )
5146 		rIn >> mnPP10Ext;
5147 	if ( mnSpecialInfoMask & 0x40 )
5148 		rIn >> mfBidi;
5149 }
5150 
PPTStyleTextPropReader(SvStream & rIn,SdrPowerPointImport & rMan,const DffRecordHeader & rTextHeader,PPTTextRulerInterpreter & rRuler,const DffRecordHeader & rExtParaHd,sal_uInt32 nInstance)5151 PPTStyleTextPropReader::PPTStyleTextPropReader( SvStream& rIn, SdrPowerPointImport& rMan, const DffRecordHeader& rTextHeader,
5152 														PPTTextRulerInterpreter& rRuler, const DffRecordHeader& rExtParaHd, sal_uInt32 nInstance )
5153 {
5154     Init(rIn, rMan, rTextHeader, rRuler, rExtParaHd, nInstance);
5155 }
5156 
ReadParaProps(SvStream & rIn,SdrPowerPointImport & rMan,const DffRecordHeader & rTextHeader,const String & aString,PPTTextRulerInterpreter & rRuler,sal_uInt32 & nCharCount,sal_Bool & bTextPropAtom)5157 void PPTStyleTextPropReader::ReadParaProps( SvStream& rIn, SdrPowerPointImport& rMan, const DffRecordHeader& rTextHeader,
5158                                             const String& aString, PPTTextRulerInterpreter& rRuler,
5159                                             sal_uInt32& nCharCount, sal_Bool& bTextPropAtom )
5160 {
5161     sal_uInt32  nMask = 0; //TODO: nMask initialized here to suppress warning for now, see corresponding TODO below
5162     sal_uInt32  nCharAnzRead = 0;
5163     sal_uInt16  nDummy16;
5164 
5165     sal_uInt16 nStringLen = aString.Len();
5166 
5167     DffRecordHeader aTextHd2;
5168     rTextHeader.SeekToContent( rIn );
5169     if ( rMan.SeekToRec( rIn, PPT_PST_StyleTextPropAtom, rTextHeader.GetRecEndFilePos(), &aTextHd2 ) )
5170         bTextPropAtom = sal_True;
5171     while ( nCharAnzRead <= nStringLen )
5172     {
5173         PPTParaPropSet aParaPropSet;
5174         ImplPPTParaPropSet& aSet = *aParaPropSet.pParaSet;
5175         if ( bTextPropAtom )
5176         {
5177             rIn >> nCharCount
5178                 >> aParaPropSet.pParaSet->mnDepth;	// Einruecktiefe
5179 
5180 			aParaPropSet.pParaSet->mnDepth =		// taking care of about using not more than 9 outliner levels
5181 				std::min(sal_uInt16(8),
5182 					aParaPropSet.pParaSet->mnDepth);
5183 
5184             nCharCount--;
5185 
5186             rIn >> nMask;
5187             aSet.mnAttrSet = nMask & 0x207df7;
5188             sal_uInt16 nBulFlg = 0;
5189             if ( nMask & 0xF )
5190                 rIn >> nBulFlg; // Bullet-HardAttr-Flags
5191             aSet.mpArry[ PPT_ParaAttr_BulletOn    ] = ( nBulFlg & 1 ) ? 1 : 0;
5192             aSet.mpArry[ PPT_ParaAttr_BuHardFont  ] = ( nBulFlg & 2 ) ? 1 : 0;
5193             aSet.mpArry[ PPT_ParaAttr_BuHardColor ] = ( nBulFlg & 4 ) ? 1 : 0;
5194 
5195             if ( nMask & 0x0080 )	// buChar
5196                 rIn >> aSet.mpArry[ PPT_ParaAttr_BulletChar ];
5197             if ( nMask & 0x0010 )	// buTypeface
5198                 rIn >> aSet.mpArry[ PPT_ParaAttr_BulletFont ];
5199             if ( nMask & 0x0040 )	// buSize
5200             {
5201                 rIn >> aSet.mpArry[ PPT_ParaAttr_BulletHeight ];
5202                 if ( ! ( ( nMask & ( 1 << PPT_ParaAttr_BuHardHeight ) )
5203                          && ( nBulFlg & ( 1 << PPT_ParaAttr_BuHardHeight ) ) ) )
5204                     aSet.mnAttrSet ^= 0x40;
5205             }
5206             if ( nMask & 0x0020 )	// buColor
5207             {
5208                 sal_uInt32 nVal32, nHiByte;
5209                 rIn >> nVal32;
5210                 nHiByte = nVal32 >> 24;
5211                 if ( nHiByte <= 8 )
5212                     nVal32 = nHiByte | PPT_COLSCHEME;
5213                 aSet.mnBulletColor = nVal32;
5214             }
5215             if ( nMask & 0x0800 )	// pfAlignment
5216             {
5217                 rIn >> nDummy16;
5218                 aSet.mpArry[ PPT_ParaAttr_Adjust ] = nDummy16 & 3;
5219             }
5220             if ( nMask & 0x1000 )	// pfLineSpacing
5221                 rIn >> aSet.mpArry[ PPT_ParaAttr_LineFeed ];
5222             if ( nMask & 0x2000 )	// pfSpaceBefore
5223                 rIn >> aSet.mpArry[ PPT_ParaAttr_UpperDist ];
5224             if ( nMask & 0x4000 )	// pfSpaceAfter
5225                 rIn >> aSet.mpArry[ PPT_ParaAttr_LowerDist ];
5226             if ( nMask & 0x100 )	// pfLeftMargin
5227             {
5228                 rIn >> aSet.mpArry[ PPT_ParaAttr_TextOfs ];
5229                 aSet.mnAttrSet |= 1 << PPT_ParaAttr_TextOfs;
5230             }
5231             if ( nMask & 0x400 )	// pfIndent
5232             {
5233                 rIn >> aSet.mpArry[ PPT_ParaAttr_BulletOfs ];
5234                 aSet.mnAttrSet |= 1 << PPT_ParaAttr_BulletOfs;
5235             }
5236             if ( nMask & 0x8000 )	// pfDefaultTabSize
5237                 rIn >> nDummy16;
5238             if ( nMask & 0x100000 )	// pfTabStops
5239             {
5240                 sal_uInt16 i, nDistance, nAlignment, nNumberOfTabStops = 0;
5241                 rIn >> nNumberOfTabStops;
5242                 for ( i = 0; i < nNumberOfTabStops; i++ )
5243                 {
5244                     rIn >> nDistance
5245                         >> nAlignment;
5246                 }
5247             }
5248             if ( nMask & 0x10000 )	// pfBaseLine
5249                 rIn >> nDummy16;
5250             if ( nMask & 0xe0000 )	// pfCharWrap, pfWordWrap, pfOverflow
5251             {
5252                 rIn >> nDummy16;
5253                 if ( nMask & 0x20000 )
5254                     aSet.mpArry[ PPT_ParaAttr_AsianLB_1 ] = nDummy16 & 1;
5255                 if ( nMask & 0x40000 )
5256                     aSet.mpArry[ PPT_ParaAttr_AsianLB_2 ] = ( nDummy16 >> 1 ) & 1;
5257                 if ( nMask & 0x80000 )
5258                     aSet.mpArry[ PPT_ParaAttr_AsianLB_3 ] = ( nDummy16 >> 2 ) & 1;
5259                 aSet.mnAttrSet |= ( ( nMask >> 17 ) & 7 ) << PPT_ParaAttr_AsianLB_1;
5260             }
5261             if ( nMask & 0x200000 )	// pfTextDirection
5262                 rIn >> aSet.mpArry[ PPT_ParaAttr_BiDi ];
5263         }
5264         else
5265             nCharCount = nStringLen;
5266 
5267         //if the textofs attr has been read at above, need not to reset.
5268         if ( ( !( aSet.mnAttrSet & 1 << PPT_ParaAttr_TextOfs ) ) && rRuler.GetTextOfs( aParaPropSet.pParaSet->mnDepth, aSet.mpArry[ PPT_ParaAttr_TextOfs ] ) )
5269             aSet.mnAttrSet |= 1 << PPT_ParaAttr_TextOfs;
5270         if ( ( !( aSet.mnAttrSet & 1 << PPT_ParaAttr_BulletOfs ) ) && rRuler.GetBulletOfs( aParaPropSet.pParaSet->mnDepth, aSet.mpArry[ PPT_ParaAttr_BulletOfs ] ) )
5271             aSet.mnAttrSet |= 1 << PPT_ParaAttr_BulletOfs;
5272         if ( rRuler.GetDefaultTab( aParaPropSet.pParaSet->mnDepth, aSet.mpArry[ PPT_ParaAttr_DefaultTab ] ) )
5273             aSet.mnAttrSet |= 1 << PPT_ParaAttr_DefaultTab;
5274 
5275         if ( ( nCharCount > nStringLen ) || ( nStringLen < nCharAnzRead + nCharCount ) )
5276         {
5277             bTextPropAtom = sal_False;
5278             nCharCount = nStringLen - nCharAnzRead;
5279             // please fix the right hand side of
5280             // PPTParaPropSet& PPTParaPropSet::operator=(PPTParaPropSet&),
5281             // it should be a const reference
5282             PPTParaPropSet aTmpPPTParaPropSet;
5283             aParaPropSet = aTmpPPTParaPropSet;
5284             DBG_ERROR( "SJ:PPTStyleTextPropReader::could not get this PPT_PST_StyleTextPropAtom by reading the paragraph attributes" );
5285         }
5286         PPTParaPropSet* pPara = new PPTParaPropSet( aParaPropSet );
5287         pPara->mnOriginalTextPos = nCharAnzRead;
5288         aParaPropList.Insert( pPara, LIST_APPEND );
5289         if ( nCharCount )
5290         {
5291             sal_uInt32	 nCount;
5292             const sal_Unicode* pDat = aString.GetBuffer() + nCharAnzRead;
5293             for ( nCount = 0; nCount < nCharCount; nCount++ )
5294             {
5295                 if ( pDat[ nCount ] == 0xd )
5296                 {
5297                     pPara = new PPTParaPropSet( aParaPropSet );
5298                     pPara->mnOriginalTextPos = nCharAnzRead + nCount + 1;
5299                     aParaPropList.Insert( pPara, LIST_APPEND );
5300                 }
5301             }
5302         }
5303         nCharAnzRead += nCharCount + 1;
5304     }
5305 }
5306 
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)5307 void PPTStyleTextPropReader::ReadCharProps( SvStream& rIn, PPTCharPropSet& aCharPropSet, const String& aString,
5308                                             sal_uInt32& nCharCount, sal_uInt32 nCharAnzRead,
5309                                             sal_Bool& bTextPropAtom, sal_uInt32 nExtParaPos,
5310                                             const std::vector< StyleTextProp9 >& aStyleTextProp9,
5311                                             sal_uInt32& nExtParaFlags, sal_uInt16& nBuBlip,
5312                                             sal_uInt16& nHasAnm, sal_uInt32& nAnmScheme )
5313 {
5314     sal_uInt32  nMask = 0; //TODO: nMask initialized here to suppress warning for now, see corresponding TODO below
5315     sal_uInt16  nDummy16;
5316     sal_Int32   nCharsToRead;
5317     sal_uInt32  nExtParaNibble = 0;
5318 
5319     sal_uInt16 nStringLen = aString.Len();
5320 
5321     rIn >> nDummy16;
5322     nCharCount = nDummy16;
5323     rIn >> nDummy16;
5324     nCharsToRead = nStringLen - ( nCharAnzRead + nCharCount );
5325     if ( nCharsToRead < 0 )
5326     {
5327         nCharCount = nStringLen - nCharAnzRead;
5328         if ( nCharsToRead < -1 )
5329         {
5330             bTextPropAtom = sal_False;
5331             DBG_ERROR( "SJ:PPTStyleTextPropReader::could not get this PPT_PST_StyleTextPropAtom by reading the character attributes" );
5332         }
5333     }
5334     ImplPPTCharPropSet& aSet = *aCharPropSet.pCharSet;
5335 
5336     // character attributes
5337     rIn >> nMask;
5338     if ( (sal_uInt16)nMask )
5339     {
5340         aSet.mnAttrSet |= (sal_uInt16)nMask;
5341         rIn >> aSet.mnFlags;
5342     }
5343     if ( nMask & 0x10000 )	// cfTypeface
5344     {
5345         rIn >> aSet.mnFont;
5346         aSet.mnAttrSet |= 1 << PPT_CharAttr_Font;
5347     }
5348     if ( nMask & 0x200000 )	// cfFEOldTypeface
5349     {
5350         rIn >> aSet.mnAsianOrComplexFont;
5351         aSet.mnAttrSet |= 1 << PPT_CharAttr_AsianOrComplexFont;
5352     }
5353     if ( nMask & 0x400000 )	// cfANSITypeface
5354     {
5355         rIn >> aSet.mnANSITypeface;
5356         aSet.mnAttrSet |= 1 << PPT_CharAttr_ANSITypeface;
5357     }
5358     if ( nMask & 0x800000 )	// cfSymbolTypeface
5359     {
5360         rIn >> aSet.mnSymbolFont;
5361         aSet.mnAttrSet |= 1 << PPT_CharAttr_Symbol;
5362     }
5363     if ( nMask & 0x20000 )	// cfSize
5364     {
5365         rIn >> aSet.mnFontHeight;
5366         aSet.mnAttrSet |= 1 << PPT_CharAttr_FontHeight;
5367     }
5368     if ( nMask & 0x40000 )	// cfColor
5369     {
5370         sal_uInt32 nVal;
5371         rIn >> nVal;
5372         if ( !( nVal & 0xff000000 ) )
5373             nVal = PPT_COLSCHEME_HINTERGRUND;
5374         aSet.mnColor = nVal;
5375         aSet.mnAttrSet |= 1 << PPT_CharAttr_FontColor;
5376     }
5377     if ( nMask & 0x80000 )	// cfPosition
5378     {
5379         rIn >> aSet.mnEscapement;
5380         aSet.mnAttrSet |= 1 << PPT_CharAttr_Escapement;
5381     }
5382     if ( nExtParaPos )
5383     {
5384         sal_uInt32 nExtBuInd = nMask & 0x3c00;
5385         if ( nExtBuInd )
5386             nExtBuInd = ( aSet.mnFlags & 0x3c00 ) >> 10;
5387         if ( nExtBuInd < aStyleTextProp9.size() )
5388         {
5389             if ( nExtParaNibble && ( ( nExtBuInd + nExtParaNibble ) < aStyleTextProp9.size() ) )
5390                 nExtBuInd += nExtParaNibble;
5391 
5392             nExtParaFlags = aStyleTextProp9[ nExtBuInd ].mnExtParagraphMask;
5393             nBuBlip = aStyleTextProp9[ nExtBuInd ].mnBuBlip;
5394             nHasAnm = aStyleTextProp9[ nExtBuInd ].mnHasAnm;
5395             nAnmScheme = aStyleTextProp9[ nExtBuInd ].mnAnmScheme;
5396         }
5397         if ( ( nExtBuInd & 0xf ) == 0xf )
5398             nExtParaNibble += 16;
5399     }
5400 }
5401 
Init(SvStream & rIn,SdrPowerPointImport & rMan,const DffRecordHeader & rTextHeader,PPTTextRulerInterpreter & rRuler,const DffRecordHeader & rExtParaHd,sal_uInt32 nInstance)5402 void PPTStyleTextPropReader::Init( SvStream& rIn, SdrPowerPointImport& rMan, const DffRecordHeader& rTextHeader,
5403                                    PPTTextRulerInterpreter& rRuler, const DffRecordHeader& rExtParaHd, sal_uInt32 nInstance )
5404 {
5405 	sal_uInt32 nMerk = rIn.Tell();
5406 	sal_uInt32 nExtParaPos = ( rExtParaHd.nRecType == PPT_PST_ExtendedParagraphAtom ) ? rExtParaHd.nFilePos + 8 : 0;
5407 
5408 	std::vector< StyleTextProp9 > aStyleTextProp9;
5409 	if ( rExtParaHd.nRecType == PPT_PST_ExtendedParagraphAtom  )
5410 	{
5411 		rIn.Seek( rExtParaHd.nFilePos + 8 );
5412 		while( ( rIn.GetError() == 0 ) && ( rIn.Tell() < rExtParaHd.GetRecEndFilePos() ) )
5413 		{
5414 			aStyleTextProp9.resize( aStyleTextProp9.size() + 1 );
5415 			aStyleTextProp9.back().Read( rIn );
5416 		}
5417 		rIn.Seek( nMerk );
5418 	}
5419 
5420 	String aString;
5421 	DffRecordHeader aTextHd;
5422 	rIn >> aTextHd;
5423 	sal_uInt32 nMaxLen = aTextHd.nRecLen;
5424 	if ( nMaxLen >= 0xFFFF )
5425 		nMaxLen = 0xFFFE;
5426 
5427 	if( aTextHd.nRecType == PPT_PST_TextCharsAtom )
5428 	{
5429 		sal_uInt32 i;
5430 		sal_Unicode nChar,*pBuf = new sal_Unicode[ ( nMaxLen >> 1 ) + 1 ];
5431 		rIn.Read( pBuf, nMaxLen );
5432 		nMaxLen >>= 1;
5433 		pBuf[ nMaxLen ] = 0;
5434 		sal_Unicode* pPtr = pBuf;
5435 #ifdef OSL_BIGENDIAN
5436 		sal_Unicode nTemp;
5437 		for ( i = 0; i < nMaxLen; i++ )
5438 		{
5439 			nTemp = *pPtr;
5440 			*pPtr++ = ( nTemp << 8 ) | ( nTemp >> 8 );
5441 		}
5442 		pPtr = pBuf;
5443 #endif
5444 
5445 		for ( i = 0; i < nMaxLen; pPtr++, i++ )
5446 		{
5447 			nChar = *pPtr;
5448 			if ( !nChar )
5449 				break;
5450 			if ( ( nChar & 0xff00 ) == 0xf000 )			// in this special case we got a symbol
5451 				aSpecMarkerList.Insert( (void*)( i | PPT_SPEC_SYMBOL ), LIST_APPEND );
5452 			else if ( nChar == 0xd )
5453 			{
5454 				if ( nInstance == TSS_TYPE_PAGETITLE )
5455 					*pPtr = 0xb;
5456 				else
5457 					aSpecMarkerList.Insert( (void*)( i | PPT_SPEC_NEWLINE ), LIST_APPEND );
5458 			}
5459 		}
5460 		if ( i )
5461 			aString = String( pBuf, (sal_uInt16)i );
5462 		delete[] pBuf;
5463 	}
5464 	else if( aTextHd.nRecType == PPT_PST_TextBytesAtom )
5465 	{
5466 		sal_Char *pBuf = new sal_Char[ nMaxLen + 1 ];
5467 		pBuf[ nMaxLen ] = 0;
5468 		rIn.Read( pBuf, nMaxLen );
5469 		sal_Char* pPtr = pBuf;
5470 		for (;;)
5471 		{
5472             sal_Char cLo = *pPtr;
5473             if ( cLo == 0 )
5474                 break;
5475 			if ( cLo == 0xd )
5476 			{
5477 				if ( nInstance == TSS_TYPE_PAGETITLE )
5478 					*pPtr = 0xb;
5479 				else
5480 					aSpecMarkerList.Insert( (void*)( (pPtr - pBuf) | PPT_SPEC_NEWLINE ), LIST_APPEND );
5481 			}
5482 			pPtr++;
5483 		}
5484 		xub_StrLen nLen = sal::static_int_cast< xub_StrLen >( pPtr - pBuf );
5485 		if ( nLen )
5486 			aString = String( pBuf, nLen, RTL_TEXTENCODING_MS_1252 );
5487 		delete[] pBuf;
5488 	}
5489     else
5490     {
5491         // no chars, but potentially char/para props?
5492 		sal_uInt32  nCharCount;
5493 		sal_Bool    bTextPropAtom = sal_False;
5494         ReadParaProps( rIn, rMan, rTextHeader, aString, rRuler, nCharCount, bTextPropAtom );
5495 
5496         if ( bTextPropAtom )
5497         {
5498             // yeah, StyleTextProp is there, read it all & push to
5499             // aParaPropList
5500             PPTCharPropSet aCharPropSet(0);
5501             aCharPropSet.mnOriginalTextPos = 0;
5502 
5503             sal_uInt32 nCharAnzRead = 0;
5504 			sal_uInt32 nExtParaFlags = 0, nAnmScheme = 0;
5505 			sal_uInt16 nBuBlip = 0xffff, nHasAnm = 0;
5506             ReadCharProps( rIn, aCharPropSet, aString, nCharCount, nCharAnzRead,
5507                            bTextPropAtom, nExtParaPos, aStyleTextProp9, nExtParaFlags,
5508                            nBuBlip, nHasAnm, nAnmScheme );
5509 
5510             aCharPropList.Insert(
5511                 new PPTCharPropSet( aCharPropSet, 0 ), LIST_APPEND );
5512         }
5513     }
5514 
5515 	if ( aString.Len() )
5516 	{
5517 		sal_uInt32  nCharCount;
5518 		sal_Bool    bTextPropAtom = sal_False;
5519 
5520         ReadParaProps( rIn, rMan, rTextHeader, aString, rRuler, nCharCount, bTextPropAtom );
5521 
5522 		sal_Bool bEmptyParaPossible = sal_True;
5523 		sal_uInt32 nCharAnzRead = 0;
5524 		sal_uInt32 nCurrentPara = 0;
5525 		sal_uInt32 nCurrentSpecMarker = (sal_uInt32)(sal_uIntPtr)aSpecMarkerList.First();
5526 		sal_uInt16 nStringLen = aString.Len();
5527 
5528 		while ( nCharAnzRead < nStringLen )
5529 		{
5530 			sal_uInt32 nExtParaFlags = 0, nLatestParaUpdate = 0xffffffff, nAnmScheme = 0;
5531 			sal_uInt16 nBuBlip = 0xffff, nHasAnm = 0;
5532 
5533 			PPTCharPropSet aCharPropSet( nCurrentPara );
5534 			if ( bTextPropAtom )
5535                 ReadCharProps( rIn, aCharPropSet, aString, nCharCount, nCharAnzRead,
5536                                bTextPropAtom, nExtParaPos, aStyleTextProp9, nExtParaFlags,
5537                                nBuBlip, nHasAnm, nAnmScheme );
5538 			else
5539 				nCharCount = nStringLen;
5540 
5541 			sal_uInt32 nLen;
5542 			while( nCharCount )
5543 			{
5544 				if ( nExtParaPos && ( nLatestParaUpdate != nCurrentPara ) && ( nCurrentPara < aParaPropList.Count() ) )
5545 				{
5546 					PPTParaPropSet* pPropSet = (PPTParaPropSet*)aParaPropList.GetObject( nCurrentPara );
5547 					pPropSet->pParaSet->mnExtParagraphMask = nExtParaFlags;
5548 					if ( nExtParaFlags & 0x800000 )
5549 						pPropSet->pParaSet->mnBuBlip = nBuBlip;
5550 					if ( nExtParaFlags & 0x01000000 )
5551 						pPropSet->pParaSet->mnAnmScheme = nAnmScheme;
5552 					if ( nExtParaFlags & 0x02000000 )
5553 						pPropSet->pParaSet->mnHasAnm = nHasAnm;
5554 					nLatestParaUpdate = nCurrentPara;
5555 				}
5556 				aCharPropSet.mnOriginalTextPos = nCharAnzRead;
5557 				if ( nCurrentSpecMarker &&  ( ( nCurrentSpecMarker & 0xffff ) < ( nCharAnzRead + nCharCount ) ) )
5558 				{
5559 					if ( nCurrentSpecMarker & PPT_SPEC_NEWLINE )
5560 					{
5561 						nLen = ( nCurrentSpecMarker & 0xffff ) - nCharAnzRead;
5562 						if ( nLen )
5563 							aCharPropSet.maString = String( aString, (sal_uInt16)nCharAnzRead, (sal_uInt16)nLen );
5564 						else if ( bEmptyParaPossible )
5565 							aCharPropSet.maString = String();
5566 						if ( nLen || bEmptyParaPossible )
5567 							aCharPropList.Insert( new PPTCharPropSet( aCharPropSet, nCurrentPara ), LIST_APPEND );
5568 						nCurrentPara++;
5569 						nLen++;
5570 						nCharAnzRead += nLen;
5571 						nCharCount -= nLen;
5572 						bEmptyParaPossible = sal_True;
5573 					}
5574 					else if ( nCurrentSpecMarker & PPT_SPEC_SYMBOL )
5575 					{
5576 						if ( ( nCurrentSpecMarker & 0xffff ) != nCharAnzRead )
5577 						{
5578 							nLen = ( nCurrentSpecMarker & 0xffff ) - nCharAnzRead;
5579 							aCharPropSet.maString = String( aString, (sal_uInt16)nCharAnzRead, (sal_uInt16)nLen );
5580 							aCharPropList.Insert( new PPTCharPropSet( aCharPropSet, nCurrentPara ), LIST_APPEND );
5581 							nCharCount -= nLen;
5582 							nCharAnzRead += nLen;
5583 						}
5584 						PPTCharPropSet* pCPropSet = new PPTCharPropSet( aCharPropSet, nCurrentPara );
5585 						pCPropSet->maString = aString.GetChar( (sal_uInt16)nCharAnzRead );
5586                         if ( aCharPropSet.pCharSet->mnAttrSet & ( 1 << PPT_CharAttr_Symbol ) )
5587 						    pCPropSet->SetFont( aCharPropSet.pCharSet->mnSymbolFont );
5588 						aCharPropList.Insert( pCPropSet, LIST_APPEND );
5589 						nCharCount--;
5590 						nCharAnzRead++;
5591 						bEmptyParaPossible = sal_False;
5592 					}
5593 					nCurrentSpecMarker = (sal_uInt32)(sal_uIntPtr)aSpecMarkerList.Next();
5594 				}
5595 				else
5596 				{
5597 					aCharPropSet.maString = String( aString, (sal_uInt16)nCharAnzRead, (sal_uInt16)nCharCount );
5598 					aCharPropList.Insert( new PPTCharPropSet( aCharPropSet, nCurrentPara ), LIST_APPEND );
5599 					nCharAnzRead += nCharCount;
5600 					bEmptyParaPossible = sal_False;
5601 					break;
5602 				}
5603 			}
5604  		}
5605 		if ( aCharPropList.Count() && ( ((PPTCharPropSet*)aCharPropList.Last())->mnParagraph != nCurrentPara ) )
5606 		{
5607 			PPTCharPropSet* pCharPropSet = new PPTCharPropSet( *(PPTCharPropSet*)aCharPropList.Last(), nCurrentPara );
5608 			pCharPropSet->maString = String();
5609 			pCharPropSet->mnOriginalTextPos = nStringLen - 1;
5610 			aCharPropList.Insert( pCharPropSet, LIST_APPEND );
5611 		}
5612 	}
5613 	rIn.Seek( nMerk );
5614 }
5615 
~PPTStyleTextPropReader()5616 PPTStyleTextPropReader::~PPTStyleTextPropReader()
5617 {
5618 	void* pTmp;
5619 	for ( pTmp = aParaPropList.First(); pTmp; pTmp = aParaPropList.Next() )
5620 		delete (PPTParaPropSet*)pTmp;
5621 	for ( pTmp = aCharPropList.First(); pTmp; pTmp = aCharPropList.Next() )
5622 		delete (PPTCharPropSet*)pTmp;
5623 }
5624 
5625 ////////////////////////////////////////////////////////////////////////////////////////////////////
5626 
5627 struct FieldEntry
5628 {
5629 	sal_uInt32	nFieldType;
5630 	sal_uInt32	nFieldStartPos;
5631 	sal_uInt32	nFieldEndPos;
5632 	String	aFieldUrl;
5633 
FieldEntryFieldEntry5634 	FieldEntry( sal_uInt32 nType, sal_uInt32 nStart, sal_uInt32 nEnd )
5635 	{
5636 		nFieldType = nType;
5637 		nFieldStartPos = nStart;
5638 		nFieldEndPos = nEnd;
5639 	}
FieldEntryFieldEntry5640 	FieldEntry( FieldEntry& rFieldEntry )
5641 	{
5642 		nFieldType = rFieldEntry.nFieldType;
5643 		nFieldStartPos = rFieldEntry.nFieldStartPos;
5644 		nFieldEndPos = rFieldEntry.nFieldEndPos;
5645 		aFieldUrl = rFieldEntry.aFieldUrl;
5646 	}
5647 };
5648 
5649 
PPTPortionObj(const PPTStyleSheet & rStyleSheet,sal_uInt32 nInstance,sal_uInt32 nDepth)5650 PPTPortionObj::PPTPortionObj( const PPTStyleSheet& rStyleSheet, sal_uInt32 nInstance, sal_uInt32 nDepth ) :
5651 	PPTCharPropSet	( 0 ),
5652 	mrStyleSheet	( rStyleSheet ),
5653 	mnInstance		( nInstance ),
5654 	mnDepth			( ( nDepth > 4 ) ? 4 : nDepth )
5655 {
5656 }
5657 
PPTPortionObj(PPTCharPropSet & rCharPropSet,const PPTStyleSheet & rStyleSheet,sal_uInt32 nInstance,sal_uInt32 nDepth)5658 PPTPortionObj::PPTPortionObj( PPTCharPropSet& rCharPropSet, const PPTStyleSheet& rStyleSheet, sal_uInt32 nInstance, sal_uInt32 nDepth ) :
5659 	PPTCharPropSet	( rCharPropSet ),
5660 	mrStyleSheet	( rStyleSheet ),
5661 	mnInstance		( nInstance ),
5662 	mnDepth			( nDepth )
5663 {
5664 }
5665 
PPTPortionObj(PPTPortionObj & rPortionObj)5666 PPTPortionObj::PPTPortionObj( PPTPortionObj& rPortionObj ) :
5667 	PPTCharPropSet		( rPortionObj ),
5668 	mrStyleSheet		( rPortionObj.mrStyleSheet ),
5669 	mnInstance			( rPortionObj.mnInstance ),
5670 	mnDepth				( rPortionObj.mnDepth )
5671 {
5672 }
5673 
~PPTPortionObj()5674 PPTPortionObj::~PPTPortionObj()
5675 {
5676 }
5677 
HasTabulator()5678 sal_Bool PPTPortionObj::HasTabulator()
5679 {
5680 	sal_Bool bRetValue =	sal_False;
5681 	sal_Int32			nCount;
5682 	const sal_Unicode*	pPtr = maString.GetBuffer();
5683 	for ( nCount = 0; nCount < maString.Len(); nCount++ )
5684 	{
5685 		if ( pPtr[ nCount ] == 0x9 )
5686 		{
5687 			bRetValue = sal_True;
5688 			break;
5689 		}
5690 
5691 	}
5692 	return bRetValue;
5693 }
5694 
GetAttrib(sal_uInt32 nAttr,sal_uInt32 & nRetValue,sal_uInt32 nDestinationInstance)5695 sal_Bool PPTPortionObj::GetAttrib( sal_uInt32 nAttr, sal_uInt32& nRetValue, sal_uInt32 nDestinationInstance )
5696 {
5697 	sal_uInt32	nMask = 1 << nAttr;
5698 	nRetValue = 0;
5699 
5700 	sal_uInt32 bIsHardAttribute = ( ( pCharSet->mnAttrSet & nMask ) != 0 ) ? 1 : 0;
5701 
5702 	if ( bIsHardAttribute )
5703 	{
5704 		switch ( nAttr )
5705 		{
5706 			case PPT_CharAttr_Bold :
5707 			case PPT_CharAttr_Italic :
5708 			case PPT_CharAttr_Underline :
5709 			case PPT_CharAttr_Shadow :
5710 			case PPT_CharAttr_Strikeout :
5711 			case PPT_CharAttr_Embossed :
5712 				nRetValue = ( pCharSet->mnFlags & nMask ) ? 1 : 0;
5713 			break;
5714 			case PPT_CharAttr_Font :
5715 				nRetValue = pCharSet->mnFont;
5716 			break;
5717 			case PPT_CharAttr_AsianOrComplexFont :
5718 				nRetValue = pCharSet->mnAsianOrComplexFont;
5719 			break;
5720 			case PPT_CharAttr_FontHeight :
5721 				nRetValue = pCharSet->mnFontHeight;
5722 			break;
5723 			case PPT_CharAttr_FontColor :
5724 				nRetValue = pCharSet->mnColor;
5725 			break;
5726 			case PPT_CharAttr_Escapement :
5727 				nRetValue = pCharSet->mnEscapement;
5728 			break;
5729 			default :
5730 				DBG_ERROR( "SJ:PPTPortionObj::GetAttrib ( hard attribute does not exist )" );
5731 		}
5732 	}
5733 	else
5734 	{
5735 		const PPTCharLevel& rCharLevel = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ mnDepth ];
5736 		PPTCharLevel* pCharLevel = NULL;
5737 		if ( ( nDestinationInstance == 0xffffffff )
5738 				|| ( mnDepth && ( ( mnInstance == TSS_TYPE_SUBTITLE ) || ( mnInstance == TSS_TYPE_TEXT_IN_SHAPE ) ) ) )
5739 			bIsHardAttribute = 1;
5740 		else if ( nDestinationInstance != mnInstance )
5741 			pCharLevel = &mrStyleSheet.mpCharSheet[ nDestinationInstance ]->maCharLevel[ mnDepth ];
5742 		switch( nAttr )
5743 		{
5744 			case PPT_CharAttr_Bold :
5745 			case PPT_CharAttr_Italic :
5746 			case PPT_CharAttr_Underline :
5747 			case PPT_CharAttr_Shadow :
5748 			case PPT_CharAttr_Strikeout :
5749 			case PPT_CharAttr_Embossed :
5750 			{
5751 				nRetValue = ( rCharLevel.mnFlags & nMask ) ? 1 : 0;
5752 				if ( pCharLevel )
5753 				{
5754 					sal_uInt32 nTmp = ( pCharLevel->mnFlags & nMask ) ? 1 : 0;
5755 					if ( nRetValue != nTmp )
5756 						bIsHardAttribute = 1;
5757 				}
5758 			}
5759 			break;
5760 			case PPT_CharAttr_Font :
5761 			{
5762 				nRetValue = rCharLevel.mnFont;
5763 				if ( pCharLevel && ( nRetValue != pCharLevel->mnFont ) )
5764 					bIsHardAttribute = 1;
5765 			}
5766 			break;
5767 			case PPT_CharAttr_AsianOrComplexFont :
5768 			{
5769 				nRetValue = rCharLevel.mnAsianOrComplexFont;
5770 				if ( pCharLevel && ( nRetValue != pCharLevel->mnAsianOrComplexFont ) )
5771 					bIsHardAttribute = 1;
5772 			}
5773 			break;
5774 			case PPT_CharAttr_FontHeight :
5775 			{
5776 				nRetValue = rCharLevel.mnFontHeight;
5777 				if ( pCharLevel && ( nRetValue != pCharLevel->mnFontHeight ) )
5778 					bIsHardAttribute = 1;
5779 			}
5780 			break;
5781 			case PPT_CharAttr_FontColor :
5782 			{
5783 				nRetValue = rCharLevel.mnFontColor;
5784 				if ( pCharLevel && ( nRetValue != pCharLevel->mnFontColor ) )
5785 					bIsHardAttribute = 1;
5786 			}
5787 			break;
5788 			case PPT_CharAttr_Escapement :
5789 			{
5790 				nRetValue = rCharLevel.mnEscapement;
5791 				if ( pCharLevel && ( nRetValue != pCharLevel->mnEscapement ) )
5792 					bIsHardAttribute = 1;
5793 			}
5794 			break;
5795 			default :
5796 				DBG_ERROR( "SJ:PPTPortionObj::GetAttrib ( attribute does not exist )" );
5797 		}
5798 	}
5799 	return (sal_Bool)bIsHardAttribute;
5800 }
5801 
ApplyTo(SfxItemSet & rSet,SdrPowerPointImport & rManager,sal_uInt32 nDestinationInstance)5802 void PPTPortionObj::ApplyTo(  SfxItemSet& rSet, SdrPowerPointImport& rManager, sal_uInt32 nDestinationInstance )
5803 {
5804 	ApplyTo( rSet, rManager, nDestinationInstance, NULL );
5805 }
5806 
ApplyTo(SfxItemSet & rSet,SdrPowerPointImport & rManager,sal_uInt32 nDestinationInstance,const PPTTextObj * pTextObj)5807 void PPTPortionObj::ApplyTo(  SfxItemSet& rSet, SdrPowerPointImport& rManager, sal_uInt32 nDestinationInstance, const PPTTextObj* pTextObj )
5808 {
5809 	sal_uInt32	nVal;
5810 	if ( GetAttrib( PPT_CharAttr_Bold, nVal, nDestinationInstance ) )
5811 	{
5812         rSet.Put( SvxWeightItem( nVal != 0 ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
5813 		rSet.Put( SvxWeightItem( nVal != 0 ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
5814 		rSet.Put( SvxWeightItem( nVal != 0 ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
5815 	}
5816 	if ( GetAttrib( PPT_CharAttr_Italic, nVal, nDestinationInstance ) )
5817 	{
5818         rSet.Put( SvxPostureItem( nVal != 0 ? ITALIC_NORMAL : ITALIC_NONE, EE_CHAR_ITALIC ) );
5819 		rSet.Put( SvxPostureItem( nVal != 0 ? ITALIC_NORMAL : ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
5820 		rSet.Put( SvxPostureItem( nVal != 0 ? ITALIC_NORMAL : ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
5821 	}
5822 	if ( GetAttrib( PPT_CharAttr_Underline, nVal, nDestinationInstance ) )
5823         rSet.Put( SvxUnderlineItem( nVal != 0 ? UNDERLINE_SINGLE : UNDERLINE_NONE, EE_CHAR_UNDERLINE ) );
5824 
5825 	if ( GetAttrib( PPT_CharAttr_Shadow, nVal, nDestinationInstance ) )
5826         rSet.Put( SvxShadowedItem( nVal != 0, EE_CHAR_SHADOW ) );
5827 
5828 	if ( GetAttrib( PPT_CharAttr_Strikeout, nVal, nDestinationInstance ) )
5829         rSet.Put( SvxCrossedOutItem( nVal != 0 ? STRIKEOUT_SINGLE : STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ) );
5830 
5831 	sal_uInt32	nAsianFontId = 0xffff;
5832 	if ( GetAttrib( PPT_CharAttr_AsianOrComplexFont, nAsianFontId, nDestinationInstance ) )
5833 	{
5834 		if ( nAsianFontId != 0xffff )
5835 		{
5836 			PptFontEntityAtom* pFontEnityAtom = rManager.GetFontEnityAtom( nAsianFontId );
5837 			if ( pFontEnityAtom )
5838 			{
5839 				rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName,
5840 							String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO_CJK ) );
5841 				rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName,
5842 							String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO_CTL ) );
5843 			}
5844 		}
5845 	}
5846 	if ( GetAttrib( PPT_CharAttr_Font, nVal, nDestinationInstance ) )
5847 	{
5848 		PptFontEntityAtom* pFontEnityAtom = rManager.GetFontEnityAtom( nVal );
5849 		if ( pFontEnityAtom )
5850 		{
5851 			rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName, String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO ) );
5852 
5853             // #119475# bullet font info for CJK and CTL
5854             if ( RTL_TEXTENCODING_SYMBOL ==  pFontEnityAtom->eCharSet )
5855 			{
5856 				rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName, String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO_CJK ) );
5857 				rSet.Put( SvxFontItem( pFontEnityAtom->eFamily, pFontEnityAtom->aName, String(), pFontEnityAtom->ePitch, pFontEnityAtom->eCharSet, EE_CHAR_FONTINFO_CTL ) );
5858 			}
5859 		}
5860 	}
5861 	if ( GetAttrib( PPT_CharAttr_FontHeight, nVal, nDestinationInstance ) )	// Schriftgrad in Point
5862 	{
5863 		sal_uInt32 nHeight = rManager.ScalePoint( nVal );
5864 		rSet.Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT ) );
5865 		rSet.Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CJK ) );
5866 		rSet.Put( SvxFontHeightItem( nHeight, 100, EE_CHAR_FONTHEIGHT_CTL ) );
5867 	}
5868 
5869 	if ( GetAttrib( PPT_CharAttr_Embossed, nVal, nDestinationInstance ) )
5870         rSet.Put( SvxCharReliefItem( nVal != 0 ? RELIEF_EMBOSSED : RELIEF_NONE, EE_CHAR_RELIEF ) );
5871 	if ( nVal )	/* if Embossed is set, the font color depends to the fillstyle/color of the object,
5872 				   if the object has no fillstyle, the font color depends to fillstyle of the background */
5873 	{
5874 		Color aDefColor( COL_BLACK );
5875 		MSO_FillType eFillType = mso_fillSolid;
5876 		if ( rManager.GetPropertyValue( DFF_Prop_fNoFillHitTest ) & 0x10 )
5877 			eFillType = (MSO_FillType)rManager.GetPropertyValue( DFF_Prop_fillType, mso_fillSolid );
5878 		else
5879 			eFillType = mso_fillBackground;
5880 		switch( eFillType )
5881 		{
5882 			case mso_fillShade :
5883 			case mso_fillShadeCenter :
5884 			case mso_fillShadeShape :
5885 			case mso_fillShadeScale :
5886 			case mso_fillShadeTitle :
5887 			case mso_fillSolid :
5888 				aDefColor = rManager.MSO_CLR_ToColor( rManager.GetPropertyValue( DFF_Prop_fillColor ) );
5889 			break;
5890 			case mso_fillPattern :
5891 				aDefColor = rManager.MSO_CLR_ToColor( rManager.GetPropertyValue( DFF_Prop_fillBackColor ) );
5892 			break;
5893 			case mso_fillTexture :
5894 			{
5895 				Graphic aGraf;
5896 				if ( rManager.GetBLIP( rManager.GetPropertyValue( DFF_Prop_fillBlip ), aGraf, NULL ) )
5897 				{
5898 					Bitmap aBmp( aGraf.GetBitmap() );
5899 					Size aSize( aBmp.GetSizePixel() );
5900 					if ( aSize.Width() && aSize.Height() )
5901 					{
5902 						if ( aSize.Width () > 64 )
5903 							aSize.Width () = 64;
5904 						if ( aSize.Height() > 64 )
5905 							aSize.Height() = 64;
5906 
5907 						sal_uLong nRt = 0, nGn = 0, nBl = 0;
5908 						BitmapReadAccess*	pAcc = aBmp.AcquireReadAccess();
5909 						if( pAcc )
5910 						{
5911 							const long nWidth = aSize.Width();
5912 							const long nHeight = aSize.Height();
5913 
5914 							if( pAcc->HasPalette() )
5915 							{
5916 								for( long nY = 0L; nY < nHeight; nY++ )
5917 								{
5918 									for( long nX = 0L; nX < nWidth; nX++ )
5919 									{
5920 										const BitmapColor& rCol = pAcc->GetPaletteColor( pAcc->GetPixelIndex( nY, nX ) );
5921 										nRt+=rCol.GetRed(); nGn+=rCol.GetGreen(); nBl+=rCol.GetBlue();
5922 									}
5923 								}
5924 							}
5925 							else
5926 							{
5927 								for( long nY = 0L; nY < nHeight; nY++ )
5928 								{
5929 									for( long nX = 0L; nX < nWidth; nX++ )
5930 									{
5931 										const BitmapColor aCol( pAcc->GetPixel( nY, nX ) );
5932 										nRt+=aCol.GetRed(); nGn+=aCol.GetGreen(); nBl+=aCol.GetBlue();
5933 									}
5934 								}
5935 							}
5936 							aBmp.ReleaseAccess( pAcc );
5937 							sal_uInt32 nC = ( aSize.Width() * aSize.Height() );
5938 							nRt /= nC;
5939 							nGn /= nC;
5940 							nBl /= nC;
5941 							aDefColor = Color(sal_uInt8( nRt ), sal_uInt8( nGn ),sal_uInt8( nBl ) );
5942 						}
5943 					}
5944 				}
5945 			}
5946 			break;
5947 			case mso_fillBackground	:
5948 			{
5949 				if ( pTextObj )	// the textobject is needed
5950 				{
5951 					const SfxItemSet* pItemSet = pTextObj->GetBackground();
5952 					if ( pItemSet )
5953 					{
5954 						const SfxPoolItem* pFillStyleItem = NULL;
5955 						pItemSet->GetItemState( XATTR_FILLSTYLE, sal_False, &pFillStyleItem );
5956 						if ( pFillStyleItem )
5957 						{
5958 							XFillStyle eFillStyle = ((XFillStyleItem*)pFillStyleItem)->GetValue();
5959 							switch( eFillStyle )
5960 							{
5961 								case XFILL_SOLID :
5962 								{
5963 									const SfxPoolItem* pFillColorItem = NULL;
5964 									pItemSet->GetItemState( XATTR_FILLCOLOR, sal_False, &pFillColorItem );
5965 									if ( pFillColorItem )
5966 										aDefColor = ((XColorItem*)pFillColorItem)->GetColorValue();
5967 								}
5968 								break;
5969 								case XFILL_GRADIENT :
5970 								{
5971 									const SfxPoolItem* pGradientItem = NULL;
5972 									pItemSet->GetItemState( XATTR_FILLGRADIENT, sal_False, &pGradientItem );
5973 									if ( pGradientItem )
5974 										aDefColor = ((XFillGradientItem*)pGradientItem)->GetGradientValue().GetStartColor();
5975 								}
5976 								break;
5977 								case XFILL_HATCH :
5978 								case XFILL_BITMAP :
5979 									aDefColor = Color( COL_WHITE );
5980 								break;
5981 								default: break;
5982 							}
5983 						}
5984 					}
5985 				}
5986 			}
5987 			break;
5988 //			case mso_fillPicture :
5989 			default: break;
5990 		}
5991 		rSet.Put( SvxColorItem( aDefColor, EE_CHAR_COLOR ) );
5992 	}
5993 	else
5994 	{
5995 		if ( GetAttrib( PPT_CharAttr_FontColor, nVal, nDestinationInstance ) )	// Textfarbe (4Byte-Arg)
5996 		{
5997 			Color aCol( rManager.MSO_TEXT_CLR_ToColor( nVal ) );
5998 			rSet.Put( SvxColorItem( aCol, EE_CHAR_COLOR ) );
5999 			if ( nDestinationInstance == 0xffffffff )
6000 				mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ mnDepth ].mnFontColorInStyleSheet = aCol;
6001 		}
6002 		else if ( nVal & 0x0f000000 )	// this is not a hard attribute, but maybe the page has a different colerscheme,
6003 		{								// so that in this case we must use a hard color attribute
6004 			Color	aCol( rManager.MSO_TEXT_CLR_ToColor( nVal ) );
6005 			Color&	aColorInSheet = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ mnDepth ].mnFontColorInStyleSheet;
6006 			if ( aColorInSheet != aCol )
6007 				rSet.Put( SvxColorItem( aCol, EE_CHAR_COLOR ) );
6008 		}
6009 	}
6010 
6011 	if ( GetAttrib( PPT_CharAttr_Escapement, nVal, nDestinationInstance ) )	// Hoch/Tiefstellung in %
6012 	{
6013 		sal_uInt16	nEsc = 0;
6014 		sal_uInt8	nProp = 100;
6015 
6016 		if ( nVal )
6017 		{
6018 			nEsc = (sal_Int16)nVal;
6019 			nProp = DFLT_ESC_PROP;
6020 		}
6021         SvxEscapementItem aItem( nEsc, nProp, EE_CHAR_ESCAPEMENT );
6022 		rSet.Put( aItem );
6023 	}
6024 	if ( mnLanguage[ 0 ] )
6025 		rSet.Put( SvxLanguageItem( mnLanguage[ 0 ], EE_CHAR_LANGUAGE ) );
6026 	if ( mnLanguage[ 1 ] )
6027 		rSet.Put( SvxLanguageItem( mnLanguage[ 1 ], EE_CHAR_LANGUAGE_CJK ) );
6028 	if ( mnLanguage[ 2 ] )
6029 		rSet.Put( SvxLanguageItem( mnLanguage[ 2 ], EE_CHAR_LANGUAGE_CTL ) );
6030 }
6031 
GetTextField()6032 SvxFieldItem* PPTPortionObj::GetTextField()
6033 {
6034 	if ( mpFieldItem )
6035 		return new SvxFieldItem( *mpFieldItem );
6036 	return NULL;
6037 }
6038 
6039 //	-----------------------------------------------------------------------
6040 
PPTParagraphObj(const PPTStyleSheet & rStyleSheet,sal_uInt32 nInstance,sal_uInt16 nDepth)6041 PPTParagraphObj::PPTParagraphObj( const PPTStyleSheet& rStyleSheet, sal_uInt32 nInstance, sal_uInt16 nDepth ) :
6042     PPTNumberFormatCreator  ( NULL ),
6043 	mrStyleSheet		    ( rStyleSheet ),
6044 	mnInstance			    ( nInstance ),
6045 	mbTab				    ( sal_True ),		// style sheets always have to get the right tabulator setting
6046 	mnPortionCount		    ( 0 ),
6047 	mpPortionList		    ( NULL )
6048 {
6049 	if ( nDepth > 4 )
6050 		nDepth = 4;
6051 	pParaSet->mnDepth = nDepth;
6052 }
6053 
PPTParagraphObj(PPTStyleTextPropReader & rPropReader,const PPTStyleSheet & rStyleSheet,sal_uInt32 nInstance,PPTTextRulerInterpreter & rRuler)6054 PPTParagraphObj::PPTParagraphObj( PPTStyleTextPropReader& rPropReader, const PPTStyleSheet& rStyleSheet,
6055 									sal_uInt32 nInstance, PPTTextRulerInterpreter& rRuler ) :
6056 	PPTParaPropSet			( *( (PPTParaPropSet*)rPropReader.aParaPropList.GetCurObject() ) ),
6057     PPTNumberFormatCreator  ( NULL ),
6058 	PPTTextRulerInterpreter	( rRuler ),
6059 	mrStyleSheet			( rStyleSheet ),
6060 	mnInstance				( nInstance ),
6061 	mbTab					( sal_False ),
6062 	mnCurrentObject			( 0 ),
6063 	mnPortionCount			( 0 ),
6064     mpPortionList			( NULL )
6065 {
6066 	sal_uInt32 nCurPos = rPropReader.aCharPropList.GetCurPos();
6067 	PPTCharPropSet* pCharPropSet = (PPTCharPropSet*)rPropReader.aCharPropList.GetCurObject();
6068 	if ( pCharPropSet )
6069 	{
6070 		sal_uInt32 nCurrentParagraph = pCharPropSet->mnParagraph;
6071 		for ( ; pCharPropSet && ( pCharPropSet->mnParagraph == nCurrentParagraph ); pCharPropSet = (PPTCharPropSet*)rPropReader.aCharPropList.Next() )
6072 			mnPortionCount++;	// counting number of portions that are part of this paragraph
6073 		pCharPropSet = (PPTCharPropSet*)rPropReader.aCharPropList.Seek( nCurPos );
6074 
6075 		mpPortionList = new PPTPortionObj*[ mnPortionCount ];
6076 		for ( sal_uInt32 i = 0; i < mnPortionCount; i++ )
6077 		{
6078 			if ( pCharPropSet )
6079 			{
6080                 PPTPortionObj* pPPTPortion = new PPTPortionObj( *pCharPropSet, rStyleSheet, nInstance, pParaSet->mnDepth );
6081 				mpPortionList[ i ] = pPPTPortion;
6082 				if ( !mbTab )
6083 					mbTab = mpPortionList[ i ]->HasTabulator();
6084 			}
6085 			else
6086 			{
6087 				DBG_ERROR( "SJ:PPTParagraphObj::It seems that there are missing some textportions" );
6088 				mpPortionList[ i ] = NULL;
6089 			}
6090 			pCharPropSet = (PPTCharPropSet*)rPropReader.aCharPropList.Next();
6091 		}
6092 	}
6093 }
6094 
~PPTParagraphObj()6095 PPTParagraphObj::~PPTParagraphObj()
6096 {
6097 	ImplClear();
6098 }
6099 
AppendPortion(PPTPortionObj & rPPTPortion)6100 void PPTParagraphObj::AppendPortion( PPTPortionObj& rPPTPortion )
6101 {
6102 	sal_uInt32 i;
6103 	PPTPortionObj** mpOldPortionList = mpPortionList;
6104 	mpPortionList = new PPTPortionObj*[ ++mnPortionCount ];
6105 	for ( i = 0; i < mnPortionCount - 1; i++ )
6106 		mpPortionList[ i ] = mpOldPortionList[ i ];
6107 	delete[] mpOldPortionList;
6108 	mpPortionList[ mnPortionCount - 1 ] = new PPTPortionObj( rPPTPortion );
6109 	if ( !mbTab )
6110 		mbTab = mpPortionList[ mnPortionCount - 1 ]->HasTabulator();
6111 }
6112 
UpdateBulletRelSize(sal_uInt32 & nBulletRelSize) const6113 void PPTParagraphObj::UpdateBulletRelSize( sal_uInt32& nBulletRelSize ) const
6114 {
6115 	if ( nBulletRelSize > 0x7fff )		// a negative value is the absolute bullet height
6116 	{
6117 		sal_uInt16 nFontHeight = 0;
6118 		if ( mpPortionList )
6119 		{
6120 			PPTPortionObj* pPortion = mpPortionList[ 0 ];
6121 			if ( pPortion && ( pPortion->pCharSet->mnAttrSet & ( 1 << PPT_CharAttr_FontHeight ) ) )
6122 				nFontHeight = pPortion->pCharSet->mnFontHeight;
6123 		}
6124 		// if we do not have a hard attributed fontheight, the fontheight is taken from the style
6125 		if ( !nFontHeight )
6126 			nFontHeight = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFontHeight;
6127 		nBulletRelSize = nFontHeight ? ((-((sal_Int16)nBulletRelSize)) * 100 ) / nFontHeight : 100;
6128 	}
6129 }
6130 
GetAttrib(sal_uInt32 nAttr,sal_uInt32 & nRetValue,sal_uInt32 nDestinationInstance)6131 sal_Bool PPTParagraphObj::GetAttrib( sal_uInt32 nAttr, sal_uInt32& nRetValue, sal_uInt32 nDestinationInstance )
6132 {
6133 	sal_uInt32	nMask = 1 << nAttr;
6134 	nRetValue = 0;
6135 
6136 	if ( nAttr > 21 )
6137 	{
6138 		DBG_ERROR( "SJ:PPTParagraphObj::GetAttrib - attribute does not exist" );
6139 		return sal_False;
6140 	}
6141 
6142 	sal_uInt32 bIsHardAttribute = ( ( pParaSet->mnAttrSet & nMask ) != 0 ) ? 1 : 0;
6143 
6144 	if ( bIsHardAttribute )
6145 	{
6146 		if ( nAttr == PPT_ParaAttr_BulletColor )
6147 		{
6148             sal_Bool bHardBulletColor;
6149             if ( pParaSet->mnAttrSet & ( 1 << PPT_ParaAttr_BuHardColor ) )
6150 			    bHardBulletColor = pParaSet->mpArry[ PPT_ParaAttr_BuHardColor ] != 0;
6151             else
6152                 bHardBulletColor = ( mrStyleSheet.mpParaSheet[ mnInstance ]->maParaLevel[ pParaSet->mnDepth ].mnBuFlags
6153                                         & ( 1 << PPT_ParaAttr_BuHardColor ) ) != 0;
6154             if ( bHardBulletColor )
6155 			    nRetValue = pParaSet->mnBulletColor;
6156             else
6157             {
6158 				nRetValue = PPT_COLSCHEME_TEXT_UND_ZEILEN;
6159 				if ( ( nDestinationInstance != 0xffffffff ) && mnPortionCount )
6160 				{
6161 					PPTPortionObj* pPortion = mpPortionList[ 0 ];
6162 					if ( pPortion )
6163 					{
6164 						if ( pPortion->pCharSet->mnAttrSet & ( 1 << PPT_CharAttr_FontColor ) )
6165 							nRetValue = pPortion->pCharSet->mnColor;
6166 						else
6167 							nRetValue = mrStyleSheet.mpCharSheet[ nDestinationInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFontColor;
6168 					}
6169 				}
6170             }
6171 		}
6172 		else if ( nAttr == PPT_ParaAttr_BulletFont )
6173 		{
6174 			sal_Bool bHardBuFont;
6175 			if ( pParaSet->mnAttrSet & ( 1 << PPT_ParaAttr_BuHardFont ) )
6176 				bHardBuFont = pParaSet->mpArry[ PPT_ParaAttr_BuHardFont ] != 0;
6177 			else
6178 				bHardBuFont = ( mrStyleSheet.mpParaSheet[ mnInstance ]->maParaLevel[ pParaSet->mnDepth ].mnBuFlags
6179                                         & ( 1 << PPT_ParaAttr_BuHardFont ) ) != 0;
6180 			if ( bHardBuFont )
6181 				nRetValue = pParaSet->mpArry[ PPT_ParaAttr_BulletFont ];
6182 			else
6183 			{
6184 				// it is the font used which assigned to the first character of the following text
6185 				nRetValue = 0;
6186 				if ( ( nDestinationInstance != 0xffffffff ) && mnPortionCount )
6187 				{
6188 					PPTPortionObj* pPortion = mpPortionList[ 0 ];
6189 					if ( pPortion )
6190 					{
6191 						if ( pPortion->pCharSet->mnAttrSet & ( 1 << PPT_CharAttr_Font ) )
6192 							nRetValue = pPortion->pCharSet->mnFont;
6193 						else
6194 							nRetValue = mrStyleSheet.mpCharSheet[ nDestinationInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFont;
6195 					}
6196 				}
6197 			}
6198 		}
6199 		else
6200 			nRetValue = pParaSet->mpArry[ nAttr ];
6201 	}
6202 	else
6203 	{
6204 		const PPTParaLevel& rParaLevel = mrStyleSheet.mpParaSheet[ mnInstance ]->maParaLevel[ pParaSet->mnDepth ];
6205 
6206 		PPTParaLevel* pParaLevel = NULL;
6207 		if ( ( nDestinationInstance == 0xffffffff )
6208 			|| ( pParaSet->mnDepth && ( ( mnInstance == TSS_TYPE_SUBTITLE ) || ( mnInstance == TSS_TYPE_TEXT_IN_SHAPE ) ) ) )
6209 			bIsHardAttribute = 1;
6210 		else if ( nDestinationInstance != mnInstance )
6211 			pParaLevel = &mrStyleSheet.mpParaSheet[ nDestinationInstance ]->maParaLevel[ pParaSet->mnDepth ];
6212 		switch ( nAttr )
6213 		{
6214 			case PPT_ParaAttr_BulletOn :
6215 			{
6216 				nRetValue = rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BulletOn );
6217 				if ( pParaLevel )
6218 				{
6219 					if ( nRetValue != ( (sal_uInt32)pParaLevel->mnBuFlags & ( 1 << PPT_ParaAttr_BulletOn ) ) )
6220 						bIsHardAttribute = 1;
6221 				}
6222 			}
6223 			break;
6224 			case PPT_ParaAttr_BuHardFont :
6225 			case PPT_ParaAttr_BuHardColor :
6226 			case PPT_ParaAttr_BuHardHeight :
6227 				DBG_ERROR( "SJ:PPTParagraphObj::GetAttrib - this attribute does not make sense" );
6228 			break;
6229 			case PPT_ParaAttr_BulletChar :
6230 			{
6231 				nRetValue = rParaLevel.mnBulletChar;
6232 				if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletChar ) )
6233 					bIsHardAttribute = 1;
6234 			}
6235 			break;
6236 			case PPT_ParaAttr_BulletFont :
6237 			{
6238 				sal_Bool bHardBuFont;
6239 				if ( pParaSet->mnAttrSet & ( 1 << PPT_ParaAttr_BuHardFont ) )
6240 					bHardBuFont = pParaSet->mpArry[ PPT_ParaAttr_BuHardFont ] != 0;
6241 				else
6242                     bHardBuFont = ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BuHardFont ) ) != 0;
6243 				if ( bHardBuFont )
6244 				{
6245 					nRetValue = rParaLevel.mnBulletFont;
6246 					if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletFont ) )
6247 						bIsHardAttribute = 1;
6248 				}
6249 				else
6250 				{
6251 					if ( mnPortionCount )
6252 					{
6253 						PPTPortionObj* pPortion = mpPortionList[ 0 ];
6254 						if ( pPortion )
6255 							bIsHardAttribute = pPortion->GetAttrib( PPT_CharAttr_Font, nRetValue, nDestinationInstance );
6256 					}
6257 					else
6258 					{
6259 						nRetValue = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFont;
6260 						bIsHardAttribute = 1;
6261 					}
6262 				}
6263 			}
6264 			break;
6265 			case PPT_ParaAttr_BulletHeight :
6266 			{
6267 				nRetValue = rParaLevel.mnBulletHeight;
6268 				if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletHeight ) )
6269 					bIsHardAttribute = 1;
6270 			}
6271 			break;
6272 			case PPT_ParaAttr_BulletColor :
6273 			{
6274                 sal_Bool bHardBulletColor;
6275                 if ( pParaSet->mnAttrSet & ( 1 << PPT_ParaAttr_BuHardColor ) )
6276 				    bHardBulletColor = pParaSet->mpArry[ PPT_ParaAttr_BuHardColor ] != 0;
6277                 else
6278                     bHardBulletColor = ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BuHardColor ) ) != 0;
6279                 if ( bHardBulletColor )
6280                 {
6281                     nRetValue = rParaLevel.mnBulletColor;
6282 				    if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletColor ) )
6283 					    bIsHardAttribute = 1;
6284                 }
6285                 else
6286                 {
6287 					if ( mnPortionCount )
6288 					{
6289 						PPTPortionObj* pPortion = mpPortionList[ 0 ];
6290 						if ( pPortion )
6291 						{
6292 							if (pPortion->mbIsHyperlink )
6293 							{
6294 								if( pPortion->mbHardHylinkOrigColor )
6295 									nRetValue = pPortion->mnHylinkOrigColor;
6296 								else
6297 									nRetValue = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFontColor;
6298 								bIsHardAttribute = sal_True;
6299 							}
6300 							else
6301 							{
6302 								bIsHardAttribute = pPortion->GetAttrib( PPT_CharAttr_FontColor, nRetValue, nDestinationInstance );
6303 							}
6304 						}
6305 					}
6306 					else
6307 					{
6308 						nRetValue = mrStyleSheet.mpCharSheet[ mnInstance ]->maCharLevel[ pParaSet->mnDepth ].mnFontColor;
6309 						bIsHardAttribute = 1;
6310 					}
6311                 }
6312 			}
6313 			break;
6314 			case PPT_ParaAttr_Adjust :
6315 			{
6316 				nRetValue = rParaLevel.mnAdjust;
6317 				if ( pParaLevel && ( nRetValue != pParaLevel->mnAdjust ) )
6318 					bIsHardAttribute = 1;
6319 			}
6320 			break;
6321 			case PPT_ParaAttr_LineFeed :
6322 			{
6323 				nRetValue = rParaLevel.mnLineFeed;
6324 				if ( pParaLevel && ( nRetValue != pParaLevel->mnLineFeed ) )
6325 					bIsHardAttribute = 1;
6326 			}
6327 			break;
6328 			case PPT_ParaAttr_UpperDist :
6329 			{
6330 				nRetValue = rParaLevel.mnUpperDist;
6331 				if ( pParaLevel && ( nRetValue != pParaLevel->mnUpperDist ) )
6332 					bIsHardAttribute = 1;
6333 			}
6334 			break;
6335 			case PPT_ParaAttr_LowerDist :
6336 			{
6337 				nRetValue = rParaLevel.mnLowerDist;
6338 				if ( pParaLevel && ( nRetValue != pParaLevel->mnLowerDist ) )
6339 					bIsHardAttribute = 1;
6340 			}
6341 			break;
6342 			case PPT_ParaAttr_TextOfs :
6343 			{
6344 				nRetValue = rParaLevel.mnTextOfs;
6345 				if ( pParaLevel && ( nRetValue != pParaLevel->mnTextOfs ) )
6346 					bIsHardAttribute = 1;
6347 			}
6348 			break;
6349 			case PPT_ParaAttr_BulletOfs :
6350 			{
6351 				nRetValue = rParaLevel.mnBulletOfs;
6352 				if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletOfs ) )
6353 					bIsHardAttribute = 1;
6354 			}
6355 			break;
6356 			case PPT_ParaAttr_DefaultTab :
6357 			{
6358 				nRetValue = rParaLevel.mnDefaultTab;
6359 				if ( pParaLevel && ( nRetValue != pParaLevel->mnBulletOfs ) )
6360 					bIsHardAttribute = 1;
6361 			}
6362             break;
6363             case PPT_ParaAttr_AsianLB_1 :
6364             {
6365                 nRetValue = rParaLevel.mnAsianLineBreak & 1;
6366                 if ( pParaLevel && ( nRetValue != ( (sal_uInt32)pParaLevel->mnAsianLineBreak & 1 ) ) )
6367                     bIsHardAttribute = 1;
6368             }
6369             break;
6370             case PPT_ParaAttr_AsianLB_2 :
6371             {
6372                 nRetValue = ( rParaLevel.mnAsianLineBreak >> 1 ) & 1;
6373                 if ( pParaLevel && ( nRetValue != ( ( (sal_uInt32)pParaLevel->mnAsianLineBreak >> 1 ) & 1 ) ) )
6374                     bIsHardAttribute = 1;
6375             }
6376             break;
6377             case PPT_ParaAttr_AsianLB_3 :
6378             {
6379                 nRetValue = ( rParaLevel.mnAsianLineBreak >> 2 ) & 1;
6380                 if ( pParaLevel && ( nRetValue != ( ( (sal_uInt32)pParaLevel->mnAsianLineBreak >> 2 ) & 1 ) ) )
6381                     bIsHardAttribute = 1;
6382             }
6383             break;
6384 			case PPT_ParaAttr_BiDi :
6385 			{
6386                 nRetValue = rParaLevel.mnBiDi;
6387                 if ( pParaLevel && ( nRetValue != pParaLevel->mnBiDi ) )
6388                     bIsHardAttribute = 1;
6389 			}
6390 			break;
6391 		}
6392 	}
6393 	return (sal_Bool)bIsHardAttribute;
6394 }
6395 
ApplyTo(SfxItemSet & rSet,boost::optional<sal_Int16> & rStartNumbering,SdrPowerPointImport & rManager,sal_uInt32 nDestinationInstance,const PPTParagraphObj *)6396 void PPTParagraphObj::ApplyTo( SfxItemSet& rSet,  boost::optional< sal_Int16 >& rStartNumbering, SdrPowerPointImport& rManager, sal_uInt32 nDestinationInstance, const PPTParagraphObj* /*pPrev*/)
6397 {
6398 	sal_Int16	nVal2;
6399 	sal_uInt32	nVal, nUpperDist, nLowerDist;
6400 	sal_uInt32	nInstance = nDestinationInstance != 0xffffffff ? nDestinationInstance : mnInstance;
6401 
6402 	if ( ( nDestinationInstance != 0xffffffff ) || ( pParaSet->mnDepth <= 1 ) )
6403 	{
6404 		SvxNumBulletItem* pNumBulletItem = mrStyleSheet.mpNumBulletItem[ nInstance ];
6405 		if ( pNumBulletItem )
6406 		{
6407 			SvxNumberFormat aNumberFormat( SVX_NUM_NUMBER_NONE );
6408 			if ( GetNumberFormat( rManager, aNumberFormat, this, nDestinationInstance, rStartNumbering ) )
6409 			{
6410 				if ( aNumberFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE )
6411 				{
6412 					aNumberFormat.SetLSpace( 0 );
6413 					aNumberFormat.SetAbsLSpace( 0 );
6414 					aNumberFormat.SetFirstLineOffset( 0 );
6415 					aNumberFormat.SetCharTextDistance( 0 );
6416 					aNumberFormat.SetFirstLineIndent( 0 );
6417 					aNumberFormat.SetIndentAt( 0 );
6418 				}
6419 				SvxNumBulletItem aNewNumBulletItem( *pNumBulletItem );
6420 				SvxNumRule* pRule = aNewNumBulletItem.GetNumRule();
6421 				if ( pRule )
6422 				{
6423 					pRule->SetLevel( pParaSet->mnDepth, aNumberFormat );
6424 					sal_uInt16 i, n;
6425 					for ( i = 0; i < pRule->GetLevelCount(); i++ )
6426 					{
6427 						if ( i != pParaSet->mnDepth )
6428 						{
6429 							n = i > 4 ? 4 : i;
6430 
6431 							SvxNumberFormat aNumberFormat2( pRule->GetLevel( i ) );
6432 							const PPTParaLevel& rParaLevel = mrStyleSheet.mpParaSheet[ nInstance ]->maParaLevel[ n ];
6433 							const PPTCharLevel& rCharLevel = mrStyleSheet.mpCharSheet[ nInstance ]->maCharLevel[ n ];
6434 							sal_uInt32 nColor;
6435 							if ( rParaLevel.mnBuFlags & ( 1 << PPT_ParaAttr_BuHardColor ) )
6436 								nColor = rParaLevel.mnBulletColor;
6437 							else
6438 								nColor = rCharLevel.mnFontColor;
6439 							aNumberFormat2.SetBulletColor( rManager.MSO_TEXT_CLR_ToColor( nColor ) );
6440 							pRule->SetLevel( i, aNumberFormat2 );
6441 						}
6442 					}
6443 					rSet.Put( aNewNumBulletItem );
6444 				}
6445 			}
6446 		}
6447 	}
6448 
6449 	sal_uInt32 nIsBullet2, _nTextOfs, _nBulletOfs, nHardAttribute = 0;
6450 	GetAttrib( PPT_ParaAttr_BulletOn, nIsBullet2, nDestinationInstance );
6451 	nHardAttribute += GetAttrib( PPT_ParaAttr_TextOfs, _nTextOfs, nDestinationInstance );
6452 	nHardAttribute += GetAttrib( PPT_ParaAttr_BulletOfs, _nBulletOfs, nDestinationInstance );
6453 	if ( !nIsBullet2 )
6454 	{
6455         SvxLRSpaceItem aLRSpaceItem( EE_PARA_LRSPACE );
6456 		sal_uInt16 nAbsLSpace = (sal_uInt16)( ( (sal_uInt32)_nTextOfs * 2540 ) / 576 );
6457 		sal_uInt16 nFirstLineOffset = nAbsLSpace - (sal_uInt16)( ( (sal_uInt32)_nBulletOfs * 2540 ) / 576 );
6458 		aLRSpaceItem.SetLeft( nAbsLSpace );
6459 		aLRSpaceItem.SetTxtFirstLineOfstValue( -nFirstLineOffset );
6460 		rSet.Put( aLRSpaceItem );
6461 	}
6462 	else
6463 	{
6464         SvxLRSpaceItem aLRSpaceItem( EE_PARA_LRSPACE );
6465 		aLRSpaceItem.SetLeft( 0 );
6466 		aLRSpaceItem.SetTxtFirstLineOfstValue( 0 );
6467 		rSet.Put( aLRSpaceItem );
6468 	}
6469 	if ( GetAttrib( PPT_ParaAttr_Adjust, nVal, nDestinationInstance ) )
6470 	{
6471 		if ( nVal <= 3 )
6472 		{	// Absatzausrichtung
6473 			static SvxAdjust __READONLY_DATA aAdj[ 4 ] = { SVX_ADJUST_LEFT, SVX_ADJUST_CENTER, SVX_ADJUST_RIGHT, SVX_ADJUST_BLOCK };
6474             rSet.Put( SvxAdjustItem( aAdj[ nVal ], EE_PARA_JUST ) );
6475 		}
6476 	}
6477 
6478     if ( GetAttrib( PPT_ParaAttr_AsianLB_1, nVal, nDestinationInstance ) )
6479         rSet.Put( SfxBoolItem( EE_PARA_FORBIDDENRULES, nVal != 0 ) );
6480     if ( GetAttrib( PPT_ParaAttr_AsianLB_3, nVal, nDestinationInstance ) )
6481         rSet.Put( SfxBoolItem( EE_PARA_HANGINGPUNCTUATION, nVal != 0 ) );
6482 
6483 	if ( GetAttrib( PPT_ParaAttr_BiDi, nVal, nDestinationInstance ) )
6484 		rSet.Put( SvxFrameDirectionItem( nVal == 1 ? FRMDIR_HORI_RIGHT_TOP : FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
6485 
6486 	// LineSpacing
6487 	PPTPortionObj* pPortion = First();
6488 	sal_Bool bIsHardAttribute = GetAttrib( PPT_ParaAttr_LineFeed, nVal, nDestinationInstance );
6489 	nVal2 = (sal_Int16)nVal;
6490     sal_uInt32 nFont = sal_uInt32();
6491     if ( pPortion && pPortion->GetAttrib( PPT_CharAttr_Font, nFont, nDestinationInstance ) )
6492         bIsHardAttribute = sal_True;
6493 
6494 	if ( bIsHardAttribute )
6495 	{
6496 		if ( pPortion && ( nVal2 > 200 ) )
6497 		{
6498 			sal_uInt32 nFontHeight;
6499 			pPortion->GetAttrib( PPT_CharAttr_FontHeight, nFontHeight, nDestinationInstance );
6500 			nVal2 = -(sal_Int16)( ( nFontHeight * nVal * 8 ) / 100 );
6501 		}
6502 		rSet.Put( SdrTextFixedCellHeightItem( sal_True ), SDRATTR_TEXT_USEFIXEDCELLHEIGHT );
6503 		SvxLineSpacingItem aItem( 200, EE_PARA_SBL );
6504 		if ( nVal2 <= 0 )
6505 		{
6506 			aItem.SetLineHeight( (sal_uInt16)( rManager.ScalePoint( -nVal2 ) / 8 ) );
6507 			aItem.GetLineSpaceRule() = SVX_LINE_SPACE_FIX;
6508 		}
6509 		else
6510 		{
6511             sal_uInt8 nPropLineSpace = (sal_uInt8)nVal2;
6512 			aItem.SetPropLineSpace( nPropLineSpace );
6513 			aItem.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
6514 		}
6515 		rSet.Put( aItem );
6516 	}
6517 
6518 	// Paragraph Spacing
6519 	sal_uInt32 nFontHeight = 0;
6520 	bIsHardAttribute = ( (sal_uInt32)GetAttrib( PPT_ParaAttr_UpperDist, nUpperDist, nDestinationInstance ) +
6521 		(sal_uInt32)GetAttrib( PPT_ParaAttr_LowerDist, nLowerDist, nDestinationInstance ) ) != 0;
6522 	if ( ( nUpperDist > 0 ) || ( nLowerDist > 0 ) )
6523 	{
6524 		if ( mnPortionCount )
6525 		{
6526 			mpPortionList[ mnPortionCount - 1 ]->GetAttrib( PPT_CharAttr_FontHeight, nFontHeight, nDestinationInstance );
6527 			if ( ((sal_Int16)nUpperDist) > 0 )
6528 				nUpperDist = - (sal_Int16)( ( nFontHeight * nUpperDist * 100 ) / 1000 );
6529 			if ( ((sal_Int16)nLowerDist) > 0 )
6530 				nLowerDist = - (sal_Int16)( ( nFontHeight * nLowerDist * 100 ) / 1000 );
6531 		}
6532 		bIsHardAttribute = sal_True;
6533 	}
6534 	if ( bIsHardAttribute )
6535 	{
6536         SvxULSpaceItem aULSpaceItem( EE_PARA_ULSPACE );
6537 		nVal2 = (sal_Int16)nUpperDist;
6538 		if ( nVal2 <= 0 )
6539 			aULSpaceItem.SetUpper( (sal_uInt16)(((sal_uInt32) - nVal2 * 2540 ) / ( 72 * 8 ) ) );
6540 		else
6541 		{
6542 			aULSpaceItem.SetUpperValue( 0 );
6543 			aULSpaceItem.SetPropUpper( (sal_uInt16)nUpperDist == 100 ? 101 : (sal_uInt16)nUpperDist );
6544 		}
6545 		nVal2 = (sal_Int16)nLowerDist;
6546 		if ( nVal2 <= 0 )
6547 			aULSpaceItem.SetLower( (sal_uInt16)(((sal_uInt32) - nVal2 * 2540 ) / ( 72 * 8 ) ) );
6548 		else
6549 		{
6550 			aULSpaceItem.SetLowerValue( 0 );
6551 			aULSpaceItem.SetPropLower( (sal_uInt16)nLowerDist == 100 ? 101 : (sal_uInt16)nLowerDist );
6552 		}
6553 		rSet.Put( aULSpaceItem );
6554 	}
6555 
6556 	if ( mbTab )	// makes it sense to apply tabsettings
6557 	{
6558 		sal_uInt32 i, nDefaultTab, nTab, nTextOfs2 = 0;
6559 		sal_uInt32 nLatestManTab = 0;
6560 		GetAttrib( PPT_ParaAttr_TextOfs, nTextOfs2, nDestinationInstance );
6561 		GetAttrib( PPT_ParaAttr_BulletOfs, nTab, nDestinationInstance );
6562 		GetAttrib( PPT_ParaAttr_BulletOn, i, nDestinationInstance );
6563 		GetAttrib( PPT_ParaAttr_DefaultTab, nDefaultTab, nDestinationInstance );
6564         SvxTabStopItem aTabItem( 0, 0, SVX_TAB_ADJUST_DEFAULT, EE_PARA_TABS );
6565 		if ( GetTabCount() )
6566 		{
6567 			//paragraph offset = MIN(first_line_offset, hanging_offset)
6568 			sal_uInt32 nParaOffset = Min( nTextOfs2, nTab );
6569 			for ( i = 0; i < GetTabCount(); i++ )
6570 			{
6571 				SvxTabAdjust eTabAdjust;
6572 				nTab = GetTabOffsetByIndex( (sal_uInt16)i );
6573 				switch( GetTabStyleByIndex( (sal_uInt16)i ) )
6574 				{
6575 					case 1 :	eTabAdjust = SVX_TAB_ADJUST_CENTER; break;
6576 					case 2 :	eTabAdjust = SVX_TAB_ADJUST_RIGHT; break;
6577 					case 3 :	eTabAdjust = SVX_TAB_ADJUST_DECIMAL; break;
6578 					default :	eTabAdjust = SVX_TAB_ADJUST_LEFT;
6579 				}
6580 				if ( nTab > nParaOffset )//If tab stop greater than paragraph offset
6581 					aTabItem.Insert( SvxTabStop( ( ( (long( nTab - nTextOfs2 )) * 2540 ) / 576 ), eTabAdjust ) );
6582 			}
6583 			nLatestManTab = nTab;
6584 		}
6585 		if ( nIsBullet2 == 0 )
6586 			aTabItem.Insert( SvxTabStop( (sal_uInt16)0 ) );
6587 		if ( nDefaultTab )
6588 		{
6589 			nTab = ( nTextOfs2 > nLatestManTab ) ? nTextOfs2 : nLatestManTab;
6590 			nTab /= nDefaultTab;
6591 			nTab = nDefaultTab * ( 1 + nTab );
6592 			for ( i = 0; ( i < 20 ) && ( nTab < 0x1b00 ); i++ )
6593 			{
6594 				aTabItem.Insert( SvxTabStop( (sal_uInt16)( ( ( nTab - nTextOfs2 ) * 2540 ) / 576 ) ) );
6595 				nTab += nDefaultTab;
6596 			}
6597 		}
6598 		rSet.Put( aTabItem );
6599 	}
6600 }
6601 
GetTextSize()6602 sal_uInt32 PPTParagraphObj::GetTextSize()
6603 {
6604 	sal_uInt32 nCount, nRetValue = 0;
6605 	for ( sal_uInt32 i = 0; i < mnPortionCount; i++ )
6606 	{
6607 		PPTPortionObj* pPortionObj = mpPortionList[ i ];
6608 		nCount = pPortionObj->Count();
6609 		if ( ( !nCount ) && pPortionObj->mpFieldItem )
6610 			nCount++;
6611 		nRetValue += nCount;
6612 	}
6613 	return nRetValue;
6614 }
6615 
First()6616 PPTPortionObj* PPTParagraphObj::First()
6617 {
6618 	mnCurrentObject = 0;
6619 	if ( !mnPortionCount )
6620 		return NULL;
6621 	return mpPortionList[ 0 ];
6622 }
6623 
Next()6624 PPTPortionObj* PPTParagraphObj::Next()
6625 {
6626 	sal_uInt32 i = mnCurrentObject + 1;
6627 	if ( i >= mnPortionCount )
6628 		return NULL;
6629 	mnCurrentObject++;
6630 	return mpPortionList[ i ];
6631 }
6632 
ImplClear()6633 void PPTParagraphObj::ImplClear()
6634 {
6635 	for ( void* pPtr = First(); pPtr; pPtr = Next() )
6636 		delete (PPTPortionObj*)pPtr;
6637 	delete[] mpPortionList;
6638 }
6639 
~PPTFieldEntry()6640 PPTFieldEntry::~PPTFieldEntry()
6641 {
6642 	delete pField1;
6643 	delete pField2;
6644 	delete pString;
6645 };
6646 
GetDateTime(const sal_uInt32 nVal,SvxDateFormat & eDateFormat,SvxTimeFormat & eTimeFormat)6647 void PPTFieldEntry::GetDateTime( const sal_uInt32 nVal, SvxDateFormat& eDateFormat, SvxTimeFormat& eTimeFormat )
6648 {
6649 	eDateFormat = SVXDATEFORMAT_APPDEFAULT;
6650 	eTimeFormat = SVXTIMEFORMAT_APPDEFAULT;
6651 	// ID auswerten
6652 	switch( nVal )
6653 	{
6654 		case 0:
6655 		case 6:
6656 			eDateFormat = SVXDATEFORMAT_A;
6657 		break;
6658 		case 1:
6659 			eDateFormat = SVXDATEFORMAT_F;
6660 		break;
6661 		case 2:
6662 		case 3:
6663 			eDateFormat = SVXDATEFORMAT_D;
6664 		break;
6665 		case 4:
6666 		case 5:
6667 			eDateFormat = SVXDATEFORMAT_C;
6668 		break;
6669 		case 7:
6670 			eDateFormat = SVXDATEFORMAT_A;
6671 		case 9:
6672 			eTimeFormat = SVXTIMEFORMAT_24_HM;
6673 		break;
6674 		case 8:
6675 			eDateFormat = SVXDATEFORMAT_A;
6676 		case 11:
6677 			eTimeFormat = SVXTIMEFORMAT_12_HM;
6678 		break;
6679 		case 10:
6680 			eTimeFormat = SVXTIMEFORMAT_24_HMS;
6681 		break;
6682 		case 12:
6683 			eTimeFormat = SVXTIMEFORMAT_12_HMS;
6684 		break;
6685 	}
6686 }
6687 
SetDateTime(sal_uInt32 nVal)6688 void PPTFieldEntry::SetDateTime( sal_uInt32 nVal )
6689 {
6690 	SvxDateFormat eDateFormat;
6691 	SvxTimeFormat eTimeFormat;
6692 	GetDateTime( nVal, eDateFormat, eTimeFormat );
6693 	if ( eDateFormat != SVXDATEFORMAT_APPDEFAULT )
6694         pField1 = new SvxFieldItem( SvxDateField( Date(), SVXDATETYPE_VAR, eDateFormat ), EE_FEATURE_FIELD );
6695 	if ( eTimeFormat != SVXTIMEFORMAT_APPDEFAULT )
6696 	{
6697         SvxFieldItem* pFieldItem = new SvxFieldItem( SvxExtTimeField( Time(), SVXTIMETYPE_VAR, eTimeFormat ), EE_FEATURE_FIELD );
6698 		if ( pField1 )
6699 			pField2 = pFieldItem;
6700 		else
6701 			pField1 = pFieldItem;
6702 	}
6703 }
6704 
6705 //	-----------------------------------------------------------------------
6706 
PPTTextObj(SvStream & rIn,SdrPowerPointImport & rSdrPowerPointImport,PptSlidePersistEntry & rPersistEntry,DffObjData * pObjData)6707 PPTTextObj::PPTTextObj( SvStream& rIn, SdrPowerPointImport& rSdrPowerPointImport, PptSlidePersistEntry& rPersistEntry, DffObjData* pObjData ) :
6708 	mpImplTextObj	( new ImplPPTTextObj( rPersistEntry ) )
6709 {
6710 	mpImplTextObj->mnRefCount = 1;
6711 	mpImplTextObj->mnShapeId = 0;
6712 	mpImplTextObj->mnShapeMaster = 0;
6713 	mpImplTextObj->mpPlaceHolderAtom = NULL;
6714 	mpImplTextObj->mnDestinationInstance = mpImplTextObj->mnInstance = 4;
6715 	mpImplTextObj->mnCurrentObject = 0;
6716 	mpImplTextObj->mnParagraphCount = 0;
6717 	mpImplTextObj->mpParagraphList = NULL;
6718 	mpImplTextObj->mnTextFlags = 0;
6719 	mpImplTextObj->meShapeType = ( pObjData && pObjData->bShapeType ) ? pObjData->eShapeType : mso_sptMin;
6720 
6721 	DffRecordHeader	aExtParaHd;
6722 	aExtParaHd.nRecType = 0;	// set empty
6723 
6724 	sal_uInt32 bStatus = sal_True;
6725 
6726 	DffRecordHeader aShapeContainerHd;
6727 	rIn >> aShapeContainerHd;
6728 
6729 	if ( ( pObjData == NULL ) || ( pObjData->bShapeType ) )
6730 	{
6731         PPTExtParaProv* pExtParaProv = rSdrPowerPointImport.pPPTStyleSheet->pExtParaProv;
6732 		if ( pObjData )
6733 		{
6734 			mpImplTextObj->mnShapeId = pObjData->nShapeId;
6735 			if ( pObjData->nSpFlags & SP_FHAVEMASTER )
6736 				mpImplTextObj->mnShapeMaster = rSdrPowerPointImport.GetPropertyValue( DFF_Prop_hspMaster, 0 );
6737 		}
6738 		////////////////
6739 		// ClientData //
6740 		////////////////
6741 		if ( rSdrPowerPointImport.maShapeRecords.SeekToContent( rIn, DFF_msofbtClientData, SEEK_FROM_CURRENT_AND_RESTART ) )
6742 		{
6743 			sal_uInt32 nOldPos = rIn.Tell();
6744 			DffRecordHeader& aClientDataContainerHd = *rSdrPowerPointImport.maShapeRecords.Current();
6745 			DffRecordHeader aPlaceHolderAtomHd;
6746             if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_OEPlaceholderAtom, aClientDataContainerHd.GetRecEndFilePos(), &aPlaceHolderAtomHd ) )
6747 			{
6748 				mpImplTextObj->mpPlaceHolderAtom = new PptOEPlaceholderAtom;
6749                 rIn >> *( mpImplTextObj->mpPlaceHolderAtom );
6750             }
6751 			rIn.Seek( nOldPos );
6752 			DffRecordHeader aProgTagHd;
6753             if ( rSdrPowerPointImport.SeekToContentOfProgTag( 9, rIn, aClientDataContainerHd, aProgTagHd ) )
6754             {
6755                 rIn >> aExtParaHd;
6756             }
6757 		}
6758 
6759 		///////////////////
6760 		// ClientTextBox //
6761 		///////////////////
6762 		if ( rSdrPowerPointImport.maShapeRecords.SeekToContent( rIn, DFF_msofbtClientTextbox, SEEK_FROM_CURRENT_AND_RESTART ) )
6763 		{
6764 			DffRecordHeader aClientTextBoxHd( *rSdrPowerPointImport.maShapeRecords.Current() );
6765 			sal_uInt32	nTextRulerAtomOfs = 0;	// case of zero -> this atom may be found in aClientDataContainerHd;
6766 											// case of -1 -> ther is no atom of this kind
6767 											// else -> this is the fileofs where we can get it
6768 
6769 			//////////////////////////////////////
6770 			// checkout if this is a referenced //
6771 			// textobj, if so the we will patch //
6772 			// the ClientTextBoxHd for a        //
6773 			// equivalent one					//
6774 			//////////////////////////////////////
6775 			DffRecordHeader aTextHd;
6776 			if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_OutlineTextRefAtom, aClientTextBoxHd.GetRecEndFilePos(), &aTextHd ) )
6777 			{
6778 				sal_uInt32 nRefNum;
6779 				rIn >> nRefNum;
6780 
6781 				if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_TextRulerAtom, aClientTextBoxHd.GetRecEndFilePos() ) )
6782 					nTextRulerAtomOfs = rIn.Tell();
6783 				else
6784 					nTextRulerAtomOfs = 0xffffffff;
6785 
6786 				sal_uInt32 nInstance = 0;
6787 				switch( rSdrPowerPointImport.eAktPageKind )
6788 				{
6789 					case PPT_NOTEPAGE :
6790 						nInstance++;
6791 					case PPT_MASTERPAGE :
6792 						nInstance++;
6793 					case PPT_SLIDEPAGE :
6794 					break;
6795 					default :
6796 						bStatus = sal_False;
6797 				}
6798 				if ( bStatus )
6799 				{
6800 					sal_uInt32 nSlideId = rSdrPowerPointImport.GetAktPageId();
6801 					if ( !nSlideId )
6802 						bStatus = sal_False;
6803 					else
6804 					{
6805 						if ( !aExtParaHd.nRecType )
6806 						{
6807 							sal_uInt32 nOldPos = rIn.Tell();
6808 							// try to locate the referenced ExtendedParaHd
6809 							DffRecordHeader* pHd = pExtParaProv->
6810 														aExtendedPresRules.GetRecordHeader( PPT_PST_ExtendedParagraphHeaderAtom,
6811 																							SEEK_FROM_CURRENT_AND_RESTART );
6812 							DffRecordHeader		aPresRuleHd;
6813 							DffRecordHeader*	pFirst = pHd;
6814 
6815 							sal_uInt32	nTmpSlideId, nTmpRef;
6816 							while ( pHd )
6817 							{
6818 								pHd->SeekToContent( rIn );
6819 								rIn >> nTmpSlideId
6820 									>> nTmpRef;			// this seems to be the instance
6821 
6822 								if ( ( nTmpSlideId == nSlideId ) && ( pHd->nRecInstance == nRefNum ) )
6823 								{
6824 									pHd->SeekToEndOfRecord( rIn );
6825 									rIn >> aPresRuleHd;
6826 									if ( aPresRuleHd.nRecType == PPT_PST_ExtendedParagraphAtom )
6827 									{
6828 										aExtParaHd = aPresRuleHd;
6829 										break;
6830 									}
6831 								}
6832 								pHd = pExtParaProv->
6833 										aExtendedPresRules.GetRecordHeader( PPT_PST_ExtendedParagraphHeaderAtom,
6834 																			SEEK_FROM_CURRENT_AND_RESTART );
6835 								if ( pHd == pFirst )
6836 									break;
6837 							}
6838 							rIn.Seek( nOldPos );
6839 						}
6840 						// now pHd points to the right SlideListWithText Container
6841 						PptSlidePersistList* pPageList = rSdrPowerPointImport.GetPageList( rSdrPowerPointImport.eAktPageKind );
6842 						PptSlidePersistEntry* pE = NULL;
6843 						if ( pPageList && ( rSdrPowerPointImport.nAktPageNum < pPageList->Count() ) )
6844 							pE = (*pPageList)[ rSdrPowerPointImport.nAktPageNum ];
6845 						if ( (!pE) || (!pE->nSlidePersistStartOffset) || ( pE->aPersistAtom.nSlideId != nSlideId ) )
6846 							bStatus = sal_False;
6847 						else
6848 						{
6849 							rIn.Seek( pE->nSlidePersistStartOffset );
6850 							// now we got the right page and are searching for the right
6851 							// TextHeaderAtom
6852 							while ( rIn.Tell() < pE->nSlidePersistEndOffset )
6853 							{
6854 								rIn >> aClientTextBoxHd;
6855 								if ( aClientTextBoxHd.nRecType == PPT_PST_TextHeaderAtom )
6856 								{
6857 									if ( aClientTextBoxHd.nRecInstance == nRefNum )
6858 									{
6859 										aClientTextBoxHd.SeekToEndOfRecord( rIn );
6860 										break;
6861 									}
6862 								}
6863 								aClientTextBoxHd.SeekToEndOfRecord( rIn );
6864 							}
6865 							if ( rIn.Tell() > pE->nSlidePersistEndOffset )
6866 								bStatus = sal_False;
6867 							else
6868 							{	// patching the RecordHeader
6869 								aClientTextBoxHd.nFilePos -= DFF_COMMON_RECORD_HEADER_SIZE;
6870 								aClientTextBoxHd.nRecLen += DFF_COMMON_RECORD_HEADER_SIZE;
6871 								aClientTextBoxHd.nRecType = DFF_msofbtClientTextbox;
6872 								aClientTextBoxHd.nRecVer = DFF_PSFLAG_CONTAINER;
6873 
6874 								// we have to calculate the correct record len
6875 								DffRecordHeader aTmpHd;
6876 								while ( rIn.Tell() < pE->nSlidePersistEndOffset )
6877 								{
6878 									rIn >> aTmpHd;
6879 									if ( ( aTmpHd.nRecType == PPT_PST_SlidePersistAtom ) || ( aTmpHd.nRecType == PPT_PST_TextHeaderAtom ) )
6880 										break;
6881 									aTmpHd.SeekToEndOfRecord( rIn );
6882 									aClientTextBoxHd.nRecLen += aTmpHd.nRecLen + DFF_COMMON_RECORD_HEADER_SIZE;
6883 								}
6884 								aClientTextBoxHd.SeekToContent( rIn );
6885 							}
6886 						}
6887 					}
6888 				}
6889 			}
6890 
6891 			if ( bStatus )
6892 			{
6893 				if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_TextHeaderAtom, aClientTextBoxHd.GetRecEndFilePos(), &aTextHd ) )
6894 				{
6895 					// TextHeaderAtom is always the first Atom
6896 					sal_uInt16 nInstance;
6897 					rIn >> nInstance;	// this number tells us the TxMasterStyleAtom Instance
6898 					if ( nInstance > 8 )
6899 						nInstance = 4;
6900 					aTextHd.SeekToEndOfRecord( rIn );
6901 					mpImplTextObj->mnInstance = nInstance;
6902 
6903 					sal_uInt32 nFilePos = rIn.Tell();
6904 					if ( rSdrPowerPointImport.SeekToRec2( PPT_PST_TextBytesAtom,
6905                                                           PPT_PST_TextCharsAtom,
6906                                                           aClientTextBoxHd.GetRecEndFilePos() )
6907                          || rSdrPowerPointImport.SeekToRec( rIn,
6908                                                             PPT_PST_StyleTextPropAtom,
6909                                                             aClientTextBoxHd.GetRecEndFilePos() ) )
6910 					{
6911 						PPTTextRulerInterpreter aTextRulerInterpreter( nTextRulerAtomOfs, rSdrPowerPointImport,
6912 																		aClientTextBoxHd, rIn );
6913 
6914 						PPTStyleTextPropReader aStyleTextPropReader( rIn, rSdrPowerPointImport,	aClientTextBoxHd,
6915 																		aTextRulerInterpreter, aExtParaHd, nInstance );
6916 						sal_uInt32 nParagraphs = mpImplTextObj->mnParagraphCount = aStyleTextPropReader.aParaPropList.Count();
6917 						if ( nParagraphs )
6918 						{
6919 							// the language settings will be merged into the list of PPTCharPropSet
6920 							DffRecordHeader aTextSpecInfoHd;
6921 							PPTTextSpecInfoAtomInterpreter aTextSpecInfoAtomInterpreter;
6922 							if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_TextSpecInfoAtom,
6923 														aClientTextBoxHd.GetRecEndFilePos(), &aTextSpecInfoHd ) )
6924 							{
6925 								if ( aTextSpecInfoAtomInterpreter.Read( rIn, aTextSpecInfoHd, PPT_PST_TextSpecInfoAtom,
6926 										&(rSdrPowerPointImport.pPPTStyleSheet->maTxSI) ) )
6927 								{
6928 									sal_uInt32	nI = 0;
6929 									PPTTextSpecInfo* pSpecInfo;
6930 									for ( pSpecInfo = (PPTTextSpecInfo*)aTextSpecInfoAtomInterpreter.aList.First();
6931 										pSpecInfo; pSpecInfo =(PPTTextSpecInfo*)aTextSpecInfoAtomInterpreter.aList.Next() )
6932 									{
6933 										sal_uInt32 nCharIdx = pSpecInfo->nCharIdx;
6934 
6935 										// portions and text have to been splitted in some cases
6936 										for ( ; nI < aStyleTextPropReader.aCharPropList.Count(); )
6937 										{
6938 											PPTCharPropSet* pSet = (PPTCharPropSet*)aStyleTextPropReader.aCharPropList.GetObject( nI );
6939 											if ( pSet->mnOriginalTextPos < nCharIdx )
6940 											{
6941 												pSet->mnLanguage[ 0 ] = pSpecInfo->nLanguage[ 0 ];
6942 												pSet->mnLanguage[ 1 ] = pSpecInfo->nLanguage[ 1 ];
6943 												pSet->mnLanguage[ 2 ] = pSpecInfo->nLanguage[ 2 ];
6944 												// test if the current portion needs to be splitted
6945 												if ( pSet->maString.Len() > 1 )
6946 												{
6947 													sal_Int32 nIndexOfNextPortion = pSet->maString.Len() + pSet->mnOriginalTextPos;
6948 													sal_Int32 nNewLen = nIndexOfNextPortion - nCharIdx;
6949 													sal_Int32 nOldLen = pSet->maString.Len() - nNewLen;
6950 
6951 													if ( ( nNewLen > 0 ) && ( nOldLen > 0 ) )
6952 													{
6953 														String aString( pSet->maString );
6954 														PPTCharPropSet* pNew = new PPTCharPropSet( *pSet );
6955 														pSet->maString = String( aString, 0, (sal_uInt16)nOldLen );
6956 														pNew->maString = String( aString, (sal_uInt16)nOldLen, (sal_uInt16)nNewLen );
6957 														pNew->mnOriginalTextPos += nOldLen;
6958 														aStyleTextPropReader.aCharPropList.Insert( pNew, nI + 1 );
6959 													}
6960 												}
6961 											}
6962 											else
6963 												break;
6964 											nI++;
6965 										}
6966 									}
6967 								}
6968 #ifdef DBG_UTIL
6969                                 else
6970                                 {
6971                                     if (!(rSdrPowerPointImport.rImportParam.nImportFlags & PPT_IMPORTFLAGS_NO_TEXT_ASSERT))
6972                                     {
6973     		                            DBG_ERROR( "SdrTextSpecInfoAtomInterpreter::Ctor(): parsing error, this document needs to be analysed (SJ)" );
6974                                     }
6975                                 }
6976 #endif
6977 							}
6978 							//
6979 							// now will search for possible textextensions such as date/time fields
6980 							// or ParaTabStops and append them on this textobj
6981 							//
6982 							rIn.Seek( nFilePos );
6983 							List* pFieldList = NULL;
6984 							while ( rIn.Tell() < aClientTextBoxHd.GetRecEndFilePos() )
6985 							{
6986 								rIn >> aTextHd;
6987 								sal_uInt16 nVal = 0;
6988 								PPTFieldEntry* pEntry = NULL;
6989 								switch ( aTextHd.nRecType )
6990 								{
6991 									case PPT_PST_DateTimeMCAtom :
6992 									{
6993 										pEntry = new PPTFieldEntry;
6994 										rIn >> pEntry->nPos
6995 											>> nVal
6996 											>> nVal;
6997 										pEntry->SetDateTime( nVal & 0xff );
6998 									}
6999 									break;
7000 
7001 									case PPT_PST_FooterMCAtom :
7002 									{
7003 										pEntry = new PPTFieldEntry;
7004 										rIn >> pEntry->nPos;
7005                                         pEntry->pField1 = new SvxFieldItem( SvxFooterField(), EE_FEATURE_FIELD );
7006 									}
7007 									break;
7008 
7009 									case PPT_PST_HeaderMCAtom :
7010 									{
7011 										pEntry = new PPTFieldEntry;
7012 										rIn >> pEntry->nPos;
7013                                         pEntry->pField1 = new SvxFieldItem( SvxHeaderField(), EE_FEATURE_FIELD );
7014 									}
7015 									break;
7016 
7017 									case PPT_PST_GenericDateMCAtom :
7018 									{
7019 										pEntry = new PPTFieldEntry;
7020 										rIn >> pEntry->nPos;
7021                                         pEntry->pField1 = new SvxFieldItem( SvxDateTimeField(), EE_FEATURE_FIELD );
7022 										if ( rPersistEntry.pHeaderFooterEntry )	// sj: #i34111# on master pages it is possible
7023 										{										// that there is no HeaderFooterEntry available
7024 											if ( rPersistEntry.pHeaderFooterEntry->nAtom & 0x20000 )	// auto date time
7025 												pEntry->SetDateTime( rPersistEntry.pHeaderFooterEntry->nAtom & 0xff );
7026 											else
7027 												pEntry->pString = new String( rPersistEntry.pHeaderFooterEntry->pPlaceholder[ nVal ] );
7028 										}
7029 									}
7030 									break;
7031 
7032 									case PPT_PST_SlideNumberMCAtom :
7033 									case PPT_PST_RTFDateTimeMCAtom :
7034 									{
7035 										pEntry = new PPTFieldEntry;
7036 										if ( aTextHd.nRecLen >= 4 )
7037 										{
7038 											rIn >> pEntry->nPos
7039 												>> nVal;
7040 
7041 											// ID auswerten
7042 											//SvxFieldItem* pFieldItem = NULL;
7043 											switch( aTextHd.nRecType )
7044 											{
7045 												case PPT_PST_SlideNumberMCAtom:
7046                                                     pEntry->pField1 = new SvxFieldItem( SvxPageField(), EE_FEATURE_FIELD );
7047 												break;
7048 
7049 												case PPT_PST_RTFDateTimeMCAtom:
7050 												{
7051 													// Rude workaround for one specal case reported
7052 													// by a customer. (#i75203#)
7053 
7054 													// Don't even attempt to handle the general use
7055 													// case for PPT_PST_RTFDateTimeMCAtom (a generic
7056 													// MS style date/time format string). Just handle
7057 													// the special case where the format string
7058 													// contains only one or several possibly empty
7059 													// quoted strings. I.e. something that doesn't
7060 													// expand to any date or time at all, but to a
7061 													// fixed string. How on earth somebody manages to
7062 													// produce such things in PPT slides I have no
7063 													// idea.
7064 													if (nVal == 0)
7065 													{
7066 														sal_Unicode n;
7067 														xub_StrLen nLen;
7068 														String aStr;
7069 														bool inquote = sal_False;
7070 														for (nLen = 0, n = 0; nLen < 64; nLen++)
7071 														{
7072 															rIn >> n;
7073 
7074 															// Collect quoted characters into aStr
7075 															if ( n == '\'')
7076 																inquote = !inquote;
7077 															else if (!n)
7078 															{
7079 																// End of format string
7080 																pEntry->pString = new String( aStr );
7081 																break;
7082 															}
7083 															else if (!inquote)
7084 															{
7085 																// Non-quoted character, i.e. a real
7086 																// format specifier. We don't handle
7087 																// those. Sorry.
7088 																break;
7089 															}
7090 															else
7091 															{
7092 																aStr += n;
7093 															}
7094 														}
7095 													}
7096 													if ( pEntry->pString == NULL )
7097 													{
7098 														// Handle as previously
7099 														pEntry->pField1 = new SvxFieldItem( SvxDateField( Date(), SVXDATETYPE_FIX ), EE_FEATURE_FIELD );
7100 													}
7101 												}
7102 											}
7103 										}
7104 									}
7105 									break;
7106 
7107 									case PPT_PST_InteractiveInfo :
7108 									{
7109 										DffRecordHeader aHdInteractiveInfoAtom;
7110 										if ( rSdrPowerPointImport.SeekToRec( rIn, PPT_PST_InteractiveInfoAtom, aTextHd.GetRecEndFilePos(), &aHdInteractiveInfoAtom ) )
7111 										{
7112 											PptInteractiveInfoAtom aInteractiveInfoAtom;
7113 											rIn >> aInteractiveInfoAtom;
7114 											for ( SdHyperlinkEntry* pHyperlink = (SdHyperlinkEntry*)rSdrPowerPointImport.aHyperList.First();
7115 													pHyperlink; pHyperlink = (SdHyperlinkEntry*)rSdrPowerPointImport.aHyperList.Next() )
7116 											{
7117 												if ( pHyperlink->nIndex == aInteractiveInfoAtom.nExHyperlinkId )
7118 												{
7119 													aTextHd.SeekToEndOfRecord( rIn );
7120 													rIn >> aTextHd;
7121 													if ( aTextHd.nRecType != PPT_PST_TxInteractiveInfoAtom )
7122 													{
7123 														aTextHd.SeekToBegOfRecord( rIn );
7124 														continue;
7125 													}
7126 													else
7127 													{
7128 														sal_uInt32 nStartPos, nEndPos;
7129 														rIn >> nStartPos
7130 															>> nEndPos;
7131 														if ( nEndPos )
7132 														{
7133 															pEntry = new PPTFieldEntry;
7134 															pEntry->nPos = (sal_uInt16)nStartPos;
7135 															pEntry->nTextRangeEnd = (sal_uInt16)nEndPos;
7136                                                             String aTarget( pHyperlink->aTarget );
7137                                                             if ( pHyperlink->aConvSubString.Len() )
7138                                                             {
7139                                                                 aTarget.Append( (sal_Unicode)'#' );
7140                                                                 aTarget.Append( pHyperlink->aConvSubString );
7141                                                             }
7142                                                             pEntry->pField1 = new SvxFieldItem( SvxURLField( aTarget, String(), SVXURLFORMAT_REPR ), EE_FEATURE_FIELD );
7143 														}
7144 													}
7145 													break;
7146 												}
7147 											}
7148 										}
7149 									}
7150 									break;
7151 								}
7152 								aTextHd.SeekToEndOfRecord( rIn );
7153 								if ( pEntry )
7154 								{
7155 									if ( !pFieldList )
7156 										pFieldList = new List;
7157 									sal_uInt32 n;
7158 									for ( n = 0; n < pFieldList->Count(); n++ )
7159 									{	// sorting fields ( hi >> lo )
7160 										if ( ( (PPTFieldEntry*)pFieldList->GetObject( n ) )->nPos < pEntry->nPos )
7161 											break;
7162 									}
7163 									pFieldList->Insert( pEntry, (sal_uInt32)n );
7164 								}
7165 							}
7166 							if ( pFieldList )
7167 							{
7168 								PPTFieldEntry* pFE = (PPTFieldEntry*)pFieldList->First();
7169 								List& aCharPropList = aStyleTextPropReader.aCharPropList;
7170 
7171 								sal_Int32	i = nParagraphs - 1;
7172 								sal_Int32	n = aCharPropList.Count() - 1;
7173 
7174 								// at this point we just have a list of textportions(aCharPropList)
7175 								// the next while loop tries to resolve the list of fields(pFieldList)
7176 								while( pFE && ( n >= 0 ) && ( i >= 0 ) )
7177 								{
7178  									PPTCharPropSet* pSet  = (PPTCharPropSet*)aCharPropList.GetObject( n );
7179 									String aString( pSet->maString );
7180 									sal_uInt32 nCount = aString.Len();
7181 									sal_uInt32 nPos = pSet->mnOriginalTextPos + nCount;
7182 									while ( pFE && nCount-- )
7183 									{
7184 										nPos--;
7185 										while ( pFE && ( pFE->nPos > nPos ) )
7186 											pFE = (PPTFieldEntry*)pFieldList->Next();
7187 										if ( !pFE )
7188 											break;
7189 
7190 										if ( pFE->nPos == nPos )
7191 										{
7192 											if ( aString.GetChar( (sal_uInt16)nCount ) == 0x2a )
7193 											{
7194 												sal_uInt32 nBehind = aString.Len() - ( nCount + 1 );
7195 												pSet->maString = String();
7196 												if ( nBehind )
7197 												{
7198 													PPTCharPropSet* pNewCPS = new PPTCharPropSet( *pSet );
7199 													pNewCPS->maString = String( aString, (sal_uInt16)nCount + 1, (sal_uInt16)nBehind );
7200 													aCharPropList.Insert( pNewCPS, n + 1 );
7201 												}
7202 												if ( pFE->pField2 )
7203 												{
7204 													PPTCharPropSet* pNewCPS = new PPTCharPropSet( *pSet );
7205 													pNewCPS->mpFieldItem = pFE->pField2, pFE->pField2 = NULL;
7206 													aCharPropList.Insert( pNewCPS, n + 1 );
7207 
7208 													pNewCPS = new PPTCharPropSet( *pSet );
7209 													pNewCPS->maString = String( String( RTL_CONSTASCII_USTRINGPARAM( " " ) ) );
7210 													aCharPropList.Insert( pNewCPS, n + 1 );
7211 												}
7212 												if ( nCount )
7213 												{
7214 													PPTCharPropSet* pNewCPS = new PPTCharPropSet( *pSet );
7215 													pNewCPS->maString = String( aString, (sal_uInt16)0, (sal_uInt16)nCount );
7216 													aCharPropList.Insert( pNewCPS, n++ );
7217 												}
7218 												if ( pFE->pField1 )
7219                                                 {
7220 													pSet->mpFieldItem = pFE->pField1, pFE->pField1 = NULL;
7221                                                 }
7222 												else if ( pFE->pString )
7223                                                     pSet->maString = *pFE->pString;
7224 											}
7225 											else
7226 											{
7227 												if ( pFE->nTextRangeEnd )	// text range hyperlink
7228 												{
7229 													sal_uInt32 nHyperLen = pFE->nTextRangeEnd - nPos;
7230 													if ( nHyperLen )
7231 													{
7232 														PPTCharPropSet* pBefCPS = NULL;
7233 														if ( nCount )
7234 														{
7235 															pBefCPS = new PPTCharPropSet( *pSet );
7236 															pSet->maString = String( pSet->maString, (sal_uInt16)nCount, (sal_uInt16)( pSet->maString.Len() - nCount ) );
7237 														}
7238 														sal_uInt32	nIdx = n;
7239 														sal_Int32	nHyperLenLeft = nHyperLen;
7240 
7241 														while ( ( aCharPropList.Count() > nIdx ) && nHyperLenLeft )
7242 														{
7243 															// the textrange hyperlink can take more than 1 paragraph
7244 															// the solution here is to clone the hyperlink...
7245 
7246 															PPTCharPropSet* pCurrent = (PPTCharPropSet*)aCharPropList.GetObject( nIdx );
7247 															sal_Int32		nNextStringLen = pCurrent->maString.Len();
7248 
7249 															DBG_ASSERT( pFE->pField1, "missing field!" );
7250 															if (!pFE->pField1)
7251 															    break;
7252 
7253 															const SvxURLField* pField = (const SvxURLField*)pFE->pField1->GetField();
7254 
7255 															pCurrent->mbIsHyperlink=sal_True;
7256                                                             pCurrent->mnHylinkOrigColor=pCurrent->pCharSet->mnColor;
7257 															pCurrent->mbHardHylinkOrigColor= ( ( pCurrent->pCharSet->mnAttrSet >>PPT_CharAttr_FontColor ) & 1)>0;
7258 
7259 															if ( pCurrent->mpFieldItem )
7260 															{
7261 																pCurrent->SetColor( PPT_COLSCHEME_A_UND_HYPERLINK );
7262 																if ( pCurrent->mpFieldItem->GetField()->ISA( SvxURLField ) )
7263 																	break;
7264 																nHyperLenLeft--;
7265 															}
7266 															else if ( nNextStringLen )
7267 															{
7268 																if ( nNextStringLen <= nHyperLenLeft )
7269 																{
7270                                                                     pCurrent->mpFieldItem = new SvxFieldItem( SvxURLField( pField->GetURL(), pCurrent->maString, SVXURLFORMAT_REPR ), EE_FEATURE_FIELD );
7271 																	nHyperLenLeft -= nNextStringLen;
7272 
7273 																	if ( nHyperLenLeft )
7274 																	{
7275 																		// if the next portion is in a higher paragraph,
7276 																		// the textrange is to decrease (because of the LineBreak character)
7277 																		if ( aCharPropList.Count() > ( nIdx + 1 ) )
7278 																		{
7279 																			PPTCharPropSet* pNext = (PPTCharPropSet*)aCharPropList.GetObject( nIdx + 1 );
7280 																			if ( pNext->mnParagraph > pCurrent->mnParagraph )
7281 																				nHyperLenLeft--;
7282 																		}
7283 																	}
7284 																}
7285 																else
7286 																{
7287 																	PPTCharPropSet* pNewCPS = new PPTCharPropSet( *pCurrent );
7288 																	pNewCPS->maString = String( pCurrent->maString, (sal_uInt16)nHyperLenLeft, (sal_uInt16)( nNextStringLen - nHyperLenLeft ) );
7289 																	aCharPropList.Insert( pNewCPS, nIdx + 1 );
7290 																	String aRepresentation( pCurrent->maString, 0, (sal_uInt16)nHyperLenLeft );
7291                                                                     pCurrent->mpFieldItem = new SvxFieldItem( SvxURLField( pField->GetURL(), aRepresentation, SVXURLFORMAT_REPR ), EE_FEATURE_FIELD );
7292 																	nHyperLenLeft = 0;
7293 																}
7294 																pCurrent->maString = String();
7295 																pCurrent->SetColor( PPT_COLSCHEME_A_UND_HYPERLINK );
7296 															}
7297 															nIdx++;
7298 														}
7299 														delete pFE->pField1, pFE->pField1 = NULL;
7300 
7301 														if ( pBefCPS )
7302 														{
7303 															pBefCPS->maString = String( aString, (sal_uInt16)0, (sal_uInt16)nCount );
7304 															aCharPropList.Insert( pBefCPS, n++ );
7305 
7306 														}
7307 													}
7308 												}
7309 											}
7310 											break;
7311 										}
7312 									}
7313 									n--;
7314 								}
7315 								for ( void* pPtr = pFieldList->First(); pPtr; pPtr = pFieldList->Next() )
7316 									delete (PPTFieldEntry*)pPtr;
7317 								delete pFieldList;
7318 							}
7319 							mpImplTextObj->mpParagraphList = new PPTParagraphObj*[ nParagraphs ];
7320 							aStyleTextPropReader.aCharPropList.First();
7321 							sal_uInt32 nCount = 0;
7322 							for ( void* pPtr = aStyleTextPropReader.aParaPropList.First();
7323 										pPtr;
7324 										pPtr = aStyleTextPropReader.aParaPropList.Next() )
7325 							{
7326                                 PPTParagraphObj* pPara = new PPTParagraphObj( aStyleTextPropReader, *rSdrPowerPointImport.pPPTStyleSheet, nInstance, aTextRulerInterpreter );
7327 								mpImplTextObj->mpParagraphList[ nCount++ ] = pPara;
7328 
7329                                 sal_uInt32 nParaAdjust, nFlags = 0;
7330 	                            pPara->GetAttrib( PPT_ParaAttr_Adjust, nParaAdjust, GetInstance() );
7331 
7332                                 switch ( nParaAdjust )
7333                                 {
7334                                     case 0 : nFlags = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT;   break;
7335                                     case 1 : nFlags = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER; break;
7336                                     case 2 : nFlags = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT;  break;
7337                                     case 3 : nFlags = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK;  break;
7338                                 }
7339                                 mpImplTextObj->mnTextFlags |= nFlags;
7340 							}
7341 						}
7342 					}
7343 				}
7344 			}
7345 		}
7346 	}
7347 }
7348 
PPTTextObj(PPTTextObj & rTextObj)7349 PPTTextObj::PPTTextObj( PPTTextObj& rTextObj )
7350 {
7351 	mpImplTextObj = rTextObj.mpImplTextObj;
7352 	mpImplTextObj->mnRefCount++;
7353 }
7354 
~PPTTextObj()7355 PPTTextObj::~PPTTextObj()
7356 {
7357 	ImplClear();
7358 }
7359 
First()7360 PPTParagraphObj* PPTTextObj::First()
7361 {
7362 	mpImplTextObj->mnCurrentObject = 0;
7363 	if ( !mpImplTextObj->mnParagraphCount )
7364 		return NULL;
7365 	return mpImplTextObj->mpParagraphList[ 0 ];
7366 }
7367 
Next()7368 PPTParagraphObj* PPTTextObj::Next()
7369 {
7370 	sal_uInt32 i = mpImplTextObj->mnCurrentObject + 1;
7371 	if ( i >= mpImplTextObj->mnParagraphCount )
7372 		return NULL;
7373 	mpImplTextObj->mnCurrentObject++;
7374 	return mpImplTextObj->mpParagraphList[ i ];
7375 }
7376 
GetBackground() const7377 const SfxItemSet* PPTTextObj::GetBackground() const
7378 {
7379 	if ( mpImplTextObj->mrPersistEntry.pBObj )
7380 		return &mpImplTextObj->mrPersistEntry.pBObj->GetMergedItemSet();
7381 	else
7382 		return NULL;
7383 }
7384 
ImplClear()7385 void PPTTextObj::ImplClear()
7386 {
7387 	if ( ! ( --mpImplTextObj->mnRefCount ) )
7388 	{
7389 		for ( PPTParagraphObj* pPtr = First(); pPtr; pPtr = Next() )
7390 			delete pPtr;
7391 		delete[] mpImplTextObj->mpParagraphList;
7392 		delete mpImplTextObj->mpPlaceHolderAtom;
7393 		delete mpImplTextObj;
7394 	}
7395 }
7396 
operator =(PPTTextObj & rTextObj)7397 PPTTextObj& PPTTextObj::operator=( PPTTextObj& rTextObj )
7398 {
7399 	if ( this != &rTextObj )
7400 	{
7401 		ImplClear();
7402 		mpImplTextObj = rTextObj.mpImplTextObj;
7403 		mpImplTextObj->mnRefCount++;
7404 	}
7405 	return *this;
7406 }
7407 
IsLine(const SdrObject * pObj)7408 sal_Bool IsLine( const SdrObject* pObj )
7409 {
7410 	return pObj->ISA( SdrPathObj ) && ((SdrPathObj*)pObj)->IsLine() && (((SdrPathObj*)pObj)->GetPointCount() == 2 );
7411 }
7412 
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)7413 sal_Bool GetCellPosition( const SdrObject* pObj, const std::set< sal_Int32 >& rRows, const std::set< sal_Int32 >& rColumns,
7414 							sal_Int32& nTableIndex, sal_Int32& nRow, sal_Int32& nRowCount, sal_Int32& nColumn, sal_Int32& nColumnCount )
7415 {
7416 	Rectangle aSnapRect( pObj->GetSnapRect() );
7417 	sal_Bool bCellObject = ( aSnapRect.GetWidth() > 1 ) && ( aSnapRect.GetHeight() > 1 );
7418 	if ( bCellObject )
7419 	{
7420 		std::set< sal_Int32 >::const_iterator aRowIter( rRows.find( aSnapRect.Top() ) );
7421 		std::set< sal_Int32 >::const_iterator aColumnIter( rColumns.find( aSnapRect.Left() ) );
7422 		if ( ( aRowIter == rRows.end() ) || ( aColumnIter == rColumns.end() ) )
7423 			bCellObject = sal_False;
7424 		else
7425 		{
7426 			nRowCount = 1;
7427 			nRow = std::distance( rRows.begin(), aRowIter );
7428 			while( ++aRowIter != rRows.end() )
7429 			{
7430 				if ( *aRowIter >= aSnapRect.Bottom() )
7431 					break;
7432 				nRowCount++;
7433 			}
7434 			nColumnCount = 1;
7435 			nColumn = std::distance( rColumns.begin(), aColumnIter );
7436 			while( ++aColumnIter != rColumns.end() )
7437 			{
7438 				if ( *aColumnIter >= aSnapRect.Right() )
7439 					break;
7440 				nColumnCount++;
7441 			}
7442 			nTableIndex = nRow * rColumns.size() + nColumn;
7443 		}
7444 	}
7445 	return bCellObject;
7446 }
7447 
7448 #define LinePositionLeft	0x01000000
7449 #define LinePositionTop		0x02000000
7450 #define LinePositionRight	0x04000000
7451 #define LinePositionBottom	0x08000000
7452 #define LinePositionTLBR	0x10000000
7453 #define LinePositionBLTR	0x20000000
7454 
7455 
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)7456 void GetRowPositions( const Rectangle& rSnapRect, const std::set< sal_Int32 >& rRows,
7457 						const std::set< sal_Int32 >& rColumns, std::vector< sal_Int32 >& rPositions, sal_Int32 nColumn, sal_Int32 nFlags )
7458 {
7459 	std::set< sal_Int32 >::const_iterator aRow( rRows.find( rSnapRect.Top() ) );
7460 	if ( aRow != rRows.end() )
7461 	{
7462 		sal_Int32 nRow = std::distance( rRows.begin(), aRow );
7463 		while( ( aRow != rRows.end() ) && ((*aRow) < rSnapRect.Bottom() ) )
7464 		{
7465 			if ( nFlags & LinePositionLeft )
7466 				rPositions.push_back( ( ( nRow * rColumns.size() ) + nColumn ) | LinePositionLeft );
7467 			if ( nFlags & LinePositionRight )
7468 				rPositions.push_back( ( ( nRow * rColumns.size() ) + ( nColumn - 1 ) ) | LinePositionRight );
7469 
7470 			nRow++;
7471 			aRow++;
7472 		}
7473 	}
7474 }
7475 
7476 
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)7477 void GetColumnPositions( const Rectangle& rSnapRect, const std::set< sal_Int32 >& /* rRows */,
7478 						const std::set< sal_Int32 >& rColumns, std::vector< sal_Int32 >& rPositions, sal_Int32 nRow, sal_Int32 nFlags )
7479 {
7480 	std::set< sal_Int32 >::const_iterator aColumn( rColumns.find( rSnapRect.Left() ) );
7481 	if ( aColumn != rColumns.end() )
7482 	{
7483 		sal_Int32 nColumn = std::distance( rColumns.begin(), aColumn );
7484 		while( ( aColumn != rColumns.end() ) && ((*aColumn) < rSnapRect.Right() ) )
7485 		{
7486 			if ( nFlags & LinePositionTop )
7487 				rPositions.push_back( ( ( nRow * rColumns.size() ) + nColumn ) | LinePositionTop );
7488 			if ( nFlags & LinePositionBottom )
7489 				rPositions.push_back( ( ( ( nRow - 1 ) * rColumns.size() ) + nColumn ) | LinePositionBottom );
7490 
7491 			nColumn++;
7492 			aColumn++;
7493 		}
7494 	}
7495 }
7496 
GetLinePositions(const SdrObject * pObj,const std::set<sal_Int32> & rRows,const std::set<sal_Int32> & rColumns,std::vector<sal_Int32> & rPositions,const Rectangle & rGroupSnap)7497 void GetLinePositions( const SdrObject* pObj, const std::set< sal_Int32 >& rRows, const std::set< sal_Int32 >& rColumns,
7498 						std::vector< sal_Int32 >& rPositions, const Rectangle& rGroupSnap )
7499 {
7500 	Rectangle aSnapRect( pObj->GetSnapRect() );
7501 	if ( aSnapRect.Left() == aSnapRect.Right() )
7502 	{
7503 		std::set< sal_Int32 >::const_iterator aColumn( rColumns.find( aSnapRect.Left() ) );
7504 		if ( ( aColumn != rColumns.end() ) || ( aSnapRect.Left() == rGroupSnap.Right() ) )
7505 		{
7506 			sal_Int32 nColumn, nFlags;
7507 			if ( aColumn != rColumns.end() )
7508 			{
7509 				nColumn = std::distance( rColumns.begin(), aColumn );
7510 				nFlags = LinePositionLeft;
7511 				if ( aColumn != rColumns.begin() )
7512 					nFlags |= LinePositionRight;
7513 			}
7514 			else
7515 			{
7516 				nColumn = rColumns.size();
7517 				nFlags = LinePositionRight;
7518 			}
7519 			GetRowPositions( aSnapRect, rRows, rColumns, rPositions, nColumn, nFlags );
7520 		}
7521 	}
7522 	else if ( aSnapRect.Top() == aSnapRect.Bottom() )
7523 	{
7524 		std::set< sal_Int32 >::const_iterator aRow( rRows.find( aSnapRect.Top() ) );
7525 		if ( ( aRow != rRows.end() ) || ( aSnapRect.Top() == rGroupSnap.Bottom() ) )
7526 		{
7527 			sal_Int32 nRow, nFlags;
7528 			if ( aRow != rRows.end() )
7529 			{
7530 				nRow = std::distance( rRows.begin(), aRow );
7531 				nFlags = LinePositionTop;
7532 				if ( aRow != rRows.begin() )
7533 					nFlags |= LinePositionBottom;
7534 			}
7535 			else
7536 			{
7537 				nRow = rRows.size();
7538 				nFlags = LinePositionBottom;
7539 			}
7540 			GetColumnPositions( aSnapRect, rRows, rColumns, rPositions, nRow, nFlags );
7541 		}
7542 	}
7543 	else
7544 	{
7545 		sal_uInt32 nPosition = 0;
7546 		Point aPt1( ((SdrPathObj*)pObj)->GetPoint( 0 ) );
7547 		Point aPt2( ((SdrPathObj*)pObj)->GetPoint( 1 ) );
7548 		if ( aPt1.X() < aPt2.X() )
7549 			nPosition |= aPt1.Y() < aPt2.Y() ? LinePositionTLBR : LinePositionBLTR;
7550 		else
7551 			nPosition |= aPt1.Y() < aPt2.Y() ? LinePositionBLTR : LinePositionTLBR;
7552 
7553 		std::set< sal_Int32 >::const_iterator aRow( rRows.find( aPt1.Y() < aPt2.Y() ? aPt1.Y() : aPt2.Y() ) );
7554 		std::set< sal_Int32 >::const_iterator aColumn( rColumns.find( aPt1.X() < aPt2.X() ? aPt1.X() : aPt2.X() ) );
7555 		if ( ( aRow != rRows.end() ) && ( aColumn != rColumns.end() ) )
7556 		{
7557 			nPosition |= ( std::distance( rRows.begin(), aRow ) * rColumns.size() ) + std::distance( rColumns.begin(), aColumn );
7558 			rPositions.push_back( nPosition );
7559 		}
7560 	}
7561 }
7562 
CreateTableRows(Reference<XTableRows> xTableRows,const std::set<sal_Int32> & rRows,sal_Int32 nTableBottom)7563 void CreateTableRows( Reference< XTableRows > xTableRows, const std::set< sal_Int32 >& rRows, sal_Int32 nTableBottom )
7564 {
7565 	if ( rRows.size() > 1 )
7566 		xTableRows->insertByIndex( 0, rRows.size() - 1 );
7567 
7568 	std::set< sal_Int32 >::const_iterator aIter( rRows.begin() );
7569 	sal_Int32 nLastPosition( *aIter );
7570 	Reference< XIndexAccess > xIndexAccess( xTableRows, UNO_QUERY_THROW );
7571 	for ( sal_Int32 n = 0; n < xIndexAccess->getCount(); n++ )
7572 	{
7573 		sal_Int32 nHeight;
7574 		if ( ++aIter != rRows.end() )
7575 		{
7576 			nHeight = *aIter - nLastPosition;
7577 			nLastPosition = *aIter;
7578 		}
7579 		else
7580 			nHeight = nTableBottom - nLastPosition;
7581 
7582 		static const rtl::OUString	sWidth( RTL_CONSTASCII_USTRINGPARAM ( "Height" ) );
7583 		Reference< XPropertySet > xPropSet( xIndexAccess->getByIndex( n ), UNO_QUERY_THROW );
7584 		xPropSet->setPropertyValue( sWidth, Any( nHeight ) );
7585 	}
7586 }
7587 
CreateTableColumns(Reference<XTableColumns> xTableColumns,const std::set<sal_Int32> & rColumns,sal_Int32 nTableRight)7588 void CreateTableColumns( Reference< XTableColumns > xTableColumns, const std::set< sal_Int32 >& rColumns, sal_Int32 nTableRight )
7589 {
7590 	if ( rColumns.size() > 1 )
7591 		xTableColumns->insertByIndex( 0, rColumns.size() - 1 );
7592 
7593 	std::set< sal_Int32 >::const_iterator aIter( rColumns.begin() );
7594 	sal_Int32 nLastPosition( *aIter );
7595 	Reference< XIndexAccess > xIndexAccess( xTableColumns, UNO_QUERY_THROW );
7596 	for ( sal_Int32 n = 0; n < xIndexAccess->getCount(); n++ )
7597 	{
7598 		sal_Int32 nWidth;
7599 		if ( ++aIter != rColumns.end() )
7600 		{
7601 			nWidth = *aIter - nLastPosition;
7602 			nLastPosition = *aIter;
7603 		}
7604 		else
7605 			nWidth = nTableRight - nLastPosition;
7606 
7607 		static const rtl::OUString	sWidth( RTL_CONSTASCII_USTRINGPARAM ( "Width" ) );
7608 		Reference< XPropertySet > xPropSet( xIndexAccess->getByIndex( n ), UNO_QUERY_THROW );
7609 		xPropSet->setPropertyValue( sWidth, Any( nWidth ) );
7610 	}
7611 }
7612 
MergeCells(const Reference<XTable> & xTable,sal_Int32 nCol,sal_Int32 nRow,sal_Int32 nColSpan,sal_Int32 nRowSpan)7613 void MergeCells( const Reference< XTable >& xTable, sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan )
7614 {
7615    DBG_ASSERT( (nColSpan > 1) || (nRowSpan > 1), "nonsense parameter!!" );
7616    DBG_ASSERT( (nCol >= 0) && (nCol < xTable->getColumnCount()) && (nRow >= 0) && (nRow < xTable->getRowCount()), "die celle gibts nicht!!" );
7617    DBG_ASSERT( (nColSpan >= 1) && ((nCol  + nColSpan - 1) < xTable->getColumnCount()), "nColSpan murks!" );
7618    DBG_ASSERT(  (nRowSpan >= 1) && ((nRow  + nRowSpan - 1) < xTable->getRowCount()), "nRowSpan murks!" );
7619 
7620    if( xTable.is() ) try
7621    {
7622        Reference< XMergeableCellRange > xRange( xTable->createCursorByRange( xTable->getCellRangeByPosition( nCol, nRow,nCol + nColSpan - 1, nRow + nRowSpan - 1 ) ), UNO_QUERY_THROW );
7623        if( xRange->isMergeable() )
7624                xRange->merge();
7625    }
7626    catch( Exception& )
7627    {
7628        DBG_ASSERT( false, "exception caught!" );
7629    }
7630 }
7631 
ApplyCellAttributes(const SdrObject * pObj,Reference<XCell> & xCell)7632 void ApplyCellAttributes( const SdrObject* pObj, Reference< XCell >& xCell )
7633 {
7634 	try
7635 	{
7636 		Reference< XPropertySet > xPropSet( xCell, UNO_QUERY_THROW );
7637 
7638 		const sal_Int32 nLeftDist(((const SdrTextLeftDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_LEFTDIST)).GetValue());
7639 		const sal_Int32 nRightDist(((const SdrTextRightDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_RIGHTDIST)).GetValue());
7640 		const sal_Int32 nUpperDist(((const SdrTextUpperDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_UPPERDIST)).GetValue());
7641 		const sal_Int32 nLowerDist(((const SdrTextLowerDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_LOWERDIST)).GetValue());
7642 		static const rtl::OUString	sTopBorder( RTL_CONSTASCII_USTRINGPARAM( "TextUpperDistance" ) );
7643 		static const rtl::OUString	sBottomBorder( RTL_CONSTASCII_USTRINGPARAM( "TextLowerDistance" ) );
7644 		static const rtl::OUString	sLeftBorder( RTL_CONSTASCII_USTRINGPARAM( "TextLeftDistance" ) );
7645 		static const rtl::OUString	sRightBorder( RTL_CONSTASCII_USTRINGPARAM( "TextRightDistance" ) );
7646 		xPropSet->setPropertyValue( sTopBorder, Any( nUpperDist ) );
7647 		xPropSet->setPropertyValue( sRightBorder, Any( nRightDist ) );
7648 		xPropSet->setPropertyValue( sLeftBorder, Any( nLeftDist ) );
7649 		xPropSet->setPropertyValue( sBottomBorder, Any( nLowerDist ) );
7650 
7651 		static const rtl::OUString	sTextVerticalAdjust( RTL_CONSTASCII_USTRINGPARAM( "TextVerticalAdjust" ) );
7652 		const SdrTextVertAdjust eTextVertAdjust(((const SdrTextVertAdjustItem&)pObj->GetMergedItem(SDRATTR_TEXT_VERTADJUST)).GetValue());
7653 		drawing::TextVerticalAdjust eVA( drawing::TextVerticalAdjust_TOP );
7654 		if ( eTextVertAdjust == SDRTEXTVERTADJUST_CENTER )
7655 			eVA = drawing::TextVerticalAdjust_CENTER;
7656 		else if ( eTextVertAdjust == SDRTEXTVERTADJUST_BOTTOM )
7657 			eVA = drawing::TextVerticalAdjust_BOTTOM;
7658 		xPropSet->setPropertyValue( sTextVerticalAdjust, Any( eVA ) );
7659 
7660 		//set textHorizontalAdjust and TextWritingMode attr
7661 		const sal_Int32 eHA(((const SdrTextLeftDistItem&)pObj->GetMergedItem(SDRATTR_TEXT_HORZADJUST)).GetValue());
7662 		const SvxFrameDirection eDirection = (const SvxFrameDirection)((( const SvxFrameDirectionItem&)pObj->GetMergedItem(EE_PARA_WRITINGDIR)).GetValue());
7663 		static const rtl::OUString	sHorizontalAdjust( RTL_CONSTASCII_USTRINGPARAM( "TextHorizontalAdjust" ) );
7664 		static const rtl::OUString	sWritingMode( RTL_CONSTASCII_USTRINGPARAM("TextWritingMode") );
7665 		xPropSet->setPropertyValue(  sHorizontalAdjust , Any( eHA ) );
7666 		if ( eDirection == FRMDIR_VERT_TOP_RIGHT )
7667 		{//vertical writing
7668 			xPropSet->setPropertyValue(  sWritingMode , Any( ::com::sun::star::text::WritingMode_TB_RL ) );
7669 		}
7670 		SfxItemSet aSet( pObj->GetMergedItemSet() );
7671 		XFillStyle eFillStyle(((XFillStyleItem&)pObj->GetMergedItem( XATTR_FILLSTYLE )).GetValue());
7672 		::com::sun::star::drawing::FillStyle eFS( com::sun::star::drawing::FillStyle_NONE );
7673 		switch( eFillStyle )
7674 		{
7675 			case XFILL_SOLID :
7676 				{
7677 					static const rtl::OUString sFillColor( String( RTL_CONSTASCII_USTRINGPARAM( "FillColor" ) ) );
7678 					eFS = com::sun::star::drawing::FillStyle_SOLID;
7679 					Color aFillColor( ((XFillColorItem&)pObj->GetMergedItem( XATTR_FILLCOLOR )).GetColorValue() );
7680 					sal_Int32 nFillColor( aFillColor.GetColor() );
7681 					xPropSet->setPropertyValue( sFillColor, Any( nFillColor ) );
7682 				}
7683 				break;
7684 			case XFILL_GRADIENT :
7685 				{
7686 					eFS = com::sun::star::drawing::FillStyle_GRADIENT;
7687 					XGradient aXGradient(((const XFillGradientItem&)pObj->GetMergedItem(XATTR_FILLGRADIENT)).GetGradientValue());
7688 
7689 					com::sun::star::awt::Gradient aGradient;
7690 					aGradient.Style = (awt::GradientStyle) aXGradient.GetGradientStyle();
7691 					aGradient.StartColor = (sal_Int32)aXGradient.GetStartColor().GetColor();
7692 					aGradient.EndColor = (sal_Int32)aXGradient.GetEndColor().GetColor();
7693 					aGradient.Angle = (short)aXGradient.GetAngle();
7694 					aGradient.Border = aXGradient.GetBorder();
7695 					aGradient.XOffset = aXGradient.GetXOffset();
7696 					aGradient.YOffset = aXGradient.GetYOffset();
7697 					aGradient.StartIntensity = aXGradient.GetStartIntens();
7698 					aGradient.EndIntensity = aXGradient.GetEndIntens();
7699 					aGradient.StepCount = aXGradient.GetSteps();
7700 
7701 					static const rtl::OUString sFillGradient( String( RTL_CONSTASCII_USTRINGPARAM( "FillGradient" ) ) );
7702 					xPropSet->setPropertyValue( sFillGradient, Any( aGradient ) );
7703 				}
7704 				break;
7705 			case XFILL_HATCH :
7706 				eFS = com::sun::star::drawing::FillStyle_HATCH;
7707 			break;
7708 			case XFILL_BITMAP :
7709 				{
7710 					eFS = com::sun::star::drawing::FillStyle_BITMAP;
7711 
7712 					const XFillBitmapItem aXFillBitmapItem((const XFillBitmapItem&)pObj->GetMergedItem( XATTR_FILLBITMAP ));
7713 					rtl::OUString aURL( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
7714 					aURL += rtl::OUString::createFromAscii(aXFillBitmapItem.GetGraphicObject().GetUniqueID().GetBuffer());
7715 
7716 					static const rtl::OUString sFillBitmapURL( String( RTL_CONSTASCII_USTRINGPARAM( "FillBitmapURL" ) ) );
7717 					xPropSet->setPropertyValue( sFillBitmapURL, Any( aURL ) );
7718 
7719 					static const rtl::OUString sFillBitmapMode( String( RTL_CONSTASCII_USTRINGPARAM( "FillBitmapMode" ) ) );
7720 					const XFillBmpStretchItem aStretchItem(( const XFillBmpStretchItem&)pObj->GetMergedItem( XATTR_FILLBMP_STRETCH ));
7721 					const XFillBmpTileItem aTileItem(( const XFillBmpTileItem&)pObj->GetMergedItem( XATTR_FILLBMP_TILE ));
7722 					if( aTileItem.GetValue() )
7723 						xPropSet->setPropertyValue( sFillBitmapMode, Any( com::sun::star::drawing::BitmapMode_REPEAT ) );
7724 					else if( aStretchItem.GetValue() )
7725 						xPropSet->setPropertyValue( sFillBitmapMode, Any( com::sun::star::drawing::BitmapMode_STRETCH ) );
7726 					else
7727 						xPropSet->setPropertyValue( sFillBitmapMode, Any( com::sun::star::drawing::BitmapMode_NO_REPEAT ) );
7728 				}
7729 			break;
7730 			case XFILL_NONE :
7731 				eFS = com::sun::star::drawing::FillStyle_NONE;
7732 			break;
7733 
7734 		}
7735 		static const rtl::OUString sFillStyle( String( RTL_CONSTASCII_USTRINGPARAM( "FillStyle" ) ) );
7736 		xPropSet->setPropertyValue( sFillStyle, Any( eFS ) );
7737 		if ( eFillStyle != XFILL_NONE )
7738 		{
7739 			sal_Int16 nFillTransparence( ( (const XFillTransparenceItem&)pObj->GetMergedItem( XATTR_FILLTRANSPARENCE ) ).GetValue() );
7740 			static const rtl::OUString sFillTransparence( String( RTL_CONSTASCII_USTRINGPARAM( "FillTransparence" ) ) );
7741 			xPropSet->setPropertyValue( sFillTransparence, Any( nFillTransparence ) );
7742 		}
7743 	}
7744 	catch( Exception& )
7745 	{
7746 	}
7747 }
7748 
ApplyCellLineAttributes(const SdrObject * pLine,Reference<XTable> & xTable,const std::vector<sal_Int32> vPositions,sal_Int32 nColumns)7749 void ApplyCellLineAttributes( const SdrObject* pLine, Reference< XTable >& xTable, const std::vector< sal_Int32 > vPositions, sal_Int32 nColumns )
7750 {
7751 	try
7752 	{
7753 		SfxItemSet aSet( pLine->GetMergedItemSet() );
7754 		XLineStyle eLineStyle(((XLineStyleItem&)pLine->GetMergedItem( XATTR_LINESTYLE )).GetValue());
7755 		com::sun::star::table::BorderLine aBorderLine;
7756 		switch( eLineStyle )
7757 		{
7758 			case XLINE_DASH :
7759 			case XLINE_SOLID :
7760 				{
7761 					Color aLineColor( ((XLineColorItem&)pLine->GetMergedItem( XATTR_LINECOLOR )).GetColorValue() );
7762 					aBorderLine.Color = aLineColor.GetColor();
7763 					// Avoid width = 0, the min value should be 1.
7764 					aBorderLine.OuterLineWidth = std::max( static_cast< sal_Int16 >( 1 ), static_cast< sal_Int16 >( ((const XLineWidthItem&)(pLine->GetMergedItem(XATTR_LINEWIDTH))).GetValue() / 4) );
7765 					aBorderLine.InnerLineWidth = std::max( static_cast< sal_Int16 >( 1 ), static_cast< sal_Int16 >( ((const XLineWidthItem&)(pLine->GetMergedItem(XATTR_LINEWIDTH))).GetValue() / 4) );
7766 					aBorderLine.LineDistance = 0;
7767 				}
7768 				break;
7769 			case XLINE_NONE :
7770 				{
7771 					aBorderLine.OuterLineWidth = 0;
7772 					aBorderLine.InnerLineWidth = 0;
7773 					aBorderLine.LineDistance = 0;
7774 				}
7775 			break;
7776 		}
7777 		Reference< XCellRange > xCellRange( xTable, UNO_QUERY_THROW );
7778 		std::vector< sal_Int32 >::const_iterator aIter( vPositions.begin() );
7779 		while( aIter != vPositions.end() )
7780 		{
7781 			static const rtl::OUString sTopBorder( String( RTL_CONSTASCII_USTRINGPARAM( "TopBorder" ) ) );
7782 			static const rtl::OUString sBottomBorder( String( RTL_CONSTASCII_USTRINGPARAM( "BottomBorder" ) ) );
7783 			static const rtl::OUString sLeftBorder( String( RTL_CONSTASCII_USTRINGPARAM( "LeftBorder" ) ) );
7784 			static const rtl::OUString sRightBorder( String( RTL_CONSTASCII_USTRINGPARAM( "RightBorder" ) ) );
7785 			static const rtl::OUString	sDiagonalTLBR( RTL_CONSTASCII_USTRINGPARAM ( "DiagonalTLBR" ) );
7786 			static const rtl::OUString	sDiagonalBLTR( RTL_CONSTASCII_USTRINGPARAM ( "DiagonalBLTR" ) );
7787 
7788 			sal_Int32 nPosition = *aIter & 0xffffff;
7789 			sal_Int32 nFlags = *aIter &~0xffffff;
7790 			sal_Int32 nRow = nPosition / nColumns;
7791 			sal_Int32 nColumn = nPosition - ( nRow * nColumns );
7792 			Reference< XCell > xCell( xCellRange->getCellByPosition( nColumn, nRow ) );
7793 			Reference< XPropertySet > xPropSet( xCell, UNO_QUERY_THROW );
7794 
7795 			if ( nFlags & LinePositionLeft )
7796 				xPropSet->setPropertyValue( sLeftBorder, Any( aBorderLine ) );
7797 			if ( nFlags & LinePositionTop )
7798 				xPropSet->setPropertyValue( sTopBorder, Any( aBorderLine ) );
7799 			if ( nFlags & LinePositionRight )
7800 				xPropSet->setPropertyValue( sRightBorder, Any( aBorderLine ) );
7801 			if ( nFlags & LinePositionBottom )
7802 				xPropSet->setPropertyValue( sBottomBorder, Any( aBorderLine ) );
7803 			if ( nFlags & LinePositionTLBR )
7804 				xPropSet->setPropertyValue( sDiagonalTLBR, Any( sal_True ) );
7805 			if ( nFlags & LinePositionBLTR )
7806 				xPropSet->setPropertyValue( sDiagonalBLTR, Any( sal_True ) );
7807 			aIter++;
7808 		}
7809 	}
7810 	catch( Exception& )
7811 	{
7812 	}
7813 }
7814 
CreateTable(SdrObject * pGroup,sal_uInt32 * pTableArry,SvxMSDffSolverContainer * pSolverContainer)7815 SdrObject* SdrPowerPointImport::CreateTable( SdrObject* pGroup, sal_uInt32* pTableArry, SvxMSDffSolverContainer* pSolverContainer )
7816 {
7817 	SdrObject* pRet = pGroup;
7818 	sal_uInt32 nRows = pTableArry[ 1 ];
7819 	if ( nRows && pGroup->ISA( SdrObjGroup ) )
7820 	{
7821 		SdrObjList* pSubList(((SdrObjGroup*)pGroup)->GetSubList());
7822 		if ( pSubList )
7823 		{
7824 			std::set< sal_Int32 > aRows;
7825 			std::set< sal_Int32 > aColumns;
7826 
7827 			SdrObjListIter aGroupIter( *pSubList, IM_DEEPNOGROUPS, sal_False );
7828 			while( aGroupIter.IsMore() )
7829 			{
7830 				const SdrObject* pObj( aGroupIter.Next() );
7831 				if ( !IsLine( pObj ) )
7832 				{
7833 					Rectangle aSnapRect( pObj->GetSnapRect() );
7834 					aRows.insert( aSnapRect.Top() );
7835 					aColumns.insert( aSnapRect.Left() );
7836 				}
7837 			}
7838 			::sdr::table::SdrTableObj* pTable = new ::sdr::table::SdrTableObj( pSdrModel );
7839 			pTable->uno_lock();
7840 			Reference< XTable > xTable( pTable->getTable() );
7841 			try
7842 			{
7843 				Reference< XColumnRowRange > xColumnRowRange( xTable, UNO_QUERY_THROW );
7844 
7845 				CreateTableRows( xColumnRowRange->getRows(), aRows, pGroup->GetSnapRect().Bottom() );
7846 				CreateTableColumns( xColumnRowRange->getColumns(), aColumns, pGroup->GetSnapRect().Right() );
7847 
7848 				sal_Int32 nCellCount = aRows.size() * aColumns.size();
7849 				sal_Int32 *pMergedCellIndexTable = new sal_Int32[ nCellCount ];
7850 				for ( sal_Int32 i = 0; i < nCellCount; i++ )
7851 					pMergedCellIndexTable[ i ] = i;
7852 
7853 				aGroupIter.Reset();
7854 				while( aGroupIter.IsMore() )
7855 				{
7856 					SdrObject* pObj( aGroupIter.Next() );
7857 					if ( !IsLine( pObj ) )
7858 					{
7859 						Rectangle aSnapRect( pObj->GetSnapRect() );
7860 						sal_Int32 nTableIndex = 0;
7861 						sal_Int32 nRow = 0;
7862 						sal_Int32 nRowCount = 0;
7863 						sal_Int32 nColumn = 0;
7864 						sal_Int32 nColumnCount = 0;
7865 						if ( GetCellPosition( pObj, aRows, aColumns, nTableIndex, nRow, nRowCount, nColumn, nColumnCount ) )
7866 						{
7867 							Reference< XCellRange > xCellRange( xTable, UNO_QUERY_THROW );
7868 							Reference< XCell > xCell( xCellRange->getCellByPosition( nColumn, nRow ) );
7869 
7870 							ApplyCellAttributes( pObj, xCell );
7871 
7872 							if ( ( nRowCount > 1 ) || ( nColumnCount > 1 ) )	// cell merging
7873 							{
7874 								MergeCells( xTable, nColumn, nRow, nColumnCount, nRowCount );
7875 								for ( sal_Int32 nRowIter = 0; nRowIter < nRowCount; nRowIter++ )
7876 								{
7877 									for ( sal_Int32 nColumnIter = 0; nColumnIter < nColumnCount; nColumnIter++ )
7878 									{	// now set the correct index for the merged cell
7879 										pMergedCellIndexTable[ ( ( nRow + nRowIter ) * aColumns.size() ) + nColumn + nColumnIter ] = nTableIndex;
7880 									}
7881 								}
7882 							}
7883 
7884 							// applying text
7885 							OutlinerParaObject* pParaObject = pObj->GetOutlinerParaObject();
7886 							if ( pParaObject )
7887 							{
7888 								SdrText* pSdrText = pTable->getText( nTableIndex );
7889 								if ( pSdrText )
7890 									pSdrText->SetOutlinerParaObject(new OutlinerParaObject(*pParaObject) );
7891 							}
7892 						}
7893 					}
7894 				}
7895 				aGroupIter.Reset();
7896 				while( aGroupIter.IsMore() )
7897 				{
7898 					SdrObject* pObj( aGroupIter.Next() );
7899 					if ( IsLine( pObj ) )
7900 					{
7901 						std::vector< sal_Int32 > vPositions;	// containing cell indexes + cell position
7902 						GetLinePositions( pObj, aRows, aColumns, vPositions, pGroup->GetSnapRect() );
7903 
7904 						// correcting merged cell position
7905 						std::vector< sal_Int32 >::iterator aIter( vPositions.begin() );
7906 						while( aIter != vPositions.end() )
7907 						{
7908 							sal_Int32 nOldPosition = *aIter & 0xffff;
7909 							sal_Int32 nOldFlags = *aIter & 0xffff0000;
7910 							sal_Int32 nNewPosition = pMergedCellIndexTable[ nOldPosition ] | nOldFlags;
7911 							*aIter++ = nNewPosition;
7912 						}
7913 						ApplyCellLineAttributes( pObj, xTable, vPositions, aColumns.size() );
7914 					}
7915 				}
7916 				delete[] pMergedCellIndexTable;
7917 
7918 				// we are replacing the whole group object by a single table object, so
7919 				// possibly connections to the group object have to be removed.
7920 				if ( pSolverContainer )
7921 				{
7922 					for ( SvxMSDffConnectorRule* pPtr = (SvxMSDffConnectorRule*)pSolverContainer->aCList.First();
7923 						pPtr; pPtr = (SvxMSDffConnectorRule*)pSolverContainer->aCList.Next() )
7924 					{
7925 						SdrObjListIter aIter( *pGroup, IM_DEEPWITHGROUPS );
7926 						while( aIter.IsMore() )
7927 						{
7928 							SdrObject* pPartObj = aIter.Next();
7929 							if ( pPtr->pAObj == pPartObj )
7930 								pPtr->pAObj = NULL;
7931 							if ( pPtr->pBObj == pPartObj )
7932 								pPtr->pBObj = NULL;
7933 						}
7934 						//In MS, the one_row_one_col table is made up of five shape,the connector is connected to some part of a table.
7935 						//but in AOO, the connector is connected to the whole group table,so the connector obj is a group table when export by AOO.
7936 						//should process this situation when import.
7937 						if ( pPtr->pAObj == pGroup )
7938 							pPtr->pAObj = pTable;
7939 						if ( pPtr->pBObj == pGroup )
7940 							pPtr->pBObj = pTable;
7941 					}
7942 				}
7943 				pTable->uno_unlock();
7944 				pTable->SetSnapRect( pGroup->GetSnapRect() );
7945 				pRet = pTable;
7946 
7947 				//Remove Objects from shape map
7948 				SdrObjListIter aIter( *pGroup, IM_DEEPWITHGROUPS );
7949 				while( aIter.IsMore() )
7950 				{
7951 					SdrObject* pPartObj = aIter.Next();
7952 					removeShapeId( pPartObj );
7953 				}
7954 
7955 				SdrObject::Free( pGroup );
7956 			}
7957 			catch( Exception& )
7958 			{
7959 				pTable->uno_unlock();
7960 				SdrObject* pObj = pTable;
7961 				SdrObject::Free( pObj );
7962 			}
7963 		}
7964 	}
7965 	return pRet;
7966 }
7967 
7968 
7969 ////////////////////////////////////////////////////////////////////////////////////////////////////
IsVerticalText() const7970 sal_Bool SdrPowerPointImport::IsVerticalText() const
7971 {
7972 	sal_Bool bVerticalText = sal_False;
7973 	if ( IsProperty( DFF_Prop_txflTextFlow ) )
7974 	{
7975 		MSO_TextFlow eTextFlow = (MSO_TextFlow)( GetPropertyValue( DFF_Prop_txflTextFlow ) & 0xFFFF );
7976 		switch( eTextFlow )
7977 		{
7978 		case mso_txflTtoBA :		            // Top to Bottom @-font, above -> below
7979 		case mso_txflTtoBN :					// Top to Bottom non-@, above -> below
7980 		case mso_txflVertN :					// Vertical, non-@, above -> below
7981 			bVerticalText = !bVerticalText;
7982 			break;
7983 		default: break;
7984 		}
7985 	}
7986 
7987 	return bVerticalText;
7988 }
7989 
ApplyTextAnchorAttributes(PPTTextObj & rTextObj,SfxItemSet & rSet) const7990 void	SdrPowerPointImport::ApplyTextAnchorAttributes( PPTTextObj& rTextObj, SfxItemSet& rSet ) const
7991 {
7992 	SdrTextVertAdjust eTVA;
7993 	SdrTextHorzAdjust eTHA;
7994 
7995 	sal_uInt32 nTextFlags = rTextObj.GetTextFlags();
7996 
7997 	nTextFlags &= PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT   | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT
7998 		| PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_CENTER | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_BLOCK;
7999 
8000 	if ( IsVerticalText() )
8001 	{
8002 		eTVA = SDRTEXTVERTADJUST_BLOCK;
8003 		eTHA = SDRTEXTHORZADJUST_CENTER;
8004 
8005 		// Textverankerung lesen
8006 		MSO_Anchor eTextAnchor = (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop );
8007 
8008 		switch( eTextAnchor )
8009 		{
8010 		case mso_anchorTop:
8011 		case mso_anchorTopCentered:
8012 			eTHA = SDRTEXTHORZADJUST_RIGHT;
8013 			break;
8014 
8015 		case mso_anchorMiddle :
8016 		case mso_anchorMiddleCentered:
8017 			eTHA = SDRTEXTHORZADJUST_CENTER;
8018 			break;
8019 
8020 		case mso_anchorBottom:
8021 		case mso_anchorBottomCentered:
8022 			eTHA = SDRTEXTHORZADJUST_LEFT;
8023 			break;
8024 
8025         default:
8026             break;
8027 		}
8028 		// if there is a 100% use of following attributes, the textbox can been aligned also in vertical direction
8029 		switch ( eTextAnchor )
8030 		{
8031 		case mso_anchorTopCentered :
8032 		case mso_anchorMiddleCentered :
8033 		case mso_anchorBottomCentered :
8034 			{
8035 				// check if it is sensible to use the centered alignment
8036 				sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT;
8037 				if ( ( nTextFlags & nMask ) != nMask )  // if the textobject has left or also right aligned pararagraphs
8038 					eTVA = SDRTEXTVERTADJUST_CENTER;    // the text has to be displayed using the full width;
8039 			}
8040 			break;
8041 
8042 		default :
8043 			{
8044 				if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT )
8045 					eTVA = SDRTEXTVERTADJUST_TOP;
8046 				else if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT )
8047 					eTVA = SDRTEXTVERTADJUST_BOTTOM;
8048 			}
8049 			break;
8050 		}
8051 	}
8052 	else
8053 	{
8054 		eTVA = SDRTEXTVERTADJUST_CENTER;
8055 		eTHA = SDRTEXTHORZADJUST_BLOCK;
8056 
8057 		// Textverankerung lesen
8058 		MSO_Anchor eTextAnchor = (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop );
8059 
8060 		switch( eTextAnchor )
8061 		{
8062 		case mso_anchorTop:
8063 		case mso_anchorTopCentered:
8064 			eTVA = SDRTEXTVERTADJUST_TOP;
8065 			break;
8066 
8067 		case mso_anchorMiddle :
8068 		case mso_anchorMiddleCentered:
8069 			eTVA = SDRTEXTVERTADJUST_CENTER;
8070 			break;
8071 
8072 		case mso_anchorBottom:
8073 		case mso_anchorBottomCentered:
8074 			eTVA = SDRTEXTVERTADJUST_BOTTOM;
8075 			break;
8076 
8077         default:
8078             break;
8079 		}
8080 		// if there is a 100% usage of following attributes, the textbox can be aligned also in horizontal direction
8081 		switch ( eTextAnchor )
8082 		{
8083 		case mso_anchorTopCentered :
8084 		case mso_anchorMiddleCentered :
8085 		case mso_anchorBottomCentered :
8086 			{
8087 				// check if it is sensible to use the centered alignment
8088 				sal_uInt32 nMask = PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT | PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT;
8089 				if ( ( nTextFlags & nMask ) != nMask )  // if the textobject has left or also right aligned pararagraphs
8090 					eTHA = SDRTEXTHORZADJUST_CENTER;    // the text has to be displayed using the full width;
8091 			}
8092 			break;
8093 
8094 		default :
8095 			{
8096 				if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_LEFT )
8097 					eTHA = SDRTEXTHORZADJUST_LEFT;
8098 				else if ( nTextFlags == PPT_TEXTOBJ_FLAGS_PARA_ALIGNMENT_USED_RIGHT )
8099 					eTHA = SDRTEXTHORZADJUST_RIGHT;
8100 			}
8101 			break;
8102 		}
8103 	}
8104 	rSet.Put( SdrTextVertAdjustItem( eTVA ) );
8105 	rSet.Put( SdrTextHorzAdjustItem( eTHA ) );
8106 }
8107