]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/gpdf.cc
33e3dda8ff0f79fd46217ca5d7f20d8b53f1128f
[evince.git] / pdf / xpdf / gpdf.cc
1 //========================================================================
2 //
3 // gpdf.cc
4 //
5 // Copyright 1996 Derek B. Noonburg
6 // Copyright 1999 Miguel de Icaza
7 // Copyright 1999 Michael Meeks.
8 //
9 //========================================================================
10
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stddef.h>
15 #include <string.h>
16 #define GString G_String
17 #include <gnome.h>
18 #undef  GString 
19 #include "gtypes.h"
20 #include "GString.h"
21 #include "parseargs.h"
22 #include "gfile.h"
23 #include "gmem.h"
24 #include "Object.h"
25 #include "Stream.h"
26 #include "Array.h"
27 #include "Dict.h"
28 #include "XRef.h"
29 #include "Catalog.h"
30 #include "Page.h"
31 #include "Link.h"
32 #include "PDFDoc.h"
33 #include "GOutputDev.h"
34 #include "PSOutputDev.h"
35 #include "TextOutputDev.h"
36 #include "Params.h"
37 #include "Error.h"
38 #include "config.h"
39
40 GBool printCommands = gFalse;
41 gint  gpdf_debug;
42 poptContext ctx;
43
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 }
48 };
49
50
51 //------------------------------------------------------------------------
52 // loadFile / displayPage
53 //------------------------------------------------------------------------
54
55 static GBool loadFile(GString *fileName) {
56   GString *title;
57   PDFDoc *newDoc;
58   char s[20];
59   char *p;
60
61   // busy cursor
62   if (win)
63     win->setBusyCursor(gTrue);
64
65   // open PDF file
66   newDoc = new PDFDoc(fileName);
67   if (!newDoc->isOk()) {
68     delete newDoc;
69     if (win)
70       win->setBusyCursor(gFalse);
71     return gFalse;
72   }
73
74   // replace old document
75   if (doc)
76     delete doc;
77   doc = newDoc;
78
79   // nothing displayed yet
80   page = -99;
81
82   // init PostScript output params
83   if (psFileName)
84     delete psFileName;
85   if (defPSFileName) {
86     psFileName = defPSFileName->copy();
87   } else {
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);
92     else
93       psFileName = fileName->copy();
94     psFileName->append(".ps");
95   }
96   psFirstPage = 1;
97   psLastPage = doc->getNumPages();
98
99   // set up title, number-of-pages display; back to normal cursor
100   if (win) {
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);
107   }
108
109   // done
110   return gTrue;
111 }
112
113 static void displayPage(int page1, int zoom1, int rotate1) {
114   char s[20];
115
116   // check for document
117   if (!doc)
118     return;
119
120   // busy cursor
121   if (win)
122     win->setBusyCursor(gTrue);
123
124   // new page/zoom/rotate values
125   page = page1;
126   zoom = zoom1;
127   rotate = rotate1;
128
129   // initialize mouse-related stuff
130   linkAction = NULL;
131   win->setDefaultCursor();
132   linkLabel->setText(NULL);
133   selectXMin = selectXMax = 0;
134   selectYMin = selectYMax = 0;
135   lastDragLeft = lastDragTop = gTrue;
136
137   // draw the page
138   doc->displayPage(out, page, zoomDPI[zoom - minZoom], rotate, gTrue);
139   layoutCbk(win);
140
141   // update page number display
142   sprintf(s, "%d", page);
143   pageNumText->setText(s);
144
145   // back to regular cursor
146   win->setBusyCursor(gFalse);
147 }
148
149 int
150 main (int argc, char *argv [])
151 {
152   char **view_files = NULL;
153   int lp;
154
155   gnome_init_with_popt_table (
156     "gpdf", "0.1", argc, argv,
157     gpdf_popt_options, 0, &ctx);
158   
159   view_files = poptGetArgs (ctx);
160   /* Load files */
161   if (view_files) {
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]);
166     }
167   } else {
168     printf ("Need filenames...\n");
169     exit (0);
170   }
171
172   poptFreeContext (ctx);
173
174   gtk_main ();
175
176   /* Destroy files */
177 }