gint gpdf_debug=1;
poptContext ctx;
+#define DEV_DEBUG 0
+
+double zoom = 86.0;
+gint page = 2;
+
#define DOC_KEY "xpdf_doc_key"
struct DOC_ROOT {
GString *title;
PDFDoc *pdf;
GtkDrawingArea *area;
- GdkPixmap *pixmap;
+ GtkPixmap *pixmap;
OutputDev *out;
GdkColor paper;
GtkScrolledWindow *scroll;
// loadFile / displayPage
//------------------------------------------------------------------------
-static gint
-doc_config_event (GtkWidget *widget, void *ugly)
+static void
+get_page_geom (int *w, int *h, Page *p)
{
- DOC_ROOT *doc;
+ double pw = p->getWidth();
+ double ph = p->getHeight();
- doc = (DOC_ROOT *)gtk_object_get_data (GTK_OBJECT (widget), DOC_KEY);
-
- g_return_val_if_fail (doc, FALSE);
+ *w = 612;
+ *h = 792;
- if (doc->pixmap)
- gdk_pixmap_unref(doc->pixmap);
+ if (!p)
+ return;
+
+ *w = (int)((pw * zoom)/72.0 + 28.0);
+ *h = (int)((ph * zoom)/72.0 + 56.0);
+}
+
+static GdkPixmap *
+setup_pixmap (DOC_ROOT *doc, GdkWindow *window)
+{
+ GdkGCValues gcValues;
+ GdkGC *strokeGC;
+ PDFDoc *pdf = doc->pdf;
+ int w, h;
+ GdkPixmap *pixmap = NULL;
+
+ if (pixmap)
+ gdk_pixmap_unref(pixmap);
- doc->pixmap = gdk_pixmap_new(widget->window,
- widget->allocation.width,
- widget->allocation.height,
- -1);
+ Catalog *cat = pdf->getCatalog();
+ get_page_geom (&w, &h, cat->getPage (page));
- printf ("Creating pixmap of size %d %d\n",
- widget->allocation.width, widget->allocation.height);
+ pixmap = gdk_pixmap_new (window, w, h, -1);
+ gtk_widget_set_usize (GTK_WIDGET (doc->scroll), w, h);
+
+ printf ("Creating pixmap of size %d %d\n", w, h);
gdk_color_white (gtk_widget_get_default_colormap(), &doc->paper);
- doc->out = new GOutputDev (doc->pixmap, doc->paper,
- gtk_widget_get_parent_window (widget));
+ doc->out = new GOutputDev (pixmap, doc->paper, window);
+
+ gdk_color_white (gtk_widget_get_default_colormap (), &gcValues.foreground);
+ gdk_color_black (gtk_widget_get_default_colormap (), &gcValues.background);
+ gcValues.line_width = 1;
+ gcValues.line_style = GDK_LINE_SOLID;
+ strokeGC = gdk_gc_new_with_values (
+ pixmap, &gcValues,
+ (enum GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_LINE_WIDTH | GDK_GC_LINE_STYLE));
+
+ gdk_draw_rectangle (pixmap, strokeGC,
+ TRUE, 0, 0,
+ w, h);
+ return pixmap;
+}
+/*static gint
+doc_config_event (GtkWidget *widget, void *ugly)
+{
+ DOC_ROOT *doc;
+
+ doc = (DOC_ROOT *)gtk_object_get_data (GTK_OBJECT (widget), DOC_KEY);
+
+ g_return_val_if_fail (doc, FALSE);
- {
- GdkGCValues gcValues;
- GdkGC *strokeGC;
-
- gdk_color_white (gtk_widget_get_default_colormap (), &gcValues.foreground);
- gdk_color_black (gtk_widget_get_default_colormap (), &gcValues.background);
- gcValues.line_width = 1;
- gcValues.line_style = GDK_LINE_SOLID;
- strokeGC = gdk_gc_new_with_values (
- doc->pixmap, &gcValues,
- (enum GdkGCValuesMask)(GDK_GC_FOREGROUND | GDK_GC_BACKGROUND | GDK_GC_LINE_WIDTH | GDK_GC_LINE_STYLE));
-
- gdk_draw_rectangle (doc->pixmap,
- strokeGC,
- TRUE,
- 0, 0,
- widget->allocation.width,
- widget->allocation.height);
- }
return TRUE;
}
g_return_val_if_fail (doc != NULL, FALSE);
if (doc->out && doc->pdf) {
+#if DEV_DEBUG > 0
printf ("There are %d pages\n", doc->pdf->getNumPages());
+#endif
doc->pdf->displayPage(doc->out, 1, 86, 0, gTrue);
gdk_draw_pixmap(widget->window,
printf ("Null pointer error %p %p\n", doc->out, doc->pdf);
return FALSE;
-}
+}*/
static PDFDoc *
getPDF (GString *fname)
DOC_ROOT *doc = new DOC_ROOT();
GtkVBox *pane;
GtkAdjustment *hadj, *vadj;
+ GdkPixmap *pix;
// open PDF file
doc->pdf = getPDF (fileName);
delete doc;
return gFalse;
}
+/* glade_xml_signal_autoconnect (doc->gui);*/
- doc->pixmap = NULL;
- doc->area = GTK_DRAWING_AREA (gtk_drawing_area_new ());
-
- gtk_object_set_data (GTK_OBJECT (doc->area), DOC_KEY, doc);
- gtk_signal_connect (GTK_OBJECT (doc->area),"configure_event",
- (GtkSignalFunc) doc_config_event, doc);
- gtk_signal_connect (GTK_OBJECT (doc->area), "expose_event",
- (GtkSignalFunc) doc_redraw_event, doc);
-
- hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 2));
- vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 2));
- doc->scroll = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (hadj, vadj));
- gtk_scrolled_window_add_with_viewport (doc->scroll, GTK_WIDGET (doc->area));
+ pix = setup_pixmap (doc, gtk_widget_get_parent_window (GTK_WIDGET (pane)));
+ doc->pixmap = GTK_PIXMAP (gtk_pixmap_new (pix, NULL));
+
+ doc->scroll = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
+ gtk_scrolled_window_set_policy (doc->scroll, GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ doc->pdf->displayPage(doc->out, page, zoom, 0, gTrue);
+ gtk_scrolled_window_add_with_viewport (doc->scroll, GTK_WIDGET (doc->pixmap));
gtk_box_pack_start (GTK_BOX (pane), GTK_WIDGET (doc->scroll), TRUE, TRUE, 0);
gtk_widget_show_all (doc->mainframe);
win->setBusyCursor(gFalse);
}*/
+extern "C" {
+ void
+ on_close_activate (GtkWidget *window, void *data)
+ {
+ printf ("Bye...");
+ gtk_widget_destroy (window);
+ }
+}
int
main (int argc, char *argv [])