]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/bonobo-image-x-pdf.cc
drag and drop, removed redundant verb popup code.
[evince.git] / pdf / xpdf / bonobo-image-x-pdf.cc
1 /*
2  * image/x-pdf BonoboObject.
3  *
4  * Author:
5  *   Michael Meeks <michael@imaginator.com>
6  *
7  */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <stddef.h>
11 #include <string.h>
12 #include <config.h>
13 extern "C" {
14 #define GString G_String
15 #include <gnome.h>
16 #include <libgnorba/gnorba.h>
17 #include <bonobo/gnome-bonobo.h>
18 #undef  GString 
19 }
20 #include "gtypes.h"
21 #include "GString.h"
22 #include "parseargs.h"
23 #include "gfile.h"
24 #include "gmem.h"
25 #include "Object.h"
26 #include "Stream.h"
27 #include "Array.h"
28 #include "Dict.h"
29 #include "XRef.h"
30 #include "Catalog.h"
31 #include "Page.h"
32 #include "Link.h"
33 #include "PDFDoc.h"
34 #include "GOutputDev.h"
35 #include "PSOutputDev.h"
36 #include "TextOutputDev.h"
37 #include "Params.h"
38 #include "Error.h"
39 #include "config.h"
40 #include "BonoboStream.h"
41
42 #define PDF_DEBUG 0
43
44 GBool printCommands = gFalse;
45
46 CORBA_Environment ev;
47 CORBA_ORB orb;
48
49 /*
50  * Number of servers running on the system
51  * when the count reaches zero, we unregister from the
52  * Name Server and we shut down.
53  */
54 static int embeddable_servers = 0;
55
56 /*
57  * Our embeddable factory
58  */
59 static GnomeEmbeddableFactory *factory;
60         
61
62 /*
63  * BonoboObject data
64  */
65 typedef struct {
66   GnomeEmbeddable *embeddable;
67
68   PDFDoc       *pdf;
69   GNOME_Stream  stream; /* To free it later */
70
71   GList *views;
72 } bed_t;
73
74 /*
75  * View data
76  */
77 typedef struct {
78   GnomeView            *view;
79   bed_t *bed;
80
81   double                scale;
82   GtkWidget            *drawing_area;
83   GdkPixmap            *pixmap;
84   GdkWindow            *win;
85   GOutputDev           *out;
86   GdkColor              paper;
87   gint                  w, h;
88   gdouble               zoom;
89   gint                  page;
90 } view_data_t;
91
92 extern "C" {
93   static void realize_drawing_areas (bed_t *bed);
94   static void setup_pixmap (bed_t *doc, view_data_t *view, GdkWindow *window);
95 }
96
97 static void
98 redraw_view (view_data_t *view_data, GdkRectangle *rect)
99 {
100   gint width, height;
101   bed_t *bed = view_data->bed;
102
103   g_return_if_fail (view_data->pixmap != NULL);
104
105   /*
106    * Do not draw outside the region that we know how to display
107    */
108   if (rect->x > view_data->w)
109     return;
110   
111   if (rect->y > view_data->h)
112     return;
113
114   /*
115    * Clip the draw region
116    */
117   if (rect->x + rect->width > view_data->w)
118     rect->width = view_data->w - rect->x;
119   
120   if (rect->y + rect->height > view_data->h)
121     rect->height = view_data->h - rect->y;
122   
123   /*
124    * Draw the exposed region.
125    */
126   gdk_draw_pixmap (view_data->drawing_area->window,
127                    view_data->drawing_area->style->white_gc,
128                    view_data->pixmap,
129                    rect->x, rect->y,
130                    rect->x, rect->y,
131                    rect->width,
132                    rect->height);
133 }
134
135 static void
136 configure_size (view_data_t *view_data)
137 {
138   gtk_widget_set_usize (
139     view_data->drawing_area,
140     view_data->w,
141     view_data->h);
142 }
143
144 static void
145 render_page (view_data_t *view_data)
146 {
147   setup_pixmap (view_data->bed, view_data,
148                 view_data->win);
149   view_data->bed->pdf->displayPage(view_data->out,
150                                    view_data->page, view_data->zoom,
151                                    0, gTrue);
152 }
153
154 static void
155 redraw_view_all (view_data_t *view_data)
156 {
157   GdkRectangle rect;
158   g_return_if_fail (view_data != NULL);
159
160 #if PDF_DEBUG > 0
161   printf ("Redraw view of page %d\n", view_data->page);
162 #endif
163   render_page (view_data);
164   rect.x = 0;
165   rect.y = 0;
166   rect.width  = view_data->w;
167   rect.height = view_data->h;
168   redraw_view (view_data, &rect);
169   gtk_widget_queue_draw (GTK_WIDGET (view_data->drawing_area));
170 }
171
172 static void
173 redraw_all (bed_t *bed)
174 {
175         GList *l;
176         
177         for (l = bed->views; l; l = l->next) {
178           GdkRectangle rect;
179           view_data_t *view_data = (view_data_t *)l->data;
180           redraw_view_all (view_data);
181         }
182 }
183
184 static int
185 save_image (GnomePersistStream *ps, GNOME_Stream stream, void *data)
186 {
187   g_warning ("Unimplemented");
188   return -1;
189 }
190
191 /*
192  * different size ?
193  */
194 static gboolean
195 setup_size (bed_t *doc, view_data_t *view)
196 {
197   int      w, h;
198   gboolean same;
199
200   if (!doc || !view || !doc->pdf) {
201     view->w = 320;
202     view->h = 200;
203     return FALSE;
204   }
205   w = (int)((doc->pdf->getPageWidth  (view->page) * view->zoom) / 72.0);
206   h = (int)((doc->pdf->getPageHeight (view->page) * view->zoom) / 72.0);
207   if (view->w == w && view->h == h)
208     same = TRUE;
209   else
210     same = FALSE;
211   view->w = w;
212   view->h = h;
213
214   return same;
215 }
216
217 /*
218  * Loads a PDF from a GNOME_Stream
219  */
220 static int
221 load_image_from_stream (GnomePersistStream *ps, GNOME_Stream stream, void *data)
222 {
223         bed_t *bed = (bed_t *)data;
224         CORBA_long length;
225         GNOME_Stream_iobuf *buffer;
226         guint lp;
227         #define CHUNK 512
228         FILE *hack;
229         char *name;
230         Object obj;
231
232         if (bed->pdf ||
233             bed->stream) {
234           g_warning ("Won't overwrite pre-existing stream: you wierdo");
235           return 0;
236         }
237
238         /* We need this for later */
239         CORBA_Object_duplicate (stream, &ev);
240         g_return_val_if_fail (ev._major == CORBA_NO_EXCEPTION, 0);
241
242 #if PDF_DEBUG > 0
243         printf ("Loading PDF from persiststream\n");
244 #endif
245         bed->stream = stream;
246         obj.initNull();
247         BonoboStream *bs = new BonoboStream (stream, 0, -1, &obj);
248         bed->pdf = new PDFDoc (bs);
249                                               
250 #if PDF_DEBUG > 0
251         printf ("Done load\n");
252 #endif
253         if (!(bed->pdf->isOk())) {
254           g_warning ("Duff pdf data\n");
255           delete bed->pdf;
256           bed->pdf = NULL;
257         }
258         if (!bed->pdf->getCatalog()) {
259           g_warning ("Duff pdf catalog\n");
260           delete bed->pdf;
261           bed->pdf = NULL;
262         }
263
264         realize_drawing_areas (bed);
265         redraw_all (bed);
266         return 0;
267 }
268
269 extern "C" {
270
271   static void
272   destroy_view (GnomeView *view, view_data_t *view_data)
273   {
274     view_data->bed->views = g_list_remove (view_data->bed->views, view_data);
275     gtk_object_unref (GTK_OBJECT (view_data->drawing_area));
276     
277     g_free (view_data);
278   }
279
280   static void
281   destroy_embed (GnomeView *view, bed_t *bed)
282   {
283     while (bed->views)
284       destroy_view (NULL, (view_data_t *)bed->views->data);
285
286     delete bed->pdf;
287     bed->pdf = NULL;
288     gtk_object_unref (GTK_OBJECT (bed->stream));
289     bed->stream = NULL;
290     g_free (bed);
291
292     embeddable_servers--;
293
294     if (embeddable_servers == 0){
295       gnome_object_unref (GNOME_OBJECT (factory));
296       gtk_main_quit ();
297     }
298   }
299
300   static void
301   setup_pixmap (bed_t *doc, view_data_t *view_data, GdkWindow *window)
302   {
303     GdkGCValues  gcValues;
304     GdkGC       *strokeGC;
305     PDFDoc      *pdf;
306     int          w, h;
307     GdkPixmap   *pixmap = NULL;
308     
309     g_return_if_fail (doc != NULL);
310     g_return_if_fail (doc->pdf != NULL);
311     g_return_if_fail (view_data != NULL);
312     
313     pdf = doc->pdf;
314
315     if (setup_size (doc, view_data) &&
316         view_data->pixmap) {
317 #if PDF_DEBUG > 0
318       printf ("No need to re-init output device\n");
319 #endif
320       return;
321     }
322
323     w = view_data->w;
324     h = view_data->h;
325
326     pixmap = gdk_pixmap_new (window, w, h, -1);
327     
328     gdk_color_white (gtk_widget_get_default_colormap(), &view_data->paper);
329     view_data->out = new GOutputDev (pixmap, view_data->paper, window);
330     
331     gdk_color_white (gtk_widget_get_default_colormap (), &gcValues.foreground);
332     gdk_color_black (gtk_widget_get_default_colormap (), &gcValues.background);
333     gcValues.line_width = 1;
334     gcValues.line_style = GDK_LINE_SOLID;
335     strokeGC = gdk_gc_new_with_values (
336       pixmap, &gcValues, 
337       (enum GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_LINE_WIDTH | GDK_GC_LINE_STYLE));
338     
339     gdk_draw_rectangle (pixmap, strokeGC,
340                         TRUE, 0, 0,
341                         w, h);
342     
343     view_data->pixmap = pixmap;
344     configure_size (view_data);
345   }
346
347   static gboolean
348   view_is_good (view_data_t *view_data)
349   {
350     if (!view_data ||
351         !view_data->bed ||
352         !view_data->bed->pdf)
353       return FALSE;
354
355     return TRUE;
356   }
357
358   static gboolean
359   first_page (view_data_t *view_data)
360   {
361     g_return_val_if_fail (view_is_good (view_data), FALSE);
362     if (view_data->page != 1) {
363       view_data->page = 1;
364       return TRUE;
365     } else
366       return FALSE;
367   }
368
369   static gboolean
370   last_page (view_data_t *view_data)
371   {
372     g_return_val_if_fail (view_is_good (view_data), FALSE);
373     if (view_data->page < view_data->bed->pdf->getNumPages()) {
374       view_data->page = view_data->bed->pdf->getNumPages();
375       return TRUE;
376     } else
377       return FALSE;
378   }
379
380   static gboolean
381   next_page (view_data_t *view_data)
382   {
383     g_return_val_if_fail (view_is_good (view_data), FALSE);
384     if (view_data->page < view_data->bed->pdf->getNumPages()) {
385       view_data->page++;
386       return TRUE;
387     } else
388       return FALSE;
389   }
390
391   static gboolean
392   prev_page (view_data_t *view_data)
393   {
394     g_return_val_if_fail (view_is_good (view_data), FALSE);
395     if (view_data->page > 1) {
396       view_data->page--;
397       return TRUE;
398     } else
399       return FALSE;
400   }
401
402   static void
403   page_first_cb (GnomeUIHandler *uih, void *data, char *path)
404   {
405     first_page ((view_data_t *)data);
406     redraw_view_all ((view_data_t *)data);
407   }
408   
409   static void
410   page_next_cb  (GnomeUIHandler *uih, void *data, char *path)
411   {
412     next_page ((view_data_t *)data);
413     redraw_view_all ((view_data_t *)data);
414   }
415   
416   static void
417   page_prev_cb  (GnomeUIHandler *uih, void *data, char *path)
418   {
419     prev_page ((view_data_t *)data);
420     redraw_view_all ((view_data_t *)data);
421   }
422
423   static void
424   page_last_cb  (GnomeUIHandler *uih, void *data, char *path)
425   {
426     last_page ((view_data_t *)data);
427     redraw_view_all ((view_data_t *)data);
428   }
429 }
430
431 static void
432 view_create_menus (view_data_t *view_data)
433 {
434   GNOME_UIHandler remote_uih;
435   GnomeView *view = view_data->view;
436   GnomeUIHandler *uih;
437   
438   uih = gnome_view_get_ui_handler (view);
439   remote_uih = gnome_view_get_remote_ui_handler (view);
440   
441   if (remote_uih == CORBA_OBJECT_NIL) {
442     g_warning ("server has no UI hander");
443     return;
444   }
445   
446   gnome_ui_handler_set_container (uih, remote_uih);
447
448   gnome_ui_handler_menu_new_subtree (uih, "/Page",
449                                      N_("Page..."),
450                                      N_("Set the currently displayed page"),
451                                      1,
452                                      GNOME_UI_HANDLER_PIXMAP_NONE, NULL,
453                                      0, (GdkModifierType)0);
454
455   gnome_ui_handler_menu_new_item (uih, "/Page/First",
456                                   N_("First"), N_("View the first page"), -1,
457                                   GNOME_UI_HANDLER_PIXMAP_NONE, NULL, 0,
458                                   (GdkModifierType)0, page_first_cb, (gpointer)view_data);
459                                  
460   gnome_ui_handler_menu_new_item (uih, "/Page/Prev",
461                                   N_("Previous"), N_("View the previous page"), -1,
462                                   GNOME_UI_HANDLER_PIXMAP_NONE, NULL, 0,
463                                   (GdkModifierType)0, page_prev_cb, (gpointer)view_data);
464                                  
465   gnome_ui_handler_menu_new_item (uih, "/Page/Next",
466                                   N_("Next"), N_("View the next page"), -1,
467                                   GNOME_UI_HANDLER_PIXMAP_NONE, NULL, 0,
468                                   (GdkModifierType)0, page_next_cb, (gpointer)view_data);
469                                  
470   gnome_ui_handler_menu_new_item (uih, "/Page/Last",
471                                   N_("Last"), N_("View the last page"), -1,
472                                   GNOME_UI_HANDLER_PIXMAP_NONE, NULL, 0,
473                                   (GdkModifierType)0, page_last_cb, (gpointer)view_data);
474
475   gnome_ui_handler_toolbar_new_item (uih, "/First", 
476                                      N_("First"), N_("View the first page"), -1,
477                                      GNOME_UI_HANDLER_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_FIRST,
478                                      0, (GdkModifierType)0, page_first_cb, (gpointer)view_data);
479   gnome_ui_handler_toolbar_new_item (uih, "/Prev",
480                                      N_("Previous"), N_("View the previous page"), -1,
481                                      GNOME_UI_HANDLER_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_BACK,
482                                      0, (GdkModifierType)0, page_prev_cb, (gpointer)view_data);
483   gnome_ui_handler_toolbar_new_item (uih, "/Next",
484                                      N_("Next"), N_("View the next page"), -1,
485                                      GNOME_UI_HANDLER_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_FORWARD,
486                                      0, (GdkModifierType)0, page_next_cb, (gpointer)view_data);
487   gnome_ui_handler_toolbar_new_item (uih, "/Last",
488                                      N_("Last"), N_("View the last page"), -1,
489                                      GNOME_UI_HANDLER_PIXMAP_STOCK, GNOME_STOCK_PIXMAP_LAST,
490                                      0, (GdkModifierType)0, page_last_cb, (gpointer)view_data);
491 }
492
493 /*
494  * When this view is deactivated, we must remove our menu items.
495  */
496 static void
497 view_remove_menus (view_data_t *view_data)
498 {
499         GnomeView *view = view_data->view;
500         GnomeUIHandler *uih;
501
502         uih = gnome_view_get_ui_handler (view);
503
504         gnome_ui_handler_unset_container (uih);
505 }
506
507 extern "C" {
508
509   static void
510   drawing_area_realize (GtkWidget *drawing_area, view_data_t *view_data)
511   {
512     g_return_if_fail (view_data != NULL);
513     g_return_if_fail (drawing_area != NULL);
514
515     view_data->win = gtk_widget_get_parent_window (drawing_area);
516   }
517
518   static int
519   drawing_area_exposed (GtkWidget *widget, GdkEventExpose *event, view_data_t *view_data)
520   {
521     if (!view_data ||
522         !view_data->bed->pdf)
523       return TRUE;
524     
525     redraw_view (view_data, &event->area);
526     
527     return TRUE;
528   }
529
530   static void
531   view_activate (GnomeView *view, gboolean activate, gpointer data)
532   {
533     view_data_t *view_data = (view_data_t *) data;
534     g_return_if_fail (view != NULL);
535     g_return_if_fail (view_data != NULL);
536     
537     gnome_view_activate_notify (view, activate);
538     
539 #if PDF_DEBUG > 0
540     printf ("View change activation to %d\n", activate);
541 #endif
542     /*
543      * If we were just activated, we merge in our menu entries.
544      * If we were just deactivated, we remove them.
545      */
546     if (activate)
547       view_create_menus (view_data);
548     else
549       view_remove_menus (view_data);
550   }
551
552   static void
553   view_size_query (GnomeView *view, int *desired_width, int *desired_height,
554                    gpointer data)
555   {
556     view_data_t *view_data = (view_data_t *) data;
557     
558     g_return_if_fail (view_data != NULL);
559
560     *desired_width  = view_data->w;
561     *desired_height = view_data->h;
562   }
563
564   static void
565   view_zoom_query (GnomeView *view, gdouble new_zoom, gpointer data)
566   {
567     view_data_t *view_data = (view_data_t *) data;
568
569     g_return_if_fail (view_data != NULL);
570
571     /* The rational behind this is that the _entire_ page is allocated
572        regardless of viewport size, so you _really_ don't want it too big ! */
573     g_return_if_fail (new_zoom > 10.0);
574     g_return_if_fail (new_zoom < 180.0);
575
576     view_data->zoom = new_zoom;
577     redraw_view_all (view_data);
578   }
579
580   static void
581   realize_drawing_areas (bed_t *bed)
582   {
583     GList *l;
584     
585     for (l = bed->views; l; l = l->next) {
586       view_data_t *view_data = (view_data_t *)l->data;
587       g_return_if_fail (view_data->win);
588       render_page (view_data);
589       configure_size (view_data);
590     }  
591   }
592
593   static void
594   view_switch_page (GnomeView *view, const char *verb_name, void *user_data)
595   {
596     view_data_t  *view_data = (view_data_t *) user_data;
597     GdkRectangle  rect;
598     gboolean      changed = FALSE;
599
600     if (!g_strcasecmp (verb_name, "firstpage")) {
601       changed = first_page (view_data);
602     } else if (!g_strcasecmp (verb_name, "prevpage")) {
603       changed = prev_page (view_data);
604     } else if (!g_strcasecmp (verb_name, "nextpage")) {
605       changed = next_page (view_data);
606     } else if (!g_strcasecmp (verb_name, "lastpage")) {
607       changed = last_page (view_data);
608     } else
609       g_warning ("Unknown verb");
610
611     if (changed) {
612       render_page (view_data);
613       redraw_view (view_data, &rect);
614       gtk_widget_queue_draw (GTK_WIDGET (view_data->drawing_area));
615     }
616   }
617 }
618
619 static GnomeView *
620 view_factory (GnomeEmbeddable *embeddable,
621               const GNOME_ViewFrame view_frame,
622               void *data)
623 {
624         GnomeView *view;
625         GnomeUIHandler *uih;
626         bed_t *bed = (bed_t *)data;
627         view_data_t *view_data = g_new (view_data_t, 1);
628
629 #if PDF_DEBUG > 0
630         printf ("Created new bonobo object view %p\n", view_data);
631 #endif
632         
633         view_data->scale  = 1.0;
634         view_data->bed    = bed;
635         view_data->drawing_area = gtk_drawing_area_new ();
636         view_data->pixmap = NULL;
637         view_data->win    = NULL;
638         view_data->out    = NULL;
639         view_data->w      = 320;
640         view_data->h      = 320;
641         view_data->zoom   = 43.0; /* 86.0; Must be small for demos :-) */
642         view_data->page   = 1;
643
644         gtk_signal_connect (
645                 GTK_OBJECT (view_data->drawing_area),
646                 "realize",
647                 GTK_SIGNAL_FUNC (drawing_area_realize), view_data);
648
649         gtk_signal_connect (
650                 GTK_OBJECT (view_data->drawing_area),
651                 "expose_event",
652                 GTK_SIGNAL_FUNC (drawing_area_exposed), view_data);
653
654         gtk_widget_show (view_data->drawing_area);
655
656         setup_size (bed, view_data);
657
658         view = gnome_view_new (view_data->drawing_area);
659         view_data->view = view;
660
661         gtk_signal_connect (
662                 GTK_OBJECT (view), "destroy",
663                 GTK_SIGNAL_FUNC (destroy_view), view_data);
664
665         /* UI handling */
666         uih = gnome_ui_handler_new ();
667         gnome_view_set_ui_handler (view, uih);
668
669         gtk_signal_connect (GTK_OBJECT (view), "view_activate",
670                             GTK_SIGNAL_FUNC (view_activate), view_data);
671
672         gtk_signal_connect (GTK_OBJECT (view), "size_query",
673                             GTK_SIGNAL_FUNC (view_size_query), view_data);
674
675         gtk_signal_connect (GTK_OBJECT (view), "set_zoom_factor",
676                             GTK_SIGNAL_FUNC (view_zoom_query), view_data);
677
678         bed->views = g_list_prepend (bed->views, view_data);
679
680         /* Verb handling */
681         gnome_view_register_verb (view, "FirstPage",
682                                   view_switch_page, view_data);
683         gnome_view_register_verb (view, "PrevPage",
684                                   view_switch_page, view_data);
685         gnome_view_register_verb (view, "NextPage",
686                                   view_switch_page, view_data);
687         gnome_view_register_verb (view, "LastPage",
688                                   view_switch_page, view_data);
689
690         return view;
691 }
692
693 static GnomeObject *
694 embeddable_factory (GnomeEmbeddableFactory *This, void *data)
695 {
696         GnomeEmbeddable *embeddable;
697         GnomePersistStream *stream;
698         bed_t *bed = (bed_t *)data;
699
700         bed = g_new0 (bed_t, 1);
701         if (!bed)
702                 return NULL;
703
704 #if PDF_DEBUG > 0
705         printf ("Created new bonobo object %p\n", bed);
706 #endif
707         /*
708          * Creates the BonoboObject server
709          */
710         embeddable = gnome_embeddable_new (view_factory, bed);
711         if (embeddable == NULL){
712                 g_free (bed);
713                 return NULL;
714         }
715
716         bed->pdf = NULL;
717
718         /*
719          * Interface GNOME::PersistStream 
720          */
721         stream = gnome_persist_stream_new ("bonobo-object:image-x-pdf",
722                                            load_image_from_stream,
723                                            save_image,
724                                            bed);
725         if (stream == NULL) {
726                 gtk_object_unref (GTK_OBJECT (embeddable));
727                 g_free (bed);
728                 return NULL;
729         }
730
731         bed->embeddable = embeddable;
732
733         /*
734          * Bind the interfaces
735          */
736         gnome_object_add_interface (GNOME_OBJECT (embeddable),
737                                     GNOME_OBJECT (stream));
738         gtk_signal_connect (
739           GTK_OBJECT (embeddable), "destroy",
740           GTK_SIGNAL_FUNC (destroy_embed), bed);
741
742         embeddable_servers++;
743
744         /* Setup some verbs */
745         gnome_embeddable_add_verb (embeddable,
746                                    "FirstPage",
747                                    _("_First page"),
748                                    _("goto the first page"));
749         gnome_embeddable_add_verb (embeddable,
750                                    "PrevPage",
751                                    _("_Previous page"),
752                                    _("goto the previous page"));
753         gnome_embeddable_add_verb (embeddable,
754                                    "NextPage",
755                                    _("_Next page"),
756                                    _("goto the next page"));
757         gnome_embeddable_add_verb (embeddable,
758                                    "LastPage",
759                                    _("_Last page"),
760                                    _("goto the last page"));
761         
762         return (GnomeObject *) embeddable;
763 }
764
765 static gboolean
766 init_bonobo_image_x_pdf_factory (void)
767 {
768         factory = gnome_embeddable_factory_new (
769                 "bonobo-object-factory:image-x-pdf",
770                 embeddable_factory, NULL);
771
772         if (factory == NULL)
773                 return FALSE;
774         else
775                 return TRUE;
776 }
777
778 static void
779 init_server_factory (int argc, char **argv)
780 {
781         gnome_CORBA_init_with_popt_table (
782                 "bonobo-image-x-pdf", "1.0",
783                 &argc, argv, NULL, 0, NULL, GNORBA_INIT_SERVER_FUNC, &ev);
784
785         if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE)
786                 g_error (_("I could not initialize Bonobo"));
787 }
788
789 int
790 main (int argc, char *argv [])
791 {
792   CORBA_exception_init (&ev);
793   
794   init_server_factory (argc, argv);
795   if (!init_bonobo_image_x_pdf_factory ()){
796     fprintf (stderr, "Could not initialize the Bonobo PDF factory\n"
797                      "probably a server is already running?");
798     exit (1);
799   }
800   
801   errorInit();
802   
803   initParams (xpdfConfigFile); /* Init font path */
804   
805   gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
806   gtk_widget_set_default_visual (gdk_rgb_get_visual ());
807
808   bonobo_main ();
809   
810   CORBA_exception_free (&ev);
811   
812   return 0;
813 }