diff options
author | Kristian Høgsberg <krh@redhat.com> | 2005-03-01 22:24:10 (GMT) |
---|---|---|
committer | Kristian Høgsberg <krh@src.gnome.org> | 2005-03-01 22:24:10 (GMT) |
commit | 02eb16fef45712a91e24f6471b9e2f31249c888e (patch) | |
tree | d5579258f1d7fbd5a280fb2f1b97b74004b1dea9 /pdf/test-gdk-output-dev.cc | |
parent | 332afee84ff4eb7df326d96f07efd6f82a87c0a2 (diff) |
Use poppler instead of including xpdf source code. Poppler is a fork of
2005-03-01 Kristian Høgsberg <krh@redhat.com>
Use poppler instead of including xpdf source code. Poppler is a
fork of xpdf to build it as a shared library. See
http://freedesktop.org/wiki/Software/poppler.
* pdf/xpdf/*, pdf/goo/*, pdf/splash/*, pdf/fofi/*: Remove included
xpdf fork.
* pdf/Makefile.am: Build libpdfdocument.a here.
* pdf/GDKSplashOutputDev.cc:
* pdf/GDKSplashOutputDev.h:
* pdf/GnomeVFSStream.cc:
* pdf/GnomeVFSStream.h:
* pdf-document.cc:
* pdf-document.h:
* test-gdk-output-dev.cc
* Thumb.cc:
* Thumb.h: Pull these files out of pdf/xpdf and adjust to compile
against poppler.
Diffstat (limited to 'pdf/test-gdk-output-dev.cc')
-rw-r--r-- | pdf/test-gdk-output-dev.cc | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/pdf/test-gdk-output-dev.cc b/pdf/test-gdk-output-dev.cc new file mode 100644 index 0000000..713cd24 --- /dev/null +++ b/pdf/test-gdk-output-dev.cc @@ -0,0 +1,174 @@ +/** + * render a PDF to GDKSplashOutputDev + * + * Copyright 2004 Red Hat, Inc. + */ + +#include <stdio.h> +#include <stdlib.h> + +#include <gtk/gtk.h> + +#include <GlobalParams.h> +#include <PDFDoc.h> +#include <ErrorCodes.h> +#include "GDKSplashOutputDev.h" + +typedef struct +{ + GtkWidget *window; + GtkWidget *sw; + GtkWidget *drawing_area; + GDKSplashOutputDev *out; + PDFDoc *doc; +} View; + +static void +drawing_area_expose (GtkWidget *drawing_area, + GdkEventExpose *event, + void *data) +{ + View *v = (View*) data; + int x, y, w, h; + GdkRectangle document; + GdkRectangle draw; + + gdk_window_clear (drawing_area->window); + + document.x = 0; + document.y = 0; + document.width = v->out->getBitmapWidth(); + document.height = v->out->getBitmapHeight(); + + if (gdk_rectangle_intersect (&document, &event->area, &draw)) + { + v->out->redraw (draw.x, draw.y, + drawing_area->window, + draw.x, draw.y, + draw.width, draw.height); + } +} + +static int +view_load (View *v, + const char *filename) +{ + PDFDoc *newDoc; + int err; + GooString *filename_g; + GtkAdjustment *hadj; + GtkAdjustment *vadj; + int w, h; + + filename_g = new GooString (filename); + + // open the PDF file + newDoc = new PDFDoc(filename_g, 0, 0); + + delete filename_g; + + if (!newDoc->isOk()) + { + err = newDoc->getErrorCode(); + delete newDoc; + return err; + } + + if (v->doc) + delete v->doc; + v->doc = newDoc; + + v->out->startDoc(v->doc->getXRef()); + + v->doc->displayPage (v->out, 1, 72, 72, 0, gTrue, gTrue); + + w = v->out->getBitmapWidth(); + h = v->out->getBitmapHeight(); + + gtk_widget_set_size_request (v->drawing_area, w, h); +} + +static void +view_show (View *v) +{ + gtk_widget_show (v->window); +} + +static void +redraw_callback (void *data) +{ + View *v = (View*) data; + + gtk_widget_queue_draw (v->drawing_area); +} + +static View* +view_new (void) +{ + View *v; + GtkWidget *window; + GtkWidget *drawing_area; + GtkWidget *sw; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + drawing_area = gtk_drawing_area_new (); + + sw = gtk_scrolled_window_new (NULL, NULL); + + gtk_container_add (GTK_CONTAINER (window), sw); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), drawing_area); + + gtk_widget_show_all (sw); + + v = g_new0 (View, 1); + + v->window = window; + v->drawing_area = drawing_area; + v->sw = sw; + v->out = new GDKSplashOutputDev (gtk_widget_get_screen (window), + redraw_callback, (void*) v); + v->doc = 0; + + g_signal_connect (drawing_area, + "expose_event", + G_CALLBACK (drawing_area_expose), + (void*) v); + + return v; +} + +int +main (int argc, char *argv []) +{ + View *v; + int i; + + gtk_init (&argc, &argv); + + globalParams = new GlobalParams("/etc/xpdfrc"); + globalParams->setupBaseFonts(NULL); + + i = 1; + while (i < argc) + { + int err; + + v = view_new (); + + err = view_load (v, argv[i]); + + if (err != errNone) + g_printerr ("Error loading document!\n"); + + view_show (v); + + ++i; + } + + gtk_main (); + + delete globalParams; + + return 0; +} |