LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sdext/source/pdfimport/xpdfwrapper - wrapper_gpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 60 60.0 %
Date: 2013-07-09 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "pdfioutdev_gpl.hxx"
      21             : #ifdef WNT
      22             : # include <io.h>
      23             : # include <fcntl.h>  /*_O_BINARY*/
      24             : #endif
      25             : 
      26           3 : FILE* g_binary_out=stderr;
      27             : 
      28             : #ifndef SYSTEM_POPPLER
      29             : static char ownerPassword[33] = "\001";
      30             : static char userPassword[33]  = "\001";
      31             : static char outputFile[256]   = "\001";
      32             : 
      33             : static ArgDesc argDesc[] = {
      34             :   {(char*)"-f",          argString,      outputFile,     sizeof(outputFile),
      35             :    (char*)"output file for binary streams"},
      36             :   {(char*)"-opw",        argString,      ownerPassword,  sizeof(ownerPassword),
      37             :    (char*)"owner password (for encrypted files)"},
      38             :   {(char*)"-upw",        argString,      userPassword,   sizeof(userPassword),
      39             :    (char*)"user password (for encrypted files)"},
      40             :   {NULL, argString, NULL, 0, NULL }
      41             : };
      42             : #else
      43             : static const char *ownerPassword = "\001";
      44             : static const char *userPassword  = "\001";
      45             : static const char *outputFile   = "\001";
      46             : #endif
      47             : 
      48           3 : int main(int argc, char **argv)
      49             : {
      50             : #ifndef SYSTEM_POPPLER
      51             :     // parse args; initialize to defaults
      52             :     if( !parseArgs(argDesc, &argc, argv) )
      53             :         return 1;
      54             : #else
      55           3 :     int k = 0;
      56          15 :     while (k < argc)
      57             :     {
      58           9 :         if (!strcmp(argv[k], "-f"))
      59             :         {
      60           0 :             outputFile = argv[k+1];
      61           0 :             --argc;
      62           0 :             for (int j = k; j < argc; ++j)
      63           0 :                 argv[j] = argv[j+1];
      64             :         }
      65           9 :         else if (!strcmp(argv[k], "-opw"))
      66             :         {
      67           0 :             ownerPassword = argv[k+1];
      68           0 :             --argc;
      69           0 :             for (int j = k; j < argc; ++j)
      70           0 :                 argv[j] = argv[j+1];
      71             :         }
      72           9 :         else if (!strcmp(argv[k], "-upw"))
      73             :         {
      74           0 :             userPassword = argv[k+1];
      75           0 :             --argc;
      76           0 :             for (int j = k; j < argc; ++j)
      77           0 :                 argv[j] = argv[j+1];
      78             :         }
      79           9 :     ++k;
      80             :     }
      81             : #endif
      82             : 
      83           3 :     if( argc != 3 )
      84           0 :         return 1;
      85             : 
      86             :     // read config file
      87             :     globalParams = new GlobalParams(
      88             : #ifndef SYSTEM_POPPLER
      89             :         (char*)""
      90             : #endif
      91           3 :     );
      92           3 :     globalParams->setErrQuiet(gTrue);
      93             : #if !defined(SYSTEM_POPPLER) || defined(_MSC_VER)
      94             :     globalParams->setupBaseFonts(NULL);
      95             : #endif
      96             : 
      97             :     // try to read a possible open password form stdin
      98             :     char aPwBuf[129];
      99           3 :     aPwBuf[128] = 0;
     100           3 :     if( ! fgets( aPwBuf, sizeof(aPwBuf)-1, stdin ) )
     101           0 :         aPwBuf[0] = 0; // mark as empty
     102             :     else
     103             :     {
     104           3 :         for( unsigned int i = 0; i < sizeof(aPwBuf); i++ )
     105             :         {
     106           3 :             if( aPwBuf[i] == '\n' )
     107             :             {
     108           3 :                 aPwBuf[i] = 0;
     109           3 :                 break;
     110             :             }
     111             :         }
     112             :     }
     113             : 
     114             :     // PDFDoc takes over ownership for all strings below
     115           3 :     GooString* pFileName    = new GooString(argv[1]);
     116           3 :     GooString* pErrFileName = new GooString(argv[2]);
     117             : 
     118             :     // check for password string(s)
     119           3 :     GooString* pOwnerPasswordStr( aPwBuf[0] != 0
     120           0 :                                  ? new GooString( aPwBuf )
     121           3 :                                  : (ownerPassword[0] != '\001'
     122           0 :                                     ? new GooString(ownerPassword)
     123           6 :                                     : (GooString *)NULL ) );
     124           3 :     GooString* pUserPasswordStr(  userPassword[0] != '\001'
     125           0 :                                   ? new GooString(userPassword)
     126           3 :                                   : (GooString *)NULL );
     127           3 :     if( outputFile[0] != '\001' )
     128           0 :         g_binary_out = fopen(outputFile,"wb");
     129             : 
     130             : #ifdef WNT
     131             :     // Win actually modifies output for O_TEXT file mode, so need to
     132             :     // revert to binary here
     133             :     _setmode( _fileno( g_binary_out ), _O_BINARY );
     134             : #endif
     135             : 
     136             :     PDFDoc aDoc( pFileName,
     137             :                  pOwnerPasswordStr,
     138           3 :                  pUserPasswordStr );
     139             : 
     140             :     PDFDoc aErrDoc( pErrFileName,
     141             :                  pOwnerPasswordStr,
     142           6 :                  pUserPasswordStr );
     143             : 
     144             : 
     145             :    // Check various permissions.
     146           3 :    if ( !aDoc.isOk() )
     147             :    {
     148           0 :         pdfi::PDFOutDev* pOutDev( new pdfi::PDFOutDev(&aErrDoc) );
     149             : 
     150           0 :         const int nPages = aErrDoc.isOk() ? aErrDoc.getNumPages() : 0;
     151             : 
     152             :         // tell receiver early - needed for proper progress calculation
     153           0 :         pOutDev->setPageNum( nPages );
     154             : 
     155             :         // virtual resolution of the PDF OutputDev in dpi
     156             :         static const int PDFI_OUTDEV_RESOLUTION=7200;
     157             : 
     158             :        // do the conversion
     159           0 :        for( int i=1; i<=nPages; ++i )
     160             :        {
     161             :           aErrDoc.displayPage( pOutDev,
     162             :                             i,
     163             :                             PDFI_OUTDEV_RESOLUTION,
     164             :                             PDFI_OUTDEV_RESOLUTION,
     165           0 :                             0, gTrue, gTrue, gTrue );
     166           0 :           aErrDoc.processLinks( pOutDev, i );
     167             :        }
     168             :    }
     169             :    else
     170             :    {
     171           3 :       pdfi::PDFOutDev* pOutDev( new pdfi::PDFOutDev(&aDoc) );
     172             : 
     173             :       // tell receiver early - needed for proper progress calculation
     174           3 :       pOutDev->setPageNum( aDoc.getNumPages() );
     175             : 
     176             :       // virtual resolution of the PDF OutputDev in dpi
     177             :       static const int PDFI_OUTDEV_RESOLUTION=7200;
     178             : 
     179             :       // do the conversion
     180           3 :       const int nPages = aDoc.getNumPages();
     181           6 :       for( int i=1; i<=nPages; ++i )
     182             :       {
     183             :         aDoc.displayPage( pOutDev,
     184             :                           i,
     185             :                           PDFI_OUTDEV_RESOLUTION,
     186             :                           PDFI_OUTDEV_RESOLUTION,
     187           3 :                           0, gTrue, gTrue, gTrue );
     188           3 :         aDoc.processLinks( pOutDev, i );
     189             :       }
     190             :    }
     191           6 :     return 0;
     192           9 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10