1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
12 #include "parseargs.h"
15 #include "GlobalParams.h"
20 //------------------------------------------------------------------------
21 // command line options
22 //------------------------------------------------------------------------
24 static GBool contView
= gFalse
;
25 static char enableT1libStr
[16] = "";
26 static char enableFreeTypeStr
[16] = "";
27 static char antialiasStr
[16] = "";
28 static char vectorAntialiasStr
[16] = "";
29 static char psFileArg
[256];
30 static char paperSize
[15] = "";
31 static int paperWidth
= 0;
32 static int paperHeight
= 0;
33 static GBool level1
= gFalse
;
34 static char textEncName
[128] = "";
35 static char textEOL
[16] = "";
36 static char ownerPassword
[33] = "\001";
37 static char userPassword
[33] = "\001";
38 static GBool fullScreen
= gFalse
;
39 static char remoteName
[100] = "xpdf_";
40 static char remoteCmd
[512] = "";
41 static GBool doRemoteReload
= gFalse
;
42 static GBool doRemoteRaise
= gFalse
;
43 static GBool doRemoteQuit
= gFalse
;
44 static GBool printCommands
= gFalse
;
45 static GBool quiet
= gFalse
;
46 static char cfgFileName
[256] = "";
47 static GBool printVersion
= gFalse
;
48 static GBool printHelp
= gFalse
;
50 static ArgDesc argDesc
[] = {
51 {"-g", argStringDummy
, NULL
, 0,
52 "initial window geometry"},
53 {"-geometry", argStringDummy
, NULL
, 0,
54 "initial window geometry"},
55 {"-title", argStringDummy
, NULL
, 0,
57 {"-cmap", argFlagDummy
, NULL
, 0,
58 "install a private colormap"},
59 {"-rgb", argIntDummy
, NULL
, 0,
60 "biggest RGB cube to allocate (default is 5)"},
61 {"-rv", argFlagDummy
, NULL
, 0,
63 {"-papercolor", argStringDummy
, NULL
, 0,
64 "color of paper background"},
65 {"-z", argStringDummy
, NULL
, 0,
66 "initial zoom level (percent, 'page', 'width')"},
67 {"-cont", argFlag
, &contView
, 0,
68 "start in continuous view mode" },
70 {"-t1lib", argString
, enableT1libStr
, sizeof(enableT1libStr
),
71 "enable t1lib font rasterizer: yes, no"},
73 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
74 {"-freetype", argString
, enableFreeTypeStr
, sizeof(enableFreeTypeStr
),
75 "enable FreeType font rasterizer: yes, no"},
77 {"-aa", argString
, antialiasStr
, sizeof(antialiasStr
),
78 "enable font anti-aliasing: yes, no"},
79 {"-aaVector", argString
, vectorAntialiasStr
, sizeof(vectorAntialiasStr
),
80 "enable vector anti-aliasing: yes, no"},
81 {"-ps", argString
, psFileArg
, sizeof(psFileArg
),
82 "default PostScript file name or command"},
83 {"-paper", argString
, paperSize
, sizeof(paperSize
),
84 "paper size (letter, legal, A4, A3, match)"},
85 {"-paperw", argInt
, &paperWidth
, 0,
86 "paper width, in points"},
87 {"-paperh", argInt
, &paperHeight
, 0,
88 "paper height, in points"},
89 {"-level1", argFlag
, &level1
, 0,
90 "generate Level 1 PostScript"},
91 {"-enc", argString
, textEncName
, sizeof(textEncName
),
92 "output text encoding name"},
93 {"-eol", argString
, textEOL
, sizeof(textEOL
),
94 "output end-of-line convention (unix, dos, or mac)"},
95 {"-opw", argString
, ownerPassword
, sizeof(ownerPassword
),
96 "owner password (for encrypted files)"},
97 {"-upw", argString
, userPassword
, sizeof(userPassword
),
98 "user password (for encrypted files)"},
99 {"-fullscreen", argFlag
, &fullScreen
, 0,
100 "run in full-screen (presentation) mode"},
101 {"-remote", argString
, remoteName
+ 5, sizeof(remoteName
) - 5,
102 "start/contact xpdf remote server with specified name"},
103 {"-exec", argString
, remoteCmd
, sizeof(remoteCmd
),
104 "execute command on xpdf remote server (with -remote only)"},
105 {"-reload", argFlag
, &doRemoteReload
, 0,
106 "reload xpdf remove server window (with -remote only)"},
107 {"-raise", argFlag
, &doRemoteRaise
, 0,
108 "raise xpdf remote server window (with -remote only)"},
109 {"-quit", argFlag
, &doRemoteQuit
, 0,
110 "kill xpdf remote server (with -remote only)"},
111 {"-cmd", argFlag
, &printCommands
, 0,
112 "print commands as they're executed"},
113 {"-q", argFlag
, &quiet
, 0,
114 "don't print any messages or errors"},
115 {"-cfg", argString
, cfgFileName
, sizeof(cfgFileName
),
116 "configuration file to use in place of .xpdfrc"},
117 {"-v", argFlag
, &printVersion
, 0,
118 "print copyright and version info"},
119 {"-h", argFlag
, &printHelp
, 0,
120 "print usage information"},
121 {"-help", argFlag
, &printHelp
, 0,
122 "print usage information"},
123 {"--help", argFlag
, &printHelp
, 0,
124 "print usage information"},
125 {"-?", argFlag
, &printHelp
, 0,
126 "print usage information"},
130 //------------------------------------------------------------------------
132 int main(int argc
, char *argv
[]) {
137 GString
*userPasswordStr
, *ownerPasswordStr
;
142 userPasswordStr
= ownerPasswordStr
= NULL
;
145 ok
= parseArgs(argDesc
, &argc
, argv
);
146 if (!ok
|| printVersion
|| printHelp
) {
147 fprintf(stderr
, "xpdf version %s\n", xpdfVersion
);
148 fprintf(stderr
, "%s\n", xpdfCopyright
);
150 printUsage("xpdf", "[<PDF-file> [<page> | +<dest>]]", argDesc
);
157 globalParams
= new GlobalParams(cfgFileName
);
158 globalParams
->setupBaseFonts(NULL
);
160 globalParams
->setContinuousView(contView
);
163 globalParams
->setPSFile(psFileArg
);
166 if (!globalParams
->setPSPaperSize(paperSize
)) {
167 fprintf(stderr
, "Invalid paper size\n");
171 globalParams
->setPSPaperWidth(paperWidth
);
174 globalParams
->setPSPaperHeight(paperHeight
);
178 globalParams
->setPSLevel(psLevel1
);
180 if (textEncName
[0]) {
181 globalParams
->setTextEncoding(textEncName
);
184 if (!globalParams
->setTextEOL(textEOL
)) {
185 fprintf(stderr
, "Bad '-eol' value on command line\n");
188 if (enableT1libStr
[0]) {
189 if (!globalParams
->setEnableT1lib(enableT1libStr
)) {
190 fprintf(stderr
, "Bad '-t1lib' value on command line\n");
193 if (enableFreeTypeStr
[0]) {
194 if (!globalParams
->setEnableFreeType(enableFreeTypeStr
)) {
195 fprintf(stderr
, "Bad '-freetype' value on command line\n");
198 if (antialiasStr
[0]) {
199 if (!globalParams
->setAntialias(antialiasStr
)) {
200 fprintf(stderr
, "Bad '-aa' value on command line\n");
203 if (vectorAntialiasStr
[0]) {
204 if (!globalParams
->setVectorAntialias(vectorAntialiasStr
)) {
205 fprintf(stderr
, "Bad '-aaVector' value on command line\n");
209 globalParams
->setPrintCommands(printCommands
);
212 globalParams
->setErrQuiet(quiet
);
215 // create the XPDFApp xObject
216 app
= new XPDFApp(&argc
, argv
);
218 // the initialZoom parameter can be set in either the config file or
219 // as an X resource (or command line arg)
220 if (app
->getInitialZoom()) {
221 globalParams
->setInitialZoom(app
->getInitialZoom()->getCString());
224 // check command line
225 ok
= ok
&& argc
>= 1 && argc
<= 3;
227 ok
= ok
&& remoteName
[5] && !doRemoteReload
&& !doRemoteRaise
&&
228 !doRemoteQuit
&& argc
== 1;
230 if (doRemoteReload
) {
231 ok
= ok
&& remoteName
[5] && !doRemoteQuit
&& argc
== 1;
234 ok
= ok
&& remoteName
[5] && !doRemoteQuit
;
237 ok
= ok
&& remoteName
[5] && argc
== 1;
239 if (!ok
|| printVersion
|| printHelp
) {
240 fprintf(stderr
, "xpdf version %s\n", xpdfVersion
);
241 fprintf(stderr
, "%s\n", xpdfCopyright
);
243 printUsage("xpdf", "[<PDF-file> [<page> | +<dest>]]", argDesc
);
249 fileName
= new GString(argv
[1]);
256 if (argv
[2][0] == '+') {
257 destName
= new GString(&argv
[2][1]);
261 fprintf(stderr
, "Invalid page number (%d)\n", pg
);
268 // handle remote server stuff
270 app
->setRemoteName(remoteName
);
271 if (app
->remoteServerRunning()) {
274 app
->remoteOpenAtDest(fileName
, destName
, doRemoteRaise
);
276 app
->remoteOpen(fileName
, pg
, doRemoteRaise
);
278 } else if (remoteCmd
[0]) {
279 app
->remoteExec(remoteCmd
);
280 } else if (doRemoteReload
) {
281 app
->remoteReload(doRemoteRaise
);
282 } else if (doRemoteRaise
) {
284 } else if (doRemoteQuit
) {
295 app
->setFullScreen(fullScreen
);
297 // check for password string(s)
298 ownerPasswordStr
= ownerPassword
[0] != '\001' ? new GString(ownerPassword
)
300 userPasswordStr
= userPassword
[0] != '\001' ? new GString(userPassword
)
303 // open the file and run the main loop
305 if (!app
->openAtDest(fileName
, destName
,
306 ownerPasswordStr
, userPasswordStr
)) {
311 if (!app
->open(fileName
, pg
, ownerPasswordStr
, userPasswordStr
)) {
322 if (userPasswordStr
) {
323 delete userPasswordStr
;
325 if (ownerPasswordStr
) {
326 delete ownerPasswordStr
;
338 // check for memory leaks
340 xObject::memCheck(stderr
);