From f2be1cf932c1306871ca4704d51f3849b439d28c Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Thu, 22 Jan 2015 10:06:11 +0100 Subject: pdf import: Kill cut'n'paste, and fix a memory leak. Change-Id: I9460e458e9ac5274d68bd11b0ed77b06d664ce0e --- sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx | 70 +++++++--------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx b/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx index d80ef66719cc..20c45c49a1dd 100644 --- a/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx +++ b/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx @@ -17,8 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include - #include "pdfioutdev_gpl.hxx" #ifdef WNT # include @@ -117,53 +115,29 @@ int main(int argc, char **argv) pOwnerPasswordStr, pUserPasswordStr ); + // Check various permissions for aDoc. + PDFDoc &rDoc = aDoc.isOk()? aDoc: aErrDoc; + + pdfi::PDFOutDev aOutDev(&rDoc); + + // tell the receiver early - needed for proper progress calculation + const int nPages = rDoc.isOk()? rDoc.getNumPages(): 0; + aOutDev.setPageNum(nPages); + + // virtual resolution of the PDF OutputDev in dpi + static const int PDFI_OUTDEV_RESOLUTION = 7200; + + // do the conversion + for (int i = 1; i <= nPages; ++i) + { + rDoc.displayPage(&aOutDev, + i, + PDFI_OUTDEV_RESOLUTION, + PDFI_OUTDEV_RESOLUTION, + 0, gTrue, gTrue, gTrue); + rDoc.processLinks(&aOutDev, i); + } - // Check various permissions. - if ( !aDoc.isOk() ) - { - pdfi::PDFOutDev* pOutDev( new pdfi::PDFOutDev(&aErrDoc) ); - - const int nPages = aErrDoc.isOk() ? aErrDoc.getNumPages() : 0; - - // tell receiver early - needed for proper progress calculation - pOutDev->setPageNum( nPages ); - - // virtual resolution of the PDF OutputDev in dpi - static const int PDFI_OUTDEV_RESOLUTION=7200; - - // do the conversion - for( int i=1; i<=nPages; ++i ) - { - aErrDoc.displayPage( pOutDev, - i, - PDFI_OUTDEV_RESOLUTION, - PDFI_OUTDEV_RESOLUTION, - 0, gTrue, gTrue, gTrue ); - aErrDoc.processLinks( pOutDev, i ); - } - } - else - { - boost::scoped_ptr pOutDev( new pdfi::PDFOutDev(&aDoc) ); - - // tell receiver early - needed for proper progress calculation - pOutDev->setPageNum( aDoc.getNumPages() ); - - // virtual resolution of the PDF OutputDev in dpi - static const int PDFI_OUTDEV_RESOLUTION=7200; - - // do the conversion - const int nPages = aDoc.getNumPages(); - for( int i=1; i<=nPages; ++i ) - { - aDoc.displayPage( pOutDev.get(), - i, - PDFI_OUTDEV_RESOLUTION, - PDFI_OUTDEV_RESOLUTION, - 0, gTrue, gTrue, gTrue ); - aDoc.processLinks( pOutDev.get(), i ); - } - } return 0; } -- cgit