1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
6 // Copyright 1999 Miguel de Icaza
7 // Copyright 1999 Michael Meeks.
9 //========================================================================
16 #define GString G_String
21 #include "parseargs.h"
33 #include "GOutputDev.h"
34 #include "PSOutputDev.h"
35 #include "TextOutputDev.h"
40 GBool printCommands = gFalse;
44 const struct poptOption gpdf_popt_options [] = {
45 { "debug", '\0', POPT_ARG_INT, &gpdf_debug, 0,
46 N_("Enables some debugging functions"), N_("LEVEL") },
47 { NULL, '\0', 0, NULL, 0 }
51 //------------------------------------------------------------------------
52 // loadFile / displayPage
53 //------------------------------------------------------------------------
55 static GBool loadFile(GString *fileName) {
63 win->setBusyCursor(gTrue);
66 newDoc = new PDFDoc(fileName);
67 if (!newDoc->isOk()) {
70 win->setBusyCursor(gFalse);
74 // replace old document
79 // nothing displayed yet
82 // init PostScript output params
86 psFileName = defPSFileName->copy();
88 p = fileName->getCString() + fileName->getLength() - 4;
89 if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF"))
90 psFileName = new GString(fileName->getCString(),
91 fileName->getLength() - 4);
93 psFileName = fileName->copy();
94 psFileName->append(".ps");
97 psLastPage = doc->getNumPages();
99 // set up title, number-of-pages display; back to normal cursor
101 title = new GString("xpdf: ");
102 title->append(fileName);
103 win->setTitle(title);
104 sprintf(s, "of %d", doc->getNumPages());
105 numPagesLabel->setText(s);
106 win->setBusyCursor(gFalse);
113 static void displayPage(int page1, int zoom1, int rotate1) {
116 // check for document
122 win->setBusyCursor(gTrue);
124 // new page/zoom/rotate values
129 // initialize mouse-related stuff
131 win->setDefaultCursor();
132 linkLabel->setText(NULL);
133 selectXMin = selectXMax = 0;
134 selectYMin = selectYMax = 0;
135 lastDragLeft = lastDragTop = gTrue;
138 doc->displayPage(out, page, zoomDPI[zoom - minZoom], rotate, gTrue);
141 // update page number display
142 sprintf(s, "%d", page);
143 pageNumText->setText(s);
145 // back to regular cursor
146 win->setBusyCursor(gFalse);
150 main (int argc, char *argv [])
152 char **view_files = NULL;
155 gnome_init_with_popt_table (
156 "gpdf", "0.1", argc, argv,
157 gpdf_popt_options, 0, &ctx);
159 view_files = poptGetArgs (ctx);
162 for (lp=0;view_files[lp];lp++) {
163 GString *name = new GString (view_files[lp]);
164 if (!name || !loadFile(name))
165 printf ("Error loading '%s'\n", view_files[lp]);
168 printf ("Need filenames...\n");
172 poptFreeContext (ctx);