LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/xpdfwrapper - wrapper_gpl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 38 62 61.3 %
Date: 2014-11-03 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 <boost/scoped_ptr.hpp>
      21             : 
      22             : #include "pdfioutdev_gpl.hxx"
      23             : #ifdef WNT
      24             : # include <io.h>
      25             : # include <fcntl.h>  /*_O_BINARY*/
      26             : #endif
      27             : 
      28           6 : FILE* g_binary_out=stderr;
      29             : 
      30             : static const char *ownerPassword = "\001";
      31             : static const char *userPassword  = "\001";
      32             : static const char *outputFile   = "\001";
      33             : 
      34           6 : int main(int argc, char **argv)
      35             : {
      36           6 :     int k = 0;
      37          30 :     while (k < argc)
      38             :     {
      39          18 :         if (!strcmp(argv[k], "-f"))
      40             :         {
      41           0 :             outputFile = argv[k+1];
      42           0 :             argc -= 2;
      43           0 :             for (int j = k; j < argc; ++j)
      44           0 :                 argv[j] = argv[j+2];
      45             :         }
      46          18 :         else if (!strcmp(argv[k], "-opw"))
      47             :         {
      48           0 :             ownerPassword = argv[k+1];
      49           0 :             argc -= 2;
      50           0 :             for (int j = k; j < argc; ++j)
      51           0 :                 argv[j] = argv[j+2];
      52             :         }
      53          18 :         else if (!strcmp(argv[k], "-upw"))
      54             :         {
      55           0 :             userPassword = argv[k+1];
      56           0 :             argc -= 2;
      57           0 :             for (int j = k; j < argc; ++j)
      58           0 :                 argv[j] = argv[j+2];
      59             :         }
      60          18 :     ++k;
      61             :     }
      62             : 
      63           6 :     if( argc != 3 )
      64           0 :         return 1;
      65             : 
      66             :     // read config file
      67           6 :     globalParams = new GlobalParams();
      68           6 :     globalParams->setErrQuiet(gTrue);
      69             : #if defined(_MSC_VER)
      70             :     globalParams->setupBaseFonts(NULL);
      71             : #endif
      72             : 
      73             :     // try to read a possible open password form stdin
      74             :     char aPwBuf[129];
      75           6 :     aPwBuf[128] = 0;
      76           6 :     if( ! fgets( aPwBuf, sizeof(aPwBuf)-1, stdin ) )
      77           0 :         aPwBuf[0] = 0; // mark as empty
      78             :     else
      79             :     {
      80           6 :         for( unsigned int i = 0; i < sizeof(aPwBuf); i++ )
      81             :         {
      82           6 :             if( aPwBuf[i] == '\n' )
      83             :             {
      84           6 :                 aPwBuf[i] = 0;
      85           6 :                 break;
      86             :             }
      87             :         }
      88             :     }
      89             : 
      90             :     // PDFDoc takes over ownership for all strings below
      91           6 :     GooString* pFileName    = new GooString(argv[1]);
      92           6 :     GooString* pErrFileName = new GooString(argv[2]);
      93             : 
      94             :     // check for password string(s)
      95           6 :     GooString* pOwnerPasswordStr( aPwBuf[0] != 0
      96           0 :                                  ? new GooString( aPwBuf )
      97           6 :                                  : (ownerPassword[0] != '\001'
      98           0 :                                     ? new GooString(ownerPassword)
      99          12 :                                     : (GooString *)NULL ) );
     100           6 :     GooString* pUserPasswordStr(  userPassword[0] != '\001'
     101           0 :                                   ? new GooString(userPassword)
     102           6 :                                   : (GooString *)NULL );
     103           6 :     if( outputFile[0] != '\001' )
     104           0 :         g_binary_out = fopen(outputFile,"wb");
     105             : 
     106             : #ifdef WNT
     107             :     // Win actually modifies output for O_TEXT file mode, so need to
     108             :     // revert to binary here
     109             :     _setmode( _fileno( g_binary_out ), _O_BINARY );
     110             : #endif
     111             : 
     112             :     PDFDoc aDoc( pFileName,
     113             :                  pOwnerPasswordStr,
     114           6 :                  pUserPasswordStr );
     115             : 
     116             :     PDFDoc aErrDoc( pErrFileName,
     117             :                  pOwnerPasswordStr,
     118          12 :                  pUserPasswordStr );
     119             : 
     120             : 
     121             :    // Check various permissions.
     122           6 :    if ( !aDoc.isOk() )
     123             :    {
     124           0 :         pdfi::PDFOutDev* pOutDev( new pdfi::PDFOutDev(&aErrDoc) );
     125             : 
     126           0 :         const int nPages = aErrDoc.isOk() ? aErrDoc.getNumPages() : 0;
     127             : 
     128             :         // tell receiver early - needed for proper progress calculation
     129           0 :         pOutDev->setPageNum( nPages );
     130             : 
     131             :         // virtual resolution of the PDF OutputDev in dpi
     132             :         static const int PDFI_OUTDEV_RESOLUTION=7200;
     133             : 
     134             :        // do the conversion
     135           0 :        for( int i=1; i<=nPages; ++i )
     136             :        {
     137             :           aErrDoc.displayPage( pOutDev,
     138             :                             i,
     139             :                             PDFI_OUTDEV_RESOLUTION,
     140             :                             PDFI_OUTDEV_RESOLUTION,
     141           0 :                             0, gTrue, gTrue, gTrue );
     142           0 :           aErrDoc.processLinks( pOutDev, i );
     143             :        }
     144             :    }
     145             :    else
     146             :    {
     147           6 :       boost::scoped_ptr<pdfi::PDFOutDev> pOutDev( new pdfi::PDFOutDev(&aDoc) );
     148             : 
     149             :       // tell receiver early - needed for proper progress calculation
     150           6 :       pOutDev->setPageNum( aDoc.getNumPages() );
     151             : 
     152             :       // virtual resolution of the PDF OutputDev in dpi
     153             :       static const int PDFI_OUTDEV_RESOLUTION=7200;
     154             : 
     155             :       // do the conversion
     156           6 :       const int nPages = aDoc.getNumPages();
     157          12 :       for( int i=1; i<=nPages; ++i )
     158             :       {
     159           6 :         aDoc.displayPage( pOutDev.get(),
     160             :                           i,
     161             :                           PDFI_OUTDEV_RESOLUTION,
     162             :                           PDFI_OUTDEV_RESOLUTION,
     163           6 :                           0, gTrue, gTrue, gTrue );
     164           6 :         aDoc.processLinks( pOutDev.get(), i );
     165           6 :       }
     166             :    }
     167          12 :     return 0;
     168          18 : }
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10