Commit f9b6017c authored by Kristian Høgsberg's avatar Kristian Høgsberg

2005-03-19 Kristian Høgsberg <krh@redhat.com>

        Land the first bits of the glib wrapper.

        * Makefile.am:
        * configure.ac: Add new glib subdirectory and configure options
        for glib wrapper.

        * glib/Makefile.am:
        * glib/poppler-document.cc:
        * glib/poppler-document.h:
        * glib/poppler-page.cc:
        * glib/poppler-page.h:
        * glib/poppler-private.h:
        * glib/poppler.cc:
        * glib/poppler.h:
        * glib/test-poppler-glib.c:
        * poppler-glib.pc.in: New files.
parent 2a31446b
2005-03-19 Kristian Høgsberg <krh@redhat.com>
Land the first bits of the glib wrapper.
* Makefile.am:
* configure.ac: Add new glib subdirectory and configure options
for glib wrapper.
* glib/Makefile.am:
* glib/poppler-document.cc:
* glib/poppler-document.h:
* glib/poppler-page.cc:
* glib/poppler-page.h:
* glib/poppler-private.h:
* glib/poppler.cc:
* glib/poppler.h:
* glib/test-poppler-glib.c:
* poppler-glib.pc.in: New files.
2005-03-16 Jeff Muizelaar <jrmuizel@nit.ca>
From Dan Sheridan <dan.sheridan@postman.org.uk>
......
if BUILD_SPLASH_OUTPUT
splash_subdir = splash
splash_pc_file = poppler-splash.pc
endif
if BUILD_CAIRO_OUTPUT
cairo_pc_file = poppler-cairo.pc
endif
SUBDIRS = goo fofi $(splash_subdir) poppler test
if BUILD_POPPLER_GLIB
glib_subdir = glib
glib_pc_file = poppler-glib.pc
endif
SUBDIRS = goo fofi $(splash_subdir) poppler $(glib_subdir) test
EXTRA_DIST = \
README-XPDF \
......@@ -10,20 +20,9 @@ EXTRA_DIST = \
poppler-cairo.pc.in \
poppler-splash.pc.in
if BUILD_SPLASH_OUTPUT
splash_pc_file = poppler-splash.pc
endif
if BUILD_CAIRO_OUTPUT
cairo_pc_file = poppler-cairo.pc
endif
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = \
poppler.pc \
$(cairo_pc_file) \
$(splash_pc_file)
$(splash_pc_file) \
$(glib_pc_file)
Release 0.2.0 (Not out yet...)
- Add glib wrapper for poppler
Release 0.1.2 (Wed Mar 9 10:45:58 EST 2005)
- cairo optimizations and fixes from Jeff Muizelaar
......
......@@ -154,15 +154,31 @@ elif test x$enable_cairo_output = xtry; then
fi
AM_CONDITIONAL(BUILD_CAIRO_OUTPUT, test x$enable_cairo_output = xyes)
AC_ARG_ENABLE(popper-glib,
AC_HELP_STRING([--disable-poppler-glib],
[Don't compile poppler glib wrapper.]),
enable_poppler_glib=$enableval,
enable_poppler_glib="try")
if test x$enable_poppler_glib = xyes; then
PKG_CHECK_MODULES(POPPLER_GLIB, gdk-pixbuf-2.0)
elif test x$enable_poppler_glib = xtry; then
PKG_CHECK_MODULES(POPPLER_GLIB, gdk-pixbuf-2.0,
[enable_poppler_glib="yes"],
[enable_poppler_glib="no"])
fi
AM_CONDITIONAL(BUILD_POPPLER_GLIB, test x$enable_poppler_glib = xyes)
AC_ARG_ENABLE(gtk-test,
AC_HELP_STRING([--disable-gtk-test],
[Don't compile GTK+ test program.]),
enable_gtk_test=$enableval,
enable_gtk_test="try")
if test x$enable_gtk_test = xyes; then
PKG_CHECK_MODULES(GTK_TEST, gtk+-2.0 >= 2.2.0)
PKG_CHECK_MODULES(GTK_TEST, gtk+-2.0 >= 2.2.0 gdk-pixbuf-2.0)
elif test x$enable_gtk_test = xtry; then
PKG_CHECK_MODULES(GTK_TEST, gtk+-2.0 >= 2.2.0,
PKG_CHECK_MODULES(GTK_TEST, gtk+-2.0 >= 2.2.0 gdk-pixbuf-2.0,
[enable_gtk_test="yes"],
[enable_gtk_test="no"])
fi
......@@ -195,14 +211,17 @@ goo/Makefile
fofi/Makefile
splash/Makefile
poppler/Makefile
glib/Makefile
test/Makefile
poppler.pc
poppler-cairo.pc
poppler-splash.pc])
poppler-splash.pc
poppler-glib.pc])
echo ""
echo "Building poppler with support for:"
echo " splash output: $enable_splash_output"
echo " cairo output: $enable_cairo_output"
echo " glib wrapper: $enable_poppler_glib"
echo " use libjpeg: $enable_libjpeg"
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/poppler \
$(cairo_includes) \
$(GTK_TEST_CFLAGS) \
-DDATADIR=\""$(datadir)"\"
poppler_glib_includedir = $(includedir)/poppler/glib
poppler_glib_include_HEADERS = \
poppler-document.h \
poppler-page.h \
poppler.h
lib_LTLIBRARIES = libpoppler-glib.la
libpoppler_glib_la_SOURCES = \
poppler-document.cc \
poppler-page.cc \
poppler.cc \
poppler-private.h
libpoppler_glib_la_LIBADD = \
$(GTK_TEST_LIBS)
noinst_PROGRAMS = test-poppler-glib
test_poppler_glib_SOURCES = \
test-poppler-glib.c
test_poppler_glib_LDADD = \
$(top_builddir)/poppler/libpoppler.la \
libpoppler-glib.la \
$(GTK_TEST_LIBS)
/* poppler-glib.h: glib wrapper for poppler
* Copyright (C) 2005, Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <goo/GooList.h>
#include <splash/SplashBitmap.h>
#include <GlobalParams.h>
#include <PDFDoc.h>
#include <Outline.h>
#include <ErrorCodes.h>
#include <UnicodeMap.h>
#include <GfxState.h>
#include <SplashOutputDev.h>
#include "poppler.h"
#include "poppler-private.h"
#define POPPLER_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), POPPLER_TYPE_DOCUMENT, PopplerDocumentClass))
#define POPPLER_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), POPPLER_TYPE_DOCUMENT))
#define POPPLER_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), POPPLER_TYPE_DOCUMENT, PopplerDocumentClass))
typedef struct _PopplerDocumentClass PopplerDocumentClass;
struct _PopplerDocumentClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE (PopplerDocument, poppler_document, G_TYPE_OBJECT);
PopplerDocument *
poppler_document_new_from_file (const char *uri,
const char *password,
GError **error)
{
PopplerDocument *document;
PDFDoc *newDoc;
GooString *filename_g;
GooString *password_g;
GooString *enc;
int err;
char *filename;
document = (PopplerDocument *) g_object_new (POPPLER_TYPE_DOCUMENT, NULL);
if (!globalParams) {
globalParams = new GlobalParams("/etc/xpdfrc");
globalParams->setupBaseFontsFc(NULL);
}
filename = g_filename_from_uri (uri, NULL, error);
if (!filename)
return NULL;
filename_g = new GooString (filename);
g_free (filename);
password_g = NULL;
if (password != NULL)
password_g = new GooString (password);
newDoc = new PDFDoc(filename_g, password_g, password_g);
if (password_g)
delete password_g;
if (!newDoc->isOk()) {
err = newDoc->getErrorCode();
delete newDoc;
if (err == errEncrypted) {
g_set_error (error, POPPLER_ERROR,
POPPLER_ERROR_ENCRYPTED,
"Document is encrypted.");
} else {
g_set_error (error, G_FILE_ERROR,
G_FILE_ERROR_FAILED,
"Failed to load document (error %d) '%s'\n",
err,
uri);
}
return NULL;
}
document->doc = newDoc;
return document;
}
static void
poppler_document_finalize (GObject *object)
{
PopplerDocument *document = POPPLER_DOCUMENT (object);
delete document->doc;
}
static gboolean
popper_document_save (PopplerDocument *document,
const char *uri,
GError **error)
{
char *filename;
gboolean retval = FALSE;
g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), FALSE);
filename = g_filename_from_uri (uri, NULL, error);
if (filename != NULL) {
GooString *filename_g = new GooString (filename);
retval = document->doc->saveAs (filename_g);
}
return retval;
}
int
poppler_document_get_n_pages (PopplerDocument *document)
{
g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), 0);
return document->doc->getNumPages();
}
PopplerPage *
poppler_document_get_page (PopplerDocument *document,
int index)
{
Catalog *catalog;
Page *page;
g_return_val_if_fail (0 <= index &&
index < poppler_document_get_n_pages (document),
NULL);
catalog = document->doc->getCatalog();
page = catalog->getPage (index + 1);
return _poppler_page_new (document, page);
}
static void
poppler_document_class_init (PopplerDocumentClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = poppler_document_finalize;
}
static void
poppler_document_init (PopplerDocument *document)
{
}
/* poppler-document.h: glib interface to poppler
* Copyright (C) 2004, Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __POPPLER_DOCUMENT_H__
#define __POPPLER_DOCUMENT_H__
#include <glib-object.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "poppler-glib.h"
G_BEGIN_DECLS
#define POPPLER_TYPE_DOCUMENT (poppler_document_get_type ())
#define POPPLER_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_DOCUMENT, PopplerDocument))
#define POPPLER_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_DOCUMENT))
typedef struct _PopplerDocument PopplerDocument;
typedef struct _PopplerPage PopplerPage;
PopplerDocument *poppler_document_new_from_file (const char *uri,
const char *password,
GError **error);
PopplerDocument *poppler_document_save (PopplerDocument *document,
const char *uri,
GError **error);
GType poppler_document_get_type (void) G_GNUC_CONST;
int poppler_document_get_n_pages (PopplerDocument *document);
PopplerPage *poppler_document_get_page (PopplerDocument *document,
int page);
G_END_DECLS
#endif /* __POPPLER_DOCUMENT_H__ */
/* poppler-glib.h: glib wrapper for poppler
* Copyright (C) 2005, Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <goo/GooList.h>
#include <splash/SplashBitmap.h>
#include <GlobalParams.h>
#include <PDFDoc.h>
#include <Outline.h>
#include <ErrorCodes.h>
#include <UnicodeMap.h>
#include <GfxState.h>
#include <SplashOutputDev.h>
#include "poppler.h"
#include "poppler-private.h"
typedef struct _PopplerPageClass PopplerPageClass;
struct _PopplerPageClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE (PopplerPage, poppler_page, G_TYPE_OBJECT);
PopplerPage *
_poppler_page_new (PopplerDocument *document, Page *page)
{
PopplerPage *poppler_page;
poppler_page = (PopplerPage *) g_object_new (POPPLER_TYPE_PAGE, NULL);
poppler_page->document = document;
poppler_page->page = page;
return poppler_page;
}
static void
poppler_page_finalize (GObject *object)
{
/* page->page is owned by the document */
}
void
poppler_page_get_dimensions (PopplerPage *page,
double *width,
double *height)
{
if (width != NULL)
*width = page->page->getWidth ();
if (height != NULL)
*height = page->page->getHeight ();
}
/**
* poppler_page_render_to_pixbuf:
* @page: the page to render from
* @src_x: x coordinate of upper left corner
* @src_y: y coordinate of upper left corner
* @src_width: width of rectangle to render
* @src_height: height of rectangle to render
* @ppp: pixels per point
* @pixbuf: pixbuf to render into
* @dest_x: x coordinate of offset into destination
* @dest_y: y cooridnate of offset into destination
*
* First scale the document to match the specified pixels per point,
* then render the rectangle given by the upper left corner at
* (src_x, src_y) and src_width and src_height. The rectangle is
* rendered into the specified pixmap with the upper left corner
* placed at (dest_x, dest_y).
**/
void
poppler_page_render_to_pixbuf (PopplerPage *page,
int src_x, int src_y,
int src_width, int src_height,
double scale,
GdkPixbuf *pixbuf,
int dest_x, int dest_y)
{
SplashOutputDev *output_dev;
SplashColor white;
SplashBitmap *bitmap;
SplashColorPtr color_ptr;
int splash_width, splash_height, splash_rowstride;
int pixbuf_width, pixbuf_height, pixbuf_rowstride, pixbuf_n_channels;
guchar *splash_data, *pixbuf_data, *src, *dst;
int x, y;
white.rgb8 = splashMakeRGB8 (0xff, 0xff, 0xff);
output_dev = new SplashOutputDev(splashModeRGB8, gFalse, white);
output_dev->startDoc(page->document->doc->getXRef ());
page->page->displaySlice(output_dev, 72.0 * scale, 72.0 * scale,
0, /* Rotate */
gTrue, /* Crop */
src_x, src_y,
src_width, src_height,
NULL, /* links */
page->document->doc->getCatalog ());
bitmap = output_dev->getBitmap ();
color_ptr = bitmap->getDataPtr ();
splash_width = bitmap->getWidth ();
splash_height = bitmap->getHeight ();
splash_data = (guchar *) color_ptr.rgb8;
splash_rowstride = bitmap->getRowSize ();
pixbuf_data = gdk_pixbuf_get_pixels (pixbuf);
pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf);
/* FIXME: Clip the rectangle to pixbuf. */
for (y = 0; y < splash_height; y++) {
src = splash_data + y * splash_rowstride;
dst = pixbuf_data + (dest_y + y) * pixbuf_rowstride +
dest_x * pixbuf_n_channels;
for (x = 0; x < splash_width; x++) {
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst += pixbuf_n_channels;
src += 4;
}
}
delete output_dev;
}
static void
poppler_page_class_init (PopplerPageClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = poppler_page_finalize;
}
static void
poppler_page_init (PopplerPage *page)
{
}
/* poppler-page.h: glib interface to poppler
* Copyright (C) 2004, Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __POPPLER_PAGE_H__
#define __POPPLER_PAGE_H__
#include <glib-object.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "poppler-glib.h"
G_BEGIN_DECLS
#define POPPLER_TYPE_PAGE (poppler_page_get_type ())
#define POPPLER_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_PAGE, PopplerPage))
#define POPPLER_IS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_PAGE))
GType poppler_page_get_type (void) G_GNUC_CONST;
void poppler_page_render_to_pixbuf (PopplerPage *page,
int src_x,
int src_y,
int src_width,
int src_height,
double scale,
GdkPixbuf *pixbuf,
int dest_x,
int dest_y);
void poppler_page_get_dimensions (PopplerPage *page,
double *widht,
double *height);
G_END_DECLS
#endif /* __POPPLER_GLIB_H__ */
#ifndef __POPPLER_PRIVATE_H__
#define __POPPLER_PRIVATE_H__
struct _PopplerDocument
{
GObject parent_instance;
PDFDoc *doc;
};
struct _PopplerPage
{
GObject parent_instance;
PopplerDocument *document;
Page *page;
};
PopplerPage *
_poppler_page_new (PopplerDocument *document, Page *page);
#endif
/* poppler-glib.h: glib wrapper for poppler
* Copyright (C) 2005, Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "poppler.h"
GQuark poppler_error_quark (void)
{
static GQuark q = 0;
if (q == 0)
q = g_quark_from_static_string ("poppler-quark");
return q;
}
/* poppler-glib.h: glib interface to poppler
* Copyright (C) 2004, Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __POPPLER_GLIB_H__
#define __POPPLER_GLIB_H__
#include <glib-object.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
G_BEGIN_DECLS
GQuark poppler_error_quark (void);
#define POPPLER_ERROR poppler_error_quark ()
typedef enum
{
POPPLER_ERROR_INVALID,
POPPLER_ERROR_ENCRYPTED
} PopplerError;
G_END_DECLS
#include "poppler-document.h"
#include "poppler-page.h"
#endif /* __POPPLER_GLIB_H__ */
#include <stdio.h>
#include <stdlib.h>
#include "poppler.h"
#define FAIL(msg) \
do { fprintf (stderr, "FAIL: %s\n", msg); exit (-1); } while (0)
int main (int argc, char *argv[])
{
PopplerDocument *document;
PopplerPage *page;
char *filename;
GError *error;
GdkPixbuf *pixbuf;
double width, height;
filename = argv[1];
if (filename == NULL)
FAIL ("specify filename");
g_type_init ();
error = NULL;
document = poppler_document_new_from_file (argv[1], NULL, &error);
if (document == NULL)
FAIL (error->message);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 100);
gdk_pixbuf_fill (pixbuf, 0x00106000);
page = poppler_document_get_page (document, 5);
poppler_page_get_dimensions (page, &width, &height);
printf ("page dimensions: %f inches by %f inches\n",
width / 72, height / 72);
poppler_page_render_to_pixbuf (page, 100, 100, 50, 50, 1, pixbuf, 10, 10);
g_object_unref (G_OBJECT (page));
gdk_pixbuf_save (pixbuf, "slice.png", "png", &error, NULL);
if (error != NULL)
FAIL (error->message);
g_object_unref (G_OBJECT (document));
}
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: poppler
Description: GLib wrapper for poppler
Version: @VERSION@
Libs: -L${libdir} -lpoppler
Cflags: -I${includedir}/poppler/glib
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment