LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/xpdfwrapper - wrapper_gpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 62 61.3 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 41 114 36.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  *  OpenOffice.org - a multi-platform office productivity suite
       5                 :            :  *
       6                 :            :  *  The Contents of this file are made available subject to
       7                 :            :  *  the terms of GNU General Public License Version 2.
       8                 :            :  *
       9                 :            :  *
      10                 :            :  *    GNU General Public License, version 2
      11                 :            :  *    =============================================
      12                 :            :  *    Copyright 2005 by Sun Microsystems, Inc.
      13                 :            :  *    901 San Antonio Road, Palo Alto, CA 94303, USA
      14                 :            :  *
      15                 :            :  *    This program is free software; you can redistribute it and/or
      16                 :            :  *    modify it under the terms of the GNU General Public License as
      17                 :            :  *    published by the Free Software Foundation; either version 2 of
      18                 :            :  *    the License, or (at your option) any later version.
      19                 :            :  *
      20                 :            :  *    This program is distributed in the hope that it will be useful,
      21                 :            :  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
      22                 :            :  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      23                 :            :  *    GNU General Public License for more details.
      24                 :            :  *
      25                 :            :  *    You should have received a copy of the GNU General Public
      26                 :            :  *    License along with this program; if not, write to the Free
      27                 :            :  *    Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      28                 :            :  *    Boston, MA 02110-1301, USA.
      29                 :            :  *
      30                 :            :  ************************************************************************/
      31                 :            : 
      32                 :            : #include "pdfioutdev_gpl.hxx"
      33                 :            : #ifdef WNT
      34                 :            : # include <io.h>
      35                 :            : # include <fcntl.h>  /*_O_BINARY*/
      36                 :            : #endif
      37                 :            : 
      38                 :         15 : FILE* g_binary_out=stderr;
      39                 :            : 
      40                 :            : #ifndef SYSTEM_POPPLER
      41                 :            : static char ownerPassword[33] = "\001";
      42                 :            : static char userPassword[33]  = "\001";
      43                 :            : static char outputFile[256]   = "\001";
      44                 :            : 
      45                 :            : static ArgDesc argDesc[] = {
      46                 :            :   {(char*)"-f",          argString,      outputFile,     sizeof(outputFile),
      47                 :            :    (char*)"output file for binary streams"},
      48                 :            :   {(char*)"-opw",        argString,      ownerPassword,  sizeof(ownerPassword),
      49                 :            :    (char*)"owner password (for encrypted files)"},
      50                 :            :   {(char*)"-upw",        argString,      userPassword,   sizeof(userPassword),
      51                 :            :    (char*)"user password (for encrypted files)"},
      52                 :            :   {NULL, argString, NULL, 0, NULL }
      53                 :            : };
      54                 :            : #else
      55                 :            : static const char *ownerPassword = "\001";
      56                 :            : static const char *userPassword  = "\001";
      57                 :            : static const char *outputFile   = "\001";
      58                 :            : #endif
      59                 :            : 
      60                 :         15 : int main(int argc, char **argv)
      61                 :            : {
      62                 :            : #ifndef SYSTEM_POPPLER
      63                 :            :     // parse args; initialize to defaults
      64                 :            :     if( !parseArgs(argDesc, &argc, argv) )
      65                 :            :         return 1;
      66                 :            : #else
      67                 :         15 :     int k = 0;
      68         [ +  + ]:         45 :     while (k < argc)
      69                 :            :     {
      70         [ -  + ]:         30 :         if (!strcmp(argv[k], "-f"))
      71                 :            :         {
      72                 :          0 :             outputFile = argv[k+1];
      73                 :          0 :             --argc;
      74         [ #  # ]:          0 :             for (int j = k; j < argc; ++j)
      75                 :          0 :                 argv[j] = argv[j+1];
      76                 :            :         }
      77         [ -  + ]:         30 :         else if (!strcmp(argv[k], "-opw"))
      78                 :            :         {
      79                 :          0 :             ownerPassword = argv[k+1];
      80                 :          0 :             --argc;
      81         [ #  # ]:          0 :             for (int j = k; j < argc; ++j)
      82                 :          0 :                 argv[j] = argv[j+1];
      83                 :            :         }
      84         [ -  + ]:         30 :         else if (!strcmp(argv[k], "-upw"))
      85                 :            :         {
      86                 :          0 :             userPassword = argv[k+1];
      87                 :          0 :             --argc;
      88         [ #  # ]:          0 :             for (int j = k; j < argc; ++j)
      89                 :          0 :                 argv[j] = argv[j+1];
      90                 :            :         }
      91                 :         30 :     ++k;
      92                 :            :     }
      93                 :            : #endif
      94                 :            : 
      95         [ -  + ]:         15 :     if( argc < 2 )
      96                 :          0 :         return 1;
      97                 :            : 
      98                 :            :     // read config file
      99                 :            :     globalParams = new GlobalParams(
     100                 :            : #ifndef SYSTEM_POPPLER
     101                 :            :         (char*)""
     102                 :            : #endif
     103 [ +  - ][ +  - ]:         15 :     );
     104         [ +  - ]:         15 :     globalParams->setErrQuiet(gTrue);
     105                 :            : #if !defined(SYSTEM_POPPLER) || defined(_MSC_VER)
     106                 :            :     globalParams->setupBaseFonts(NULL);
     107                 :            : #endif
     108                 :            : 
     109                 :            :     // try to read a possible open password form stdin
     110                 :            :     char aPwBuf[129];
     111                 :         15 :     aPwBuf[128] = 0;
     112 [ +  - ][ -  + ]:         15 :     if( ! fgets( aPwBuf, sizeof(aPwBuf)-1, stdin ) )
     113                 :          0 :         aPwBuf[0] = 0; // mark as empty
     114                 :            :     else
     115                 :            :     {
     116         [ +  - ]:         15 :         for( unsigned int i = 0; i < sizeof(aPwBuf); i++ )
     117                 :            :         {
     118         [ +  - ]:         15 :             if( aPwBuf[i] == '\n' )
     119                 :            :             {
     120                 :         15 :                 aPwBuf[i] = 0;
     121                 :         15 :                 break;
     122                 :            :             }
     123                 :            :         }
     124                 :            :     }
     125                 :            : 
     126                 :            :     // PDFDoc takes over ownership for all strings below
     127 [ +  - ][ +  - ]:         15 :     GooString* pFileName    = new GooString(argv[1]);
     128 [ +  - ][ +  - ]:         15 :     GooString* pTempErrFileName     = new GooString("_err.pdf");
     129 [ +  - ][ +  - ]:         15 :     GooString* pTempErrFileNamePath = new GooString(argv[0]);
     130                 :            : 
     131 [ +  - ][ +  - ]:         15 :     GooString* pErrFileName = new GooString(pTempErrFileNamePath,pTempErrFileName);
     132                 :            : 
     133                 :            : 
     134                 :            :     // check for password string(s)
     135                 :         15 :     GooString* pOwnerPasswordStr( aPwBuf[0] != 0
     136         [ #  # ]:          0 :                                  ? new GooString( aPwBuf )
     137                 :         15 :                                  : (ownerPassword[0] != '\001'
     138         [ #  # ]:          0 :                                     ? new GooString(ownerPassword)
     139 [ -  + ][ #  # ]:         15 :                                     : (GooString *)NULL ) );
         [ -  + ][ #  # ]
     140                 :         15 :     GooString* pUserPasswordStr(  userPassword[0] != '\001'
     141         [ #  # ]:          0 :                                   ? new GooString(userPassword)
     142 [ -  + ][ #  # ]:         15 :                                   : (GooString *)NULL );
     143         [ -  + ]:         15 :     if( outputFile[0] != '\001' )
     144         [ #  # ]:          0 :         g_binary_out = fopen(outputFile,"wb");
     145                 :            : 
     146                 :            : #ifdef WNT
     147                 :            :     // Win actually modifies output for O_TEXT file mode, so need to
     148                 :            :     // revert to binary here
     149                 :            :     _setmode( _fileno( g_binary_out ), _O_BINARY );
     150                 :            : #endif
     151                 :            : 
     152                 :            :     PDFDoc aDoc( pFileName,
     153                 :            :                  pOwnerPasswordStr,
     154         [ +  - ]:         15 :                  pUserPasswordStr );
     155                 :            : 
     156                 :            :     PDFDoc aErrDoc( pErrFileName,
     157                 :            :                  pOwnerPasswordStr,
     158         [ +  - ]:         15 :                  pUserPasswordStr );
     159                 :            : 
     160                 :            : 
     161                 :            :    // Check various permissions.
     162         [ -  + ]:         15 :    if ( !aDoc.isOk() )
     163                 :            :    {
     164 [ #  # ][ #  # ]:          0 :         pdfi::PDFOutDev* pOutDev( new pdfi::PDFOutDev(&aErrDoc) );
     165                 :            : 
     166 [ #  # ][ #  # ]:          0 :         const int nPages = aErrDoc.isOk() ? aErrDoc.getNumPages() : 0;
     167                 :            : 
     168                 :            :         // tell receiver early - needed for proper progress calculation
     169         [ #  # ]:          0 :         pOutDev->setPageNum( nPages );
     170                 :            : 
     171                 :            :         // virtual resolution of the PDF OutputDev in dpi
     172                 :            :         static const int PDFI_OUTDEV_RESOLUTION=7200;
     173                 :            : 
     174                 :            :        // do the conversion
     175         [ #  # ]:          0 :        for( int i=1; i<=nPages; ++i )
     176                 :            :        {
     177                 :            :           aErrDoc.displayPage( pOutDev,
     178                 :            :                             i,
     179                 :            :                             PDFI_OUTDEV_RESOLUTION,
     180                 :            :                             PDFI_OUTDEV_RESOLUTION,
     181         [ #  # ]:          0 :                             0, gTrue, gTrue, gTrue );
     182         [ #  # ]:          0 :           aErrDoc.processLinks( pOutDev, i );
     183                 :            :        }
     184                 :            :    }
     185                 :            :    else
     186                 :            :    {
     187 [ +  - ][ +  - ]:         15 :       pdfi::PDFOutDev* pOutDev( new pdfi::PDFOutDev(&aDoc) );
     188                 :            : 
     189                 :            :       // tell receiver early - needed for proper progress calculation
     190 [ +  - ][ +  - ]:         15 :       pOutDev->setPageNum( aDoc.getNumPages() );
     191                 :            : 
     192                 :            :       // virtual resolution of the PDF OutputDev in dpi
     193                 :            :       static const int PDFI_OUTDEV_RESOLUTION=7200;
     194                 :            : 
     195                 :            :       // do the conversion
     196         [ +  - ]:         15 :       const int nPages = aDoc.getNumPages();
     197         [ +  + ]:         30 :       for( int i=1; i<=nPages; ++i )
     198                 :            :       {
     199                 :            :         aDoc.displayPage( pOutDev,
     200                 :            :                           i,
     201                 :            :                           PDFI_OUTDEV_RESOLUTION,
     202                 :            :                           PDFI_OUTDEV_RESOLUTION,
     203         [ +  - ]:         15 :                           0, gTrue, gTrue, gTrue );
     204         [ +  - ]:         15 :         aDoc.processLinks( pOutDev, i );
     205                 :            :       }
     206                 :            :    }
     207 [ +  - ][ +  - ]:         15 :     return 0;
     208 [ +  - ][ +  - ]:         45 : }
     209                 :            : 
     210                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10