]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/gpdf.cc
Fix some amusing bugs.
[evince.git] / pdf / xpdf / gpdf.cc
1 //========================================================================
2 //
3 // gpdf.cc
4 //
5 // Copyright 1996 Derek B. Noonburg
6 // Copyright 1999 Michael Meeks.
7 // Copyright 1999 Miguel de Icaza
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 #define DOC_ROOT_MAGIC 0xad3f556d
45 struct DOC_ROOT {
46   guint32        magic;
47   GString        *title;
48   PDFDoc         *pdf;
49   GtkWidget      *toplevel;
50   GtkWidget      *table;
51   GnomeAppBar    *appbar;
52   GtkDrawingArea *area;
53   GdkPixmap      *pixmap;
54   OutputDev      *out;
55   GdkColor        paper;
56 };
57
58 DOC_ROOT *hack_global = NULL;
59
60 static void
61 crummy_cmd (GtkWidget *widget, DOC_ROOT *tmp)
62 {
63   printf ("Crummy\n");
64 }
65
66
67 const struct poptOption gpdf_popt_options [] = {
68   { "debug", '\0', POPT_ARG_INT, &gpdf_debug, 0,
69     N_("Enables some debugging functions"), N_("LEVEL") },
70   { NULL, '\0', 0, NULL, 0 }
71 };
72
73
74 static GnomeUIInfo dummy_menu [] = {
75         { GNOME_APP_UI_ITEM, N_("_dummy"),
76           N_("What a dummy!"), crummy_cmd },
77         GNOMEUIINFO_END
78 };
79
80 static GnomeUIInfo main_menu [] = {
81         { GNOME_APP_UI_SUBTREE, N_("_Dummy"), NULL, dummy_menu },
82         GNOMEUIINFO_END
83 };
84
85 //------------------------------------------------------------------------
86 // loadFile / displayPage
87 //------------------------------------------------------------------------
88
89 static gint
90 doc_config_event (GtkWidget *widget, void *ugly)
91 {
92   DOC_ROOT *doc = hack_global;
93
94   g_return_val_if_fail (doc, FALSE);
95   g_return_val_if_fail (doc->magic == DOC_ROOT_MAGIC, FALSE);
96
97   if (doc->pixmap)
98     gdk_pixmap_unref(doc->pixmap);
99
100   doc->pixmap = gdk_pixmap_new(widget->window,
101                                widget->allocation.width,
102                                widget->allocation.height,
103                                -1);
104
105   gdk_color_white (gtk_widget_get_default_colormap(), &doc->paper);
106   doc->out    = new GOutputDev (doc->pixmap, doc->paper);
107
108 /*  gdk_draw_rectangle (doc->pixmap,
109                       widget->style->white_gc,
110                       TRUE,
111                       0, 0,
112                       widget->allocation.width,
113                       widget->allocation.height);*/
114   printf ("Configured...\n");
115   return TRUE;
116 }
117
118 static gint
119 doc_redraw_event (GtkWidget *widget, void *ugly)
120 {
121   DOC_ROOT *doc = hack_global;
122
123   g_return_val_if_fail (doc, FALSE);
124   g_return_val_if_fail (doc->magic == DOC_ROOT_MAGIC, FALSE);
125
126   if (doc->out && doc->pdf) {
127     printf ("There are %d pages\n", doc->pdf->getNumPages());
128
129     doc->pdf->displayPage(doc->out, 1, 72, 0, gTrue);
130     gdk_draw_pixmap (widget->window,
131                      widget->style->white_gc,
132                      doc->pixmap,
133                      0, 0,
134                      0, 0,
135                      widget->allocation.width,
136                      widget->allocation.height);
137     
138   } else
139     printf ("Null pointer error %p %p\n", doc->out, doc->pdf);
140   
141   return FALSE;
142 }
143
144 static GBool
145 loadFile(GString *fileName)
146 {
147   DOC_ROOT *doc = new DOC_ROOT();
148   char s[20];
149   char *p;
150
151   hack_global = doc;
152
153   doc->magic = DOC_ROOT_MAGIC;
154   // open PDF file
155   doc->pdf = new PDFDoc(fileName);
156   if (!doc->pdf->isOk()) {
157     delete doc->pdf;
158     delete doc;
159     return gFalse;
160   }
161
162   g_assert (doc->pdf->getCatalog());
163
164   doc->toplevel = gnome_app_new ("gpdf", "gpdf");
165   gtk_window_set_policy(GTK_WINDOW(doc->toplevel), 1, 1, 0);
166   gtk_window_set_default_size (GTK_WINDOW(doc->toplevel), 600, 400);
167   doc->table  = GTK_WIDGET (gtk_table_new (0, 0, 0));
168   doc->appbar = GNOME_APPBAR (gnome_appbar_new (FALSE, TRUE,
169                                                 GNOME_PREFERENCES_USER));
170   gnome_app_set_statusbar (GNOME_APP (doc->toplevel),
171                            GTK_WIDGET (doc->appbar));
172   gnome_app_set_contents (GNOME_APP (doc->toplevel), doc->table);
173   gnome_app_create_menus_with_data (GNOME_APP (doc->toplevel), main_menu, doc);
174   gnome_app_install_menu_hints(GNOME_APP (doc->toplevel), main_menu);
175
176   doc->pixmap = NULL;
177   doc->area   = GTK_DRAWING_AREA (gtk_drawing_area_new ());
178   gtk_signal_connect (GTK_OBJECT(doc->area),"configure_event",
179                       (GtkSignalFunc) doc_config_event, doc);
180   gtk_signal_connect (GTK_OBJECT (doc->area), "expose_event",
181                       (GtkSignalFunc) doc_redraw_event, doc);
182
183   gtk_table_attach (GTK_TABLE (doc->table), GTK_WIDGET (doc->area),
184                     0, 1, 1, 2,
185                     GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND,
186                     0, 0);
187
188   gtk_widget_show_all (doc->toplevel);
189
190   return gTrue;
191 }
192
193 /*static void displayPage(int page1, int zoom1, int rotate1) {
194   char s[20];
195
196   // check for document
197   if (!doc)
198     return;
199
200   // busy cursor
201   if (win)
202     win->setBusyCursor(gTrue);
203
204   // new page/zoom/rotate values
205   page = page1;
206   zoom = zoom1;
207   rotate = rotate1;
208
209   // initialize mouse-related stuff
210   linkAction = NULL;
211   win->setDefaultCursor();
212   linkLabel->setText(NULL);
213   selectXMin = selectXMax = 0;
214   selectYMin = selectYMax = 0;
215   lastDragLeft = lastDragTop = gTrue;
216
217   // draw the page
218   doc->displayPage(out, page, zoomDPI[zoom - minZoom], rotate, gTrue);
219   layoutCbk(win);
220
221   // update page number display
222   sprintf(s, "%d", page);
223   pageNumText->setText(s);
224
225   // back to regular cursor
226   win->setBusyCursor(gFalse);
227   }*/
228
229 int
230 main (int argc, char *argv [])
231 {
232   char **view_files = NULL;
233   int lp;
234
235   gnome_init_with_popt_table (
236     "gpdf", "0.1", argc, argv,
237     gpdf_popt_options, 0, &ctx);
238   
239   initParams (xpdfConfigFile); /* Init font path */
240
241   view_files = poptGetArgs (ctx);
242   /* Load files */
243   if (view_files) {
244     for (lp=0;view_files[lp];lp++) {
245       GString *name = new GString (view_files[lp]);
246       if (!name || !loadFile(name))
247         printf ("Error loading '%s'\n", view_files[lp]);
248     }
249   } else {
250     printf ("Need filenames...\n");
251     exit (0);
252   }
253
254   poptFreeContext (ctx);
255
256   gtk_main ();
257
258   freeParams();
259
260   /* Destroy files */
261 }