1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
12 #include "parseargs.h"
15 #include "GlobalParams.h"
18 #include "xpdfconfig.h"
20 //------------------------------------------------------------------------
21 // command line options
22 //------------------------------------------------------------------------
24 static char enableT1libStr[16] = "";
25 static char enableFreeTypeStr[16] = "";
26 static char antialiasStr[16] = "";
27 static char psFileArg[256];
28 static char paperSize[15] = "";
29 static int paperWidth = 0;
30 static int paperHeight = 0;
31 static GBool level1 = gFalse;
32 static char textEncName[128] = "";
33 static char textEOL[16] = "";
34 static char ownerPassword[33] = "\001";
35 static char userPassword[33] = "\001";
36 static GBool fullScreen = gFalse;
37 static char remoteName[100] = "xpdf_";
38 static GBool doRemoteReload = gFalse;
39 static GBool doRemoteRaise = gFalse;
40 static GBool doRemoteQuit = gFalse;
41 static GBool printCommands = gFalse;
42 static GBool quiet = gFalse;
43 static char cfgFileName[256] = "";
44 static GBool printVersion = gFalse;
45 static GBool printHelp = gFalse;
47 static ArgDesc argDesc[] = {
48 {"-g", argStringDummy, NULL, 0,
49 "initial window geometry"},
50 {"-geometry", argStringDummy, NULL, 0,
51 "initial window geometry"},
52 {"-title", argStringDummy, NULL, 0,
54 {"-cmap", argFlagDummy, NULL, 0,
55 "install a private colormap"},
56 {"-rgb", argIntDummy, NULL, 0,
57 "biggest RGB cube to allocate (default is 5)"},
58 {"-rv", argFlagDummy, NULL, 0,
60 {"-papercolor", argStringDummy, NULL, 0,
61 "color of paper background"},
62 {"-z", argStringDummy, NULL, 0,
63 "initial zoom level (percent, 'page', 'width')"},
65 {"-t1lib", argString, enableT1libStr, sizeof(enableT1libStr),
66 "enable t1lib font rasterizer: yes, no"},
68 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
69 {"-freetype", argString, enableFreeTypeStr, sizeof(enableFreeTypeStr),
70 "enable FreeType font rasterizer: yes, no"},
72 {"-aa", argString, antialiasStr, sizeof(antialiasStr),
73 "enable font anti-aliasing: yes, no"},
74 {"-ps", argString, psFileArg, sizeof(psFileArg),
75 "default PostScript file name or command"},
76 {"-paper", argString, paperSize, sizeof(paperSize),
77 "paper size (letter, legal, A4, A3, match)"},
78 {"-paperw", argInt, &paperWidth, 0,
79 "paper width, in points"},
80 {"-paperh", argInt, &paperHeight, 0,
81 "paper height, in points"},
82 {"-level1", argFlag, &level1, 0,
83 "generate Level 1 PostScript"},
84 {"-enc", argString, textEncName, sizeof(textEncName),
85 "output text encoding name"},
86 {"-eol", argString, textEOL, sizeof(textEOL),
87 "output end-of-line convention (unix, dos, or mac)"},
88 {"-opw", argString, ownerPassword, sizeof(ownerPassword),
89 "owner password (for encrypted files)"},
90 {"-upw", argString, userPassword, sizeof(userPassword),
91 "user password (for encrypted files)"},
92 {"-fullscreen", argFlag, &fullScreen, 0,
93 "run in full-screen (presentation) mode"},
94 {"-remote", argString, remoteName + 5, sizeof(remoteName) - 5,
95 "start/contact xpdf remote server with specified name"},
96 {"-reload", argFlag, &doRemoteReload, 0,
97 "reload xpdf remove server window (with -remote only)"},
98 {"-raise", argFlag, &doRemoteRaise, 0,
99 "raise xpdf remote server window (with -remote only)"},
100 {"-quit", argFlag, &doRemoteQuit, 0,
101 "kill xpdf remote server (with -remote only)"},
102 {"-cmd", argFlag, &printCommands, 0,
103 "print commands as they're executed"},
104 {"-q", argFlag, &quiet, 0,
105 "don't print any messages or errors"},
106 {"-cfg", argString, cfgFileName, sizeof(cfgFileName),
107 "configuration file to use in place of .xpdfrc"},
108 {"-v", argFlag, &printVersion, 0,
109 "print copyright and version info"},
110 {"-h", argFlag, &printHelp, 0,
111 "print usage information"},
112 {"-help", argFlag, &printHelp, 0,
113 "print usage information"},
114 {"--help", argFlag, &printHelp, 0,
115 "print usage information"},
116 {"-?", argFlag, &printHelp, 0,
117 "print usage information"},
121 //------------------------------------------------------------------------
123 int main(int argc, char *argv[]) {
128 GString *userPasswordStr, *ownerPasswordStr;
133 userPasswordStr = ownerPasswordStr = NULL;
136 ok = parseArgs(argDesc, &argc, argv);
137 if (!ok || printVersion || printHelp) {
138 fprintf(stderr, "xpdf version %s\n", xpdfVersion);
139 fprintf(stderr, "%s\n", xpdfCopyright);
141 printUsage("xpdf", "[<PDF-file> [<page> | +<dest>]]", argDesc);
148 globalParams = new GlobalParams(cfgFileName);
149 globalParams->setupBaseFonts(NULL);
151 globalParams->setPSFile(psFileArg);
154 if (!globalParams->setPSPaperSize(paperSize)) {
155 fprintf(stderr, "Invalid paper size\n");
159 globalParams->setPSPaperWidth(paperWidth);
162 globalParams->setPSPaperHeight(paperHeight);
166 globalParams->setPSLevel(psLevel1);
168 if (textEncName[0]) {
169 globalParams->setTextEncoding(textEncName);
172 if (!globalParams->setTextEOL(textEOL)) {
173 fprintf(stderr, "Bad '-eol' value on command line\n");
176 if (enableT1libStr[0]) {
177 if (!globalParams->setEnableT1lib(enableT1libStr)) {
178 fprintf(stderr, "Bad '-t1lib' value on command line\n");
181 if (enableFreeTypeStr[0]) {
182 if (!globalParams->setEnableFreeType(enableFreeTypeStr)) {
183 fprintf(stderr, "Bad '-freetype' value on command line\n");
186 if (antialiasStr[0]) {
187 if (!globalParams->setAntialias(antialiasStr)) {
188 fprintf(stderr, "Bad '-aa' value on command line\n");
192 globalParams->setPrintCommands(printCommands);
195 globalParams->setErrQuiet(quiet);
198 // create the XPDFApp object
199 app = new XPDFApp(&argc, argv);
201 // the initialZoom parameter can be set in either the config file or
202 // as an X resource (or command line arg)
203 if (app->getInitialZoom()) {
204 globalParams->setInitialZoom(app->getInitialZoom()->getCString());
207 // check command line
208 ok = ok && argc >= 1 && argc <= 3;
209 if (doRemoteReload) {
210 ok = ok && remoteName[5] && !doRemoteQuit && argc == 1;
213 ok = ok && remoteName[5] && !doRemoteQuit;
216 ok = ok && remoteName[5] && argc == 1;
218 if (!ok || printVersion || printHelp) {
219 fprintf(stderr, "xpdf version %s\n", xpdfVersion);
220 fprintf(stderr, "%s\n", xpdfCopyright);
222 printUsage("xpdf", "[<PDF-file> [<page> | +<dest>]]", argDesc);
228 fileName = new GString(argv[1]);
235 if (argv[2][0] == '+') {
236 destName = new GString(&argv[2][1]);
242 // handle remote server stuff
244 app->setRemoteName(remoteName);
245 if (app->remoteServerRunning()) {
248 app->remoteOpenAtDest(fileName, destName, doRemoteRaise);
250 app->remoteOpen(fileName, pg, doRemoteRaise);
252 } else if (doRemoteReload) {
253 app->remoteReload(doRemoteRaise);
254 } else if (doRemoteRaise) {
256 } else if (doRemoteQuit) {
267 app->setFullScreen(fullScreen);
269 // check for password string(s)
270 ownerPasswordStr = ownerPassword[0] != '\001' ? new GString(ownerPassword)
272 userPasswordStr = userPassword[0] != '\001' ? new GString(userPassword)
275 // open the file and run the main loop
277 if (!app->openAtDest(fileName, destName,
278 ownerPasswordStr, userPasswordStr)) {
283 if (!app->open(fileName, pg, ownerPasswordStr, userPasswordStr)) {
294 if (userPasswordStr) {
295 delete userPasswordStr;
297 if (ownerPasswordStr) {
298 delete ownerPasswordStr;
310 // check for memory leaks
312 Object::memCheck(stderr);