LibreOffice Module vcl (master)  1
pdfextoutdevdata.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <vcl/canvastools.hxx>
21 #include <vcl/pdfextoutdevdata.hxx>
22 #include <vcl/graph.hxx>
23 #include <vcl/outdev.hxx>
24 #include <vcl/gfxlink.hxx>
25 #include <vcl/metaact.hxx>
26 #include <vcl/graphicfilter.hxx>
29 #include <sal/log.hxx>
30 #include <osl/diagnose.h>
31 #include <tools/stream.hxx>
32 
33 #include <memory>
34 #include <map>
35 
36 namespace vcl
37 {
39 {
52 
64  };
65 
66  sal_uInt32 nIdx;
68 };
69 
71 {
74  sal_Int32 mPageNr;
76 };
77 
79 {
80  std::deque< PDFExtOutDevDataSync::Action > mActions;
81  std::deque< MapMode > mParaMapModes;
82  std::deque< tools::Rectangle > mParaRects;
83  std::deque< sal_Int32 > mParaInts;
84  std::deque< sal_uInt32 > mParauInts;
85  std::deque< OUString > mParaOUStrings;
86  std::deque< PDFWriter::DestAreaType > mParaDestAreaTypes;
87  std::deque< PDFNote > mParaPDFNotes;
88  std::deque< PDFWriter::PageTransition > mParaPageTransitions;
89  ::std::map< sal_Int32, PDFLinkDestination > mFutureDestinations;
90 
91  sal_Int32 GetMappedId();
92  sal_Int32 GetMappedStructId( sal_Int32 );
93 
94  sal_Int32 mCurId;
95  std::vector< sal_Int32 > mParaIds;
96  std::vector< sal_Int32 > mStructIdMap;
97 
99  std::vector< sal_Int32 > mStructParents;
101  mCurId ( 0 ),
102  mCurrentStructElement( 0 )
103  {
104  mStructParents.push_back( 0 );
105  mStructIdMap.push_back( 0 );
106  }
107  void PlayGlobalActions( PDFWriter& rWriter );
108 };
109 
111 {
112  sal_Int32 nLinkId = mParaInts.front();
113  mParaInts.pop_front();
114 
115  /* negative values are intentionally passed as invalid IDs
116  * e.g. to create a new top level outline item
117  */
118  if( nLinkId >= 0 )
119  {
120  if ( static_cast<sal_uInt32>(nLinkId) < mParaIds.size() )
121  nLinkId = mParaIds[ nLinkId ];
122  else
123  nLinkId = -1;
124 
125  SAL_WARN_IF( nLinkId < 0, "vcl", "unmapped id in GlobalSyncData" );
126  }
127 
128  return nLinkId;
129 }
130 
131 sal_Int32 GlobalSyncData::GetMappedStructId( sal_Int32 nStructId )
132 {
133  if ( static_cast<sal_uInt32>(nStructId) < mStructIdMap.size() )
134  nStructId = mStructIdMap[ nStructId ];
135  else
136  nStructId = -1;
137 
138  SAL_WARN_IF( nStructId < 0, "vcl", "unmapped structure id in GlobalSyncData" );
139 
140  return nStructId;
141 }
142 
144 {
145  for (auto const& action : mActions)
146  {
147  switch (action)
148  {
150  {
151  rWriter.Push( PushFlags::MAPMODE );
152  rWriter.SetMapMode( mParaMapModes.front() );
153  mParaMapModes.pop_front();
154  mParaIds.push_back( rWriter.CreateNamedDest( mParaOUStrings.front(), mParaRects.front(), mParaInts.front(), mParaDestAreaTypes.front() ) );
155  mParaOUStrings.pop_front();
156  mParaRects.pop_front();
157  mParaInts.pop_front();
158  mParaDestAreaTypes.pop_front();
159  rWriter.Pop();
160  }
161  break;
163  {
164  rWriter.Push( PushFlags::MAPMODE );
165  rWriter.SetMapMode( mParaMapModes.front() );
166  mParaMapModes.pop_front();
167  mParaIds.push_back( rWriter.CreateDest( mParaRects.front(), mParaInts.front(), mParaDestAreaTypes.front() ) );
168  mParaRects.pop_front();
169  mParaInts.pop_front();
170  mParaDestAreaTypes.pop_front();
171  rWriter.Pop();
172  }
173  break;
175  {
176  rWriter.Push( PushFlags::MAPMODE );
177  rWriter.SetMapMode( mParaMapModes.front() );
178  mParaMapModes.pop_front();
179  mParaIds.push_back( rWriter.CreateLink( mParaRects.front(), mParaInts.front() ) );
180  // resolve LinkAnnotation structural attribute
181  rWriter.SetLinkPropertyID( mParaIds.back(), sal_Int32(mParaIds.size()-1) );
182  mParaRects.pop_front();
183  mParaInts.pop_front();
184  rWriter.Pop();
185  }
186  break;
188  {
189  rWriter.Push(PushFlags::MAPMODE);
190  rWriter.SetMapMode(mParaMapModes.front());
191  mParaMapModes.pop_front();
192  mParaIds.push_back(rWriter.CreateScreen(mParaRects.front(), mParaInts.front()));
193  mParaRects.pop_front();
194  mParaInts.pop_front();
195  rWriter.Pop();
196  }
197  break;
199  {
200  sal_Int32 nLinkId = GetMappedId();
201  sal_Int32 nDestId = GetMappedId();
202  rWriter.SetLinkDest( nLinkId, nDestId );
203  }
204  break;
206  {
207  sal_Int32 nLinkId = GetMappedId();
208  rWriter.SetLinkURL( nLinkId, mParaOUStrings.front() );
209  mParaOUStrings.pop_front();
210  }
211  break;
213  {
214  sal_Int32 nScreenId = GetMappedId();
215  rWriter.SetScreenURL(nScreenId, mParaOUStrings.front());
216  mParaOUStrings.pop_front();
217  }
218  break;
220  {
221  sal_Int32 nScreenId = GetMappedId();
222  rWriter.SetScreenStream(nScreenId, mParaOUStrings.front());
223  mParaOUStrings.pop_front();
224  }
225  break;
227  {
228  const sal_Int32 nDestId = mParaInts.front();
229  mParaInts.pop_front();
230  OSL_ENSURE( mFutureDestinations.find( nDestId ) != mFutureDestinations.end(),
231  "GlobalSyncData::PlayGlobalActions: DescribeRegisteredRequest has not been called for that destination!" );
232 
233  PDFLinkDestination& rDest = mFutureDestinations[ nDestId ];
234 
235  rWriter.Push( PushFlags::MAPMODE );
236  rWriter.SetMapMode( rDest.mMapMode );
237  mParaIds.push_back( rWriter.RegisterDestReference( nDestId, rDest.mRect, rDest.mPageNr, rDest.mAreaType ) );
238  rWriter.Pop();
239  }
240  break;
242  {
243  sal_Int32 nParent = GetMappedId();
244  sal_Int32 nLinkId = GetMappedId();
245  mParaIds.push_back( rWriter.CreateOutlineItem( nParent, mParaOUStrings.front(), nLinkId ) );
246  mParaOUStrings.pop_front();
247  }
248  break;
250  {
251  rWriter.Push( PushFlags::MAPMODE );
252  rWriter.SetMapMode( mParaMapModes.front() );
253  rWriter.CreateNote( mParaRects.front(), mParaPDFNotes.front(), mParaInts.front() );
254  mParaMapModes.pop_front();
255  mParaRects.pop_front();
256  mParaPDFNotes.pop_front();
257  mParaInts.pop_front();
258  }
259  break;
261  {
262  rWriter.SetPageTransition( mParaPageTransitions.front(), mParauInts.front(), mParaInts.front() );
263  mParaPageTransitions.pop_front();
264  mParauInts.pop_front();
265  mParaInts.pop_front();
266  }
267  break;
279  break;
280  }
281  }
282 }
283 
285 {
286  std::deque< PDFExtOutDevDataSync > mActions;
287  std::deque< tools::Rectangle > mParaRects;
288  std::deque< sal_Int32 > mParaInts;
289  std::deque< OUString > mParaOUStrings;
290  std::deque< PDFWriter::StructElement > mParaStructElements;
291  std::deque< PDFWriter::StructAttribute > mParaStructAttributes;
292  std::deque< PDFWriter::StructAttributeValue > mParaStructAttributeValues;
293  std::deque< Graphic > mGraphics;
295  std::deque< std::shared_ptr< PDFWriter::AnyWidget > >
298 
300 
301 
302  explicit PageSyncData( GlobalSyncData* pGlobal )
303  : mbGroupIgnoreGDIMtfActions ( false )
304  { mpGlobalData = pGlobal; }
305 
306  void PushAction( const OutputDevice& rOutDev, const PDFExtOutDevDataSync::Action eAct );
307  bool PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAction, const GDIMetaFile& rMtf, const PDFExtOutDevData& rOutDevData );
308 };
309 
311 {
312  GDIMetaFile* pMtf = rOutDev.GetConnectMetaFile();
313  SAL_WARN_IF( !pMtf, "vcl", "PageSyncData::PushAction -> no ConnectMetaFile !!!" );
314 
315  PDFExtOutDevDataSync aSync;
316  aSync.eAct = eAct;
317  if ( pMtf )
318  aSync.nIdx = pMtf->GetActionSize();
319  else
320  aSync.nIdx = 0x7fffffff; // sync not possible
321  mActions.push_back( aSync );
322 }
323 bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAction, const GDIMetaFile& rMtf, const PDFExtOutDevData& rOutDevData )
324 {
325  bool bRet = false;
326  if ( !mActions.empty() && ( mActions.front().nIdx == rCurGDIMtfAction ) )
327  {
328  bRet = true;
329  PDFExtOutDevDataSync aDataSync = mActions.front();
330  mActions.pop_front();
331  switch( aDataSync.eAct )
332  {
334  {
335  sal_Int32 nNewEl = rWriter.BeginStructureElement( mParaStructElements.front(), mParaOUStrings.front() ) ;
336  mParaStructElements.pop_front();
337  mParaOUStrings.pop_front();
338  mpGlobalData->mStructIdMap.push_back( nNewEl );
339  }
340  break;
342  {
343  rWriter.EndStructureElement();
344  }
345  break;
347  {
349  mParaInts.pop_front();
350  }
351  break;
353  {
355  mParaStructAttributeValues.pop_front();
356  mParaStructAttributes.pop_front();
357  }
358  break;
360  {
362  mParaStructAttributes.pop_front();
363  mParaInts.pop_front();
364  }
365  break;
367  {
368  rWriter.SetStructureBoundingBox( mParaRects.front() );
369  mParaRects.pop_front();
370  }
371  break;
373  {
374  rWriter.SetActualText( mParaOUStrings.front() );
375  mParaOUStrings.pop_front();
376  }
377  break;
379  {
380  rWriter.SetAlternateText( mParaOUStrings.front() );
381  mParaOUStrings.pop_front();
382  }
383  break;
385  {
386  std::shared_ptr< PDFWriter::AnyWidget > pControl( mControls.front() );
387  SAL_WARN_IF( !pControl.get(), "vcl", "PageSyncData::PlaySyncPageAct: invalid widget!" );
388  if ( pControl.get() )
389  rWriter.CreateControl( *pControl );
390  mControls.pop_front();
391  }
392  break;
394  {
395  /* first determining if this BeginGroup is starting a GfxLink,
396  by searching for an EndGroup or an EndGroupGfxLink */
398  auto isStartingGfxLink = std::any_of(mActions.begin(), mActions.end(),
399  [](const PDFExtOutDevDataSync& rAction) { return rAction.eAct == PDFExtOutDevDataSync::EndGroupGfxLink; });
400  if ( isStartingGfxLink )
401  {
402  Graphic& rGraphic = mGraphics.front();
403  if ( rGraphic.IsGfxLink() && mParaRects.size() >= 2 )
404  {
405  GfxLinkType eType = rGraphic.GetGfxLink().GetType();
406  if ( eType == GfxLinkType::NativeJpg )
407  {
410  mCurrentGraphic = rGraphic;
411  }
412  else if ( eType == GfxLinkType::NativePng || eType == GfxLinkType::NativePdf )
413  {
414  if ( eType == GfxLinkType::NativePdf || rOutDevData.HasAdequateCompression(rGraphic, mParaRects[0], mParaRects[1]) )
415  mCurrentGraphic = rGraphic;
416  }
417  }
418  }
419  }
420  break;
422  {
423  tools::Rectangle aOutputRect, aVisibleOutputRect;
424  Graphic aGraphic( mGraphics.front() );
425 
426  mGraphics.pop_front();
427  sal_Int32 nTransparency = mParaInts.front();
428  mParaInts.pop_front();
429  aOutputRect = mParaRects.front();
430  mParaRects.pop_front();
431  aVisibleOutputRect = mParaRects.front();
432  mParaRects.pop_front();
433 
435  {
436  bool bClippingNeeded = ( aOutputRect != aVisibleOutputRect ) && !aVisibleOutputRect.IsEmpty();
437 
438  GfxLink aGfxLink( aGraphic.GetGfxLink() );
439  if ( aGfxLink.GetType() == GfxLinkType::NativeJpg )
440  {
441  if ( bClippingNeeded )
442  {
443  rWriter.Push();
445  vcl::unotools::b2DRectangleFromRectangle(aVisibleOutputRect) ) );
446  rWriter.SetClipRegion( aRect);
447  }
448 
449  Bitmap aMask;
450  if (nTransparency)
451  {
452  AlphaMask aAlphaMask(aGraphic.GetSizePixel());
453  aAlphaMask.Erase(nTransparency);
454  aMask = aAlphaMask.GetBitmap();
455  }
456 
457  SvMemoryStream aTmp;
458  const sal_uInt8* pData = aGfxLink.GetData();
459  sal_uInt32 nBytes = aGfxLink.GetDataSize();
460  if( pData && nBytes )
461  {
462  aTmp.WriteBytes( pData, nBytes );
463 
464  // Look up the output rectangle from the previous
465  // bitmap scale action if possible. This has the
466  // correct position and size for images with a
467  // custom translation (Writer header) or scaling
468  // (Impress notes page).
469  if (rCurGDIMtfAction > 0)
470  {
471  const MetaAction* pAction = rMtf.GetAction(rCurGDIMtfAction - 1);
472  if (pAction && pAction->GetType() == MetaActionType::BMPSCALE)
473  {
474  const MetaBmpScaleAction* pA
475  = static_cast<const MetaBmpScaleAction*>(pAction);
476  aOutputRect.SetPos(pA->GetPoint());
477  aOutputRect.SetSize(pA->GetSize());
478  }
479  }
480 
481  rWriter.DrawJPGBitmap( aTmp, aGraphic.GetBitmapEx().GetBitCount() > 8, aGraphic.GetSizePixel(), aOutputRect, aMask, aGraphic );
482  }
483 
484  if ( bClippingNeeded )
485  rWriter.Pop();
486  }
488  }
490  }
491  break;
504  break;
505  }
506  }
507  else if ( mbGroupIgnoreGDIMtfActions )
508  {
509  rCurGDIMtfAction++;
510  bRet = true;
511  }
512  return bRet;
513 }
514 
516  mrOutDev ( rOutDev ),
517  mbTaggedPDF ( false ),
518  mbExportNotes ( true ),
519  mbExportNotesPages ( false ),
520  mbTransitionEffects ( true ),
521  mbUseLosslessCompression( true ),
522  mbReduceImageResolution ( false ),
523  mbExportFormFields ( false ),
524  mbExportBookmarks ( false ),
525  mbExportHiddenSlides ( false ),
526  mbExportNDests ( false ),
527  mnPage ( -1 ),
528  mnCompressionQuality ( 90 ),
529  mpGlobalSyncData ( new GlobalSyncData() )
530 {
531  mpPageSyncData.reset( new PageSyncData( mpGlobalSyncData.get() ) );
532 }
533 
535 {
536  mpPageSyncData.reset();
537  mpGlobalSyncData.reset();
538 }
539 
541 {
542  return mpPageSyncData->mCurrentGraphic;
543 }
544 
545 void PDFExtOutDevData::SetDocumentLocale( const css::lang::Locale& rLoc )
546 {
547  maDocLocale = rLoc;
548 }
549 void PDFExtOutDevData::SetCurrentPageNumber( const sal_Int32 nPage )
550 {
551  mnPage = nPage;
552 }
553 void PDFExtOutDevData::SetIsLosslessCompression( const bool bUseLosslessCompression )
554 {
555  mbUseLosslessCompression = bUseLosslessCompression;
556 }
557 void PDFExtOutDevData::SetCompressionQuality( const sal_Int32 nQuality )
558 {
559  mnCompressionQuality = nQuality;
560 }
561 void PDFExtOutDevData::SetIsReduceImageResolution( const bool bReduceImageResolution )
562 {
563  mbReduceImageResolution = bReduceImageResolution;
564 }
565 void PDFExtOutDevData::SetIsExportNotes( const bool bExportNotes )
566 {
567  mbExportNotes = bExportNotes;
568 }
569 void PDFExtOutDevData::SetIsExportNotesPages( const bool bExportNotesPages )
570 {
571  mbExportNotesPages = bExportNotesPages;
572 }
573 void PDFExtOutDevData::SetIsExportTaggedPDF( const bool bTaggedPDF )
574 {
575  mbTaggedPDF = bTaggedPDF;
576 }
577 void PDFExtOutDevData::SetIsExportTransitionEffects( const bool bTransitionEffects )
578 {
579  mbTransitionEffects = bTransitionEffects;
580 }
581 void PDFExtOutDevData::SetIsExportFormFields( const bool bExportFomtFields )
582 {
583  mbExportFormFields = bExportFomtFields;
584 }
585 void PDFExtOutDevData::SetIsExportBookmarks( const bool bExportBookmarks )
586 {
587  mbExportBookmarks = bExportBookmarks;
588 }
589 void PDFExtOutDevData::SetIsExportHiddenSlides( const bool bExportHiddenSlides )
590 {
591  mbExportHiddenSlides = bExportHiddenSlides;
592 }
593 void PDFExtOutDevData::SetIsExportNamedDestinations( const bool bExportNDests )
594 {
595  mbExportNDests = bExportNDests;
596 }
598 {
600 }
601 bool PDFExtOutDevData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rIdx, const GDIMetaFile& rMtf )
602 {
603  return mpPageSyncData->PlaySyncPageAct( rWriter, rIdx, rMtf, *this );
604 }
606 {
607  mpGlobalSyncData->PlayGlobalActions( rWriter );
608 }
609 
610 /* global actions, synchronisation to the recorded metafile isn't needed,
611  all actions will be played after the last page was recorded
612 */
613 //--->i56629
614 sal_Int32 PDFExtOutDevData::CreateNamedDest(const OUString& sDestName, const tools::Rectangle& rRect, sal_Int32 nPageNr )
615 {
617  mpGlobalSyncData->mParaOUStrings.push_back( sDestName );
618  mpGlobalSyncData->mParaRects.push_back( rRect );
619  mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
620  mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
621  mpGlobalSyncData->mParaDestAreaTypes.push_back( PDFWriter::DestAreaType::XYZ );
622 
623  return mpGlobalSyncData->mCurId++;
624 }
625 //<---i56629
627 {
628  const sal_Int32 nLinkDestID = mpGlobalSyncData->mCurId++;
630  mpGlobalSyncData->mParaInts.push_back( nLinkDestID );
631 
632  return nLinkDestID;
633 }
634 void PDFExtOutDevData::DescribeRegisteredDest( sal_Int32 nDestId, const tools::Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType )
635 {
636  OSL_PRECOND( nDestId != -1, "PDFExtOutDevData::DescribeRegisteredDest: invalid destination Id!" );
637  PDFLinkDestination aLinkDestination;
638  aLinkDestination.mRect = rRect;
639  aLinkDestination.mMapMode = mrOutDev.GetMapMode();
640  aLinkDestination.mPageNr = nPageNr == -1 ? mnPage : nPageNr;
641  aLinkDestination.mAreaType = eType;
642  mpGlobalSyncData->mFutureDestinations[ nDestId ] = aLinkDestination;
643 }
644 sal_Int32 PDFExtOutDevData::CreateDest( const tools::Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType )
645 {
646  mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateDest );
647  mpGlobalSyncData->mParaRects.push_back( rRect );
648  mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
649  mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
650  mpGlobalSyncData->mParaDestAreaTypes.push_back( eType );
651  return mpGlobalSyncData->mCurId++;
652 }
653 sal_Int32 PDFExtOutDevData::CreateLink( const tools::Rectangle& rRect, sal_Int32 nPageNr )
654 {
655  mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateLink );
656  mpGlobalSyncData->mParaRects.push_back( rRect );
657  mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
658  mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
659  return mpGlobalSyncData->mCurId++;
660 }
661 
662 sal_Int32 PDFExtOutDevData::CreateScreen(const tools::Rectangle& rRect, sal_Int32 nPageNr)
663 {
665  mpGlobalSyncData->mParaRects.push_back(rRect);
666  mpGlobalSyncData->mParaMapModes.push_back(mrOutDev.GetMapMode());
667  mpGlobalSyncData->mParaInts.push_back(nPageNr);
668  return mpGlobalSyncData->mCurId++;
669 }
670 
671 void PDFExtOutDevData::SetLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId )
672 {
674  mpGlobalSyncData->mParaInts.push_back( nLinkId );
675  mpGlobalSyncData->mParaInts.push_back( nDestId );
676 }
677 void PDFExtOutDevData::SetLinkURL( sal_Int32 nLinkId, const OUString& rURL )
678 {
679  mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::SetLinkURL );
680  mpGlobalSyncData->mParaInts.push_back( nLinkId );
681  mpGlobalSyncData->mParaOUStrings.push_back( rURL );
682 }
683 
684 void PDFExtOutDevData::SetScreenURL(sal_Int32 nScreenId, const OUString& rURL)
685 {
687  mpGlobalSyncData->mParaInts.push_back(nScreenId);
688  mpGlobalSyncData->mParaOUStrings.push_back(rURL);
689 }
690 
691 void PDFExtOutDevData::SetScreenStream(sal_Int32 nScreenId, const OUString& rURL)
692 {
694  mpGlobalSyncData->mParaInts.push_back(nScreenId);
695  mpGlobalSyncData->mParaOUStrings.push_back(rURL);
696 }
697 
698 sal_Int32 PDFExtOutDevData::CreateOutlineItem( sal_Int32 nParent, const OUString& rText, sal_Int32 nDestID )
699 {
700  if (nParent == -1)
701  // Has no parent, it's a chapter / heading 1.
702  maChapterNames.push_back(rText);
703 
705  mpGlobalSyncData->mParaInts.push_back( nParent );
706  mpGlobalSyncData->mParaOUStrings.push_back( rText );
707  mpGlobalSyncData->mParaInts.push_back( nDestID );
708  return mpGlobalSyncData->mCurId++;
709 }
710 void PDFExtOutDevData::CreateNote( const tools::Rectangle& rRect, const PDFNote& rNote, sal_Int32 nPageNr )
711 {
712  mpGlobalSyncData->mActions.push_back( PDFExtOutDevDataSync::CreateNote );
713  mpGlobalSyncData->mParaRects.push_back( rRect );
714  mpGlobalSyncData->mParaMapModes.push_back( mrOutDev.GetMapMode() );
715  mpGlobalSyncData->mParaPDFNotes.push_back( rNote );
716  mpGlobalSyncData->mParaInts.push_back( nPageNr == -1 ? mnPage : nPageNr );
717 }
719 {
721  mpGlobalSyncData->mParaPageTransitions.push_back( eType );
722  mpGlobalSyncData->mParauInts.push_back( nMilliSec );
723  mpGlobalSyncData->mParaInts.push_back( mnPage );
724 }
725 
726 /* local (page), actions have to be played synchronously to the actions of
727  of the recorded metafile (created by each xRenderable->render()) */
728  sal_Int32 PDFExtOutDevData::BeginStructureElement( PDFWriter::StructElement eType, const OUString& rAlias )
729 {
731  mpPageSyncData->mParaStructElements.push_back( eType );
732  mpPageSyncData->mParaOUStrings.push_back( rAlias );
733  // need a global id
734  sal_Int32 nNewId = mpGlobalSyncData->mStructParents.size();
735  mpGlobalSyncData->mStructParents.push_back( mpGlobalSyncData->mCurrentStructElement );
736  mpGlobalSyncData->mCurrentStructElement = nNewId;
737  return nNewId;
738 }
740 {
742  mpGlobalSyncData->mCurrentStructElement = mpGlobalSyncData->mStructParents[ mpGlobalSyncData->mCurrentStructElement ];
743 }
745 {
746  bool bSuccess = false;
747  if( sal_uInt32(nStructId) < mpGlobalSyncData->mStructParents.size() )
748  {
749  mpGlobalSyncData->mCurrentStructElement = nStructId;
751  mpPageSyncData->mParaInts.push_back( nStructId );
752  bSuccess = true;
753  }
754  return bSuccess;
755 }
757 {
758  return mpGlobalSyncData->mCurrentStructElement;
759 }
761 {
763  mpPageSyncData->mParaStructAttributes.push_back( eAttr );
764  mpPageSyncData->mParaStructAttributeValues.push_back( eVal );
765 }
767 {
769  mpPageSyncData->mParaStructAttributes.push_back( eAttr );
770  mpPageSyncData->mParaInts.push_back( nValue );
771 }
773 {
775  mpPageSyncData->mParaRects.push_back( rRect );
776 }
777 void PDFExtOutDevData::SetActualText( const OUString& rText )
778 {
780  mpPageSyncData->mParaOUStrings.push_back( rText );
781 }
782 void PDFExtOutDevData::SetAlternateText( const OUString& rText )
783 {
785  mpPageSyncData->mParaOUStrings.push_back( rText );
786 }
787 
789 {
791 
792  std::shared_ptr< PDFWriter::AnyWidget > pClone( rControlType.Clone() );
793  mpPageSyncData->mControls.push_back( pClone );
794 }
795 
797 {
799 }
800 
801 void PDFExtOutDevData::EndGroup( const Graphic& rGraphic,
802  sal_uInt8 nTransparency,
803  const tools::Rectangle& rOutputRect,
804  const tools::Rectangle& rVisibleOutputRect )
805 {
807  mpPageSyncData->mGraphics.push_back( rGraphic );
808  mpPageSyncData->mParaInts.push_back( nTransparency );
809  mpPageSyncData->mParaRects.push_back( rOutputRect );
810  mpPageSyncData->mParaRects.push_back( rVisibleOutputRect );
811 }
812 
813 // Avoids expensive de-compression and re-compression of large images.
815  const tools::Rectangle & rOutputRect,
816  const tools::Rectangle & rVisibleOutputRect ) const
817 {
818  assert(rGraphic.IsGfxLink() &&
819  (rGraphic.GetGfxLink().GetType() == GfxLinkType::NativeJpg ||
820  rGraphic.GetGfxLink().GetType() == GfxLinkType::NativePng ||
821  rGraphic.GetGfxLink().GetType() == GfxLinkType::NativePdf));
822 
823  if (rOutputRect != rVisibleOutputRect)
824  // rOutputRect is the crop rectangle, re-compress cropped image.
825  return false;
826 
828  // Reducing resolution was requested, implies that re-compressing is
829  // wanted.
830  return false;
831 
832  if (rGraphic.GetGfxLink().GetDataSize() == 0)
833  return false;
834 
835  GfxLink aLink = rGraphic.GetGfxLink();
836  SvMemoryStream aMemoryStream(const_cast<sal_uInt8*>(aLink.GetData()), aLink.GetDataSize(),
837  StreamMode::READ | StreamMode::WRITE);
838  GraphicDescriptor aDescriptor(aMemoryStream, nullptr);
839  if (aDescriptor.Detect(true) && aDescriptor.GetNumberOfImageComponents() == 4)
840  // 4 means CMYK, which is not handled.
841  return false;
842 
843  const Size aSize = rGraphic.GetSizePixel();
844 
845  // small items better off as PNG anyway
846  if ( aSize.Width() < 32 &&
847  aSize.Height() < 32 )
848  return false;
849 
851  return !GetIsReduceImageResolution();
852 
853  // FIXME: ideally we'd also pre-empt the DPI related scaling too.
854  sal_Int32 nCurrentRatio = (100 * aSize.Width() * aSize.Height() * 4) /
855  rGraphic.GetGfxLink().GetDataSize();
856 
857  static const struct {
858  sal_Int32 const mnQuality;
859  sal_Int32 const mnRatio;
860  } aRatios[] = { // minimum tolerable compression ratios
861  { 100, 400 }, { 95, 700 }, { 90, 1000 }, { 85, 1200 },
862  { 80, 1500 }, { 75, 1700 }
863  };
864  sal_Int32 nTargetRatio = 10000;
865  bool bIsTargetRatioReached = false;
866  for (auto & rRatio : aRatios)
867  {
868  if ( mnCompressionQuality > rRatio.mnQuality )
869  {
870  bIsTargetRatioReached = true;
871  break;
872  }
873  nTargetRatio = rRatio.mnRatio;
874  }
875 
876  return ((nCurrentRatio > nTargetRatio) && bIsTargetRatioReached);
877 }
878 
879 }
880 
881 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::deque< PDFWriter::StructAttributeValue > mParaStructAttributeValues
void SetCurrentPageNumber(const sal_Int32 nPage)
long Width() const
std::deque< PDFWriter::StructAttribute > mParaStructAttributes
void SetPos(const Point &rPoint)
std::deque< PDFWriter::StructElement > mParaStructElements
void PushAction(const OutputDevice &rOutDev, const PDFExtOutDevDataSync::Action eAct)
const Point & GetPoint() const
Definition: metaact.hxx:701
void SetIsExportNotes(const bool bExportNotes)
void SetPageTransition(PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr)
Sets the transitional effect to be applied when the current page gets shown.
Definition: pdfwriter.cxx:429
void BeginGroup()
Start a new group of render output.
sal_Int32 RegisterDest()
registers a destination for which a destination ID needs to be known immediately, instead of later on...
std::deque< sal_Int32 > mParaInts
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
Definition: graph.cxx:421
long Height() const
bool PlaySyncPageAct(PDFWriter &rWriter, sal_uInt32 &rCurGDIMtfAction, const GDIMetaFile &rMtf)
bool SetCurrentStructureElement(sal_Int32 nElement)
set the current structure element
void SetScreenURL(sal_Int32 nScreenId, const OUString &rURL)
Set URL for a linked Screen annotation.
void SetAlternateText(const OUString &rText)
set the Alt attribute of a strutural element
sal_Int32 BeginStructureElement(enum StructElement eType, const OUString &rAlias)
begin a new logical structure element
Definition: pdfwriter.cxx:389
std::deque< PDFWriter::DestAreaType > mParaDestAreaTypes
void SetStructureAttribute(PDFWriter::StructAttribute eAttr, PDFWriter::StructAttributeValue eVal)
set a structure attribute on the current structural element
void SetActualText(const OUString &rText)
set the ActualText attribute of a structural element
Definition: pdfwriter.cxx:419
std::deque< sal_Int32 > mParaInts
const Size & GetSize() const
Definition: metaact.hxx:702
const MapMode & GetMapMode() const
Definition: outdev.hxx:1673
void SetIsReduceImageResolution(const bool bReduceImageResolution)
virtual ~PDFExtOutDevData() override
GDIMetaFile * GetConnectMetaFile() const
Definition: outdev.hxx:417
std::deque< tools::Rectangle > mParaRects
void SetIsExportNamedDestinations(const bool bExportNDests)
std::vector< sal_Int32 > mStructParents
bool IsGfxLink() const
Definition: graph.cxx:524
void SetStructureBoundingBox(const tools::Rectangle &rRect)
set the bounding box of a structural element
Definition: pdfwriter.cxx:414
std::unique_ptr< GlobalSyncData > mpGlobalSyncData
bool IsEmpty() const
void Clear()
Definition: graph.cxx:299
bool GetIsLosslessCompression() const
void SetLinkPropertyID(sal_Int32 nLinkId, sal_Int32 nPropertyID)
Resolve link in logical structure.
Definition: pdfwriter.cxx:374
std::deque< std::shared_ptr< PDFWriter::AnyWidget > > mControls
std::deque< sal_uInt32 > mParauInts
void EndStructureElement()
end the current logical structure element
Definition: pdfwriter.cxx:394
std::vector< sal_Int32 > mParaIds
sal_Int32 CreateNamedDest(const OUString &sDestName, const tools::Rectangle &rRect, sal_Int32 nPageNr, DestAreaType eType)
Create a new named destination to be used in a link from another PDF document.
Definition: pdfwriter.cxx:345
void EndGroup(const Graphic &rGraphic, sal_uInt8 nTransparency, const tools::Rectangle &rOutputRect, const tools::Rectangle &rVisibleOutputRect)
End render output.
PDFWriter::DestAreaType mAreaType
void SetLinkDest(sal_Int32 nLinkId, sal_Int32 nDestId)
Set the destination for a link.
PageSyncData(GlobalSyncData *pGlobal)
std::vector< OUString > maChapterNames
sal_Int32 GetCurrentStructureElement() const
get the current structure element id
void DrawJPGBitmap(SvStream &rJPGData, bool bIsTrueColor, const Size &rSrcSizePixel, const tools::Rectangle &rTargetArea, const Bitmap &rMask, const Graphic &rGraphic)
Insert a JPG encoded image (optionally with mask)
Definition: pdfwriter.cxx:325
void SetIsExportFormFields(const bool bExportFormFields)
std::deque< Graphic > mGraphics
std::deque< OUString > mParaOUStrings
void SetAlternateText(const OUString &rText)
set the Alt attribute of a strutural element
Definition: pdfwriter.cxx:424
std::deque< PDFExtOutDevDataSync::Action > mActions
void SetIsExportBookmarks(const bool bExportBookmarks)
void Erase(sal_uInt8 cTransparency)
Definition: alpha.cxx:75
PDFExtOutDevData(const OutputDevice &rOutDev)
void SetLinkDest(sal_Int32 nLinkId, sal_Int32 nDestId)
Set the destination for a link will change a URL type link to a dest link if necessary.
Definition: pdfwriter.cxx:354
void PlayGlobalActions(PDFWriter &rWriter)
void SetCompressionQuality(const sal_Int32 nQuality)
void SetStructureAttributeNumerical(PDFWriter::StructAttribute eAttr, sal_Int32 nValue)
set a structure attribute on the current structural element
void SetIsExportNotesPages(const bool bExportNotesPages)
std::deque< PDFNote > mParaPDFNotes
void SetSize(const Size &rSize)
void SetIsExportHiddenSlides(const bool bExportHiddenSlides)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
GlobalSyncData * mpGlobalData
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
std::size_t WriteBytes(const void *pData, std::size_t nSize)
sal_Int32 CreateDest(const tools::Rectangle &rRect, sal_Int32 nPageNr=-1, PDFWriter::DestAreaType eType=PDFWriter::DestAreaType::XYZ)
Create a new destination to be used in a link.
void SetStructureAttributeNumerical(enum StructAttribute eAttr, sal_Int32 nValue)
set a structure attribute on the current structural element
Definition: pdfwriter.cxx:409
virtual std::unique_ptr< AnyWidget > Clone() const =0
std::deque< OUString > mParaOUStrings
void SetIsLosslessCompression(const bool bLosslessCompression)
void SetIsExportTaggedPDF(const bool bTaggedPDF)
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: pdfwriter.cxx:225
std::deque< PDFExtOutDevDataSync > mActions
void SetMapMode(const MapMode &rNewMapMode)
Definition: pdfwriter.cxx:235
GfxLink GetGfxLink() const
Definition: graph.cxx:519
DocumentType const eType
sal_Int32 BeginStructureElement(PDFWriter::StructElement eType, const OUString &rAlias=OUString())
begin a new logical structure element
sal_Int32 CreateScreen(const tools::Rectangle &rRect, sal_Int32 nPageNr)
Create a Screen annotation.
sal_Int32 RegisterDestReference(sal_Int32 nDestId, const tools::Rectangle &rRect, sal_Int32 nPageNr, DestAreaType eType)
creates a destination which is not intended to be referred to by a link, but by a public destination ...
Definition: pdfwriter.cxx:340
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
void DescribeRegisteredDest(sal_Int32 nDestId, const tools::Rectangle &rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType=PDFWriter::DestAreaType::XYZ)
provides detailed information about a destination range which previously has been registered using Re...
bool HasAdequateCompression(const Graphic &rGraphic, const tools::Rectangle &rOutputRect, const tools::Rectangle &rVisibleOutputRect) const
Detect if stream is compressed enough to avoid de-compress / scale & re-compress. ...
void SetLinkURL(sal_Int32 nLinkId, const OUString &rURL)
Set the URL for a link.
std::vector< sal_Int32 > mStructIdMap
void CreateNote(const tools::Rectangle &rRect, const PDFNote &rNote, sal_Int32 nPageNr=-1)
Create a new note on a page.
::std::map< sal_Int32, PDFLinkDestination > mFutureDestinations
sal_Int32 CreateControl(const AnyWidget &rControlType)
create a new form control
Definition: pdfwriter.cxx:434
sal_Int32 CreateOutlineItem(sal_Int32 nParent, const OUString &rText, sal_Int32 nDestID)
Create a new outline item.
Definition: pdfwriter.cxx:379
css::lang::Locale maDocLocale
std::unique_ptr< PageSyncData > mpPageSyncData
void PlayGlobalActions(PDFWriter &rWriter)
void SetStructureAttribute(enum StructAttribute eAttr, enum StructAttributeValue eVal)
set a structure attribute on the current structural element
Definition: pdfwriter.cxx:404
sal_Int32 CreateLink(const tools::Rectangle &rRect, sal_Int32 nPageNr)
Create a new link on a page.
Definition: pdfwriter.cxx:330
#define SAL_WARN_IF(condition, area, stream)
OutputDevice & mrOutDev
void SetScreenURL(sal_Int32 nScreenId, const OUString &rURL)
Sets the URL of a linked screen annotation.
Definition: pdfwriter.cxx:364
unsigned char sal_uInt8
MetaAction * GetAction(size_t nAction) const
Definition: gdimtf.cxx:157
void SetLinkURL(sal_Int32 nLinkId, const OUString &rURL)
Set the URL for a link will change a dest type link to a URL type link if necessary.
Definition: pdfwriter.cxx:359
sal_Int32 CreateNamedDest(const OUString &sDestName, const tools::Rectangle &rRect, sal_Int32 nPageNr=-1)
Create a new named destination to be used in a link to this document from another PDF document (see P...
sal_Int32 CreateLink(const tools::Rectangle &rRect, sal_Int32 nPageNr=-1)
Create a new link on a page.
bool PlaySyncPageAct(PDFWriter &rWriter, sal_uInt32 &rCurGDIMtfAction, const GDIMetaFile &rMtf, const PDFExtOutDevData &rOutDevData)
size_t GetActionSize() const
Definition: gdimtf.cxx:152
void SetDocumentLocale(const css::lang::Locale &rLoc)
MetaActionType GetType() const
Definition: metaact.hxx:89
std::deque< tools::Rectangle > mParaRects
sal_Int32 CreateOutlineItem(sal_Int32 nParent, const OUString &rText, sal_Int32 nDestID)
Create a new outline item.
sal_Int32 CreateDest(const tools::Rectangle &rRect, sal_Int32 nPageNr, DestAreaType eType)
Create a new destination to be used in a link.
Definition: pdfwriter.cxx:349
void SetActualText(const OUString &rText)
set the ActualText attribute of a structural element
void CreateNote(const tools::Rectangle &rRect, const PDFNote &rNote, sal_Int32 nPageNr)
Create a new note on a page.
Definition: pdfwriter.cxx:384
const OutputDevice & mrOutDev
void SetIsExportTransitionEffects(const bool bTransitionalEffects)
sal_Int32 GetMappedStructId(sal_Int32)
const Graphic & GetCurrentGraphic() const
void CreateControl(const PDFWriter::AnyWidget &rControlType)
create a new form control
sal_Int32 CreateScreen(const tools::Rectangle &rRect, sal_Int32 nPageNr)
Creates a screen annotation.
Definition: pdfwriter.cxx:335
void SetScreenStream(sal_Int32 nScreenId, const OUString &rURL)
Set URL for an embedded Screen annotation.
void SetPageTransition(PDFWriter::PageTransition eType, sal_uInt32 nMilliSec)
Sets the transitional effect to be applied when the current page gets shown.
void SetScreenStream(sal_Int32 nScreenId, const OUString &rURL)
Sets the URL of an embedded screen annotation.
Definition: pdfwriter.cxx:369
void SetClipRegion()
Definition: pdfwriter.cxx:250
std::deque< MapMode > mParaMapModes
void SetStructureBoundingBox(const tools::Rectangle &rRect)
set the bounding box of a structural element
void EndStructureElement()
end a logical structure element
std::deque< PDFWriter::PageTransition > mParaPageTransitions
bool GetIsReduceImageResolution() const
void SetCurrentStructureElement(sal_Int32 nElement)
set the current structure element
Definition: pdfwriter.cxx:399
const void * GetData()