summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2005-03-03 19:45:58 +0000
committerKristian Høgsberg <krh@redhat.com>2005-03-03 19:45:58 +0000
commitcb02d5d0e770e2a8cbe5a8ac810820a2ce5fec0c (patch)
tree89a707862fc867a1aaa879ad3f6fbfb5f16a0a30 /test
Initial revision
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am48
-rw-r--r--test/gtk-cairo-test.cc298
-rw-r--r--test/gtk-splash-test.cc314
3 files changed, 660 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 00000000..c9f41b94
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,48 @@
+if BUILD_GTK_TEST
+
+if BUILD_SPLASH_OUTPUT
+
+gtk_splash_test = \
+ gtk-splash-test
+
+splash_includes = \
+ -I$(top_srcdir)/splash
+
+endif
+
+if BUILD_CAIRO_OUTPUT
+
+gtk_cairo_test = \
+ gtk-cairo-test
+
+cairo_includes = \
+ $(CAIRO_CFLAGS)
+
+endif
+
+endif
+
+
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/poppler \
+ $(cairo_includes) \
+ $(GTK_TEST_CFLAGS) \
+ -DDATADIR=\""$(datadir)"\"
+
+noinst_PROGRAMS = $(gtk_splash_test) $(gtk_cairo_test)
+
+gtk_splash_test_SOURCES = \
+ gtk-splash-test.cc
+
+gtk_splash_test_LDADD = \
+ $(top_builddir)/poppler/libpoppler.la \
+ $(GTK_TEST_LIBS)
+
+gtk_cairo_test_SOURCES = \
+ gtk-cairo-test.cc
+
+gtk_cairo_test_LDADD = \
+ $(top_builddir)/poppler/libpoppler.la \
+ $(CAIRO_LIBS) \
+ $(GTK_TEST_LIBS)
diff --git a/test/gtk-cairo-test.cc b/test/gtk-cairo-test.cc
new file mode 100644
index 00000000..59653911
--- /dev/null
+++ b/test/gtk-cairo-test.cc
@@ -0,0 +1,298 @@
+//========================================================================
+//
+// GDKSplashOutputDev.cc
+//
+// Copyright 2003 Glyph & Cog, LLC
+// Copyright 2004 Red Hat, Inc. (GDK port)
+//
+//========================================================================
+
+#include <config.h>
+
+#ifdef USE_GCC_PRAGMAS
+#pragma implementation
+#endif
+
+#include <goo/gmem.h>
+#include <splash/SplashTypes.h>
+#include <splash/SplashBitmap.h>
+#include "Object.h"
+#include "GfxState.h"
+
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+#include "CairoOutputDev.h"
+#include <cairo-xlib.h>
+
+#include "PDFDoc.h"
+#include "GlobalParams.h"
+#include "ErrorCodes.h"
+#include <gtk/gtk.h>
+
+class GDKCairoOutputDev: public CairoOutputDev {
+public:
+
+ GDKCairoOutputDev(GdkDrawable *drawable,
+ void (*redrawCbkA)(void *data),
+ void *redrawCbkDataA);
+
+ virtual ~GDKCairoOutputDev();
+
+ virtual void GDKCairoOutputDev::createCairo(GfxState *state);
+
+ //----- special access
+
+ // Clear out the document (used when displaying an empty window).
+ void clear();
+
+ // Copy the rectangle (srcX, srcY, width, height) to (destX, destY)
+ // in destDC.
+ void redraw(int srcX, int srcY,
+ GdkDrawable *drawable,
+ int destX, int destY,
+ int width, int height);
+
+ int getPixmapWidth (void) { return pixmapWidth; }
+ int getPixmapHeight (void) { return pixmapHeight; }
+
+private:
+
+ int incrementalUpdate;
+ void (*redrawCbk)(void *data);
+ void *redrawCbkData;
+ int pixmapWidth, pixmapHeight;
+ GdkPixmap *pixmap, *drawable;
+};
+
+GDKCairoOutputDev::GDKCairoOutputDev(GdkDrawable *drawableA,
+ void (*redrawCbkA)(void *data),
+ void *redrawCbkDataA):
+ CairoOutputDev()
+{
+ drawable = drawableA;
+ redrawCbk = redrawCbkA;
+ redrawCbkData = redrawCbkDataA;
+ pixmap = NULL;
+ createCairo (NULL);
+}
+
+GDKCairoOutputDev::~GDKCairoOutputDev() {
+}
+
+void
+GDKCairoOutputDev::createCairo(GfxState *state) {
+ Display *display;
+ Drawable xid;
+ GdkGC *gc;
+ GdkColor white;
+ int w, h;
+
+ cairo = cairo_create ();
+
+ w = state ? (int)(state->getPageWidth() + 0.5) : 1;
+ h = state ? (int)(state->getPageHeight() + 0.5) : 1;
+
+ if (!pixmap || pixmapWidth != w || h != pixmapHeight != h) {
+ if (pixmap)
+ g_object_unref (G_OBJECT (pixmap));
+
+ pixmap = gdk_pixmap_new (drawable, w, h, -1);
+ pixmapWidth = w;
+ pixmapHeight = h;
+
+ gc = gdk_gc_new (pixmap);
+ white.red = 0xffff;
+ white.green = 0xffff;
+ white.blue = 0xffff;
+ gdk_gc_set_rgb_fg_color (gc, &white);
+ gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, w, h);
+ g_object_unref (G_OBJECT (gc));
+ }
+
+ if (pixmap) {
+ display = gdk_x11_drawable_get_xdisplay (pixmap);
+ xid = gdk_x11_drawable_get_xid (pixmap);
+
+ cairo_set_target_drawable (cairo, display, xid);
+ }
+}
+
+void GDKCairoOutputDev::redraw(int srcX, int srcY,
+ GdkDrawable *drawable,
+ int destX, int destY,
+ int width, int height) {
+ GdkGC *gc;
+ int gdk_rowstride;
+
+ gc = gdk_gc_new (drawable);
+ gdk_draw_drawable (drawable, gc,
+ pixmap, srcX, srcY,
+ destX, destY, width, height);
+ g_object_unref (gc);
+}
+
+typedef struct
+{
+ GtkWidget *window;
+ GtkWidget *sw;
+ GtkWidget *drawing_area;
+ GDKCairoOutputDev *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->getPixmapWidth();
+ document.height = v->out->getPixmapHeight();
+
+ 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->getPixmapWidth();
+ h = v->out->getPixmapHeight();
+
+ 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);
+ gtk_widget_realize (window);
+
+ v = g_new0 (View, 1);
+
+ v->window = window;
+ v->drawing_area = drawing_area;
+ v->sw = sw;
+ v->out = new GDKCairoOutputDev (window->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);
+
+ if (argc == 1)
+ {
+ fprintf (stderr, "usage: %s PDF-FILES...\n", argv[0]);
+ return -1;
+ }
+
+
+ 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;
+}
diff --git a/test/gtk-splash-test.cc b/test/gtk-splash-test.cc
new file mode 100644
index 00000000..6925cd5d
--- /dev/null
+++ b/test/gtk-splash-test.cc
@@ -0,0 +1,314 @@
+//========================================================================
+//
+// GDKSplashOutputDev.cc
+//
+// Copyright 2003 Glyph & Cog, LLC
+// Copyright 2004 Red Hat, Inc. (GDK port)
+//
+//========================================================================
+
+#include <config.h>
+
+#ifdef USE_GCC_PRAGMAS
+#pragma implementation
+#endif
+
+#include <goo/gmem.h>
+#include <splash/SplashTypes.h>
+#include <splash/SplashBitmap.h>
+#include "SplashOutputDev.h"
+#include "Object.h"
+#include "GfxState.h"
+
+#include <gdk/gdk.h>
+
+#include "PDFDoc.h"
+#include "GlobalParams.h"
+#include "ErrorCodes.h"
+#include <gtk/gtk.h>
+
+//------------------------------------------------------------------------
+
+#define xOutMaxRGBCube 6 // max size of RGB color cube
+
+//------------------------------------------------------------------------
+// GDKSplashOutputDev
+//------------------------------------------------------------------------
+
+class GDKSplashOutputDev: public SplashOutputDev {
+public:
+
+ GDKSplashOutputDev(GdkScreen *screen,
+ void (*redrawCbkA)(void *data),
+ void *redrawCbkDataA);
+
+ virtual ~GDKSplashOutputDev();
+
+ //----- initialization and control
+
+ // End a page.
+ virtual void endPage();
+
+ // Dump page contents to display.
+ virtual void dump();
+
+ //----- update text state
+ virtual void updateFont(GfxState *state);
+
+ //----- special access
+
+ // Clear out the document (used when displaying an empty window).
+ void clear();
+
+ // Copy the rectangle (srcX, srcY, width, height) to (destX, destY)
+ // in destDC.
+ void redraw(int srcX, int srcY,
+ GdkDrawable *drawable,
+ int destX, int destY,
+ int width, int height);
+
+private:
+
+ int incrementalUpdate;
+ void (*redrawCbk)(void *data);
+ void *redrawCbkData;
+};
+
+//------------------------------------------------------------------------
+// Constants and macros
+//------------------------------------------------------------------------
+
+#define xoutRound(x) ((int)(x + 0.5))
+
+//------------------------------------------------------------------------
+// GDKSplashOutputDev
+//------------------------------------------------------------------------
+
+static SplashColor makeSplashColor(int r, int g, int b)
+{
+ SplashColor c;
+ c.rgb8 = splashMakeRGB8 (r, g, b);
+ return c;
+}
+
+GDKSplashOutputDev::GDKSplashOutputDev(GdkScreen *screen,
+ void (*redrawCbkA)(void *data),
+ void *redrawCbkDataA):
+ SplashOutputDev(splashModeRGB8Packed, gFalse, makeSplashColor (255,255,255)),
+ incrementalUpdate (1)
+{
+ redrawCbk = redrawCbkA;
+ redrawCbkData = redrawCbkDataA;
+}
+
+GDKSplashOutputDev::~GDKSplashOutputDev() {
+}
+
+void GDKSplashOutputDev::clear() {
+ startDoc(NULL);
+ startPage(0, NULL);
+}
+
+void GDKSplashOutputDev::endPage() {
+ SplashOutputDev::endPage();
+ if (!incrementalUpdate) {
+ (*redrawCbk)(redrawCbkData);
+ }
+}
+
+void GDKSplashOutputDev::dump() {
+ if (incrementalUpdate && redrawCbk) {
+ (*redrawCbk)(redrawCbkData);
+ }
+}
+
+void GDKSplashOutputDev::updateFont(GfxState *state) {
+ SplashOutputDev::updateFont(state);
+}
+
+void GDKSplashOutputDev::redraw(int srcX, int srcY,
+ GdkDrawable *drawable,
+ int destX, int destY,
+ int width, int height) {
+ GdkGC *gc;
+ int gdk_rowstride;
+
+ gdk_rowstride = getBitmap()->getRowSize();
+ gc = gdk_gc_new (drawable);
+
+ gdk_draw_rgb_image (drawable, gc,
+ destX, destY,
+ width, height,
+ GDK_RGB_DITHER_NORMAL,
+ getBitmap()->getDataPtr().rgb8p + srcY * gdk_rowstride + srcX * 3,
+ gdk_rowstride);
+
+ g_object_unref (gc);
+}
+
+
+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);
+
+ if (argc == 1)
+ {
+ fprintf (stderr, "usage: %s PDF-FILES...\n", argv[0]);
+ return -1;
+ }
+
+
+ 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;
+}