1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 #include "vcl/pdfextoutdevdata.hxx"
31 #include "vcl/graph.hxx"
32 #include "vcl/outdev.hxx"
33 #include "vcl/gfxlink.hxx"
34 #include "vcl/dllapi.h"
35 #include "basegfx/polygon/b2dpolygon.hxx"
36 #include "basegfx/polygon/b2dpolygontools.hxx"
37 
38 
39 #include <boost/shared_ptr.hpp>
40 #include <set>
41 #include <map>
42 
43 namespace vcl
44 {
45 struct SAL_DLLPRIVATE PDFExtOutDevDataSync
46 {
47     enum Action{    CreateNamedDest,
48                     CreateDest,
49 					CreateLink,
50 					SetLinkDest,
51 					SetLinkURL,
52                     RegisterDest,
53 					CreateOutlineItem,
54 					SetOutlineItemParent,
55 					SetOutlineItemText,
56 					SetOutlineItemDest,
57 					CreateNote,
58 					SetAutoAdvanceTime,
59 					SetPageTransition,
60 
61 					BeginStructureElement,
62 					EndStructureElement,
63                     SetCurrentStructureElement,
64 					SetStructureAttribute,
65 					SetStructureAttributeNumerical,
66 					SetStructureBoundingBox,
67 					SetActualText,
68 					SetAlternateText,
69                     CreateControl,
70 					BeginGroup,
71 					EndGroup,
72 					EndGroupGfxLink
73 	};
74 
75 	sal_uInt32	nIdx;
76 	Action		eAct;
77 };
78 
79 struct SAL_DLLPRIVATE PDFLinkDestination
80 {
81     Rectangle               mRect;
82     MapMode                 mMapMode;
83     sal_Int32               mPageNr;
84     PDFWriter::DestAreaType mAreaType;
85 };
86 
87 struct SAL_DLLPRIVATE GlobalSyncData
88 {
89 	std::deque< PDFExtOutDevDataSync::Action >	mActions;
90 	std::deque< MapMode >						mParaMapModes;
91 	std::deque< Rectangle >						mParaRects;
92 	std::deque< sal_Int32 >						mParaInts;
93 	std::deque< sal_uInt32 >					mParauInts;
94 	std::deque< rtl::OUString >					mParaOUStrings;
95 	std::deque< PDFWriter::DestAreaType >		mParaDestAreaTypes;
96 	std::deque< PDFNote >						mParaPDFNotes;
97 	std::deque< PDFWriter::PageTransition >		mParaPageTransitions;
98     ::std::map< sal_Int32, PDFLinkDestination > mFutureDestinations;
99 
100 	sal_Int32 GetMappedId();
101     sal_Int32 GetMappedStructId( sal_Int32 );
102 
103 	sal_Int32					mCurId;
104 	std::vector< sal_Int32 >	mParaIds;
105     std::vector< sal_Int32 >	mStructIdMap;
106 
107     sal_Int32					mCurrentStructElement;
108     std::vector< sal_Int32 >	mStructParents;
109 	GlobalSyncData() :
110             mCurId ( 0 ),
111             mCurrentStructElement( 0 )
112     {
113         mStructParents.push_back( 0 );
114         mStructIdMap.push_back( 0 );
115     }
116 	void PlayGlobalActions( PDFWriter& rWriter );
117 };
118 
119 sal_Int32 GlobalSyncData::GetMappedId()
120 {
121 	sal_Int32 nLinkId = mParaInts.front();
122 	mParaInts.pop_front();
123 
124     /*  negative values are intentionally passed as invalid IDs
125      *  e.g. to create a new top level outline item
126      */
127     if( nLinkId >= 0 )
128     {
129         if ( (sal_uInt32)nLinkId < mParaIds.size() )
130             nLinkId = mParaIds[ nLinkId ];
131         else
132             nLinkId = -1;
133 
134         DBG_ASSERT( nLinkId >= 0, "unmapped id in GlobalSyncData" );
135     }
136 
137 	return nLinkId;
138 }
139 
140 sal_Int32 GlobalSyncData::GetMappedStructId( sal_Int32 nStructId )
141 {
142 	if ( (sal_uInt32)nStructId < mStructIdMap.size() )
143 		nStructId = mStructIdMap[ nStructId ];
144 	else
145 		nStructId = -1;
146 
147     DBG_ASSERT( nStructId >= 0, "unmapped structure id in GlobalSyncData" );
148 
149 	return nStructId;
150 }
151 
152 void GlobalSyncData::PlayGlobalActions( PDFWriter& rWriter )
153 {
154 	std::deque< PDFExtOutDevDataSync::Action >::iterator aIter( mActions.begin() );
155 	std::deque< PDFExtOutDevDataSync::Action >::iterator aEnd( mActions.end() );
156 	while( aIter != aEnd )
157 	{
158 		switch( *aIter )
159 		{
160             case PDFExtOutDevDataSync::CreateNamedDest : //i56629
161 			{
162  				rWriter.Push( PUSH_MAPMODE );
163 				rWriter.SetMapMode( mParaMapModes.front() );
164 				mParaMapModes.pop_front();
165 				mParaIds.push_back( rWriter.CreateNamedDest( mParaOUStrings.front(), mParaRects.front(), mParaInts.front(), mParaDestAreaTypes.front() ) );
166                 mParaOUStrings.pop_front();
167 				mParaRects.pop_front();
168 				mParaInts.pop_front();
169 				mParaDestAreaTypes.pop_front();
170 				rWriter.Pop();
171 			}
172 			break;
173 			case PDFExtOutDevDataSync::CreateDest :
174 			{
175 				rWriter.Push( PUSH_MAPMODE );
176 				rWriter.SetMapMode( mParaMapModes.front() );
177 				mParaMapModes.pop_front();
178 				mParaIds.push_back( rWriter.CreateDest( mParaRects.front(), mParaInts.front(), mParaDestAreaTypes.front() ) );
179 				mParaRects.pop_front();
180 				mParaInts.pop_front();
181 				mParaDestAreaTypes.pop_front();
182 				rWriter.Pop();
183 			}
184 			break;
185 			case PDFExtOutDevDataSync::CreateLink :
186 			{
187 				rWriter.Push( PUSH_MAPMODE );
188 				rWriter.SetMapMode( mParaMapModes.front() );
189 				mParaMapModes.pop_front();
190 				mParaIds.push_back( rWriter.CreateLink( mParaRects.front(), mParaInts.front() ) );
191                 // resolve LinkAnnotation structural attribute
192                 rWriter.SetLinkPropertyID( mParaIds.back(), sal_Int32(mParaIds.size()-1) );
193 				mParaRects.pop_front();
194 				mParaInts.pop_front();
195 				rWriter.Pop();
196 			}
197 			break;
198 			case PDFExtOutDevDataSync::SetLinkDest :
199 			{
200 				sal_Int32 nLinkId = GetMappedId();
201 				sal_Int32 nDestId = GetMappedId();
202 				rWriter.SetLinkDest( nLinkId, nDestId );
203 			}
204 			break;
205 			case PDFExtOutDevDataSync::SetLinkURL :
206 			{
207 				sal_Int32 nLinkId = GetMappedId();
208 				rWriter.SetLinkURL( nLinkId, mParaOUStrings.front() );
209 				mParaOUStrings.pop_front();
210 			}
211 			break;
212             case PDFExtOutDevDataSync::RegisterDest :
213             {
214 				const sal_Int32 nDestId = mParaInts.front();
215                 mParaInts.pop_front();
216                 OSL_ENSURE( mFutureDestinations.find( nDestId ) != mFutureDestinations.end(),
217                     "GlobalSyncData::PlayGlobalActions: DescribeRegisteredRequest has not been called for that destination!" );
218 
219                 PDFLinkDestination& rDest = mFutureDestinations[ nDestId ];
220 
221                 rWriter.Push( PUSH_MAPMODE );
222 				rWriter.SetMapMode( rDest.mMapMode );
223 				mParaIds.push_back( rWriter.RegisterDestReference( nDestId, rDest.mRect, rDest.mPageNr, rDest.mAreaType ) );
224 				rWriter.Pop();
225             }
226             break;
227 			case PDFExtOutDevDataSync::CreateOutlineItem :
228 			{
229 				sal_Int32 nParent = GetMappedId();
230 				sal_Int32 nLinkId = GetMappedId();
231 				mParaIds.push_back( rWriter.CreateOutlineItem( nParent, mParaOUStrings.front(), nLinkId ) );
232 				mParaOUStrings.pop_front();
233 			}
234 			break;
235 			case PDFExtOutDevDataSync::SetOutlineItemParent :
236 			{
237 				sal_Int32 nItem = GetMappedId();
238 				sal_Int32 nNewParent = GetMappedId();
239 				rWriter.SetOutlineItemParent( nItem, nNewParent );
240 			}
241 			break;
242 			case PDFExtOutDevDataSync::SetOutlineItemText :
243 			{
244 				sal_Int32 nItem = GetMappedId();
245 				rWriter.SetOutlineItemText( nItem, mParaOUStrings.front() );
246 				mParaOUStrings.pop_front();
247 			}
248 			break;
249 			case PDFExtOutDevDataSync::SetOutlineItemDest :
250 			{
251 				sal_Int32 nItem = GetMappedId();
252 				sal_Int32 nDestId = GetMappedId();
253 				rWriter.SetOutlineItemDest( nItem, nDestId );
254 			}
255 			break;
256 			case PDFExtOutDevDataSync::CreateNote :
257 			{
258 				rWriter.Push( PUSH_MAPMODE );
259 				rWriter.SetMapMode( mParaMapModes.front() );
260 				rWriter.CreateNote( mParaRects.front(), mParaPDFNotes.front(), mParaInts.front() );
261 				mParaMapModes.pop_front();
262 				mParaRects.pop_front();
263 				mParaPDFNotes.pop_front();
264 				mParaInts.pop_front();
265 			}
266 			break;
267 			case PDFExtOutDevDataSync::SetAutoAdvanceTime :
268 			{
269 				rWriter.SetAutoAdvanceTime( mParauInts.front(), mParaInts.front() );
270 				mParauInts.pop_front();
271 				mParaInts.pop_front();
272 			}
273 			break;
274 			case PDFExtOutDevDataSync::SetPageTransition :
275 			{
276 				rWriter.SetPageTransition( mParaPageTransitions.front(), mParauInts.front(), mParaInts.front() );
277 				mParaPageTransitions.pop_front();
278 				mParauInts.pop_front();
279 				mParaInts.pop_front();
280 			}
281 			break;
282             case PDFExtOutDevDataSync::BeginStructureElement:
283             case PDFExtOutDevDataSync::EndStructureElement:
284             case PDFExtOutDevDataSync::SetCurrentStructureElement:
285             case PDFExtOutDevDataSync::SetStructureAttribute:
286             case PDFExtOutDevDataSync::SetStructureAttributeNumerical:
287             case PDFExtOutDevDataSync::SetStructureBoundingBox:
288             case PDFExtOutDevDataSync::SetActualText:
289             case PDFExtOutDevDataSync::SetAlternateText:
290             case PDFExtOutDevDataSync::CreateControl:
291             case PDFExtOutDevDataSync::BeginGroup:
292             case PDFExtOutDevDataSync::EndGroup:
293             case PDFExtOutDevDataSync::EndGroupGfxLink:
294                 break;
295 		}
296 		aIter++;
297 	}
298 }
299 
300 struct PageSyncData
301 {
302 	std::deque< PDFExtOutDevDataSync >				mActions;
303 	std::deque< Rectangle >							mParaRects;
304 	std::deque< sal_Int32 >							mParaInts;
305 	std::deque< rtl::OUString >						mParaOUStrings;
306 	std::deque< PDFWriter::StructElement >			mParaStructElements;
307 	std::deque< PDFWriter::StructAttribute >		mParaStructAttributes;
308 	std::deque< PDFWriter::StructAttributeValue >	mParaStructAttributeValues;
309 	std::deque< Graphic >							mGraphics;
310     std::deque< ::boost::shared_ptr< PDFWriter::AnyWidget > >
311                                                     mControls;
312     GlobalSyncData*									mpGlobalData;
313 
314 	sal_Bool										mbGroupIgnoreGDIMtfActions;
315 
316 	PageSyncData( GlobalSyncData* pGlobal ) : mbGroupIgnoreGDIMtfActions ( sal_False ) { mpGlobalData = pGlobal; }
317 
318 	void PushAction( const OutputDevice& rOutDev, const PDFExtOutDevDataSync::Action eAct );
319 	sal_Bool PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAction, const PDFExtOutDevData& rOutDevData );
320 };
321 void PageSyncData::PushAction( const OutputDevice& rOutDev, const PDFExtOutDevDataSync::Action eAct )
322 {
323 	GDIMetaFile* pMtf = rOutDev.GetConnectMetaFile();
324 	DBG_ASSERT( pMtf, "PageSyncData::PushAction -> no ConnectMetaFile !!!" );
325 
326 	PDFExtOutDevDataSync aSync;
327 	aSync.eAct = eAct;
328 	if ( pMtf )
329 		aSync.nIdx = pMtf->GetActionCount();
330 	else
331 		aSync.nIdx = 0x7fffffff;	// sync not possible
332 	mActions.push_back( aSync );
333 }
334 sal_Bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAction, const PDFExtOutDevData& rOutDevData )
335 {
336 	sal_Bool bRet = sal_False;
337 	if ( mActions.size() && ( mActions.front().nIdx == rCurGDIMtfAction ) )
338 	{
339 		bRet = sal_True;
340 		PDFExtOutDevDataSync aDataSync = mActions.front();
341 		mActions.pop_front();
342 		switch( aDataSync.eAct )
343 		{
344 			case PDFExtOutDevDataSync::BeginStructureElement :
345 			{
346                 sal_Int32 nNewEl = rWriter.BeginStructureElement( mParaStructElements.front(), mParaOUStrings.front() ) ;
347 				mParaStructElements.pop_front();
348                 mParaOUStrings.pop_front();
349 				mpGlobalData->mStructIdMap.push_back( nNewEl );
350 			}
351 			break;
352 			case PDFExtOutDevDataSync::EndStructureElement :
353 			{
354 				rWriter.EndStructureElement();
355 			}
356 			break;
357             case PDFExtOutDevDataSync::SetCurrentStructureElement:
358             {
359                 rWriter.SetCurrentStructureElement( mpGlobalData->GetMappedStructId( mParaInts.front() ) );
360                 mParaInts.pop_front();
361             }
362             break;
363 			case PDFExtOutDevDataSync::SetStructureAttribute :
364 			{
365 				rWriter.SetStructureAttribute( mParaStructAttributes.front(), mParaStructAttributeValues.front() );
366 				mParaStructAttributeValues.pop_front();
367 				mParaStructAttributes.pop_front();
368 			}
369 			break;
370 			case PDFExtOutDevDataSync::SetStructureAttributeNumerical :
371 			{
372 				rWriter.SetStructureAttributeNumerical( mParaStructAttributes.front(), mParaInts.front() );
373 				mParaStructAttributes.pop_front();
374 				mParaInts.pop_front();
375 			}
376 			break;
377 			case PDFExtOutDevDataSync::SetStructureBoundingBox :
378 			{
379 				rWriter.SetStructureBoundingBox( mParaRects.front() );
380 				mParaRects.pop_front();
381 			}
382 			break;
383 			case PDFExtOutDevDataSync::SetActualText :
384 			{
385 				rWriter.SetActualText( mParaOUStrings.front() );
386 				mParaOUStrings.pop_front();
387 			}
388 			break;
389 			case PDFExtOutDevDataSync::SetAlternateText :
390 			{
391 				rWriter.SetAlternateText( mParaOUStrings.front() );
392 				mParaOUStrings.pop_front();
393 			}
394 			break;
395             case PDFExtOutDevDataSync::CreateControl:
396             {
397                 ::boost::shared_ptr< PDFWriter::AnyWidget > pControl( mControls.front() );
398                 DBG_ASSERT( pControl.get(), "PageSyncData::PlaySyncPageAct: invalid widget!" );
399                 if ( pControl.get() )
400                     rWriter.CreateControl( *pControl );
401 				mControls.pop_front();
402             }
403             break;
404 			case PDFExtOutDevDataSync::BeginGroup :
405 			{
406 				/* first determining if this BeginGroup is starting a GfxLink,
407 				   by searching for a EndGroup or a EndGroupGfxLink */
408 				mbGroupIgnoreGDIMtfActions = sal_False;
409 				std::deque< PDFExtOutDevDataSync >::iterator aBeg = mActions.begin();
410 				std::deque< PDFExtOutDevDataSync >::iterator aEnd = mActions.end();
411 				while ( aBeg != aEnd )
412 				{
413 					if ( aBeg->eAct == PDFExtOutDevDataSync::EndGroup )
414 					{
415 						break;
416 					}
417 					else if ( aBeg->eAct == PDFExtOutDevDataSync::EndGroupGfxLink )
418 					{
419 						if ( rOutDevData.GetIsLosslessCompression() && !rOutDevData.GetIsReduceImageResolution() )
420 						{
421 							Graphic& rGraphic = mGraphics.front();
422 							if ( rGraphic.IsLink() && rGraphic.GetLink().GetType() == GFX_LINK_TYPE_NATIVE_JPG )
423 							{
424 								mbGroupIgnoreGDIMtfActions = sal_True;
425 							}
426 						}
427 						break;
428 					}
429 					aBeg++;
430 				}
431 			}
432 			break;
433 			case PDFExtOutDevDataSync::EndGroup :
434 			{
435 				mbGroupIgnoreGDIMtfActions = sal_False;
436 			}
437 			break;
438 			case PDFExtOutDevDataSync::EndGroupGfxLink :
439 			{
440                 sal_Int32 nTransparency;
441                 Rectangle aOutputRect, aVisibleOutputRect;
442                 Graphic   aGraphic( mGraphics.front() );
443 
444                 mGraphics.pop_front();
445                 nTransparency = mParaInts.front();
446                 mParaInts.pop_front();
447                 aOutputRect = mParaRects.front();
448                 mParaRects.pop_front();
449                 aVisibleOutputRect = mParaRects.front();
450                 mParaRects.pop_front();
451 
452 				if ( mbGroupIgnoreGDIMtfActions )
453 				{
454 					sal_Bool bClippingNeeded = ( aOutputRect != aVisibleOutputRect ) && !aVisibleOutputRect.IsEmpty();
455 
456 					GfxLink	  aGfxLink( aGraphic.GetLink() );
457 					if ( aGfxLink.GetType() == GFX_LINK_TYPE_NATIVE_JPG )
458 					{
459 						if ( bClippingNeeded )
460 						{
461 							rWriter.Push();
462                             basegfx::B2DPolyPolygon aRect( basegfx::tools::createPolygonFromRect(
463                                 basegfx::B2DRectangle( aVisibleOutputRect.Left(), aVisibleOutputRect.Top(),
464                                                        aVisibleOutputRect.Right(), aVisibleOutputRect.Bottom() ) ) );
465 							rWriter.SetClipRegion( aRect);
466 						}
467 						Bitmap aMask;
468 						SvMemoryStream aTmp;
469                         const sal_uInt8* pData = aGfxLink.GetData();
470                         sal_uInt32 nBytes = aGfxLink.GetDataSize();
471                         if( pData && nBytes )
472                         {
473                             aTmp.Write( pData, nBytes );
474                             rWriter.DrawJPGBitmap( aTmp, aGraphic.GetBitmap().GetBitCount() > 8, aGraphic.GetSizePixel(), aOutputRect, aMask );
475                         }
476 
477 						if ( bClippingNeeded )
478 							rWriter.Pop();
479 					}
480 					mbGroupIgnoreGDIMtfActions = sal_False;
481 				}
482 			}
483 			break;
484             case PDFExtOutDevDataSync::CreateNamedDest:
485             case PDFExtOutDevDataSync::CreateDest:
486             case PDFExtOutDevDataSync::CreateLink:
487             case PDFExtOutDevDataSync::SetLinkDest:
488             case PDFExtOutDevDataSync::SetLinkURL:
489             case PDFExtOutDevDataSync::RegisterDest:
490             case PDFExtOutDevDataSync::CreateOutlineItem:
491             case PDFExtOutDevDataSync::SetOutlineItemParent:
492             case PDFExtOutDevDataSync::SetOutlineItemText:
493             case PDFExtOutDevDataSync::SetOutlineItemDest:
494             case PDFExtOutDevDataSync::CreateNote:
495             case PDFExtOutDevDataSync::SetAutoAdvanceTime:
496             case PDFExtOutDevDataSync::SetPageTransition:
497                 break;
498 		}
499 	}
500 	else if ( mbGroupIgnoreGDIMtfActions )
501 	{
502 		rCurGDIMtfAction++;
503 		bRet = sal_True;
504 	}
505 	return bRet;
506 }
507 
508 TYPEINIT1(PDFExtOutDevData,ExtOutDevData);
509 PDFExtOutDevData::PDFExtOutDevData( const OutputDevice& rOutDev ) :
510 	mrOutDev				( rOutDev ),
511 	mbTaggedPDF				( sal_False ),
512 	mbExportNotes			( sal_True ),
513 	mbTransitionEffects		( sal_True ),
514 	mbUseLosslessCompression( sal_True ),
515 	mbReduceImageResolution	( sal_False ),
516     mbExportNDests          ( sal_False ),
517 	mnFormsFormat			( 0 ),
518 	mnPage					( -1 ),
519 	mpPageSyncData			( NULL ),
520 	mpGlobalSyncData		( new GlobalSyncData() )
521 {
522     mpPageSyncData = new PageSyncData( mpGlobalSyncData );
523 }
524 
525 PDFExtOutDevData::~PDFExtOutDevData()
526 {
527 	delete mpPageSyncData;
528 	delete mpGlobalSyncData;
529 }
530 
531 const com::sun::star::lang::Locale& PDFExtOutDevData::GetDocumentLocale() const
532 {
533     return maDocLocale;
534 }
535 void PDFExtOutDevData::SetDocumentLocale( const com::sun::star::lang::Locale& rLoc )
536 {
537     maDocLocale = rLoc;
538 }
539 sal_Int32 PDFExtOutDevData::GetCurrentPageNumber() const
540 {
541 	return mnPage;
542 }
543 void PDFExtOutDevData::SetCurrentPageNumber( const sal_Int32 nPage )
544 {
545 	mnPage = nPage;
546 }
547 sal_Bool PDFExtOutDevData::GetIsLosslessCompression() const
548 {
549 	return mbUseLosslessCompression;
550 }
551 void PDFExtOutDevData::SetIsLosslessCompression( const sal_Bool bUseLosslessCompression )
552 {
553 	mbUseLosslessCompression = bUseLosslessCompression;
554 }
555 sal_Bool PDFExtOutDevData::GetIsReduceImageResolution() const
556 {
557 	return mbReduceImageResolution;
558 }
559 void PDFExtOutDevData::SetIsReduceImageResolution( const sal_Bool bReduceImageResolution )
560 {
561 	mbReduceImageResolution = bReduceImageResolution;
562 }
563 sal_Bool PDFExtOutDevData::GetIsExportNotes() const
564 {
565 	return mbExportNotes;
566 }
567 void PDFExtOutDevData::SetIsExportNotes( const sal_Bool bExportNotes )
568 {
569 	mbExportNotes = bExportNotes;
570 }
571 sal_Bool PDFExtOutDevData::GetIsExportTaggedPDF() const
572 {
573 	return mbTaggedPDF;
574 }
575 void PDFExtOutDevData::SetIsExportTaggedPDF( const sal_Bool bTaggedPDF )
576 {
577 	mbTaggedPDF = bTaggedPDF;
578 }
579 sal_Bool PDFExtOutDevData::GetIsExportTransitionEffects() const
580 {
581 	return mbTransitionEffects;
582 }
583 void PDFExtOutDevData::SetIsExportTransitionEffects( const sal_Bool bTransitionEffects )
584 {
585 	mbTransitionEffects = bTransitionEffects;
586 }
587 sal_Bool PDFExtOutDevData::GetIsExportFormFields() const
588 {
589     return mbExportFormFields;
590 }
591 void PDFExtOutDevData::SetIsExportFormFields( const sal_Bool bExportFomtFields )
592 {
593     mbExportFormFields = bExportFomtFields;
594 }
595 sal_Int32 PDFExtOutDevData::GetFormsFormat() const
596 {
597 	return mnFormsFormat;
598 }
599 void PDFExtOutDevData::SetFormsFormat( const sal_Int32 nFormsFormat )
600 {
601 	mnFormsFormat = nFormsFormat;
602 }
603 sal_Bool PDFExtOutDevData::GetIsExportBookmarks() const
604 {
605     return mbExportBookmarks;
606 }
607 void PDFExtOutDevData::SetIsExportBookmarks( const sal_Bool bExportBookmarks )
608 {
609     mbExportBookmarks = bExportBookmarks;
610 }
611 std::vector< PDFExtOutDevBookmarkEntry >& PDFExtOutDevData::GetBookmarks()
612 {
613 	return maBookmarks;
614 }
615 sal_Bool PDFExtOutDevData::GetIsExportNamedDestinations() const
616 {
617     return mbExportNDests;
618 }
619 void PDFExtOutDevData::SetIsExportNamedDestinations( const sal_Bool bExportNDests )
620 {
621     mbExportNDests = bExportNDests;
622 }
623 void PDFExtOutDevData::ResetSyncData()
624 {
625 	*mpPageSyncData = PageSyncData( mpGlobalSyncData );
626 }
627 sal_Bool PDFExtOutDevData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rIdx )
628 {
629 	return mpPageSyncData->PlaySyncPageAct( rWriter, rIdx, *this );
630 }
631 void PDFExtOutDevData::PlayGlobalActions( PDFWriter& rWriter )
632 {
633 	mpGlobalSyncData->PlayGlobalActions( rWriter );
634 }
635 
636 /* global actions, syncronisation to the recorded metafile isn't needed,
637    all actions will be played after the last page was recorded
638 */
639 //--->i56629
640 sal_Int32 PDFExtOutDevData::CreateNamedDest(const String& sDestName,  const Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType )
641 {
642     mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateNamedDest );
643     mpGlobalSyncData->mParaOUStrings.push_back( sDestName );
644     mpGlobalSyncData->mParaRects.push_back( rRect );
645     mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
646     mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
647     mpGlobalSyncData->mParaDestAreaTypes.push_back( eType );
648 
649     return mpGlobalSyncData->mCurId++;
650 }
651 //<---i56629
652 sal_Int32 PDFExtOutDevData::RegisterDest()
653 {
654     const sal_Int32 nLinkDestID = mpGlobalSyncData->mCurId++;
655     mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::RegisterDest );
656     mpGlobalSyncData->mParaInts.push_back( nLinkDestID );
657 
658     return nLinkDestID;
659 }
660 void PDFExtOutDevData::DescribeRegisteredDest( sal_Int32 nDestId, const Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType )
661 {
662     OSL_PRECOND( nDestId != -1, "PDFExtOutDevData::DescribeRegisteredDest: invalid destination Id!" );
663     PDFLinkDestination aLinkDestination;
664     aLinkDestination.mRect = rRect;
665     aLinkDestination.mMapMode = mrOutDev.GetMapMode();
666     aLinkDestination.mPageNr = nPageNr == -1 ? mnPage : nPageNr;
667     aLinkDestination.mAreaType = eType;
668     mpGlobalSyncData->mFutureDestinations[ nDestId ] = aLinkDestination;
669 }
670 sal_Int32 PDFExtOutDevData::CreateDest( const Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType )
671 {
672 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateDest );
673 	mpGlobalSyncData->mParaRects.push_back( rRect );
674 	mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
675 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
676 	mpGlobalSyncData->mParaDestAreaTypes.push_back( eType );
677 	return mpGlobalSyncData->mCurId++;
678 }
679 sal_Int32 PDFExtOutDevData::CreateLink( const Rectangle& rRect, sal_Int32 nPageNr )
680 {
681 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateLink );
682 	mpGlobalSyncData->mParaRects.push_back( rRect );
683 	mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
684 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
685 	return mpGlobalSyncData->mCurId++;
686 }
687 sal_Int32 PDFExtOutDevData::SetLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId )
688 {
689 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetLinkDest );
690 	mpGlobalSyncData->mParaInts.push_back( nLinkId );
691 	mpGlobalSyncData->mParaInts.push_back( nDestId );
692 	return 0;
693 }
694 sal_Int32 PDFExtOutDevData::SetLinkURL( sal_Int32 nLinkId, const rtl::OUString& rURL )
695 {
696 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetLinkURL );
697 	mpGlobalSyncData->mParaInts.push_back( nLinkId );
698 	mpGlobalSyncData->mParaOUStrings.push_back( rURL );
699 	return 0;
700 }
701 sal_Int32 PDFExtOutDevData::CreateOutlineItem( sal_Int32 nParent, const rtl::OUString& rText, sal_Int32 nDestID )
702 {
703 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateOutlineItem );
704 	mpGlobalSyncData->mParaInts.push_back( nParent );
705 	mpGlobalSyncData->mParaOUStrings.push_back( rText );
706 	mpGlobalSyncData->mParaInts.push_back( nDestID );
707 	return mpGlobalSyncData->mCurId++;
708 }
709 sal_Int32 PDFExtOutDevData::SetOutlineItemParent( sal_Int32 nItem, sal_Int32 nNewParent )
710 {
711 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetOutlineItemParent );
712 	mpGlobalSyncData->mParaInts.push_back( nItem );
713 	mpGlobalSyncData->mParaInts.push_back( nNewParent );
714 	return 0;
715 }
716 sal_Int32 PDFExtOutDevData::SetOutlineItemText( sal_Int32 nItem, const rtl::OUString& rText )
717 {
718 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetOutlineItemText );
719 	mpGlobalSyncData->mParaInts.push_back( nItem );
720 	mpGlobalSyncData->mParaOUStrings.push_back( rText );
721 	return 0;
722 }
723 sal_Int32 PDFExtOutDevData::SetOutlineItemDest( sal_Int32 nItem, sal_Int32 nDestID )
724 {
725 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetOutlineItemDest );
726 	mpGlobalSyncData->mParaInts.push_back( nItem );
727 	mpGlobalSyncData->mParaInts.push_back( nDestID );
728 	return 0;
729 }
730 void PDFExtOutDevData::CreateNote( const Rectangle& rRect, const PDFNote& rNote, sal_Int32 nPageNr )
731 {
732 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateNote );
733 	mpGlobalSyncData->mParaRects.push_back( rRect );
734 	mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
735 	mpGlobalSyncData->mParaPDFNotes.push_back( rNote );
736 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
737 }
738 void PDFExtOutDevData::SetAutoAdvanceTime( sal_uInt32 nSeconds, sal_Int32 nPageNr )
739 {
740 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetAutoAdvanceTime );
741 	mpGlobalSyncData->mParauInts.push_back( nSeconds );
742 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
743 }
744 void PDFExtOutDevData::SetPageTransition( PDFWriter::PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr )
745 {
746 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetPageTransition );
747 	mpGlobalSyncData->mParaPageTransitions.push_back( eType );
748 	mpGlobalSyncData->mParauInts.push_back( nMilliSec );
749 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
750 }
751 
752 /* local (page), actions have to be played synchroniously to the actions of
753    of the recorded metafile (created by each xRenderable->render()) */
754    sal_Int32 PDFExtOutDevData::BeginStructureElement( PDFWriter::StructElement eType, const rtl::OUString& rAlias )
755 {
756 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::BeginStructureElement );
757 	mpPageSyncData->mParaStructElements.push_back( eType );
758     mpPageSyncData->mParaOUStrings.push_back( rAlias );
759     // need a global id
760     sal_Int32 nNewId = mpGlobalSyncData->mStructParents.size();
761     mpGlobalSyncData->mStructParents.push_back( mpGlobalSyncData->mCurrentStructElement );
762     mpGlobalSyncData->mCurrentStructElement = nNewId;
763     return nNewId;
764 }
765 void PDFExtOutDevData::EndStructureElement()
766 {
767 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::EndStructureElement );
768     mpGlobalSyncData->mCurrentStructElement = mpGlobalSyncData->mStructParents[ mpGlobalSyncData->mCurrentStructElement ];
769 }
770 bool PDFExtOutDevData::SetCurrentStructureElement( sal_Int32 nStructId )
771 {
772     bool bSuccess = false;
773     if( sal_uInt32(nStructId) < mpGlobalSyncData->mStructParents.size() )
774     {
775         mpGlobalSyncData->mCurrentStructElement = nStructId;
776         mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetCurrentStructureElement );
777         mpPageSyncData->mParaInts.push_back( nStructId );
778         bSuccess = true;
779     }
780     return bSuccess;
781 }
782 sal_Int32 PDFExtOutDevData::GetCurrentStructureElement()
783 {
784     return mpGlobalSyncData->mCurrentStructElement;
785 }
786 bool PDFExtOutDevData::SetStructureAttribute( PDFWriter::StructAttribute eAttr, PDFWriter::StructAttributeValue eVal )
787 {
788 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetStructureAttribute );
789 	mpPageSyncData->mParaStructAttributes.push_back( eAttr );
790 	mpPageSyncData->mParaStructAttributeValues.push_back( eVal );
791 	return true;
792 }
793 bool PDFExtOutDevData::SetStructureAttributeNumerical( PDFWriter::StructAttribute eAttr, sal_Int32 nValue )
794 {
795 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetStructureAttributeNumerical );
796 	mpPageSyncData->mParaStructAttributes.push_back( eAttr );
797 	mpPageSyncData->mParaInts.push_back( nValue );
798 	return true;
799 }
800 void PDFExtOutDevData::SetStructureBoundingBox( const Rectangle& rRect )
801 {
802 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetStructureBoundingBox );
803 	mpPageSyncData->mParaRects.push_back( rRect );
804 }
805 void PDFExtOutDevData::SetActualText( const String& rText )
806 {
807 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetActualText );
808 	mpPageSyncData->mParaOUStrings.push_back( rText );
809 }
810 void PDFExtOutDevData::SetAlternateText( const String& rText )
811 {
812 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetAlternateText );
813 	mpPageSyncData->mParaOUStrings.push_back( rText );
814 }
815 
816 void PDFExtOutDevData::CreateControl( const PDFWriter::AnyWidget& rControlType, sal_Int32 /*nPageNr*/ )
817 {
818 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::CreateControl );
819 
820     ::boost::shared_ptr< PDFWriter::AnyWidget > pClone( rControlType.Clone() );
821     mpPageSyncData->mControls.push_back( pClone );
822 }
823 
824 void PDFExtOutDevData::BeginGroup()
825 {
826 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::BeginGroup );
827 }
828 
829 void PDFExtOutDevData::EndGroup()
830 {
831 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::EndGroup );
832 }
833 void PDFExtOutDevData::EndGroup( const Graphic& 	rGraphic,
834                                  sal_uInt8				nTransparency,
835                                  const Rectangle& 	rOutputRect,
836                                  const Rectangle& 	rVisibleOutputRect )
837 {
838 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::EndGroupGfxLink );
839 	mpPageSyncData->mGraphics.push_back( rGraphic );
840 	mpPageSyncData->mParaInts.push_back( nTransparency );
841 	mpPageSyncData->mParaRects.push_back( rOutputRect );
842 	mpPageSyncData->mParaRects.push_back( rVisibleOutputRect );
843 }
844 
845 }
846