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 	mbExportNotesPages		( sal_False ),
514 	mbTransitionEffects		( sal_True ),
515 	mbUseLosslessCompression( sal_True ),
516 	mbReduceImageResolution	( sal_False ),
517     mbExportNDests          ( sal_False ),
518 	mnFormsFormat			( 0 ),
519 	mnPage					( -1 ),
520 	mpPageSyncData			( NULL ),
521 	mpGlobalSyncData		( new GlobalSyncData() )
522 {
523     mpPageSyncData = new PageSyncData( mpGlobalSyncData );
524 }
525 
526 PDFExtOutDevData::~PDFExtOutDevData()
527 {
528 	delete mpPageSyncData;
529 	delete mpGlobalSyncData;
530 }
531 
532 const com::sun::star::lang::Locale& PDFExtOutDevData::GetDocumentLocale() const
533 {
534     return maDocLocale;
535 }
536 void PDFExtOutDevData::SetDocumentLocale( const com::sun::star::lang::Locale& rLoc )
537 {
538     maDocLocale = rLoc;
539 }
540 sal_Int32 PDFExtOutDevData::GetCurrentPageNumber() const
541 {
542 	return mnPage;
543 }
544 void PDFExtOutDevData::SetCurrentPageNumber( const sal_Int32 nPage )
545 {
546 	mnPage = nPage;
547 }
548 sal_Bool PDFExtOutDevData::GetIsLosslessCompression() const
549 {
550 	return mbUseLosslessCompression;
551 }
552 void PDFExtOutDevData::SetIsLosslessCompression( const sal_Bool bUseLosslessCompression )
553 {
554 	mbUseLosslessCompression = bUseLosslessCompression;
555 }
556 sal_Bool PDFExtOutDevData::GetIsReduceImageResolution() const
557 {
558 	return mbReduceImageResolution;
559 }
560 void PDFExtOutDevData::SetIsReduceImageResolution( const sal_Bool bReduceImageResolution )
561 {
562 	mbReduceImageResolution = bReduceImageResolution;
563 }
564 sal_Bool PDFExtOutDevData::GetIsExportNotes() const
565 {
566 	return mbExportNotes;
567 }
568 void PDFExtOutDevData::SetIsExportNotes( const sal_Bool bExportNotes )
569 {
570 	mbExportNotes = bExportNotes;
571 }
572 sal_Bool PDFExtOutDevData::GetIsExportNotesPages() const
573 {
574 	return mbExportNotesPages;
575 }
576 void PDFExtOutDevData::SetIsExportNotesPages( const sal_Bool bExportNotesPages )
577 {
578 	mbExportNotesPages = bExportNotesPages;
579 }
580 sal_Bool PDFExtOutDevData::GetIsExportTaggedPDF() const
581 {
582 	return mbTaggedPDF;
583 }
584 void PDFExtOutDevData::SetIsExportTaggedPDF( const sal_Bool bTaggedPDF )
585 {
586 	mbTaggedPDF = bTaggedPDF;
587 }
588 sal_Bool PDFExtOutDevData::GetIsExportTransitionEffects() const
589 {
590 	return mbTransitionEffects;
591 }
592 void PDFExtOutDevData::SetIsExportTransitionEffects( const sal_Bool bTransitionEffects )
593 {
594 	mbTransitionEffects = bTransitionEffects;
595 }
596 sal_Bool PDFExtOutDevData::GetIsExportFormFields() const
597 {
598     return mbExportFormFields;
599 }
600 void PDFExtOutDevData::SetIsExportFormFields( const sal_Bool bExportFomtFields )
601 {
602     mbExportFormFields = bExportFomtFields;
603 }
604 sal_Int32 PDFExtOutDevData::GetFormsFormat() const
605 {
606 	return mnFormsFormat;
607 }
608 void PDFExtOutDevData::SetFormsFormat( const sal_Int32 nFormsFormat )
609 {
610 	mnFormsFormat = nFormsFormat;
611 }
612 sal_Bool PDFExtOutDevData::GetIsExportBookmarks() const
613 {
614     return mbExportBookmarks;
615 }
616 void PDFExtOutDevData::SetIsExportBookmarks( const sal_Bool bExportBookmarks )
617 {
618     mbExportBookmarks = bExportBookmarks;
619 }
620 std::vector< PDFExtOutDevBookmarkEntry >& PDFExtOutDevData::GetBookmarks()
621 {
622 	return maBookmarks;
623 }
624 sal_Bool PDFExtOutDevData::GetIsExportNamedDestinations() const
625 {
626     return mbExportNDests;
627 }
628 void PDFExtOutDevData::SetIsExportNamedDestinations( const sal_Bool bExportNDests )
629 {
630     mbExportNDests = bExportNDests;
631 }
632 void PDFExtOutDevData::ResetSyncData()
633 {
634 	*mpPageSyncData = PageSyncData( mpGlobalSyncData );
635 }
636 sal_Bool PDFExtOutDevData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rIdx )
637 {
638 	return mpPageSyncData->PlaySyncPageAct( rWriter, rIdx, *this );
639 }
640 void PDFExtOutDevData::PlayGlobalActions( PDFWriter& rWriter )
641 {
642 	mpGlobalSyncData->PlayGlobalActions( rWriter );
643 }
644 
645 /* global actions, syncronisation to the recorded metafile isn't needed,
646    all actions will be played after the last page was recorded
647 */
648 //--->i56629
649 sal_Int32 PDFExtOutDevData::CreateNamedDest(const String& sDestName,  const Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType )
650 {
651     mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateNamedDest );
652     mpGlobalSyncData->mParaOUStrings.push_back( sDestName );
653     mpGlobalSyncData->mParaRects.push_back( rRect );
654     mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
655     mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
656     mpGlobalSyncData->mParaDestAreaTypes.push_back( eType );
657 
658     return mpGlobalSyncData->mCurId++;
659 }
660 //<---i56629
661 sal_Int32 PDFExtOutDevData::RegisterDest()
662 {
663     const sal_Int32 nLinkDestID = mpGlobalSyncData->mCurId++;
664     mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::RegisterDest );
665     mpGlobalSyncData->mParaInts.push_back( nLinkDestID );
666 
667     return nLinkDestID;
668 }
669 void PDFExtOutDevData::DescribeRegisteredDest( sal_Int32 nDestId, const Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType )
670 {
671     OSL_PRECOND( nDestId != -1, "PDFExtOutDevData::DescribeRegisteredDest: invalid destination Id!" );
672     PDFLinkDestination aLinkDestination;
673     aLinkDestination.mRect = rRect;
674     aLinkDestination.mMapMode = mrOutDev.GetMapMode();
675     aLinkDestination.mPageNr = nPageNr == -1 ? mnPage : nPageNr;
676     aLinkDestination.mAreaType = eType;
677     mpGlobalSyncData->mFutureDestinations[ nDestId ] = aLinkDestination;
678 }
679 sal_Int32 PDFExtOutDevData::CreateDest( const Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType )
680 {
681 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateDest );
682 	mpGlobalSyncData->mParaRects.push_back( rRect );
683 	mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
684 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
685 	mpGlobalSyncData->mParaDestAreaTypes.push_back( eType );
686 	return mpGlobalSyncData->mCurId++;
687 }
688 sal_Int32 PDFExtOutDevData::CreateLink( const Rectangle& rRect, sal_Int32 nPageNr )
689 {
690 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateLink );
691 	mpGlobalSyncData->mParaRects.push_back( rRect );
692 	mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
693 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
694 	return mpGlobalSyncData->mCurId++;
695 }
696 sal_Int32 PDFExtOutDevData::SetLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId )
697 {
698 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetLinkDest );
699 	mpGlobalSyncData->mParaInts.push_back( nLinkId );
700 	mpGlobalSyncData->mParaInts.push_back( nDestId );
701 	return 0;
702 }
703 sal_Int32 PDFExtOutDevData::SetLinkURL( sal_Int32 nLinkId, const rtl::OUString& rURL )
704 {
705 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetLinkURL );
706 	mpGlobalSyncData->mParaInts.push_back( nLinkId );
707 	mpGlobalSyncData->mParaOUStrings.push_back( rURL );
708 	return 0;
709 }
710 sal_Int32 PDFExtOutDevData::CreateOutlineItem( sal_Int32 nParent, const rtl::OUString& rText, sal_Int32 nDestID )
711 {
712 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateOutlineItem );
713 	mpGlobalSyncData->mParaInts.push_back( nParent );
714 	mpGlobalSyncData->mParaOUStrings.push_back( rText );
715 	mpGlobalSyncData->mParaInts.push_back( nDestID );
716 	return mpGlobalSyncData->mCurId++;
717 }
718 sal_Int32 PDFExtOutDevData::SetOutlineItemParent( sal_Int32 nItem, sal_Int32 nNewParent )
719 {
720 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetOutlineItemParent );
721 	mpGlobalSyncData->mParaInts.push_back( nItem );
722 	mpGlobalSyncData->mParaInts.push_back( nNewParent );
723 	return 0;
724 }
725 sal_Int32 PDFExtOutDevData::SetOutlineItemText( sal_Int32 nItem, const rtl::OUString& rText )
726 {
727 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetOutlineItemText );
728 	mpGlobalSyncData->mParaInts.push_back( nItem );
729 	mpGlobalSyncData->mParaOUStrings.push_back( rText );
730 	return 0;
731 }
732 sal_Int32 PDFExtOutDevData::SetOutlineItemDest( sal_Int32 nItem, sal_Int32 nDestID )
733 {
734 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetOutlineItemDest );
735 	mpGlobalSyncData->mParaInts.push_back( nItem );
736 	mpGlobalSyncData->mParaInts.push_back( nDestID );
737 	return 0;
738 }
739 void PDFExtOutDevData::CreateNote( const Rectangle& rRect, const PDFNote& rNote, sal_Int32 nPageNr )
740 {
741 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateNote );
742 	mpGlobalSyncData->mParaRects.push_back( rRect );
743 	mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
744 	mpGlobalSyncData->mParaPDFNotes.push_back( rNote );
745 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
746 }
747 void PDFExtOutDevData::SetAutoAdvanceTime( sal_uInt32 nSeconds, sal_Int32 nPageNr )
748 {
749 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetAutoAdvanceTime );
750 	mpGlobalSyncData->mParauInts.push_back( nSeconds );
751 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
752 }
753 void PDFExtOutDevData::SetPageTransition( PDFWriter::PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr )
754 {
755 	mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetPageTransition );
756 	mpGlobalSyncData->mParaPageTransitions.push_back( eType );
757 	mpGlobalSyncData->mParauInts.push_back( nMilliSec );
758 	mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
759 }
760 
761 /* local (page), actions have to be played synchroniously to the actions of
762    of the recorded metafile (created by each xRenderable->render()) */
763    sal_Int32 PDFExtOutDevData::BeginStructureElement( PDFWriter::StructElement eType, const rtl::OUString& rAlias )
764 {
765 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::BeginStructureElement );
766 	mpPageSyncData->mParaStructElements.push_back( eType );
767     mpPageSyncData->mParaOUStrings.push_back( rAlias );
768     // need a global id
769     sal_Int32 nNewId = mpGlobalSyncData->mStructParents.size();
770     mpGlobalSyncData->mStructParents.push_back( mpGlobalSyncData->mCurrentStructElement );
771     mpGlobalSyncData->mCurrentStructElement = nNewId;
772     return nNewId;
773 }
774 void PDFExtOutDevData::EndStructureElement()
775 {
776 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::EndStructureElement );
777     mpGlobalSyncData->mCurrentStructElement = mpGlobalSyncData->mStructParents[ mpGlobalSyncData->mCurrentStructElement ];
778 }
779 bool PDFExtOutDevData::SetCurrentStructureElement( sal_Int32 nStructId )
780 {
781     bool bSuccess = false;
782     if( sal_uInt32(nStructId) < mpGlobalSyncData->mStructParents.size() )
783     {
784         mpGlobalSyncData->mCurrentStructElement = nStructId;
785         mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetCurrentStructureElement );
786         mpPageSyncData->mParaInts.push_back( nStructId );
787         bSuccess = true;
788     }
789     return bSuccess;
790 }
791 sal_Int32 PDFExtOutDevData::GetCurrentStructureElement()
792 {
793     return mpGlobalSyncData->mCurrentStructElement;
794 }
795 bool PDFExtOutDevData::SetStructureAttribute( PDFWriter::StructAttribute eAttr, PDFWriter::StructAttributeValue eVal )
796 {
797 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetStructureAttribute );
798 	mpPageSyncData->mParaStructAttributes.push_back( eAttr );
799 	mpPageSyncData->mParaStructAttributeValues.push_back( eVal );
800 	return true;
801 }
802 bool PDFExtOutDevData::SetStructureAttributeNumerical( PDFWriter::StructAttribute eAttr, sal_Int32 nValue )
803 {
804 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetStructureAttributeNumerical );
805 	mpPageSyncData->mParaStructAttributes.push_back( eAttr );
806 	mpPageSyncData->mParaInts.push_back( nValue );
807 	return true;
808 }
809 void PDFExtOutDevData::SetStructureBoundingBox( const Rectangle& rRect )
810 {
811 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetStructureBoundingBox );
812 	mpPageSyncData->mParaRects.push_back( rRect );
813 }
814 void PDFExtOutDevData::SetActualText( const String& rText )
815 {
816 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetActualText );
817 	mpPageSyncData->mParaOUStrings.push_back( rText );
818 }
819 void PDFExtOutDevData::SetAlternateText( const String& rText )
820 {
821 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetAlternateText );
822 	mpPageSyncData->mParaOUStrings.push_back( rText );
823 }
824 
825 void PDFExtOutDevData::CreateControl( const PDFWriter::AnyWidget& rControlType, sal_Int32 /*nPageNr*/ )
826 {
827 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::CreateControl );
828 
829     ::boost::shared_ptr< PDFWriter::AnyWidget > pClone( rControlType.Clone() );
830     mpPageSyncData->mControls.push_back( pClone );
831 }
832 
833 void PDFExtOutDevData::BeginGroup()
834 {
835 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::BeginGroup );
836 }
837 
838 void PDFExtOutDevData::EndGroup()
839 {
840 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::EndGroup );
841 }
842 void PDFExtOutDevData::EndGroup( const Graphic& 	rGraphic,
843                                  sal_uInt8				nTransparency,
844                                  const Rectangle& 	rOutputRect,
845                                  const Rectangle& 	rVisibleOutputRect )
846 {
847 	mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::EndGroupGfxLink );
848 	mpPageSyncData->mGraphics.push_back( rGraphic );
849 	mpPageSyncData->mParaInts.push_back( nTransparency );
850 	mpPageSyncData->mParaRects.push_back( rOutputRect );
851 	mpPageSyncData->mParaRects.push_back( rVisibleOutputRect );
852 }
853 
854 }
855