filters

xpdf.cc

00001 //========================================================================
00002 //
00003 // xpdf.cc
00004 //
00005 // Copyright 1996-2002 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #include <aconf.h>
00010 #include "gtypes.h"
00011 #include "GString.h"
00012 #include "parseargs.h"
00013 #include "gfile.h"
00014 #include "gmem.h"
00015 #include "GlobalParams.h"
00016 #include "Object.h"
00017 #include "XPDFApp.h"
00018 #include "config.h"
00019 
00020 //------------------------------------------------------------------------
00021 // command line options
00022 //------------------------------------------------------------------------
00023 
00024 static char t1libControlStr[16] = "";
00025 static char freetypeControlStr[16] = "";
00026 static char psFileArg[256];
00027 static char paperSize[15] = "";
00028 static int paperWidth = 0;
00029 static int paperHeight = 0;
00030 static GBool level1 = gFalse;
00031 static char textEncName[128] = "";
00032 static char textEOL[16] = "";
00033 static char ownerPassword[33] = "";
00034 static char userPassword[33] = "";
00035 static GBool fullScreen = gFalse;
00036 static char remoteName[100] = "xpdf_";
00037 static GBool doRemoteRaise = gFalse;
00038 static GBool doRemoteQuit = gFalse;
00039 static GBool printCommands = gFalse;
00040 static GBool quiet = gFalse;
00041 static char cfgFileName[256] = "";
00042 static GBool printVersion = gFalse;
00043 static GBool printHelp = gFalse;
00044 
00045 static ArgDesc argDesc[] = {
00046   {"-g",          argStringDummy, NULL,           0,
00047    "initial window geometry"},
00048   {"-geometry",   argStringDummy, NULL,           0,
00049    "initial window geometry"},
00050   {"-title",      argStringDummy, NULL,           0,
00051    "window title"},
00052   {"-cmap",       argFlagDummy,   NULL,           0,
00053    "install a private colormap"},
00054   {"-rgb",        argIntDummy,    NULL,           0,
00055    "biggest RGB cube to allocate (default is 5)"},
00056   {"-rv",         argFlagDummy,   NULL,           0,
00057    "reverse video"},
00058   {"-papercolor", argStringDummy, NULL,           0,
00059    "color of paper background"},
00060   {"-z",          argStringDummy, NULL,           0,
00061    "initial zoom level (-5..5, page, width)"},
00062 #if HAVE_T1LIB_H
00063   {"-t1lib",      argString,      t1libControlStr, sizeof(t1libControlStr),
00064    "t1lib font rasterizer control: none, plain, low, high"},
00065 #endif
00066 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
00067   {"-freetype",   argString,      freetypeControlStr, sizeof(freetypeControlStr),
00068    "FreeType font rasterizer control: none, plain, low, high"},
00069 #endif
00070   {"-ps",         argString,      psFileArg,      sizeof(psFileArg),
00071    "default PostScript file name or command"},
00072   {"-paper",      argString,      paperSize,      sizeof(paperSize),
00073    "paper size (letter, legal, A4, A3)"},
00074   {"-paperw",     argInt,         &paperWidth,    0,
00075    "paper width, in points"},
00076   {"-paperh",     argInt,         &paperHeight,   0,
00077    "paper height, in points"},
00078   {"-level1",     argFlag,        &level1,        0,
00079    "generate Level 1 PostScript"},
00080   {"-enc",    argString,   textEncName,    sizeof(textEncName),
00081    "output text encoding name"},
00082   {"-eol",    argString,   textEOL,        sizeof(textEOL),
00083    "output end-of-line convention (unix, dos, or mac)"},
00084   {"-opw",        argString,      ownerPassword,  sizeof(ownerPassword),
00085    "owner password (for encrypted files)"},
00086   {"-upw",        argString,      userPassword,   sizeof(userPassword),
00087    "user password (for encrypted files)"},
00088   {"-fullscreen", argFlag,        &fullScreen,    0,
00089    "run in full-screen (presentation) mode"},
00090   {"-remote",     argString,      remoteName + 5, sizeof(remoteName) - 5,
00091    "start/contact xpdf remote server with specified name"},
00092   {"-raise",      argFlag,        &doRemoteRaise, 0,
00093    "raise xpdf remote server window (with -remote only)"},
00094   {"-quit",       argFlag,        &doRemoteQuit,  0,
00095    "kill xpdf remote server (with -remote only)"},
00096   {"-cmd",        argFlag,        &printCommands, 0,
00097    "print commands as they're executed"},
00098   {"-q",          argFlag,        &quiet,         0,
00099    "don't print any messages or errors"},
00100   {"-cfg",        argString,      cfgFileName,    sizeof(cfgFileName),
00101    "configuration file to use in place of .xpdfrc"},
00102   {"-v",          argFlag,        &printVersion,  0,
00103    "print copyright and version info"},
00104   {"-h",          argFlag,        &printHelp,     0,
00105    "print usage information"},
00106   {"-help",       argFlag,        &printHelp,     0,
00107    "print usage information"},
00108   {"--help",  argFlag,     &printHelp,     0,
00109    "print usage information"},
00110   {"-?",      argFlag,     &printHelp,     0,
00111    "print usage information"},
00112   {NULL}
00113 };
00114 
00115 //------------------------------------------------------------------------
00116 
00117 int main(int argc, char *argv[]) {
00118   XPDFApp *app;
00119   GString *fileName;
00120   int pg;
00121   GString *destName;
00122   GString *userPasswordStr, *ownerPasswordStr;
00123   GBool ok;
00124   int exitCode;
00125 
00126   exitCode = 0;
00127   userPasswordStr = ownerPasswordStr = NULL;
00128 
00129   // parse args
00130   ok = parseArgs(argDesc, &argc, argv);
00131 
00132   // read config file
00133   globalParams = new GlobalParams(cfgFileName);
00134   if (psFileArg[0]) {
00135     globalParams->setPSFile(psFileArg);
00136   }
00137   if (paperSize[0]) {
00138     if (!globalParams->setPSPaperSize(paperSize)) {
00139       fprintf(stderr, "Invalid paper size\n");
00140     }
00141   } else {
00142     if (paperWidth) {
00143       globalParams->setPSPaperWidth(paperWidth);
00144     }
00145     if (paperHeight) {
00146       globalParams->setPSPaperHeight(paperHeight);
00147     }
00148   }
00149   if (level1) {
00150     globalParams->setPSLevel(psLevel1);
00151   }
00152   if (textEncName[0]) {
00153     globalParams->setTextEncoding(textEncName);
00154   }
00155   if (textEOL[0]) {
00156     if (!globalParams->setTextEOL(textEOL)) {
00157       fprintf(stderr, "Bad '-eol' value on command line\n");
00158     }
00159   }
00160   if (t1libControlStr[0]) {
00161     if (!globalParams->setT1libControl(t1libControlStr)) {
00162       fprintf(stderr, "Bad '-t1lib' value on command line\n");
00163     }
00164   }
00165   if (freetypeControlStr[0]) {
00166     if (!globalParams->setFreeTypeControl(freetypeControlStr)) {
00167       fprintf(stderr, "Bad '-freetype' value on command line\n");
00168     }
00169   }
00170   if (printCommands) {
00171     globalParams->setPrintCommands(printCommands);
00172   }
00173   if (quiet) {
00174     globalParams->setErrQuiet(quiet);
00175   }
00176 
00177   // create the XPDFApp object
00178   app = new XPDFApp(&argc, argv);
00179 
00180   // the initialZoom parameter can be set in either the config file or
00181   // as an X resource (or command line arg)
00182   if (app->getInitialZoom()) {
00183     globalParams->setInitialZoom(app->getInitialZoom()->getCString());
00184   }
00185 
00186   // check command line
00187   if (doRemoteRaise) {
00188     ok = ok && remoteName[5] && !doRemoteQuit && argc >= 1 && argc <= 3;
00189   } else if (doRemoteQuit) {
00190     ok = ok && remoteName[5] && argc == 1;
00191   } else {
00192     ok = ok && argc >= 1 && argc <= 3;
00193   }
00194   if (!ok || printVersion || printHelp) {
00195     fprintf(stderr, "xpdf version %s\n", xpdfVersion);
00196     fprintf(stderr, "%s\n", xpdfCopyright);
00197     if (!printVersion) {
00198       printUsage("xpdf", "[<PDF-file> [<page> | +<dest>]]", argDesc);
00199     }
00200     exitCode = 99;
00201     goto done1;
00202   }
00203   if (argc >= 2) {
00204     fileName = new GString(argv[1]);
00205   } else {
00206     fileName = NULL;
00207   }
00208   pg = 1;
00209   destName = NULL;
00210   if (argc == 3) {
00211     if (argv[2][0] == '+') {
00212       destName = new GString(&argv[2][1]);
00213     } else {
00214       pg = atoi(argv[2]);
00215     }
00216   }
00217 
00218   // handle remote server stuff
00219   if (remoteName[5]) {
00220     app->setRemoteName(remoteName);
00221     if (app->remoteServerRunning()) {
00222       if (fileName) {
00223     if (destName) {
00224       app->remoteOpenAtDest(fileName, destName, doRemoteRaise);
00225     } else {
00226       app->remoteOpen(fileName, pg, doRemoteRaise);
00227     }
00228       } else if (doRemoteRaise) {
00229     app->remoteRaise();
00230       } else if (doRemoteQuit) {
00231     app->remoteQuit();
00232       }
00233       goto done2;
00234     }
00235     if (doRemoteQuit) {
00236       goto done2;
00237     }
00238   }
00239 
00240   // set options
00241   app->setFullScreen(fullScreen);
00242 
00243   // check for password string(s)
00244   ownerPasswordStr = ownerPassword[0] ? new GString(ownerPassword)
00245                                       : (GString *)NULL;
00246   userPasswordStr = userPassword[0] ? new GString(userPassword)
00247                                     : (GString *)NULL;
00248 
00249   // open the file and run the main loop
00250   if (destName) {
00251     if (!app->openAtDest(fileName, destName,
00252              ownerPasswordStr, userPasswordStr)) {
00253       exitCode = 1;
00254       goto done2;
00255     }
00256   } else {
00257     if (!app->open(fileName, pg, ownerPasswordStr, userPasswordStr)) {
00258       exitCode = 1;
00259       goto done2;
00260     }
00261   }
00262   app->run();
00263 
00264   exitCode = 0;
00265 
00266   // clean up
00267  done2:
00268   if (userPasswordStr) {
00269     delete userPasswordStr;
00270   }
00271   if (ownerPasswordStr) {
00272     delete ownerPasswordStr;
00273   }
00274   if (destName) {
00275     delete destName;
00276   }
00277   if (fileName) {
00278     delete fileName;
00279   }
00280  done1:
00281   delete app;
00282   delete globalParams;
00283 
00284   // check for memory leaks
00285   Object::memCheck(stderr);
00286   gMemReport(stderr);
00287 
00288   return exitCode;
00289 }
KDE Home | KDE Accessibility Home | Description of Access Keys