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