LCOV - code coverage report
Current view: top level - filter/source/pdf - pdfexport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 580 0.0 %
Date: 2012-08-25 Functions: 0 17 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "pdfexport.hxx"
      31                 :            : #include "impdialog.hxx"
      32                 :            : 
      33                 :            : #include "pdf.hrc"
      34                 :            : #include "tools/urlobj.hxx"
      35                 :            : #include "tools/fract.hxx"
      36                 :            : #include "tools/poly.hxx"
      37                 :            : #include "vcl/mapmod.hxx"
      38                 :            : #include "vcl/virdev.hxx"
      39                 :            : #include "vcl/metaact.hxx"
      40                 :            : #include "vcl/gdimtf.hxx"
      41                 :            : #include "vcl/jobset.hxx"
      42                 :            : #include "vcl/bmpacc.hxx"
      43                 :            : #include "vcl/svapp.hxx"
      44                 :            : #include "toolkit/awt/vclxdevice.hxx"
      45                 :            : #include "unotools/localfilehelper.hxx"
      46                 :            : #include "svtools/FilterConfigItem.hxx"
      47                 :            : #include "svtools/filter.hxx"
      48                 :            : #include "svl/solar.hrc"
      49                 :            : #include "comphelper/string.hxx"
      50                 :            : #include "comphelper/storagehelper.hxx"
      51                 :            : #include "unotools/streamwrap.hxx"
      52                 :            : #include "com/sun/star/io/XSeekable.hpp"
      53                 :            : 
      54                 :            : #include "basegfx/polygon/b2dpolygon.hxx"
      55                 :            : #include "basegfx/polygon/b2dpolypolygon.hxx"
      56                 :            : #include "basegfx/polygon/b2dpolygontools.hxx"
      57                 :            : 
      58                 :            : #include "unotools/saveopt.hxx" // only for testing of relative saving options in PDF
      59                 :            : 
      60                 :            : #include "vcl/graphictools.hxx"
      61                 :            : #include "com/sun/star/beans/XPropertySet.hpp"
      62                 :            : #include "com/sun/star/configuration/theDefaultProvider.hpp"
      63                 :            : #include "com/sun/star/awt/Rectangle.hpp"
      64                 :            : #include "com/sun/star/awt/XDevice.hpp"
      65                 :            : #include "com/sun/star/util/MeasureUnit.hpp"
      66                 :            : #include "com/sun/star/frame/XModel.hpp"
      67                 :            : #include "com/sun/star/frame/XModuleManager.hpp"
      68                 :            : #include "com/sun/star/frame/XStorable.hpp"
      69                 :            : #include "com/sun/star/frame/XController.hpp"
      70                 :            : #include "com/sun/star/document/XDocumentProperties.hpp"
      71                 :            : #include "com/sun/star/document/XDocumentPropertiesSupplier.hpp"
      72                 :            : #include "com/sun/star/container/XNameAccess.hpp"
      73                 :            : #include "com/sun/star/view/XViewSettingsSupplier.hpp"
      74                 :            : #include "com/sun/star/task/XInteractionRequest.hpp"
      75                 :            : #include "com/sun/star/task/PDFExportException.hpp"
      76                 :            : 
      77                 :            : #include "unotools/configmgr.hxx"
      78                 :            : #include "cppuhelper/exc_hlp.hxx"
      79                 :            : #include "cppuhelper/compbase1.hxx"
      80                 :            : #include "cppuhelper/basemutex.hxx"
      81                 :            : 
      82                 :            : #include "com/sun/star/lang/XServiceInfo.hpp"
      83                 :            : #include "com/sun/star/drawing/XShapes.hpp"
      84                 :            : #include "com/sun/star/graphic/XGraphicProvider.hpp"
      85                 :            : 
      86                 :            : using namespace ::rtl;
      87                 :            : using namespace ::vcl;
      88                 :            : using namespace ::com::sun::star;
      89                 :            : using namespace ::com::sun::star::uno;
      90                 :            : using namespace ::com::sun::star::lang;
      91                 :            : using namespace ::com::sun::star::beans;
      92                 :            : using namespace ::com::sun::star::view;
      93                 :            : using namespace ::com::sun::star::graphic;
      94                 :            : 
      95                 :            : // -------------
      96                 :            : // - PDFExport -
      97                 :            : // -------------
      98                 :            : 
      99                 :          0 : PDFExport::PDFExport( const Reference< XComponent >& rxSrcDoc,
     100                 :            :                       const Reference< task::XStatusIndicator >& rxStatusIndicator,
     101                 :            :                       const Reference< task::XInteractionHandler >& rxIH,
     102                 :            :                       const Reference< lang::XMultiServiceFactory >& xFactory ) :
     103                 :            :     mxSrcDoc                    ( rxSrcDoc ),
     104                 :            :     mxMSF                       ( xFactory ),
     105                 :            :     mxStatusIndicator           ( rxStatusIndicator ),
     106                 :            :     mxIH                        ( rxIH ),
     107                 :            :     mbUseTaggedPDF              ( sal_False ),
     108                 :            :     mnPDFTypeSelection          ( 0 ),
     109                 :            :     mbExportNotes               ( sal_True ),
     110                 :            :     mbExportNotesPages          ( sal_False ),
     111                 :            :     mbEmbedStandardFonts        ( sal_False ),//in preparation for i54636 and i76458.
     112                 :            :                                               //already used for i59651 (PDF/A-1)
     113                 :            :     mbUseTransitionEffects      ( sal_True ),
     114                 :            :     mbExportBookmarks           ( sal_True ),
     115                 :            :     mbExportHiddenSlides        ( sal_False ),
     116                 :            :     mnOpenBookmarkLevels        ( -1 ),
     117                 :            :     mbUseLosslessCompression    ( sal_False ),
     118                 :            :     mbReduceImageResolution     ( sal_False ),
     119                 :            :     mbSkipEmptyPages            ( sal_True ),
     120                 :            :     mbAddStream                 ( sal_False ),
     121                 :            :     mnMaxImageResolution        ( 300 ),
     122                 :            :     mnQuality                   ( 90 ),
     123                 :            :     mnFormsFormat               ( 0 ),
     124                 :            :     mbExportFormFields          ( sal_True ),
     125                 :            :     mbAllowDuplicateFieldNames  ( sal_False ),
     126                 :            :     mnProgressValue             ( 0 ),
     127                 :            :     mbRemoveTransparencies      ( sal_False ),
     128                 :            :     mbWatermark                 ( sal_False ),
     129                 :            : 
     130                 :            :     mbHideViewerToolbar         ( sal_False ),
     131                 :            :     mbHideViewerMenubar         ( sal_False ),
     132                 :            :     mbHideViewerWindowControls  ( sal_False ),
     133                 :            :     mbFitWindow                 ( sal_False ),
     134                 :            :     mbCenterWindow              ( sal_False ),
     135                 :            :     mbOpenInFullScreenMode      ( sal_False ),
     136                 :            :     mbDisplayPDFDocumentTitle   ( sal_True ),
     137                 :            :     mnPDFDocumentMode           ( 0 ),
     138                 :            :     mnPDFDocumentAction         ( 0 ),
     139                 :            :     mnZoom                      ( 100 ),
     140                 :            :     mnInitialPage               ( 1 ),
     141                 :            :     mnPDFPageLayout             ( 0 ),
     142                 :            :     mbFirstPageLeft             ( sal_False ),
     143                 :            : 
     144                 :            :     mbEncrypt                   ( sal_False ),
     145                 :            :     mbRestrictPermissions       ( sal_False ),
     146                 :            :     mnPrintAllowed              ( 2 ),
     147                 :            :     mnChangesAllowed            ( 4 ),
     148                 :            :     mbCanCopyOrExtract          ( sal_True ),
     149                 :            :     mbCanExtractForAccessibility( sal_True ),
     150                 :            : 
     151                 :            :     mnCachePatternId            ( -1 ),
     152                 :            : 
     153                 :            : //--->i56629
     154                 :            :     mbExportRelativeFsysLinks       ( sal_False ),
     155                 :            :     mnDefaultLinkAction         ( 0 ),
     156                 :            :     mbConvertOOoTargetToPDFTarget( sal_False ),
     157                 :          0 :     mbExportBmkToDest           ( sal_False )
     158                 :            : {
     159                 :          0 : }
     160                 :            : 
     161                 :            : // -----------------------------------------------------------------------------
     162                 :            : 
     163                 :          0 : PDFExport::~PDFExport()
     164                 :            : {
     165                 :          0 : }
     166                 :            : 
     167                 :            : // -----------------------------------------------------------------------------
     168                 :            : 
     169                 :          0 : sal_Bool PDFExport::ExportSelection( vcl::PDFWriter& rPDFWriter,
     170                 :            :     Reference< com::sun::star::view::XRenderable >& rRenderable,
     171                 :            :     const Any& rSelection,
     172                 :            :     const StringRangeEnumerator& rRangeEnum,
     173                 :            :     Sequence< PropertyValue >& rRenderOptions,
     174                 :            :     sal_Int32 nPageCount )
     175                 :            : {
     176                 :          0 :     sal_Bool        bRet = sal_False;
     177                 :            :     try
     178                 :            :     {
     179                 :          0 :         Any* pFirstPage = NULL;
     180                 :          0 :         Any* pLastPage = NULL;
     181                 :            : 
     182                 :          0 :         sal_Bool bExportNotesPages = sal_False;
     183                 :            : 
     184                 :          0 :         for( sal_Int32 nData = 0, nDataCount = rRenderOptions.getLength(); nData < nDataCount; ++nData )
     185                 :            :         {
     186                 :          0 :             if ( rRenderOptions[ nData ].Name == "IsFirstPage" )
     187                 :          0 :                 pFirstPage = &rRenderOptions[ nData ].Value;
     188                 :          0 :             else if ( rRenderOptions[ nData ].Name == "IsLastPage" )
     189                 :          0 :                 pLastPage = &rRenderOptions[ nData ].Value;
     190                 :          0 :             else if ( rRenderOptions[ nData ].Name == "ExportNotesPages" )
     191                 :          0 :                 rRenderOptions[ nData ].Value >>= bExportNotesPages;
     192                 :            :         }
     193                 :            : 
     194                 :          0 :         OutputDevice* pOut = rPDFWriter.GetReferenceDevice();
     195                 :            : 
     196                 :          0 :         if( pOut )
     197                 :            :         {
     198                 :          0 :             vcl::PDFExtOutDevData* pPDFExtOutDevData = PTR_CAST( vcl::PDFExtOutDevData, pOut->GetExtOutDevData() );
     199                 :          0 :             if ( nPageCount )
     200                 :            :             {
     201                 :          0 :                 pPDFExtOutDevData->SetIsExportNotesPages( bExportNotesPages );
     202                 :            : 
     203                 :          0 :                 sal_Int32 nCurrentPage(0);
     204                 :          0 :                 StringRangeEnumerator::Iterator aIter = rRangeEnum.begin();
     205                 :          0 :                 StringRangeEnumerator::Iterator aEnd  = rRangeEnum.end();
     206                 :          0 :                 while ( aIter != aEnd )
     207                 :            :                 {
     208                 :          0 :                     Sequence< PropertyValue >   aRenderer( rRenderable->getRenderer( *aIter, rSelection, rRenderOptions ) );
     209                 :          0 :                     awt::Size                   aPageSize;
     210                 :            : 
     211                 :          0 :                     for( sal_Int32 nProperty = 0, nPropertyCount = aRenderer.getLength(); nProperty < nPropertyCount; ++nProperty )
     212                 :            :                     {
     213                 :          0 :                         if ( aRenderer[ nProperty ].Name == "PageSize" )
     214                 :          0 :                             aRenderer[ nProperty].Value >>= aPageSize;
     215                 :            :                     }
     216                 :            : 
     217                 :          0 :                     pPDFExtOutDevData->SetCurrentPageNumber( nCurrentPage );
     218                 :            : 
     219                 :          0 :                     GDIMetaFile                 aMtf;
     220                 :          0 :                     const MapMode               aMapMode( MAP_100TH_MM );
     221                 :          0 :                     const Size                  aMtfSize( aPageSize.Width, aPageSize.Height );
     222                 :            : 
     223                 :          0 :                     pOut->Push();
     224                 :          0 :                     pOut->EnableOutput( sal_False );
     225                 :          0 :                     pOut->SetMapMode( aMapMode );
     226                 :            : 
     227                 :          0 :                     aMtf.SetPrefSize( aMtfSize );
     228                 :          0 :                     aMtf.SetPrefMapMode( aMapMode );
     229                 :          0 :                     aMtf.Record( pOut );
     230                 :            : 
     231                 :            :                     // #i35176#
     232                 :            :                     // IsLastPage property.
     233                 :          0 :                     const sal_Int32 nCurrentRenderer = *aIter;
     234                 :          0 :                     ++aIter;
     235                 :          0 :                     if ( pLastPage && aIter == aEnd )
     236                 :          0 :                         *pLastPage <<= sal_True;
     237                 :            : 
     238                 :          0 :                     rRenderable->render( nCurrentRenderer, rSelection, rRenderOptions );
     239                 :            : 
     240                 :          0 :                     aMtf.Stop();
     241                 :          0 :                     aMtf.WindStart();
     242                 :            : 
     243                 :          0 :                     if( aMtf.GetActionSize() &&
     244                 :          0 :                              ( !mbSkipEmptyPages || aPageSize.Width || aPageSize.Height ) )
     245                 :          0 :                         bRet = ImplExportPage( rPDFWriter, *pPDFExtOutDevData, aMtf ) || bRet;
     246                 :            : 
     247                 :          0 :                     pOut->Pop();
     248                 :            : 
     249                 :          0 :                     if ( mxStatusIndicator.is() )
     250                 :          0 :                         mxStatusIndicator->setValue( mnProgressValue );
     251                 :          0 :                     if ( pFirstPage )
     252                 :          0 :                         *pFirstPage <<= sal_False;
     253                 :            : 
     254                 :          0 :                     ++mnProgressValue;
     255                 :          0 :                     ++nCurrentPage;
     256                 :          0 :                 }
     257                 :            :             }
     258                 :            :             else
     259                 :            :             {
     260                 :          0 :                 bRet = sal_True;                        // #i18334# SJ: nPageCount == 0,
     261                 :          0 :                 rPDFWriter.NewPage( 10000, 10000 );     // creating dummy page
     262                 :          0 :                 rPDFWriter.SetMapMode( MAP_100TH_MM );  //
     263                 :            :             }
     264                 :            :         }
     265                 :            :     }
     266                 :          0 :     catch(const RuntimeException &)
     267                 :            :     {
     268                 :            :     }
     269                 :          0 :     return bRet;
     270                 :            : }
     271                 :            : 
     272                 :            : class PDFExportStreamDoc : public vcl::PDFOutputStream
     273                 :            : {
     274                 :            :     Reference< XComponent >             m_xSrcDoc;
     275                 :            :     Sequence< beans::NamedValue >       m_aPreparedPassword;
     276                 :            :     public:
     277                 :          0 :         PDFExportStreamDoc( const Reference< XComponent >& xDoc, const Sequence<beans::NamedValue>& rPwd )
     278                 :            :     : m_xSrcDoc( xDoc ),
     279                 :          0 :       m_aPreparedPassword( rPwd )
     280                 :          0 :     {}
     281                 :            :     virtual ~PDFExportStreamDoc();
     282                 :            : 
     283                 :            :     virtual void write( const Reference< XOutputStream >& xStream );
     284                 :            : };
     285                 :            : 
     286                 :          0 : PDFExportStreamDoc::~PDFExportStreamDoc()
     287                 :            : {
     288                 :          0 : }
     289                 :            : 
     290                 :          0 : void PDFExportStreamDoc::write( const Reference< XOutputStream >& xStream )
     291                 :            : {
     292                 :          0 :     Reference< com::sun::star::frame::XStorable > xStore( m_xSrcDoc, UNO_QUERY );
     293                 :          0 :     if( xStore.is() )
     294                 :            :     {
     295                 :          0 :         Sequence< beans::PropertyValue > aArgs( 2 + ((m_aPreparedPassword.getLength() > 0) ? 1 : 0) );
     296                 :          0 :         aArgs.getArray()[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
     297                 :          0 :         aArgs.getArray()[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OutputStream" ) );
     298                 :          0 :         aArgs.getArray()[1].Value <<= xStream;
     299                 :          0 :         if( m_aPreparedPassword.getLength() )
     300                 :            :         {
     301                 :          0 :             aArgs.getArray()[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) );
     302                 :          0 :             aArgs.getArray()[2].Value <<= m_aPreparedPassword;
     303                 :            :         }
     304                 :            : 
     305                 :            :         try
     306                 :            :         {
     307                 :          0 :             xStore->storeToURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:stream" ) ),
     308                 :          0 :                                 aArgs );
     309                 :            :         }
     310                 :          0 :         catch( const IOException& )
     311                 :            :         {
     312                 :          0 :         }
     313                 :          0 :     }
     314                 :          0 : }
     315                 :            : 
     316                 :          0 : static OUString getMimetypeForDocument( const Reference< XMultiServiceFactory >& xFactory,
     317                 :            :                                         const Reference< XComponent >& xDoc ) throw()
     318                 :            : {
     319                 :          0 :     OUString aDocMimetype;
     320                 :            :         // get document service name
     321                 :          0 :     Reference< com::sun::star::frame::XStorable > xStore( xDoc, UNO_QUERY );
     322                 :            :     Reference< frame::XModuleManager > xModuleManager(
     323                 :          0 :         xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ),
     324                 :          0 :                                uno::UNO_QUERY );
     325                 :          0 :     if( xModuleManager.is() && xStore.is() )
     326                 :            :     {
     327                 :          0 :         OUString aDocServiceName = xModuleManager->identify( Reference< XInterface >( xStore, uno::UNO_QUERY ) );
     328                 :          0 :         if ( !aDocServiceName.isEmpty() )
     329                 :            :         {
     330                 :            :             // get the actual filter name
     331                 :          0 :             OUString aFilterName;
     332                 :            :             Reference< lang::XMultiServiceFactory > xConfigProvider(
     333                 :            :                 configuration::theDefaultProvider::get(
     334                 :          0 :                     comphelper::getComponentContext( xFactory ) ) );
     335                 :          0 :             uno::Sequence< uno::Any > aArgs( 1 );
     336                 :          0 :             beans::NamedValue aPathProp;
     337                 :          0 :             aPathProp.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) );
     338                 :          0 :             aPathProp.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Setup/Office/Factories/" ) );
     339                 :          0 :             aArgs[0] <<= aPathProp;
     340                 :            : 
     341                 :            :             Reference< container::XNameAccess > xSOFConfig(
     342                 :          0 :                 xConfigProvider->createInstanceWithArguments(
     343                 :            :                     OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ),
     344                 :          0 :                     aArgs ),
     345                 :          0 :                 uno::UNO_QUERY );
     346                 :            : 
     347                 :          0 :             Reference< container::XNameAccess > xApplConfig;
     348                 :          0 :             xSOFConfig->getByName( aDocServiceName ) >>= xApplConfig;
     349                 :          0 :             if ( xApplConfig.is() )
     350                 :            :             {
     351                 :          0 :                 xApplConfig->getByName( OUString( RTL_CONSTASCII_USTRINGPARAM( "ooSetupFactoryActualFilter" ) ) ) >>= aFilterName;
     352                 :          0 :                 if( !aFilterName.isEmpty() )
     353                 :            :                 {
     354                 :            :                     // find the related type name
     355                 :          0 :                     OUString aTypeName;
     356                 :            :                     Reference< container::XNameAccess > xFilterFactory(
     357                 :          0 :                         xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" )) ),
     358                 :          0 :                         uno::UNO_QUERY );
     359                 :            : 
     360                 :          0 :                     Sequence< beans::PropertyValue > aFilterData;
     361                 :          0 :                     xFilterFactory->getByName( aFilterName ) >>= aFilterData;
     362                 :          0 :                     for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
     363                 :          0 :                         if ( aFilterData[nInd].Name == "Type" )
     364                 :          0 :                             aFilterData[nInd].Value >>= aTypeName;
     365                 :            : 
     366                 :          0 :                     if ( !aTypeName.isEmpty() )
     367                 :            :                     {
     368                 :            :                         // find the mediatype
     369                 :            :                         Reference< container::XNameAccess > xTypeDetection(
     370                 :          0 :                             xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" )) ),
     371                 :          0 :                             UNO_QUERY );
     372                 :            : 
     373                 :          0 :                         Sequence< beans::PropertyValue > aTypeData;
     374                 :          0 :                         xTypeDetection->getByName( aTypeName ) >>= aTypeData;
     375                 :          0 :                         for ( sal_Int32 nInd = 0; nInd < aTypeData.getLength(); nInd++ )
     376                 :          0 :                             if ( aTypeData[nInd].Name == "MediaType" )
     377                 :          0 :                                 aTypeData[nInd].Value >>= aDocMimetype;
     378                 :          0 :                     }
     379                 :            :                 }
     380                 :          0 :             }
     381                 :          0 :         }
     382                 :            :     }
     383                 :          0 :     return aDocMimetype;
     384                 :            : }
     385                 :            : 
     386                 :          0 : sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& rFilterData )
     387                 :            : {
     388                 :          0 :     INetURLObject   aURL( rFile );
     389                 :          0 :     sal_Bool        bRet = sal_False;
     390                 :            : 
     391                 :          0 :     std::set< PDFWriter::ErrorCode > aErrors;
     392                 :            : 
     393                 :          0 :     if( aURL.GetProtocol() != INET_PROT_FILE )
     394                 :            :     {
     395                 :          0 :         rtl::OUString aTmp;
     396                 :            : 
     397                 :          0 :         if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rFile, aTmp ) )
     398                 :          0 :             aURL = INetURLObject(aTmp);
     399                 :            :     }
     400                 :            : 
     401                 :          0 :     if( aURL.GetProtocol() == INET_PROT_FILE )
     402                 :            :     {
     403                 :          0 :         Reference< XRenderable > xRenderable( mxSrcDoc, UNO_QUERY );
     404                 :            : 
     405                 :          0 :         if( xRenderable.is() )
     406                 :            :         {
     407                 :          0 :             VCLXDevice*                 pXDevice = new VCLXDevice;
     408                 :          0 :             OUString                    aPageRange;
     409                 :          0 :             Any                         aSelection;
     410                 :          0 :             PDFWriter::PDFWriterContext aContext;
     411                 :          0 :             rtl::OUString aOpenPassword, aPermissionPassword;
     412                 :          0 :             Reference< beans::XMaterialHolder > xEnc;
     413                 :          0 :             Sequence< beans::NamedValue > aPreparedPermissionPassword;
     414                 :            : 
     415                 :            : 
     416                 :            :             // getting the string for the creator
     417                 :          0 :             String aCreator;
     418                 :          0 :             Reference< XServiceInfo > xInfo( mxSrcDoc, UNO_QUERY );
     419                 :          0 :             if ( xInfo.is() )
     420                 :            :             {
     421                 :          0 :                 if ( xInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" )) ) )
     422                 :          0 :                     aCreator.AppendAscii( "Impress" );
     423                 :          0 :                 else if ( xInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" )) ) )
     424                 :          0 :                     aCreator.AppendAscii( "Draw" );
     425                 :          0 :                 else if ( xInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" )) ) )
     426                 :          0 :                     aCreator.AppendAscii( "Writer" );
     427                 :          0 :                 else if ( xInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocument" )) ) )
     428                 :          0 :                     aCreator.AppendAscii( "Calc" );
     429                 :          0 :                 else if ( xInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.formula.FormulaProperties" )) ) )
     430                 :          0 :                     aCreator.AppendAscii( "Math" );
     431                 :            :             }
     432                 :            : 
     433                 :          0 :             Reference< document::XDocumentPropertiesSupplier > xDocumentPropsSupplier( mxSrcDoc, UNO_QUERY );
     434                 :          0 :             if ( xDocumentPropsSupplier.is() )
     435                 :            :             {
     436                 :          0 :                 Reference< document::XDocumentProperties > xDocumentProps( xDocumentPropsSupplier->getDocumentProperties() );
     437                 :          0 :                 if ( xDocumentProps.is() )
     438                 :            :                 {
     439                 :          0 :                     aContext.DocumentInfo.Title = xDocumentProps->getTitle();
     440                 :          0 :                     aContext.DocumentInfo.Author = xDocumentProps->getAuthor();
     441                 :          0 :                     aContext.DocumentInfo.Subject = xDocumentProps->getSubject();
     442                 :          0 :                     aContext.DocumentInfo.Keywords = ::comphelper::string::convertCommaSeparated(xDocumentProps->getKeywords());
     443                 :          0 :                 }
     444                 :            :             }
     445                 :            :             // getting the string for the producer
     446                 :            :             aContext.DocumentInfo.Producer =
     447                 :            :                 utl::ConfigManager::getProductName() +
     448                 :            :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")) +
     449                 :          0 :                 utl::ConfigManager::getProductVersion();
     450                 :          0 :             aContext.DocumentInfo.Creator = aCreator;
     451                 :            : 
     452                 :          0 :             for( sal_Int32 nData = 0, nDataCount = rFilterData.getLength(); nData < nDataCount; ++nData )
     453                 :            :             {
     454                 :          0 :                 if ( rFilterData[ nData ].Name == "PageRange" )
     455                 :          0 :                     rFilterData[ nData ].Value >>= aPageRange;
     456                 :          0 :                 else if ( rFilterData[ nData ].Name == "Selection" )
     457                 :          0 :                     rFilterData[ nData ].Value >>= aSelection;
     458                 :          0 :                 else if ( rFilterData[ nData ].Name == "UseLosslessCompression" )
     459                 :          0 :                     rFilterData[ nData ].Value >>= mbUseLosslessCompression;
     460                 :          0 :                 else if ( rFilterData[ nData ].Name == "Quality" )
     461                 :          0 :                     rFilterData[ nData ].Value >>= mnQuality;
     462                 :          0 :                 else if ( rFilterData[ nData ].Name == "ReduceImageResolution" )
     463                 :          0 :                     rFilterData[ nData ].Value >>= mbReduceImageResolution;
     464                 :          0 :                 else if ( rFilterData[ nData ].Name == "IsSkipEmptyPages" )
     465                 :          0 :                     rFilterData[ nData ].Value >>= mbSkipEmptyPages;
     466                 :          0 :                 else if ( rFilterData[ nData ].Name == "MaxImageResolution" )
     467                 :          0 :                     rFilterData[ nData ].Value >>= mnMaxImageResolution;
     468                 :          0 :                 else if ( rFilterData[ nData ].Name == "UseTaggedPDF" )
     469                 :          0 :                     rFilterData[ nData ].Value >>= mbUseTaggedPDF;
     470                 :          0 :                 else if ( rFilterData[ nData ].Name == "SelectPdfVersion" )
     471                 :          0 :                     rFilterData[ nData ].Value >>= mnPDFTypeSelection;
     472                 :          0 :                 else if ( rFilterData[ nData ].Name == "ExportNotes" )
     473                 :          0 :                     rFilterData[ nData ].Value >>= mbExportNotes;
     474                 :          0 :                 else if ( rFilterData[ nData ].Name == "ExportNotesPages" )
     475                 :          0 :                     rFilterData[ nData ].Value >>= mbExportNotesPages;
     476                 :          0 :                 else if ( rFilterData[ nData ].Name == "EmbedStandardFonts" )
     477                 :          0 :                     rFilterData[ nData ].Value >>= mbEmbedStandardFonts;
     478                 :          0 :                 else if ( rFilterData[ nData ].Name == "UseTransitionEffects" )
     479                 :          0 :                     rFilterData[ nData ].Value >>= mbUseTransitionEffects;
     480                 :          0 :                 else if ( rFilterData[ nData ].Name == "ExportFormFields" )
     481                 :          0 :                     rFilterData[ nData ].Value >>= mbExportFormFields;
     482                 :          0 :                 else if ( rFilterData[ nData ].Name == "FormsType" )
     483                 :          0 :                     rFilterData[ nData ].Value >>= mnFormsFormat;
     484                 :          0 :                 else if ( rFilterData[ nData ].Name == "AllowDuplicateFieldNames" )
     485                 :          0 :                     rFilterData[ nData ].Value >>= mbAllowDuplicateFieldNames;
     486                 :            : //viewer properties
     487                 :          0 :                 else if ( rFilterData[ nData ].Name == "HideViewerToolbar" )
     488                 :          0 :                     rFilterData[ nData ].Value >>= mbHideViewerToolbar;
     489                 :          0 :                 else if ( rFilterData[ nData ].Name == "HideViewerMenubar" )
     490                 :          0 :                     rFilterData[ nData ].Value >>= mbHideViewerMenubar;
     491                 :          0 :                 else if ( rFilterData[ nData ].Name == "HideViewerWindowControls" )
     492                 :          0 :                     rFilterData[ nData ].Value >>= mbHideViewerWindowControls;
     493                 :          0 :                 else if ( rFilterData[ nData ].Name == "ResizeWindowToInitialPage" )
     494                 :          0 :                     rFilterData[ nData ].Value >>= mbFitWindow;
     495                 :          0 :                 else if ( rFilterData[ nData ].Name == "CenterWindow" )
     496                 :          0 :                     rFilterData[ nData ].Value >>= mbCenterWindow;
     497                 :          0 :                 else if ( rFilterData[ nData ].Name == "OpenInFullScreenMode" )
     498                 :          0 :                     rFilterData[ nData ].Value >>= mbOpenInFullScreenMode;
     499                 :          0 :                 else if ( rFilterData[ nData ].Name == "DisplayPDFDocumentTitle" )
     500                 :          0 :                     rFilterData[ nData ].Value >>= mbDisplayPDFDocumentTitle;
     501                 :          0 :                 else if ( rFilterData[ nData ].Name == "InitialView" )
     502                 :          0 :                     rFilterData[ nData ].Value >>= mnPDFDocumentMode;
     503                 :          0 :                 else if ( rFilterData[ nData ].Name == "Magnification" )
     504                 :          0 :                     rFilterData[ nData ].Value >>= mnPDFDocumentAction;
     505                 :          0 :                 else if ( rFilterData[ nData ].Name == "Zoom" )
     506                 :          0 :                     rFilterData[ nData ].Value >>= mnZoom;
     507                 :          0 :                 else if ( rFilterData[ nData ].Name == "InitialPage" )
     508                 :          0 :                     rFilterData[ nData ].Value >>= mnInitialPage;
     509                 :          0 :                 else if ( rFilterData[ nData ].Name == "PageLayout" )
     510                 :          0 :                     rFilterData[ nData ].Value >>= mnPDFPageLayout;
     511                 :          0 :                 else if ( rFilterData[ nData ].Name == "FirstPageOnLeft" )
     512                 :          0 :                     rFilterData[ nData ].Value >>= aContext.FirstPageLeft;
     513                 :          0 :                 else if ( rFilterData[ nData ].Name == "IsAddStream" )
     514                 :          0 :                     rFilterData[ nData ].Value >>= mbAddStream;
     515                 :          0 :                 else if ( rFilterData[ nData ].Name == "Watermark" )
     516                 :            :                 {
     517                 :          0 :                     maWatermark = rFilterData[ nData ].Value;
     518                 :          0 :                     mbWatermark = sal_True;
     519                 :            :                 }
     520                 :            : //now all the security related properties...
     521                 :          0 :                 else if ( rFilterData[ nData ].Name == "EncryptFile" )
     522                 :          0 :                     rFilterData[ nData ].Value >>= mbEncrypt;
     523                 :          0 :                 else if ( rFilterData[ nData ].Name == "DocumentOpenPassword" )
     524                 :          0 :                     rFilterData[ nData ].Value >>= aOpenPassword;
     525                 :          0 :                 else if ( rFilterData[ nData ].Name == "RestrictPermissions" )
     526                 :          0 :                     rFilterData[ nData ].Value >>= mbRestrictPermissions;
     527                 :          0 :                 else if ( rFilterData[ nData ].Name == "PermissionPassword" )
     528                 :          0 :                     rFilterData[ nData ].Value >>= aPermissionPassword;
     529                 :          0 :                 else if ( rFilterData[ nData ].Name == "PreparedPasswords" )
     530                 :          0 :                     rFilterData[ nData ].Value >>= xEnc;
     531                 :          0 :                 else if ( rFilterData[ nData ].Name == "PreparedPermissionPassword" )
     532                 :          0 :                     rFilterData[ nData ].Value >>= aPreparedPermissionPassword;
     533                 :          0 :                 else if ( rFilterData[ nData ].Name == "Printing" )
     534                 :          0 :                     rFilterData[ nData ].Value >>= mnPrintAllowed;
     535                 :          0 :                 else if ( rFilterData[ nData ].Name == "Changes" )
     536                 :          0 :                     rFilterData[ nData ].Value >>= mnChangesAllowed;
     537                 :          0 :                 else if ( rFilterData[ nData ].Name == "EnableCopyingOfContent" )
     538                 :          0 :                     rFilterData[ nData ].Value >>= mbCanCopyOrExtract;
     539                 :          0 :                 else if ( rFilterData[ nData ].Name == "EnableTextAccessForAccessibilityTools" )
     540                 :          0 :                     rFilterData[ nData ].Value >>= mbCanExtractForAccessibility;
     541                 :            : //--->i56629 links extra (relative links and other related stuff)
     542                 :          0 :                  else if ( rFilterData[ nData ].Name == "ExportLinksRelativeFsys" )
     543                 :          0 :                      rFilterData[ nData ].Value >>= mbExportRelativeFsysLinks;
     544                 :          0 :                  else if ( rFilterData[ nData ].Name == "PDFViewSelection" )
     545                 :          0 :                      rFilterData[ nData ].Value >>= mnDefaultLinkAction;
     546                 :          0 :                  else if ( rFilterData[ nData ].Name == "ConvertOOoTargetToPDFTarget" )
     547                 :          0 :                      rFilterData[ nData ].Value >>= mbConvertOOoTargetToPDFTarget;
     548                 :          0 :                   else if ( rFilterData[ nData ].Name == "ExportBookmarksToPDFDestination" )
     549                 :          0 :                       rFilterData[ nData ].Value >>= mbExportBmkToDest;
     550                 :          0 :                 else if ( rFilterData[ nData ].Name == "ExportBookmarks" )
     551                 :          0 :                     rFilterData[ nData ].Value >>= mbExportBookmarks;
     552                 :          0 :                 else if ( rFilterData[ nData ].Name == "ExportHiddenSlides" )
     553                 :          0 :                     rFilterData[ nData ].Value >>= mbExportHiddenSlides;
     554                 :          0 :                 else if ( rFilterData[ nData ].Name == "OpenBookmarkLevels" )
     555                 :          0 :                     rFilterData[ nData ].Value >>= mnOpenBookmarkLevels;
     556                 :          0 :                 else if ( rFilterData[ nData ].Name == "SignPDF" )
     557                 :          0 :                     rFilterData[ nData ].Value >>= mbSignPDF;
     558                 :          0 :                 else if ( rFilterData[ nData ].Name == "SignatureLocation" )
     559                 :          0 :                     rFilterData[ nData ].Value >>= msSignLocation;
     560                 :          0 :                 else if ( rFilterData[ nData ].Name == "SignatureReason" )
     561                 :          0 :                     rFilterData[ nData ].Value >>= msSignReason;
     562                 :          0 :                 else if ( rFilterData[ nData ].Name == "SignatureContactInfo" )
     563                 :          0 :                     rFilterData[ nData ].Value >>= msSignContact;
     564                 :          0 :                 else if ( rFilterData[ nData ].Name == "SignaturePassword" )
     565                 :          0 :                     rFilterData[ nData ].Value >>= msSignPassword;
     566                 :          0 :                 else if ( rFilterData[ nData ].Name == "SignatureCertificate" )
     567                 :          0 :                     rFilterData[ nData ].Value >>= maSignCertificate;
     568                 :            :             }
     569                 :          0 :             aContext.URL        = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
     570                 :            : 
     571                 :            : //set the correct version, depending on user request
     572                 :          0 :             switch( mnPDFTypeSelection )
     573                 :            :             {
     574                 :            :             default:
     575                 :            :             case 0:
     576                 :          0 :                 aContext.Version    = PDFWriter::PDF_1_4;
     577                 :          0 :                 break;
     578                 :            :             case 1:
     579                 :          0 :                 aContext.Version    = PDFWriter::PDF_A_1;
     580                 :            :                 //force the tagged PDF as well
     581                 :          0 :                 mbUseTaggedPDF = sal_True;
     582                 :            :                 //force embedding of standard fonts
     583                 :          0 :                 mbEmbedStandardFonts = sal_True;
     584                 :            :                 //force disabling of form conversion
     585                 :          0 :                 mbExportFormFields = sal_False;
     586                 :            :                 // PDF/A does not allow transparencies
     587                 :          0 :                 mbRemoveTransparencies = sal_True;
     588                 :            :                 // no encryption
     589                 :          0 :                 mbEncrypt = sal_False;
     590                 :          0 :                 xEnc.clear();
     591                 :          0 :                 break;
     592                 :            :             }
     593                 :            : 
     594                 :            : //copy in context the values default in the contructor or set by the FilterData sequence of properties
     595                 :          0 :             aContext.Tagged     = mbUseTaggedPDF;
     596                 :            : 
     597                 :            : //values used in viewer
     598                 :          0 :             aContext.HideViewerToolbar          = mbHideViewerToolbar;
     599                 :          0 :             aContext.HideViewerMenubar          = mbHideViewerMenubar;
     600                 :          0 :             aContext.HideViewerWindowControls   = mbHideViewerWindowControls;
     601                 :          0 :             aContext.FitWindow                  = mbFitWindow;
     602                 :          0 :             aContext.CenterWindow               = mbCenterWindow;
     603                 :          0 :             aContext.OpenInFullScreenMode       = mbOpenInFullScreenMode;
     604                 :          0 :             aContext.DisplayPDFDocumentTitle    = mbDisplayPDFDocumentTitle;
     605                 :          0 :             aContext.InitialPage                = mnInitialPage-1;
     606                 :          0 :             aContext.OpenBookmarkLevels         = mnOpenBookmarkLevels;
     607                 :          0 :             aContext.EmbedStandardFonts         = mbEmbedStandardFonts;
     608                 :            : 
     609                 :          0 :             switch( mnPDFDocumentMode )
     610                 :            :             {
     611                 :            :                 default:
     612                 :            :                 case 0:
     613                 :          0 :                     aContext.PDFDocumentMode = PDFWriter::ModeDefault;
     614                 :          0 :                     break;
     615                 :            :                 case 1:
     616                 :          0 :                     aContext.PDFDocumentMode = PDFWriter::UseOutlines;
     617                 :          0 :                     break;
     618                 :            :                 case 2:
     619                 :          0 :                     aContext.PDFDocumentMode = PDFWriter::UseThumbs;
     620                 :          0 :                     break;
     621                 :            :             }
     622                 :          0 :             switch( mnPDFDocumentAction )
     623                 :            :             {
     624                 :            :                 default:
     625                 :            :                 case 0:
     626                 :          0 :                     aContext.PDFDocumentAction = PDFWriter::ActionDefault;
     627                 :          0 :                     break;
     628                 :            :                 case 1:
     629                 :          0 :                     aContext.PDFDocumentAction = PDFWriter::FitInWindow;
     630                 :          0 :                     break;
     631                 :            :                 case 2:
     632                 :          0 :                     aContext.PDFDocumentAction = PDFWriter::FitWidth;
     633                 :          0 :                     break;
     634                 :            :                 case 3:
     635                 :          0 :                     aContext.PDFDocumentAction = PDFWriter::FitVisible;
     636                 :          0 :                     break;
     637                 :            :                 case 4:
     638                 :          0 :                     aContext.PDFDocumentAction = PDFWriter::ActionZoom;
     639                 :          0 :                     aContext.Zoom = mnZoom;
     640                 :          0 :                     break;
     641                 :            :             }
     642                 :            : 
     643                 :          0 :             switch( mnPDFPageLayout )
     644                 :            :             {
     645                 :            :                 default:
     646                 :            :                 case 0:
     647                 :          0 :                     aContext.PageLayout = PDFWriter::DefaultLayout;
     648                 :          0 :                     break;
     649                 :            :                 case 1:
     650                 :          0 :                     aContext.PageLayout = PDFWriter::SinglePage;
     651                 :          0 :                     break;
     652                 :            :                 case 2:
     653                 :          0 :                     aContext.PageLayout = PDFWriter::Continuous;
     654                 :          0 :                     break;
     655                 :            :                 case 3:
     656                 :          0 :                     aContext.PageLayout = PDFWriter::ContinuousFacing;
     657                 :          0 :                     break;
     658                 :            :             }
     659                 :            : 
     660                 :          0 :             aContext.FirstPageLeft = mbFirstPageLeft;
     661                 :            : 
     662                 :            : //check if PDF/A, which does not allow encryption
     663                 :          0 :             if( aContext.Version != PDFWriter::PDF_A_1 )
     664                 :            :             {
     665                 :            : //set values needed in encryption
     666                 :            : //set encryption level, fixed, but here it can set by the UI if needed.
     667                 :            : // true is 128 bit, false 40
     668                 :            : //note that in 40 bit mode the UI needs reworking, since the current UI is meaningfull only for
     669                 :            : //128bit security mode
     670                 :          0 :                 aContext.Encryption.Security128bit = sal_True;
     671                 :            : 
     672                 :            : //set check for permission change password
     673                 :            : // if not enabled and no permission password, force permissions to default as if PDF where without encryption
     674                 :          0 :                 if( mbRestrictPermissions && (xEnc.is() || !aPermissionPassword.isEmpty()) )
     675                 :            :                 {
     676                 :          0 :                     mbEncrypt = sal_True;
     677                 :            : //permission set as desired, done after
     678                 :            :                 }
     679                 :            :                 else
     680                 :            :                 {
     681                 :            : //force permission to default
     682                 :          0 :                     mnPrintAllowed                  = 2 ;
     683                 :          0 :                     mnChangesAllowed                = 4 ;
     684                 :          0 :                     mbCanCopyOrExtract              = sal_True;
     685                 :          0 :                     mbCanExtractForAccessibility    = sal_True ;
     686                 :            :                 }
     687                 :            : 
     688                 :          0 :                 switch( mnPrintAllowed )
     689                 :            :                 {
     690                 :            :                 case 0: //initialized when aContext is build, means no printing
     691                 :          0 :                     break;
     692                 :            :                 default:
     693                 :            :                 case 2:
     694                 :          0 :                     aContext.Encryption.CanPrintFull            = sal_True;
     695                 :            :                 case 1:
     696                 :          0 :                     aContext.Encryption.CanPrintTheDocument     = sal_True;
     697                 :          0 :                     break;
     698                 :            :                 }
     699                 :            : 
     700                 :          0 :                 switch( mnChangesAllowed )
     701                 :            :                 {
     702                 :            :                 case 0: //already in struct PDFSecPermissions CTOR
     703                 :          0 :                     break;
     704                 :            :                 case 1:
     705                 :          0 :                     aContext.Encryption.CanAssemble             = sal_True;
     706                 :          0 :                     break;
     707                 :            :                 case 2:
     708                 :          0 :                     aContext.Encryption.CanFillInteractive      = sal_True;
     709                 :          0 :                     break;
     710                 :            :                 case 3:
     711                 :          0 :                     aContext.Encryption.CanAddOrModify          = sal_True;
     712                 :          0 :                     break;
     713                 :            :                 default:
     714                 :            :                 case 4:
     715                 :            :                     aContext.Encryption.CanModifyTheContent     =
     716                 :            :                         aContext.Encryption.CanCopyOrExtract    =
     717                 :            :                         aContext.Encryption.CanAddOrModify      =
     718                 :          0 :                         aContext.Encryption.CanFillInteractive  = sal_True;
     719                 :          0 :                     break;
     720                 :            :                 }
     721                 :            : 
     722                 :          0 :                 aContext.Encryption.CanCopyOrExtract                = mbCanCopyOrExtract;
     723                 :          0 :                 aContext.Encryption.CanExtractForAccessibility  = mbCanExtractForAccessibility;
     724                 :          0 :                 if( mbEncrypt && ! xEnc.is() )
     725                 :          0 :                     xEnc = PDFWriter::InitEncryption( aPermissionPassword, aOpenPassword, aContext.Encryption.Security128bit );
     726                 :          0 :                 if( mbEncrypt && !aPermissionPassword.isEmpty() && ! aPreparedPermissionPassword.getLength() )
     727                 :          0 :                     aPreparedPermissionPassword = comphelper::OStorageHelper::CreatePackageEncryptionData( aPermissionPassword );
     728                 :            :             }
     729                 :            :             // after this point we don't need the legacy clear passwords anymore
     730                 :            :             // however they are still inside the passed filter data sequence
     731                 :            :             // which is sadly out out our control
     732                 :          0 :             aPermissionPassword = rtl::OUString();
     733                 :          0 :             aOpenPassword = rtl::OUString();
     734                 :            : 
     735                 :            :             /*
     736                 :            :             * FIXME: the entries are only implicitly defined by the resource file. Should there
     737                 :            :             * ever be an additional form submit format this could get invalid.
     738                 :            :             */
     739                 :          0 :             switch( mnFormsFormat )
     740                 :            :             {
     741                 :            :                 case 1:
     742                 :          0 :                     aContext.SubmitFormat = PDFWriter::PDF;
     743                 :          0 :                     break;
     744                 :            :                 case 2:
     745                 :          0 :                     aContext.SubmitFormat = PDFWriter::HTML;
     746                 :          0 :                     break;
     747                 :            :                 case 3:
     748                 :          0 :                     aContext.SubmitFormat = PDFWriter::XML;
     749                 :          0 :                     break;
     750                 :            :                 default:
     751                 :            :                 case 0:
     752                 :          0 :                     aContext.SubmitFormat = PDFWriter::FDF;
     753                 :          0 :                     break;
     754                 :            :             }
     755                 :          0 :             aContext.AllowDuplicateFieldNames = mbAllowDuplicateFieldNames;
     756                 :            : 
     757                 :            :             //get model
     758                 :          0 :             Reference< frame::XModel > xModel( mxSrcDoc, UNO_QUERY );
     759                 :            :             {
     760                 :            : //---> i56629 Relative link stuff
     761                 :            : //set the base URL of the file:
     762                 :            : //then base URL
     763                 :          0 :                 aContext.BaseURL = xModel->getURL();
     764                 :            : //relative link option is private to PDF Export filter and limited to local filesystem only
     765                 :          0 :                 aContext.RelFsys = mbExportRelativeFsysLinks;
     766                 :            : //determine the default acton for PDF links
     767                 :          0 :                 switch( mnDefaultLinkAction )
     768                 :            :                 {
     769                 :            :                 default:
     770                 :            : //default: URI, without fragment conversion (the bookmark in PDF may not work)
     771                 :            :                 case 0:
     772                 :          0 :                     aContext.DefaultLinkAction = PDFWriter::URIAction;
     773                 :          0 :                     break;
     774                 :            : //view PDF through the reader application
     775                 :            :                 case 1:
     776                 :          0 :                     aContext.ForcePDFAction = sal_True;
     777                 :          0 :                     aContext.DefaultLinkAction = PDFWriter::LaunchAction;
     778                 :          0 :                     break;
     779                 :            : //view PDF through an Internet browser
     780                 :            :                 case 2:
     781                 :          0 :                     aContext.DefaultLinkAction = PDFWriter::URIActionDestination;
     782                 :          0 :                     break;
     783                 :            :                 }
     784                 :          0 :                 aContext.ConvertOOoTargetToPDFTarget = mbConvertOOoTargetToPDFTarget;
     785                 :            : // check for Link Launch action, not allowed on PDF/A-1
     786                 :            : // this code chunk checks when the filter is called from scripting
     787                 :          0 :                 if( aContext.Version == PDFWriter::PDF_A_1 &&
     788                 :            :                     aContext.DefaultLinkAction == PDFWriter::LaunchAction )
     789                 :            :                 {   //force the similar allowed URI action
     790                 :          0 :                     aContext.DefaultLinkAction = PDFWriter::URIActionDestination;
     791                 :            :                     //and remove the remote goto action forced on PDF file
     792                 :          0 :                     aContext.ForcePDFAction = sal_False;
     793                 :            :                 }
     794                 :            :             }
     795                 :            : 
     796                 :          0 :             aContext.SignPDF = mbSignPDF;
     797                 :          0 :             aContext.SignLocation = msSignLocation;
     798                 :          0 :             aContext.SignContact = msSignContact;
     799                 :          0 :             aContext.SignReason = msSignReason;
     800                 :          0 :             aContext.SignPassword = msSignPassword;
     801                 :          0 :             aContext.SignCertificate = maSignCertificate;
     802                 :            : 
     803                 :            : // all context data set, time to create the printing device
     804                 :          0 :             PDFWriter*          pPDFWriter = new PDFWriter( aContext, xEnc );
     805                 :          0 :             OutputDevice*       pOut = pPDFWriter->GetReferenceDevice();
     806                 :          0 :             vcl::PDFExtOutDevData* pPDFExtOutDevData = NULL;
     807                 :            : 
     808                 :            :             DBG_ASSERT( pOut, "PDFExport::Export: no reference device" );
     809                 :          0 :             pXDevice->SetOutputDevice( pOut );
     810                 :            : 
     811                 :          0 :             if( mbAddStream )
     812                 :            :             {
     813                 :            :                 // export stream
     814                 :            :                 // get mimetype
     815                 :          0 :                 OUString aSrcMimetype = getMimetypeForDocument( mxMSF, mxSrcDoc );
     816                 :            :                 pPDFWriter->AddStream( aSrcMimetype,
     817                 :          0 :                                        new PDFExportStreamDoc( mxSrcDoc, aPreparedPermissionPassword ),
     818                 :            :                                        false
     819                 :          0 :                                        );
     820                 :            :             }
     821                 :            : 
     822                 :          0 :             if ( pOut )
     823                 :            :             {
     824                 :            :                 DBG_ASSERT( pOut->GetExtOutDevData() == NULL, "PDFExport: ExtOutDevData already set!!!" );
     825                 :          0 :                 pPDFExtOutDevData = new vcl::PDFExtOutDevData( *pOut );
     826                 :          0 :                 pOut->SetExtOutDevData( pPDFExtOutDevData );
     827                 :          0 :                 pPDFExtOutDevData->SetIsExportNotes( mbExportNotes );
     828                 :          0 :                 pPDFExtOutDevData->SetIsExportTaggedPDF( mbUseTaggedPDF );
     829                 :          0 :                 pPDFExtOutDevData->SetIsExportTransitionEffects( mbUseTransitionEffects );
     830                 :          0 :                 pPDFExtOutDevData->SetFormsFormat( mnFormsFormat );
     831                 :          0 :                 pPDFExtOutDevData->SetIsExportFormFields( mbExportFormFields );
     832                 :          0 :                 pPDFExtOutDevData->SetIsExportBookmarks( mbExportBookmarks );
     833                 :          0 :                 pPDFExtOutDevData->SetIsExportHiddenSlides( mbExportHiddenSlides );
     834                 :          0 :                 pPDFExtOutDevData->SetIsLosslessCompression( mbUseLosslessCompression );
     835                 :          0 :                 pPDFExtOutDevData->SetIsReduceImageResolution( mbReduceImageResolution );
     836                 :          0 :                 pPDFExtOutDevData->SetIsExportNamedDestinations( mbExportBmkToDest );
     837                 :            : 
     838                 :          0 :                 Sequence< PropertyValue > aRenderOptions( 6 );
     839                 :          0 :                 aRenderOptions[ 0 ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) );
     840                 :          0 :                 aRenderOptions[ 0 ].Value <<= Reference< awt::XDevice >( pXDevice );
     841                 :          0 :                 aRenderOptions[ 1 ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportNotesPages" ) );
     842                 :          0 :                 aRenderOptions[ 1 ].Value <<= sal_False;
     843                 :          0 :                 Any& rExportNotesValue = aRenderOptions[ 1 ].Value;
     844                 :          0 :                 aRenderOptions[ 2 ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFirstPage" ) );
     845                 :          0 :                 aRenderOptions[ 2 ].Value <<= sal_True;
     846                 :          0 :                 aRenderOptions[ 3 ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsLastPage" ) );
     847                 :          0 :                 aRenderOptions[ 3 ].Value <<= sal_False;
     848                 :          0 :                 aRenderOptions[ 4 ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsSkipEmptyPages" ) );
     849                 :          0 :                 aRenderOptions[ 4 ].Value <<= mbSkipEmptyPages;
     850                 :          0 :                 aRenderOptions[ 5 ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageRange" ) );
     851                 :          0 :                 aRenderOptions[ 5 ].Value <<= aPageRange;
     852                 :            : 
     853                 :          0 :                 if( !aPageRange.isEmpty() || !aSelection.hasValue() )
     854                 :            :                 {
     855                 :          0 :                     aSelection = Any();
     856                 :          0 :                     aSelection <<= mxSrcDoc;
     857                 :            :                 }
     858                 :          0 :                 sal_Bool        bSecondPassForImpressNotes = sal_False;
     859                 :          0 :                 bool bReChangeToNormalView = false;
     860                 :          0 :                   ::rtl::OUString sShowOnlineLayout( RTL_CONSTASCII_USTRINGPARAM( "ShowOnlineLayout"));
     861                 :          0 :                   uno::Reference< beans::XPropertySet > xViewProperties;
     862                 :            : 
     863                 :          0 :                 if ( aCreator.EqualsAscii( "Writer" ) )
     864                 :            :                 {
     865                 :            :                     //i92835 if Writer is in web layout mode this has to be switched to normal view and back to web view in the end
     866                 :            :                     try
     867                 :            :                     {
     868                 :          0 :                         Reference< view::XViewSettingsSupplier > xVSettingsSupplier( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
     869                 :          0 :                         xViewProperties =  xVSettingsSupplier->getViewSettings();
     870                 :          0 :                         xViewProperties->getPropertyValue( sShowOnlineLayout ) >>= bReChangeToNormalView;
     871                 :          0 :                         if( bReChangeToNormalView )
     872                 :            :                         {
     873                 :          0 :                             xViewProperties->setPropertyValue( sShowOnlineLayout, uno::makeAny( false ) );
     874                 :          0 :                         }
     875                 :            :                     }
     876                 :          0 :                     catch( const uno::Exception& )
     877                 :            :                     {
     878                 :            :                     }
     879                 :            : 
     880                 :            :                 }
     881                 :            : 
     882                 :          0 :                 const sal_Int32 nPageCount = xRenderable->getRendererCount( aSelection, aRenderOptions );
     883                 :            : 
     884                 :          0 :                 if ( mbExportNotesPages && aCreator.EqualsAscii( "Impress" ) )
     885                 :            :                 {
     886                 :          0 :                     uno::Reference< drawing::XShapes > xShapes;     // sj: do not allow to export notes when
     887                 :          0 :                     if ( ! ( aSelection >>= xShapes ) )             // exporting a selection -> todo: in the dialog
     888                 :          0 :                         bSecondPassForImpressNotes = sal_True;      // the export notes checkbox needs to be disabled
     889                 :            :                 }
     890                 :            : 
     891                 :          0 :                 if( aPageRange.isEmpty() )
     892                 :            :                 {
     893                 :            :                     aPageRange = OUStringBuffer()
     894                 :          0 :                         .append( static_cast< sal_Int32 >( 1 ) )
     895                 :          0 :                         .append( static_cast< sal_Unicode >( '-' ) )
     896                 :          0 :                         .append( nPageCount ).makeStringAndClear();
     897                 :            :                 }
     898                 :          0 :                 StringRangeEnumerator aRangeEnum( aPageRange, 0, nPageCount-1 );
     899                 :            : 
     900                 :          0 :                 if ( mxStatusIndicator.is() )
     901                 :            :                 {
     902                 :          0 :                     ResMgr* pResMgr = ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILocale() );
     903                 :          0 :                     if ( pResMgr )
     904                 :            :                     {
     905                 :          0 :                         sal_Int32 nTotalPageCount = aRangeEnum.size();
     906                 :          0 :                         if ( bSecondPassForImpressNotes )
     907                 :          0 :                             nTotalPageCount *= 2;
     908                 :          0 :                         mxStatusIndicator->start( String( ResId( PDF_PROGRESS_BAR, *pResMgr ) ), nTotalPageCount );
     909                 :          0 :                         delete pResMgr;
     910                 :            :                     }
     911                 :            :                 }
     912                 :            : 
     913                 :          0 :                 if( nPageCount > 0 )
     914                 :          0 :                     bRet = ExportSelection( *pPDFWriter, xRenderable, aSelection, aRangeEnum, aRenderOptions, nPageCount );
     915                 :            :                 else
     916                 :          0 :                     bRet = sal_False;
     917                 :            : 
     918                 :          0 :                 if ( bRet && bSecondPassForImpressNotes )
     919                 :            :                 {
     920                 :          0 :                     rExportNotesValue <<= sal_True;
     921                 :          0 :                     bRet = ExportSelection( *pPDFWriter, xRenderable, aSelection, aRangeEnum, aRenderOptions, nPageCount );
     922                 :            :                 }
     923                 :          0 :                 if ( mxStatusIndicator.is() )
     924                 :          0 :                     mxStatusIndicator->end();
     925                 :            : 
     926                 :            :                 // if during the export the doc locale was set copy it to PDF writer
     927                 :          0 :                 const com::sun::star::lang::Locale& rLoc( pPDFExtOutDevData->GetDocumentLocale() );
     928                 :          0 :                 if( !rLoc.Language.isEmpty() )
     929                 :          0 :                     pPDFWriter->SetDocumentLocale( rLoc );
     930                 :            : 
     931                 :          0 :                 if( bRet )
     932                 :            :                 {
     933                 :          0 :                     pPDFExtOutDevData->PlayGlobalActions( *pPDFWriter );
     934                 :          0 :                     pPDFWriter->Emit();
     935                 :          0 :                     aErrors = pPDFWriter->GetErrors();
     936                 :            :                 }
     937                 :          0 :                 pOut->SetExtOutDevData( NULL );
     938                 :          0 :                 if( bReChangeToNormalView )
     939                 :            :                 {
     940                 :            :                     try
     941                 :            :                     {
     942                 :          0 :                         xViewProperties->setPropertyValue( sShowOnlineLayout, uno::makeAny( true ) );
     943                 :            :                     }
     944                 :          0 :                     catch( const uno::Exception& )
     945                 :            :                     {
     946                 :            :                     }
     947                 :          0 :                 }
     948                 :            :             }
     949                 :            : 
     950                 :          0 :             delete pPDFExtOutDevData;
     951                 :          0 :             delete pPDFWriter;
     952                 :          0 :         }
     953                 :            :     }
     954                 :            : 
     955                 :            :     // show eventual errors during export
     956                 :          0 :     showErrors( aErrors );
     957                 :            : 
     958                 :          0 :     return bRet;
     959                 :            : }
     960                 :            : 
     961                 :            : namespace
     962                 :            : {
     963                 :            : 
     964                 :            : typedef cppu::WeakComponentImplHelper1< task::XInteractionRequest > PDFErrorRequestBase;
     965                 :            : 
     966                 :          0 : class PDFErrorRequest : private cppu::BaseMutex,
     967                 :            :                         public PDFErrorRequestBase
     968                 :            : {
     969                 :            :     task::PDFExportException maExc;
     970                 :            : public:
     971                 :            :     PDFErrorRequest( const task::PDFExportException& i_rExc );
     972                 :            : 
     973                 :            :     // XInteractionRequest
     974                 :            :     virtual uno::Any SAL_CALL getRequest() throw (uno::RuntimeException);
     975                 :            :     virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations() throw (uno::RuntimeException);
     976                 :            : };
     977                 :            : 
     978                 :          0 : PDFErrorRequest::PDFErrorRequest( const task::PDFExportException& i_rExc ) :
     979                 :            :     PDFErrorRequestBase( m_aMutex ),
     980                 :          0 :     maExc( i_rExc )
     981                 :            : {
     982                 :          0 : }
     983                 :            : 
     984                 :          0 : uno::Any SAL_CALL PDFErrorRequest::getRequest() throw (uno::RuntimeException)
     985                 :            : {
     986                 :          0 :     osl::MutexGuard const guard( m_aMutex );
     987                 :            : 
     988                 :          0 :     uno::Any aRet;
     989                 :          0 :     aRet <<= maExc;
     990                 :          0 :     return aRet;
     991                 :            : }
     992                 :            : 
     993                 :          0 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL PDFErrorRequest::getContinuations() throw (uno::RuntimeException)
     994                 :            : {
     995                 :          0 :     return uno::Sequence< uno::Reference< task::XInteractionContinuation > >();
     996                 :            : }
     997                 :            : 
     998                 :            : } // namespace
     999                 :            : 
    1000                 :          0 : void PDFExport::showErrors( const std::set< PDFWriter::ErrorCode >& rErrors )
    1001                 :            : {
    1002                 :          0 :     if( ! rErrors.empty() && mxIH.is() )
    1003                 :            :     {
    1004                 :          0 :         task::PDFExportException aExc;
    1005                 :          0 :         aExc.ErrorCodes.realloc( sal_Int32(rErrors.size()) );
    1006                 :          0 :         sal_Int32 i = 0;
    1007                 :          0 :         for( std::set< PDFWriter::ErrorCode >::const_iterator it = rErrors.begin();
    1008                 :          0 :              it != rErrors.end(); ++it, i++ )
    1009                 :            :         {
    1010                 :          0 :             aExc.ErrorCodes.getArray()[i] = (sal_Int32)*it;
    1011                 :            :         }
    1012                 :          0 :         Reference< task::XInteractionRequest > xReq( new PDFErrorRequest( aExc ) );
    1013                 :          0 :         mxIH->handle( xReq );
    1014                 :            :     }
    1015                 :          0 : }
    1016                 :            : 
    1017                 :            : // -----------------------------------------------------------------------------
    1018                 :            : 
    1019                 :          0 : sal_Bool PDFExport::ImplExportPage( PDFWriter& rWriter, PDFExtOutDevData& rPDFExtOutDevData, const GDIMetaFile& rMtf )
    1020                 :            : {
    1021                 :          0 :     const Size      aSizePDF( OutputDevice::LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_POINT ) );
    1022                 :          0 :     Point           aOrigin;
    1023                 :          0 :     Rectangle       aPageRect( aOrigin, rMtf.GetPrefSize() );
    1024                 :          0 :     sal_Bool        bRet = sal_True;
    1025                 :            : 
    1026                 :          0 :     rWriter.NewPage( aSizePDF.Width(), aSizePDF.Height() );
    1027                 :          0 :     rWriter.SetMapMode( rMtf.GetPrefMapMode() );
    1028                 :            : 
    1029                 :          0 :     vcl::PDFWriter::PlayMetafileContext aCtx;
    1030                 :          0 :     GDIMetaFile aMtf;
    1031                 :          0 :     if( mbRemoveTransparencies )
    1032                 :            :     {
    1033                 :            :         aCtx.m_bTransparenciesWereRemoved = rWriter.GetReferenceDevice()->
    1034                 :            :             RemoveTransparenciesFromMetaFile( rMtf, aMtf, mnMaxImageResolution, mnMaxImageResolution,
    1035                 :          0 :                                               false, true, mbReduceImageResolution );
    1036                 :            :     }
    1037                 :            :     else
    1038                 :            :     {
    1039                 :          0 :         aMtf = rMtf;
    1040                 :            :     }
    1041                 :          0 :     aCtx.m_nMaxImageResolution      = mbReduceImageResolution ? mnMaxImageResolution : 0;
    1042                 :          0 :     aCtx.m_bOnlyLosslessCompression = mbUseLosslessCompression;
    1043                 :          0 :     aCtx.m_nJPEGQuality             = mnQuality;
    1044                 :            : 
    1045                 :            : 
    1046                 :          0 :     basegfx::B2DRectangle aB2DRect( aPageRect.Left(), aPageRect.Top(), aPageRect.Right(), aPageRect.Bottom() );
    1047                 :          0 :     rWriter.SetClipRegion( basegfx::B2DPolyPolygon( basegfx::tools::createPolygonFromRect( aB2DRect ) ) );
    1048                 :            : 
    1049                 :          0 :     rWriter.PlayMetafile( aMtf, aCtx, &rPDFExtOutDevData );
    1050                 :            : 
    1051                 :          0 :     rPDFExtOutDevData.ResetSyncData();
    1052                 :            : 
    1053                 :          0 :     if( mbWatermark )
    1054                 :          0 :         ImplWriteWatermark( rWriter, aSizePDF );
    1055                 :            : 
    1056                 :          0 :     return bRet;
    1057                 :            : }
    1058                 :            : 
    1059                 :            : // -----------------------------------------------------------------------------
    1060                 :            : 
    1061                 :          0 : void PDFExport::ImplWriteWatermark( PDFWriter& rWriter, const Size& rPageSize )
    1062                 :            : {
    1063                 :          0 :     OUString aText( RTL_CONSTASCII_USTRINGPARAM( "Watermark" ) );
    1064                 :          0 :     Font aFont( OUString( RTL_CONSTASCII_USTRINGPARAM( "Helvetica" ) ), Size( 0, 3*rPageSize.Height()/4 ) );
    1065                 :          0 :     aFont.SetItalic( ITALIC_NONE );
    1066                 :          0 :     aFont.SetWidthType( WIDTH_NORMAL );
    1067                 :          0 :     aFont.SetWeight( WEIGHT_NORMAL );
    1068                 :          0 :     aFont.SetAlign( ALIGN_BOTTOM );
    1069                 :          0 :     long nTextWidth = rPageSize.Width();
    1070                 :          0 :     if( rPageSize.Width() < rPageSize.Height() )
    1071                 :            :     {
    1072                 :          0 :         nTextWidth = rPageSize.Height();
    1073                 :          0 :         aFont.SetOrientation( 2700 );
    1074                 :            :     }
    1075                 :            : 
    1076                 :          0 :     if( ! ( maWatermark >>= aText ) )
    1077                 :            :     {
    1078                 :            :         // more complicated watermark ?
    1079                 :            :     }
    1080                 :            : 
    1081                 :            :     // adjust font height for text to fit
    1082                 :          0 :     OutputDevice* pDev = rWriter.GetReferenceDevice();
    1083                 :          0 :     pDev->Push( PUSH_ALL );
    1084                 :          0 :     pDev->SetFont( aFont );
    1085                 :          0 :     pDev->SetMapMode( MapMode( MAP_POINT ) );
    1086                 :          0 :     int w = 0;
    1087                 :          0 :     while( ( w = pDev->GetTextWidth( aText ) ) > nTextWidth )
    1088                 :            :     {
    1089                 :          0 :         long nNewHeight = aFont.GetHeight() * nTextWidth / w;
    1090                 :          0 :         if( nNewHeight == aFont.GetHeight() )
    1091                 :            :         {
    1092                 :          0 :             nNewHeight--;
    1093                 :          0 :             if( nNewHeight <= 0 )
    1094                 :          0 :                 break;
    1095                 :            :         }
    1096                 :          0 :         aFont.SetHeight( nNewHeight );
    1097                 :          0 :         pDev->SetFont( aFont );
    1098                 :            :     }
    1099                 :          0 :     long nTextHeight = pDev->GetTextHeight();
    1100                 :            :     // leave some maneuvering room for rounding issues, also
    1101                 :            :     // some fonts go a little outside ascent/descent
    1102                 :          0 :     nTextHeight += nTextHeight/20;
    1103                 :          0 :     pDev->Pop();
    1104                 :            : 
    1105                 :          0 :     rWriter.Push( PUSH_ALL );
    1106                 :          0 :     rWriter.SetMapMode( MapMode( MAP_POINT ) );
    1107                 :          0 :     rWriter.SetFont( aFont );
    1108                 :          0 :     rWriter.SetTextColor( COL_LIGHTGREEN );
    1109                 :          0 :     Point aTextPoint;
    1110                 :          0 :     Rectangle aTextRect;
    1111                 :          0 :     if( rPageSize.Width() > rPageSize.Height() )
    1112                 :            :     {
    1113                 :          0 :         aTextPoint = Point( (rPageSize.Width()-w)/2,
    1114                 :          0 :                             rPageSize.Height()-(rPageSize.Height()-nTextHeight)/2 );
    1115                 :          0 :         aTextRect = Rectangle( Point( (rPageSize.Width()-w)/2,
    1116                 :          0 :                                       (rPageSize.Height()-nTextHeight)/2 ),
    1117                 :          0 :                                Size( w, nTextHeight ) );
    1118                 :            :     }
    1119                 :            :     else
    1120                 :            :     {
    1121                 :          0 :         aTextPoint = Point( (rPageSize.Width()-nTextHeight)/2,
    1122                 :          0 :                             (rPageSize.Height()-w)/2 );
    1123                 :          0 :         aTextRect = Rectangle( aTextPoint, Size( nTextHeight, w ) );
    1124                 :            :     }
    1125                 :          0 :     rWriter.SetClipRegion();
    1126                 :          0 :     rWriter.BeginTransparencyGroup();
    1127                 :          0 :     rWriter.DrawText( aTextPoint, aText );
    1128                 :          0 :     rWriter.EndTransparencyGroup( aTextRect, 50 );
    1129                 :          0 :     rWriter.Pop();
    1130                 :          0 : }
    1131                 :            : 
    1132                 :            : 
    1133                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10