]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/gpdf.cc
More bits.
[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   printf ("Creating pixmap of size %d %d\n",
106           widget->allocation.width, widget->allocation.height);
107   gdk_color_white (gtk_widget_get_default_colormap(), &doc->paper);
108   doc->out    = new GOutputDev (doc->pixmap, doc->paper);
109
110   return TRUE;
111 }
112
113 static gint
114 doc_redraw_event (GtkWidget *widget, void *ugly)
115 {
116   DOC_ROOT *doc = hack_global;
117
118   g_return_val_if_fail (doc, FALSE);
119   g_return_val_if_fail (doc->magic == DOC_ROOT_MAGIC, FALSE);
120
121   if (doc->out && doc->pdf) {
122     printf ("There are %d pages\n", doc->pdf->getNumPages());
123
124     doc->pdf->displayPage(doc->out, 1, 72, 0, gTrue);
125     gdk_draw_pixmap (widget->window,
126                      widget->style->white_gc,
127                      doc->pixmap,
128                      0, 0,
129                      0, 0,
130                      widget->allocation.width,
131                      widget->allocation.height);
132     
133   } else
134     printf ("Null pointer error %p %p\n", doc->out, doc->pdf);
135   
136   return FALSE;
137 }
138
139 static GBool
140 loadFile(GString *fileName)
141 {
142   DOC_ROOT *doc = new DOC_ROOT();
143   char s[20];
144   char *p;
145
146   hack_global = doc;
147
148   doc->magic = DOC_ROOT_MAGIC;
149   // open PDF file
150   doc->pdf = new PDFDoc(fileName);
151   if (!doc->pdf->isOk()) {
152     delete doc->pdf;
153     delete doc;
154     return gFalse;
155   }
156
157   g_assert (doc->pdf->getCatalog());
158
159   doc->toplevel = gnome_app_new ("gpdf", "gpdf");
160   gtk_window_set_policy(GTK_WINDOW(doc->toplevel), 1, 1, 0);
161   gtk_window_set_default_size (GTK_WINDOW(doc->toplevel), 600, 400);
162   doc->table  = GTK_WIDGET (gtk_table_new (0, 0, 0));
163   doc->appbar = GNOME_APPBAR (gnome_appbar_new (FALSE, TRUE,
164                                                 GNOME_PREFERENCES_USER));
165   gnome_app_set_statusbar (GNOME_APP (doc->toplevel),
166                            GTK_WIDGET (doc->appbar));
167   gnome_app_set_contents (GNOME_APP (doc->toplevel), doc->table);
168   gnome_app_create_menus_with_data (GNOME_APP (doc->toplevel), main_menu, doc);
169   gnome_app_install_menu_hints(GNOME_APP (doc->toplevel), main_menu);
170
171   doc->pixmap = NULL;
172   doc->area   = GTK_DRAWING_AREA (gtk_drawing_area_new ());
173   gtk_signal_connect (GTK_OBJECT(doc->area),"configure_event",
174                       (GtkSignalFunc) doc_config_event, doc);
175   gtk_signal_connect (GTK_OBJECT (doc->area), "expose_event",
176                       (GtkSignalFunc) doc_redraw_event, doc);
177
178   gtk_table_attach (GTK_TABLE (doc->table), GTK_WIDGET (doc->area),
179                     0, 1, 1, 2,
180                     GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND,
181                     0, 0);
182
183   gtk_widget_show_all (doc->toplevel);
184
185   return gTrue;
186 }
187
188 /*static void displayPage(int page1, int zoom1, int rotate1) {
189   char s[20];
190
191   // check for document
192   if (!doc)
193     return;
194
195   // busy cursor
196   if (win)
197     win->setBusyCursor(gTrue);
198
199   // new page/zoom/rotate values
200   page = page1;
201   zoom = zoom1;
202   rotate = rotate1;
203
204   // initialize mouse-related stuff
205   linkAction = NULL;
206   win->setDefaultCursor();
207   linkLabel->setText(NULL);
208   selectXMin = selectXMax = 0;
209   selectYMin = selectYMax = 0;
210   lastDragLeft = lastDragTop = gTrue;
211
212   // draw the page
213   doc->displayPage(out, page, zoomDPI[zoom - minZoom], rotate, gTrue);
214   layoutCbk(win);
215
216   // update page number display
217   sprintf(s, "%d", page);
218   pageNumText->setText(s);
219
220   // back to regular cursor
221   win->setBusyCursor(gFalse);
222   }*/
223
224 int
225 main (int argc, char *argv [])
226 {
227   char **view_files = NULL;
228   int lp;
229
230   gnome_init_with_popt_table (
231     "gpdf", "0.1", argc, argv,
232     gpdf_popt_options, 0, &ctx);
233   
234   initParams (xpdfConfigFile); /* Init font path */
235
236   view_files = poptGetArgs (ctx);
237   /* Load files */
238   if (view_files) {
239     for (lp=0;view_files[lp];lp++) {
240       GString *name = new GString (view_files[lp]);
241       if (!name || !loadFile(name))
242         printf ("Error loading '%s'\n", view_files[lp]);
243     }
244   } else {
245     printf ("Need filenames...\n");
246     exit (0);
247   }
248
249   poptFreeContext (ctx);
250
251   gtk_main ();
252
253   freeParams();
254
255   /* Destroy files */
256 }