/* Copyright Krzysztof Kowalczyk 2006-2007
Copyright Hib Eris <hib@hiberis.nl> 2008
License: GPLv2 */
/*
A tool to stress-test poppler rendering and measure rendering times for
very simplistic performance measuring.
TODO:
* make it work with cairo output as well
* print more info about document like e.g. enumarate images,
streams, compression, encryption, password-protection. Each should have
a command-line arguments to turn it on/off
* never over-write file given as -out argument (optionally, provide -force
option to force writing the -out file). It's way too easy too lose results
of a previous run.
*/
#ifdef _MSC_VER
// this sucks but I don't know any other way
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#ifdef _WIN32
#include <windows.h>
#else
#include <strings.h>
#endif
// Define COPY_FILE if you want the file to be copied to a local disk first
// before it's tested. This is desired if a file is on a slow drive.
// Currently copying only works on Windows.
// Not enabled by default.
//#define COPY_FILE 1
#include <assert.h>
#include <config.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
#include "Error.h"
#include "ErrorCodes.h"
#include "goo/GooString.h"
#include "goo/GooList.h"
#include "goo/GooTimer.h"
#include "GlobalParams.h"
#include "splash/SplashBitmap.h"
#include "Object.h" /* must be included before SplashOutputDev.h because of sloppiness in SplashOutputDev.h */
#include "SplashOutputDev.h"
#include "TextOutputDev.h"
#include "PDFDoc.h"
#include "Link.h"
#ifdef _MSC_VER
#define strdup _strdup
#define strcasecmp _stricmp
#endif
#define dimof(X) (sizeof(X)/sizeof((X)[0]))
#define INVALID_PAGE_NO -1
/* Those must be implemented in order to provide preview during execution.
They can be no-ops. An implementation for windows is in
perf-test-preview-win.cc
*/
extern void PreviewBitmapInit(void);
extern void PreviewBitmapDestroy(void);
extern void PreviewBitmapSplash(SplashBitmap *bmpSplash);
class PdfEnginePoppler {
public:
PdfEnginePoppler();
~PdfEnginePoppler();
const char *fileName(void) const { return _fileName; };
void setFileName(const char *fileName) {
assert(!_fileName);
_fileName = (char*)strdup(fileName);
}
int pageCount(void) const { return _pageCount; }
bool load(const char *fileName);
SplashBitmap *renderBitmap(int pageNo, double zoomReal, int rotation);
SplashOutputDev * outputDevice();
private:
char * _fileName;
int _pageCount;
PDFDoc * _pdfDoc;
SplashOutputDev * _outputDev;
};
typedef struct StrList {
struct StrList *next;
char * str;
} StrList;
/* List of all command-line arguments that are not switches.
We assume those are:
- names of PDF files
- names of a file with a list of PDF files
- names of directories with PDF files
*/
static StrList *gArgsListRoot = NULL;
/* Names of all command-line switches we recognize */
#define TIMINGS_ARG "-timings"
#define RESOLUTION_ARG "-resolution"
#define RECURSIVE_ARG "-recursive"
#define OUT_ARG "-out"
#define PREVIEW_ARG "-preview"
#define SLOW_PREVIEW_ARG "-slowpreview"
#define LOAD_ONLY_ARG "-loadonly"
#define PAGE_ARG "-page"
#define TEXT_ARG "-text"
/* Should we record timings? True if -timings command-line argument was given. */
static bool gfTimings = false;
/* If true, we use render each page at resolution 'gResolutionX'/'gResolutionY'.
If false, we render each page at its native resolution.
True if -resolution NxM command-line argument was given. */
static bool gfForceResolution = false;
static int gResolutionX =<