Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf
diff options
context:
space:
mode:
authorNickolay V. Shmyrev <nshmyrev@src.gnome.org>2005-10-14 08:07:23 (GMT)
committer Nickolay V. Shmyrev <nshmyrev@src.gnome.org>2005-10-14 08:07:23 (GMT)
commit5c5368f7406cabbac729397a4e946a8d8202a78a (patch)
tree25d8723de06b97ff0c0a9c334856a701315cb188 /pdf
parent4b77c0328f6ae40dbb7b56cc678e89e60ff27240 (diff)
Remove old unused files.
* pdf/GDKSplashOutputDev.cc: * pdf/GDKSplashOutputDev.h: * pdf/Thumb.cc: * pdf/Thumb.h: * pdf/pdf-document.cc: * pdf/pdf-document.h: * pdf/test-gdk-output-dev.cc: Remove old unused files.
Diffstat (limited to 'pdf')
-rw-r--r--pdf/GDKSplashOutputDev.cc151
-rw-r--r--pdf/GDKSplashOutputDev.h100
-rw-r--r--pdf/Thumb.cc190
-rw-r--r--pdf/Thumb.h63
-rw-r--r--pdf/pdf-document.cc1493
-rw-r--r--pdf/pdf-document.h38
-rw-r--r--pdf/test-gdk-output-dev.cc174
7 files changed, 0 insertions, 2209 deletions
diff --git a/pdf/GDKSplashOutputDev.cc b/pdf/GDKSplashOutputDev.cc
deleted file mode 100644
index 2dc3dc9..0000000
--- a/pdf/GDKSplashOutputDev.cc
+++ /dev/null
@@ -1,151 +0,0 @@
-//========================================================================
-//
-// GDKSplashOutputDev.cc
-//
-// Copyright 2003 Glyph & Cog, LLC
-// Copyright 2004 Red Hat, Inc. (GDK port)
-//
-//========================================================================
-
-#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 <TextOutputDev.h>
-#include <GDKSplashOutputDev.h>
-
-//------------------------------------------------------------------------
-// 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;
-
- // create text object
- text = new TextPage(gFalse);
-}
-
-GDKSplashOutputDev::~GDKSplashOutputDev() {
- delete text;
-}
-
-void GDKSplashOutputDev::drawChar(GfxState *state, double x, double y,
- double dx, double dy,
- double originX, double originY,
- CharCode code, Unicode *u, int uLen) {
- text->addChar(state, x, y, dx, dy, code, u, uLen);
- SplashOutputDev::drawChar(state, x, y, dx, dy, originX, originY,
- code, u, uLen);
-}
-
-GBool GDKSplashOutputDev::beginType3Char(GfxState *state, double x, double y,
- double dx, double dy,
- CharCode code, Unicode *u, int uLen) {
- text->addChar(state, x, y, dx, dy, code, u, uLen);
- return SplashOutputDev::beginType3Char(state, x, y, dx, dy, code, u, uLen);
-}
-
-void GDKSplashOutputDev::clear() {
- startDoc(NULL);
- startPage(0, NULL);
-}
-
-void GDKSplashOutputDev::startPage(int pageNum, GfxState *state) {
- SplashOutputDev::startPage(pageNum, state);
- text->startPage(state);
-}
-
-void GDKSplashOutputDev::endPage() {
- SplashOutputDev::endPage();
- if (!incrementalUpdate) {
- (*redrawCbk)(redrawCbkData);
- }
- text->coalesce(gTrue);
-}
-
-void GDKSplashOutputDev::dump() {
- if (incrementalUpdate && redrawCbk) {
- (*redrawCbk)(redrawCbkData);
- }
-}
-
-void GDKSplashOutputDev::updateFont(GfxState *state) {
- SplashOutputDev::updateFont(state);
- text->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);
-}
-
-void GDKSplashOutputDev::drawToPixbuf(GdkPixbuf *pixbuf, int pageNum) {
-
-}
-
-GBool GDKSplashOutputDev::findText(Unicode *s, int len,
- GBool startAtTop, GBool stopAtBottom,
- GBool startAtLast, GBool stopAtLast,
- int *xMin, int *yMin,
- int *xMax, int *yMax) {
- double xMin1, yMin1, xMax1, yMax1;
-
- xMin1 = (double)*xMin;
- yMin1 = (double)*yMin;
- xMax1 = (double)*xMax;
- yMax1 = (double)*yMax;
- if (text->findText(s, len, startAtTop, stopAtBottom,
- startAtLast, stopAtLast,
- &xMin1, &yMin1, &xMax1, &yMax1)) {
- *xMin = xoutRound(xMin1);
- *xMax = xoutRound(xMax1);
- *yMin = xoutRound(yMin1);
- *yMax = xoutRound(yMax1);
- return gTrue;
- }
- return gFalse;
-}
-
-GooString *GDKSplashOutputDev::getText(int xMin, int yMin, int xMax, int yMax) {
- return text->getText((double)xMin, (double)yMin,
- (double)xMax, (double)yMax);
-}
diff --git a/pdf/GDKSplashOutputDev.h b/pdf/GDKSplashOutputDev.h
deleted file mode 100644
index 197beb5..0000000
--- a/pdf/GDKSplashOutputDev.h
+++ /dev/null
@@ -1,100 +0,0 @@
-//========================================================================
-//
-// GDKSplashOutputDev.h
-//
-// Copyright 2003 Glyph & Cog, LLC
-// Copyright 2004 Red Hat, Inc. (GDK port)
-//
-//========================================================================
-
-#ifndef XSPLASHOUTPUTDEV_H
-#define XSPLASHOUTPUTDEV_H
-
-#ifdef USE_GCC_PRAGMAS
-#pragma interface
-#endif
-
-#include <gdk/gdk.h>
-#include <splash/SplashTypes.h>
-#include <SplashOutputDev.h>
-#include <TextOutputDev.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
-
- // Start a page.
- virtual void startPage(int pageNum, GfxState *state);
-
- // End a page.
- virtual void endPage();
-
- // Dump page contents to display.
- virtual void dump();
-
- //----- update text state
- virtual void updateFont(GfxState *state);
-
- //----- text drawing
- virtual void drawChar(GfxState *state, double x, double y,
- double dx, double dy,
- double originX, double originY,
- CharCode code, Unicode *u, int uLen);
- virtual GBool beginType3Char(GfxState *state, double x, double y,
- double dx, double dy,
- CharCode code, Unicode *u, int uLen);
-
- //----- 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);
-
- void drawToPixbuf(GdkPixbuf *pixbuf, int pageNum);
-
- // Find a string. If <startAtTop> is true, starts looking at the
- // top of the page; else if <startAtLast> is true, starts looking
- // immediately after the last find result; else starts looking at
- // <xMin>,<yMin>. If <stopAtBottom> is true, stops looking at the
- // bottom of the page; else if <stopAtLast> is true, stops looking
- // just before the last find result; else stops looking at
- // <xMax>,<yMax>.
- GBool findText(Unicode *s, int len,
- GBool startAtTop, GBool stopAtBottom,
- GBool startAtLast, GBool stopAtLast,
- int *xMin, int *yMin,
- int *xMax, int *yMax);
-
- // Get the text which is inside the specified rectangle.
- GooString *getText(int xMin, int yMin, int xMax, int yMax);
-
-private:
-
- int incrementalUpdate;
- void (*redrawCbk)(void *data);
- void *redrawCbkData;
- TextPage *text; // text from the current page
-};
-
-#endif
diff --git a/pdf/Thumb.cc b/pdf/Thumb.cc
deleted file mode 100644
index 02b4d23..0000000
--- a/pdf/Thumb.cc
+++ /dev/null
@@ -1,190 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-indent-level: 8; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2003 Remi Cohen-Scali
- *
- * Author:
- * Remi Cohen-Scali <Remi@Cohen-Scali.com>
- *
- * GPdf 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 of the License, or
- * (at your option) any later version.
- *
- * GPdf 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 <string.h>
-
-#ifdef USE_GCC_PRAGMAS
-#pragma implementation
-#endif
-
-#include <glib.h>
-#include <goo/gmem.h>
-#include <Object.h>
-#include <Gfx.h>
-#include <GfxState.h>
-#include "Thumb.h"
-
-/*
- * Thumb
- */
-
-Thumb::Thumb(XRef *xrefA, Object *obj) :
- xref(xrefA),
- str(NULL),
- ok_flag(0)
-{
- Object obj1, obj2;
- Dict *dict;
- GfxColorSpace *colorSpace;
-
- do {
- /* Get stream dict */
- dict = obj->streamGetDict ();
- str = obj->getStream();
-
- /* Get width */
- dict->lookup ("Width", &obj1);
- if (obj1.isNull ())
- {
- obj1.free ();
- dict->lookup ("W", &obj1);
- }
- if (!obj1.isInt ()) {
- fprintf (stderr, "Error: Invalid Width object %s\n",
- obj1.getTypeName ());
- obj1.free ();
- break;
- }
- width = obj1.getInt ();
- obj1.free ();
-
- /* Get heigth */
- dict->lookup ("Height", &obj1);
- if (obj1.isNull ())
- {
- obj1.free ();
- dict->lookup ("H", &obj1);
- }
- if (!obj1.isInt ()) {
- fprintf (stderr, "Error: Invalid Height object %s\n",
- obj1.getTypeName ());
- obj1.free ();
- break;
- }
- height = obj1.getInt ();
- obj1.free ();
-
- /* bit depth */
- dict->lookup ("BitsPerComponent", &obj1);
- if (obj1.isNull ())
- {
- obj1.free ();
- dict->lookup ("BPC", &obj1);
- }
- if (!obj1.isInt ()) {
- fprintf (stderr, "Error: Invalid BitsPerComponent object %s\n",
- obj1.getTypeName ());
- obj1.free ();
- break;
- }
- bits = obj1.getInt ();
- obj1.free ();
-
- /* Get color space */
- dict->lookup ("ColorSpace", &obj1);
- if (obj1.isNull ())
- {
- obj1.free ();
- dict->lookup ("CS", &obj1);
- }
- colorSpace = GfxColorSpace::parse(&obj1);
- obj1.free();
- if (!colorSpace) {
- fprintf (stderr, "Error: Cannot parse color space\n");
- break;
- }
-
- dict->lookup("Decode", &obj1);
- if (obj1.isNull()) {
- obj1.free();
- dict->lookup("D", &obj1);
- }
- colorMap = new GfxImageColorMap(bits, &obj1, colorSpace);
- obj1.free();
- if (!colorMap->isOk()) {
- fprintf (stderr, "Error: invalid colormap\n");
- delete colorMap;
- colorMap = NULL;
- }
-
- dict->lookup ("Length", &obj1);
- if (!obj1.isInt ()) {
- fprintf (stderr, "Error: Invalid Length Object %s\n",
- obj1.getTypeName ());
- obj1.free ();
- break;
- }
- length = obj1.getInt ();
- obj1.free ();
-
- str->addFilters(obj);
-
- ok_flag = 1;
- }
- while (0);
-}
-
-unsigned char *
-Thumb::getPixbufData()
-{
- ImageStream *imgstr;
- unsigned char *pixbufdata;
- unsigned int pixbufdatasize;
- int row, col;
- unsigned char *p;
-
- /* RGB Pixbuf data */
- pixbufdatasize = width * height * 3;
- if (colorMap) {
- pixbufdata =(unsigned char *)g_malloc(pixbufdatasize);
- } else {
- pixbufdata =(unsigned char *)g_malloc0(pixbufdatasize);
- return pixbufdata;
- }
-
- p = pixbufdata;
-
- imgstr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
- imgstr->reset();
- for (row = 0; row < height; ++row) {
- for (col = 0; col < width; ++col) {
- Guchar pix[gfxColorMaxComps];
- GfxRGB rgb;
-
- imgstr->getPixel(pix);
- colorMap->getRGB(pix, &rgb);
-
- *p++ = (guchar)(rgb.r * 255.99999);
- *p++ = (guchar)(rgb.g * 255.99999);
- *p++ = (guchar)(rgb.b * 255.99999);
- }
- }
- delete imgstr;
-
- return pixbufdata;
-}
-
-Thumb::~Thumb() {
- delete colorMap;
- delete str;
-}
-
diff --git a/pdf/Thumb.h b/pdf/Thumb.h
deleted file mode 100644
index 1ed4a28..0000000
--- a/pdf/Thumb.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-indent-level: 8; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2003 Remi Cohen-Scali
- *
- * Author:
- * Remi Cohen-Scali <Remi@Cohen-Scali.com>
- *
- * GPdf 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 of the License, or
- * (at your option) any later version.
- *
- * GPdf 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 THUMB_H
-#define THUMB_H
-
-class XRef;
-class GfxColorSpace;
-
-/* FIXME: Should have a class to avoid reading same colormap for every thumb */
-
-/*
- * Thumb
- */
-
-class Thumb {
-
- public:
- Thumb(XRef *xrefA, Object *obj);
- ~Thumb();
-
- int getWidth(void) {return width; };
- int getHeight(void) {return height; };
- GfxColorSpace *getColorSpace(void) {return colorMap->getColorSpace(); };
- int getBitsPerComponent(void) {return colorMap->getBits(); };
- int getLength(void) {return length; };
-
- Stream *getStream() {return str; };
-
- unsigned char *getPixbufData();
-
- char ok() {return ok_flag != 0; };
-
- private:
- XRef *xref;
- Stream *str;
- GfxImageColorMap *colorMap;
- int width, height, bits;
- int length;
- char ok_flag;
-};
-
-#endif
-
diff --git a/pdf/pdf-document.cc b/pdf/pdf-document.cc
deleted file mode 100644
index a0bb935..0000000
--- a/pdf/pdf-document.cc
+++ /dev/null
@@ -1,1493 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
-/* pdfdocument.h: Implementation of EvDocument for PDF
- * 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.
- */
-
-#include <glib/gi18n.h>
-
-#include "pdf-document.h"
-#include "ev-ps-exporter.h"
-#include "ev-document-find.h"
-#include "ev-document-misc.h"
-#include "ev-document-links.h"
-#include "ev-document-security.h"
-#include "ev-document-thumbnails.h"
-
-#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 <PSOutputDev.h>
-
-#include "Thumb.h"
-#include "GDKSplashOutputDev.h"
-
-enum {
- PROP_0,
- PROP_TITLE
-};
-
-typedef struct
-{
- PdfDocument *document;
- gunichar *ucs4;
- glong ucs4_len;
- guint idle;
- /* full results are only possible for the rendered current page */
- int current_page;
- GArray *current_page_results;
- int *other_page_flags; /* length n_pages + 1, first element ignored */
- int start_page; /* skip this one as we iterate, since we did it first */
- int search_page; /* the page we're searching now */
- TextOutputDev *output_dev;
-} PdfDocumentSearch;
-
-typedef struct _PdfDocumentClass PdfDocumentClass;
-
-#define PDF_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDF_TYPE_DOCUMENT, PdfDocumentClass))
-#define PDF_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDF_TYPE_DOCUMENT))
-#define PDF_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDF_TYPE_DOCUMENT, PdfDocumentClass))
-
-struct _PdfDocumentClass
-{
- GObjectClass parent_class;
-};
-
-struct _PdfDocument
-{
- GObject parent_instance;
-
- int page;
- int page_x_offset;
- int page_y_offset;
- double scale;
- GdkDrawable *target;
-
- GDKSplashOutputDev *out;
- PSOutputDev *ps_out;
- PDFDoc *doc;
- Links *links;
- UnicodeMap *umap;
-
- gchar *password;
-
- PdfDocumentSearch *search;
-};
-
-static EvLink *build_link_from_action (PdfDocument *pdf_document,
- LinkAction *link_action,
- const char *title);
-
-static void pdf_document_document_links_iface_init (EvDocumentLinksIface *iface);
-static void pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
-static void pdf_document_document_iface_init (EvDocumentIface *iface);
-static void pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface);
-static void pdf_document_find_iface_init (EvDocumentFindIface *iface);
-static void pdf_document_security_iface_init (EvDocumentSecurityIface *iface);
-static void pdf_document_search_free (PdfDocumentSearch *search);
-static void pdf_document_search_page_changed (PdfDocumentSearch *search);
-
-static GdkPixbuf *bitmap_to_pixbuf (SplashBitmap *bitmap,
- GdkPixbuf *target,
- gint x_offset,
- gint y_offset);
-
-
-G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
- {
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
- pdf_document_document_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_LINKS,
- pdf_document_document_links_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
- pdf_document_document_thumbnails_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_PS_EXPORTER,
- pdf_document_ps_exporter_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
- pdf_document_find_iface_init);
- G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_SECURITY,
- pdf_document_security_iface_init);
- });
-
-static void
-document_init_links (PdfDocument *pdf_document)
-{
- Page *page;
- Object obj;
-
- if (pdf_document->links) {
- delete pdf_document->links;
- }
- page = pdf_document->doc->getCatalog ()->getPage (pdf_document->page);
- pdf_document->links = new Links (page->getAnnots (&obj),
- pdf_document->doc->getCatalog ()->getBaseURI ());
- obj.free ();
-}
-
-static void
-document_display_page (PdfDocument *pdf_document)
-{
- if (pdf_document->out != NULL) {
- pdf_document->doc->displayPage (pdf_document->out, pdf_document->page,
- 72 * pdf_document->scale,
- 72 * pdf_document->scale,
- 0, gTrue, gTrue);
-
- document_init_links (pdf_document);
-
- /* Update the search results available to the app since
- * we only provide full results on the current page
- */
- if (pdf_document->search)
- pdf_document_search_page_changed (pdf_document->search);
- }
-}
-
-static gboolean
-pdf_document_load (EvDocument *document,
- const char *uri,
- GError **error)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- PDFDoc *newDoc;
- int err;
- char *filename;
- GooString *filename_g;
- GooString *enc;
-
- if (!globalParams) {
- globalParams = new GlobalParams("/etc/xpdfrc");
- globalParams->setupBaseFontsFc(NULL);
- }
-
- if (! pdf_document->umap) {
- enc = new GooString("UTF-8");
- pdf_document->umap = globalParams->getUnicodeMap(enc);
- pdf_document->umap->incRefCnt ();
- delete enc;
- }
-
- filename = g_filename_from_uri (uri, NULL, error);
- if (!filename)
- return FALSE;
-
- filename_g = new GooString (filename);
- g_free (filename);
-
- // open the PDF file, assumes ownership of filename_g
- GooString *password = NULL;
- if (pdf_document->password)
- password = new GooString (pdf_document->password);
- newDoc = new PDFDoc(filename_g, password, password);
- if (password)
- delete password;
-
- if (!newDoc->isOk()) {
- err = newDoc->getErrorCode();
- delete newDoc;
- if (err == errEncrypted) {
- g_set_error (error, EV_DOCUMENT_ERROR,
- EV_DOCUMENT_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 FALSE;
- }
-
- if (pdf_document->doc)
- delete pdf_document->doc;
- pdf_document->doc = newDoc;
-
- pdf_document->page = 1;
-
- if (pdf_document->out)
- pdf_document->out->startDoc(pdf_document->doc->getXRef());
-
- g_object_notify (G_OBJECT (pdf_document), "title");
-
- return TRUE;
-}
-
-static gboolean
-pdf_document_save (EvDocument *document,
- const char *uri,
- GError **error)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- char *filename;
- gboolean retval = FALSE;
-
- filename = g_filename_from_uri (uri, NULL, error);
- if (filename != NULL) {
- GooString *fname = new GooString (filename);
-
- retval = pdf_document->doc->saveAs (fname);
- }
-
- return retval;
-}
-
-static int
-pdf_document_get_n_pages (EvDocument *document)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- if (pdf_document->doc)
- return pdf_document->doc->getNumPages();
- else
- return 1;
-}
-
-static void
-pdf_document_set_page (EvDocument *document,
- int page)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- page = CLAMP (page, 1, pdf_document_get_n_pages (document));
-
- if (page != pdf_document->page) {
- pdf_document->page = page;
- document_display_page (pdf_document);
- ev_document_page_changed (EV_DOCUMENT (pdf_document));
- }
-}
-
-static int
-pdf_document_get_page (EvDocument *document)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- return pdf_document->page;
-}
-
-static void
-redraw_callback (void *data)
-{
- /* Need to hook up through a EvDocument callback? */
-}
-
-static void
-pdf_document_set_target (EvDocument *document,
- GdkDrawable *target)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- if (pdf_document->target != target) {
- if (pdf_document->target)
- g_object_unref (pdf_document->target);
-
- pdf_document->target = target;
-
- if (pdf_document->target)
- g_object_ref (pdf_document->target);
-
- if (pdf_document->out) {
- delete pdf_document->out;
- pdf_document->out = NULL;
- }
-
- if (pdf_document->target) {
- pdf_document->out = new GDKSplashOutputDev (gdk_drawable_get_screen (pdf_document->target),
- redraw_callback, (void*) document);
-
- if (pdf_document->doc)
- pdf_document->out->startDoc(pdf_document->doc->getXRef());
-
- document_display_page (pdf_document);
- }
- }
-}
-
-static void
-pdf_document_set_scale (EvDocument *document,
- double scale)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- if (pdf_document->scale != scale) {
- pdf_document->scale = scale;
- document_display_page (pdf_document);
- ev_document_scale_changed (EV_DOCUMENT (pdf_document));
- }
-}
-
-static void
-pdf_document_set_page_offset (EvDocument *document,
- int x,
- int y)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- pdf_document->page_x_offset = x;
- pdf_document->page_y_offset = y;
-}
-
-static gint
-canonical_multiple_of_90 (gint n)
-{
- while (n >= 360) {
- n -= 360;
- }
- while (n < 0) {
- n += 360;
- }
-
- return 90 * (gint)((n / 90.0) + .5);
-}
-
-static void
-pdf_document_get_page_size (EvDocument *document,
- int page,
- int *width,
- int *height)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- Page *doc_page;
- int page_width = 1, page_height = 1;
- double scale = pdf_document->scale;
-
- if (page == -1)
- page = pdf_document->page;
-
- doc_page = pdf_document->doc->getCatalog ()->getPage (page);
-
- if (page) {
- int page_rotate;
-
- page_rotate = canonical_multiple_of_90 (doc_page->getRotate ());
- if (page_rotate == 90 || page_rotate == 270) {
- page_width = (int) ((doc_page->getHeight () * scale) + 0.5);
- page_height = (int) ((doc_page->getWidth () * scale) + 0.5);
- } else /* if (page_rotate == 0 || page_rotate == 180) */ {
- page_width = (int) ((doc_page->getWidth () * scale) + 0.5);
- page_height = (int) ((doc_page->getHeight () * scale) + 0.5);
- }
- }
-
- if (width) *width = page_width;
- if (height) *height = page_height;
-}
-
-static void
-pdf_document_render (EvDocument *document,
- int clip_x,
- int clip_y,
- int clip_width,
- int clip_height)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- GdkRectangle page;
- GdkRectangle draw;
-
- if (!pdf_document->target)
- return;
-
- page.x = pdf_document->page_x_offset;
- page.y = pdf_document->page_y_offset;
- page.width = pdf_document->out->getBitmapWidth();
- page.height = pdf_document->out->getBitmapHeight();
-
- draw.x = clip_x;
- draw.y = clip_y;
- draw.width = clip_width;
- draw.height = clip_height;
-
- if (gdk_rectangle_intersect (&page, &draw, &draw))
- pdf_document->out->redraw (draw.x - page.x, draw.y - page.y,
- pdf_document->target,
- draw.x, draw.y,
- draw.width, draw.height);
-}
-
-
-
-static GdkPixbuf *
-pdf_document_render_pixbuf (EvDocument *document)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- SplashOutputDev *output;
- GdkPixbuf *pixbuf;
- SplashColor color;
-
- color.rgb8 = splashMakeRGB8 (255, 255, 255);
-
- output = new SplashOutputDev (splashModeRGB8, gFalse, color);
- output->startDoc (pdf_document->doc->getXRef());
-
- pdf_document->doc->displayPage (output,
- pdf_document->page,
- 72*pdf_document->scale,
- 72*pdf_document->scale,
- 0, gTrue, gFalse);
-
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
- FALSE, 8,
- output->getBitmap()->getWidth(),
- output->getBitmap()->getHeight());
-
- bitmap_to_pixbuf (output->getBitmap(), pixbuf, 0, 0);
- delete output;
-
- return pixbuf;
-}
-
-double
-pdf_document_find_get_progress (EvDocumentFind *document_find)
-{
- PdfDocumentSearch *search;
- int n_pages, pages_done;
-
- search = PDF_DOCUMENT (document_find)->search;
-
- if (search == NULL) {
- return 0;
- }
-
- n_pages = pdf_document_get_n_pages (EV_DOCUMENT (document_find));
- if (search->search_page > search->start_page) {
- pages_done = search->search_page - search->start_page + 1;
- } else if (search->search_page == search->start_page) {
- pages_done = n_pages;
- } else {
- pages_done = n_pages - search->start_page + search->search_page;
- }
-
- return pages_done / (double) n_pages;
-}
-
-int
-pdf_document_find_page_has_results (EvDocumentFind *document_find,
- int page)
-{
- PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
-
- g_return_val_if_fail (search != NULL, FALSE);
-
- return search->other_page_flags[page];
-}
-
-int
-pdf_document_find_get_n_results (EvDocumentFind *document_find)
-{
- PdfDocumentSearch *search = PDF_DOCUMENT (document_find)->search;
-
- if (search) {
- return search->current_page_results->len;
- } else {
- return 0;
- }
-}
-
-gboolean
-pdf_document_find_get_result (EvDocumentFind *document_find,
- int n_result,
- GdkRectangle *rectangle)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document_find);
- PdfDocumentSearch *search = pdf_document->search;
- GdkRectangle r;
-
- if (search != NULL &&
- n_result < search->current_page_results->len) {
- r = g_array_index (search->current_page_results,
- GdkRectangle, n_result);
-
- rectangle->x = r.x + pdf_document->page_x_offset;
- rectangle->y = r.y + pdf_document->page_y_offset;
- rectangle->width = r.width;
- rectangle->height = r.height;
-
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-static void
-pdf_document_search_page_changed (PdfDocumentSearch *search)
-{
- PdfDocument *pdf_document = search->document;
- int current_page;
- GdkRectangle result;
- int xMin, yMin, xMax, yMax;
-
- current_page = pdf_document->page;
-
- if (search->current_page == current_page)
- return;
-
- /* We need to create current_page_results for the new current page */
- g_array_set_size (search->current_page_results, 0);
-
- if (pdf_document->out->findText (search->ucs4, search->ucs4_len,
- gTrue, gTrue, // startAtTop, stopAtBottom
- gFalse, gFalse, // startAtLast, stopAtLast
- &xMin, &yMin, &xMax, &yMax)) {
- result.x = xMin;
- result.y = yMin;
- result.width = xMax - xMin;
- result.height = yMax - yMin;
-
- g_array_append_val (search->current_page_results, result);
- /* Now find further results */
-
- while (pdf_document->out->findText (search->ucs4, search->ucs4_len,
- gFalse, gTrue,
- gTrue, gFalse,
- &xMin, &yMin, &xMax, &yMax)) {
- result.x = xMin;
- result.y = yMin;
- result.width = xMax - xMin;
- result.height = yMax - yMin;
-
- g_array_append_val (search->current_page_results, result);
- }
- }
-}
-
-static gboolean
-pdf_document_search_idle_callback (void *data)
-{
- PdfDocumentSearch *search = (PdfDocumentSearch*) data;
- PdfDocument *pdf_document = search->document;
- int n_pages, changed_page;
- double xMin, yMin, xMax, yMax;
-
- /* Note that PDF page count is 1 through n_pages INCLUSIVE
- * like a real book. We are looking to add one result for each
- * page with a match, because the coordinates are meaningless
- * with TextOutputDev, so we just want to flag matching pages
- * and then when the user switches to the current page, we
- * will emit "found" again with the real results.
- */
- n_pages = pdf_document_get_n_pages (EV_DOCUMENT (search->document));
-
- if (search->output_dev == 0) {
- /* First time through here... */
- search->output_dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
- if (!search->output_dev->isOk()) {
- goto end_search;
- }
- }
-
- pdf_document->doc->displayPage (search->output_dev,
- search->search_page,
- 72, 72, 0, gTrue, gFalse);
-
- if (search->output_dev->findText (search->ucs4,
- search->ucs4_len,
- gTrue, gTrue, // startAtTop, stopAtBottom
- gFalse, gFalse, // startAtLast, stopAtLast
- &xMin, &yMin, &xMax, &yMax)) {
- /* This page has results */
- search->other_page_flags[search->search_page] = 1;
- } else {
- search->other_page_flags[search->search_page] = 0;
- }
-
- changed_page = search->start_page;
-
- search->search_page += 1;
- if (search->search_page > n_pages) {
- /* wrap around */
- search->search_page = 1;
- }
-
- if (search->search_page != search->start_page) {
- ev_document_find_changed (EV_DOCUMENT_FIND (pdf_document),
- changed_page);
- return TRUE;
- }
-
-end_search:
- /* We're done. */
- search->idle = 0; /* will return FALSE to remove */
- return FALSE;
-}
-
-static void
-pdf_document_find_begin (EvDocumentFind *document,
- const char *search_string,
- gboolean case_sensitive)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- PdfDocumentSearch *search;
- int n_pages, i;
- gunichar *ucs4;
- glong ucs4_len;
-
- /* FIXME handle case_sensitive (right now XPDF
- * code is always case insensitive for ASCII
- * and case sensitive for all other languaages)
- */
-
- g_assert (sizeof (gunichar) == sizeof (Unicode));
- ucs4 = g_utf8_to_ucs4_fast (search_string, -1,
- &ucs4_len);
-
- if (pdf_document->search &&
- pdf_document->search->ucs4_len == ucs4_len &&
- memcmp (pdf_document->search->ucs4,
- ucs4,
- sizeof (gunichar) * ucs4_len) == 0) {
- /* Search is unchanged */
- g_free (ucs4);
- return;
- }
-
- if (pdf_document->search) {
- pdf_document_search_free (pdf_document->search);
- pdf_document->search = NULL;
- }
-
- search = g_new0 (PdfDocumentSearch, 1);
-
- search->ucs4 = ucs4;
- search->ucs4_len = ucs4_len;
-
- search->current_page_results = g_array_new (FALSE,
- FALSE,
- sizeof (GdkRectangle));
- n_pages = pdf_document_get_n_pages (EV_DOCUMENT (document));
-
- search->other_page_flags = g_new0 (int, n_pages + 1);
- for (i = 0; i <= n_pages; i++) {
- search->other_page_flags[i] = -1;
- }
-
- search->document = pdf_document;
-
- /* We add at low priority so the progress bar repaints */
- search->idle = g_idle_add_full (G_PRIORITY_LOW,
- pdf_document_search_idle_callback,
- search,
- NULL);
-
- search->output_dev = 0;
-
- search->start_page = pdf_document->page;
- search->search_page = search->start_page;
-
- search->current_page = -1;
-
- pdf_document->search = search;
-
- /* Update for the current page right away */
- pdf_document_search_page_changed (search);
-}
-
-static void
-pdf_document_find_cancel (EvDocumentFind *document)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- if (pdf_document->search) {
- pdf_document_search_free (pdf_document->search);
- pdf_document->search = NULL;
- }
-}
-
-static void
-pdf_document_search_free (PdfDocumentSearch *search)
-{
- if (search->idle != 0)
- g_source_remove (search->idle);
-
- if (search->output_dev)
- delete search->output_dev;
-
- g_array_free (search->current_page_results, TRUE);
- g_free (search->other_page_flags);
-
- g_free (search->ucs4);
- g_free (search);
-}
-
-static gboolean
-pdf_document_has_document_security (EvDocumentSecurity *document_security)
-{
- /* FIXME: do we really need to have this? */
- return FALSE;
-}
-
-static void
-pdf_document_set_password (EvDocumentSecurity *document_security,
- const char *password)
-{
- PdfDocument *document = PDF_DOCUMENT (document_security);
-
- if (document->password)
- g_free (document->password);
-
- document->password = g_strdup (password);
-}
-
-static void
-pdf_document_ps_export_begin (EvPSExporter *exporter, const char *filename)
-{
- PdfDocument *document = PDF_DOCUMENT (exporter);
-
- if (document->ps_out)
- delete document->ps_out;
-
- document->ps_out = new PSOutputDev ((char *)filename, document->doc->getXRef(),
- document->doc->getCatalog(), 1,
- pdf_document_get_n_pages (EV_DOCUMENT (document)),
- psModePS);
-}
-
-static void
-pdf_document_ps_export_do_page (EvPSExporter *exporter, int page)
-{
- PdfDocument *document = PDF_DOCUMENT (exporter);
-
- document->doc->displayPage (document->ps_out, page,
- 72.0, 72.0, 0, gTrue, gFalse);
-}
-
-static void
-pdf_document_ps_export_end (EvPSExporter *exporter)
-{
- PdfDocument *document = PDF_DOCUMENT (exporter);
-
- delete document->ps_out;
- document->ps_out = NULL;
-}
-
-
-/* EvDocumentLinks Implementation */
-typedef struct
-{
- GooList *items;
- int index;
- int level;
-} LinksIter;
-
-static gchar *
-unicode_to_char (OutlineItem *outline_item,
- UnicodeMap *uMap)
-{
- GooString gstr;
- gchar buf[8]; /* 8 is enough for mapping an unicode char to a string */
- int i, n;
-
- for (i = 0; i < outline_item->getTitleLength(); ++i) {
- n = uMap->mapUnicode(outline_item->getTitle()[i], buf, sizeof(buf));
- gstr.append(buf, n);
- }
-
- return g_strdup (gstr.getCString ());
-}
-
-
-static gboolean
-pdf_document_links_has_document_links (EvDocumentLinks *document_links)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
- Outline *outline;
-
- g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
-
- outline = pdf_document->doc->getOutline();
- if (outline->getItems() != NULL &&
- outline->getItems()->getLength() > 0)
- return TRUE;
-
- return FALSE;
-}
-
-static void
-build_tree (PdfDocument *pdf_document,
- GtkTreeModel *model,
- GtkTreeIter *parent,
- GooList *items)
-{
- int i;
-
- for (i = 0; i < items->getLength (); i++) {
- OutlineItem *item;
- GtkTreeIter iter;
- LinkAction *link_action;
- gchar *title;
- EvLink *link;
-
- item = (OutlineItem *)items->get (i);
- gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent);
-
- link_action = item->getAction ();
- title = unicode_to_char (item, pdf_document->umap);
- link = build_link_from_action (pdf_document, link_action, title);
-
- gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
- EV_DOCUMENT_LINKS_COLUMN_MARKUP, title,
- EV_DOCUMENT_LINKS_COLUMN_LINK, link,
- -1);
-
- item->open ();
- if (item->hasKids () && item->getKids ()) {
- build_tree (pdf_document,
- model,
- &iter,
- item->getKids ());
- }
- }
-}
-
-static GtkTreeModel *
-pdf_document_links_get_links_model (EvDocumentLinks *document_links)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
- GtkTreeModel *model = NULL;
- Outline *outline;
- GooList *items;
-
- g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
-
- outline = pdf_document->doc->getOutline();
- items = outline->getItems();
-
- /* Create the model iff we have items*/
- if (items != NULL) {
- model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
- G_TYPE_STRING,
- G_TYPE_POINTER);
- build_tree (pdf_document, model, NULL, items);
- }
-
- return model;
-}
-
-static EvLink *
-build_link_from_action (PdfDocument *pdf_document,
- LinkAction *link_action,
- const char *title)
-{
- EvLink *link = NULL;
-
- if (link_action == NULL) {
- link = ev_link_new_title (title);
- } else if (link_action->getKind () == actionGoToR) {
- g_warning ("actionGoToR links not implemented");
- } else if (link_action->getKind () == actionLaunch) {
- g_warning ("actionLaunch links not implemented");
- } else if (link_action->getKind () == actionNamed) {
- g_warning ("actionNamed links not implemented");
- } else if (link_action->getKind () == actionMovie) {
- g_warning ("actionMovie links not implemented");
- } else if (link_action->getKind () == actionGoTo) {
- LinkDest *link_dest;
- LinkGoTo *link_goto;
- Ref page_ref;
- gint page_num = 0;
- GooString *named_dest;
-
- link_goto = dynamic_cast <LinkGoTo *> (link_action);
- link_dest = link_goto->getDest ();
- named_dest = link_goto->getNamedDest ();
-
- /* Wow! This seems excessively slow on large
- * documents. I need to investigate more... -jrb */
- if (link_dest != NULL) {
- link_dest = link_dest->copy ();
- } else if (named_dest != NULL) {
- named_dest = named_dest->copy ();
- link_dest = pdf_document->doc->findDest (named_dest);
- delete named_dest;
- }
- if (link_dest != NULL) {
- if (link_dest->isPageRef ()) {
- page_ref = link_dest->getPageRef ();
- page_num = pdf_document->doc->findPage (page_ref.num, page_ref.gen);
- } else {
- page_num = link_dest->getPageNum ();
- }
- delete link_dest;
- }
-
- link = ev_link_new_page (title, page_num);
- } else if (link_action->getKind () == actionURI) {
- LinkURI *link_uri;
-
- link_uri = dynamic_cast <LinkURI *> (link_action);
- link = ev_link_new_external
- (title, link_uri->getURI()->getCString());
- } else if (link_action->getKind () == actionUnknown) {
- LinkUnknown *link_unknown;
-
- link_unknown = dynamic_cast <LinkUnknown *> (link_action);
-
- g_warning ("Unknown link type %s",
- link_unknown->getAction()->getCString());
- }
-
- if (link == NULL) {
- link = ev_link_new_title (title);
- }
-
- return link;
-}
-
-
-#if 0
-static EvDocumentLinksIter *
-pdf_document_links_begin_read (EvDocumentLinks *document_links)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
- Outline *outline;
- LinksIter *iter;
- GooList *items;
-
- g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
-
- outline = pdf_document->doc->getOutline();
- items = outline->getItems();
- if (! items)
- return NULL;
-
- iter = g_new0 (LinksIter, 1);
- iter->items = items;
- iter->index = 0;
- iter->level = 0;
-
- return (EvDocumentLinksIter *) iter;
-}
-
-/* FIXME This returns a new object every time, probably we should cache it
- in the iter */
-static EvLink *
-pdf_document_links_get_link (EvDocumentLinks *document_links,
- EvDocumentLinksIter *links_iter)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document_links);
- LinksIter *iter = (LinksIter *)links_iter;
- OutlineItem *anItem;
- LinkAction *link_action;
- Unicode *link_title;
- const char *title;
-
- g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
-
- anItem = (OutlineItem *)iter->items->get(iter->index);
- link_action = anItem->getAction ();
- link_title = anItem->getTitle ();
- title = unicode_to_char (anItem, pdf_document->umap);
-
- return build_link_from_action (pdf_document, link_action, title);
-}
-
-static EvDocumentLinksIter *
-pdf_document_links_get_child (EvDocumentLinks *document_links,
- EvDocumentLinksIter *links_iter)
-{
- LinksIter *iter = (LinksIter *)links_iter;
- LinksIter *child_iter;
- OutlineItem *anItem;
-
- g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
-
- anItem = (OutlineItem *)iter->items->get(iter->index);
- anItem->open ();
- if (! (anItem->hasKids() && anItem->getKids()) )
- return NULL;
-
- child_iter = g_new0 (LinksIter, 1);
- child_iter->index = 0;
- child_iter->level = iter->level + 1;
- child_iter->items = anItem->getKids ();
- g_assert (child_iter->items);
-
- return (EvDocumentLinksIter *) child_iter;
-}
-
-static gboolean
-pdf_document_links_next (EvDocumentLinks *document_links,
- EvDocumentLinksIter *links_iter)
-{
- LinksIter *iter = (LinksIter *) links_iter;
-
- g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), FALSE);
-
- iter->index++;
- if (iter->index >= iter->items->getLength())
- return FALSE;
-
- return TRUE;
-}
-
-static void
-pdf_document_links_free_iter (EvDocumentLinks *document_links,
- EvDocumentLinksIter *iter)
-{
- g_return_if_fail (PDF_IS_DOCUMENT (document_links));
- g_return_if_fail (iter != NULL);
-
- /* FIXME: Should I close all the nodes?? Free them? */
- g_free (iter);
-}
-#endif
-
-static void
-pdf_document_finalize (GObject *object)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (object);
-
- if (pdf_document->links) {
- delete pdf_document->links;
- }
-
- if (pdf_document->umap) {
- pdf_document->umap->decRefCnt ();
- pdf_document->umap = NULL;
- }
-
- if (pdf_document->search)
- pdf_document_search_free (pdf_document->search);
-
- if (pdf_document->target)
- g_object_unref (pdf_document->target);
-
- if (pdf_document->out)
- delete pdf_document->out;
- if (pdf_document->ps_out)
- delete pdf_document->ps_out;
- if (pdf_document->doc)
- delete pdf_document->doc;
-
-}
-
-static void
-pdf_document_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- switch (prop_id)
-
- {
- case PROP_TITLE:
- /* read only */
- break;
- }
-}
-
-static gboolean
-has_unicode_marker (GooString *string)
-{
- return ((string->getChar (0) & 0xff) == 0xfe &&
- (string->getChar (1) & 0xff) == 0xff);
-}
-
-static gchar *
-pdf_info_dict_get_string (Dict *info_dict, const gchar *key) {
- Object obj;
- GooString *value;
- gchar *result;
-
- g_return_val_if_fail (info_dict != NULL, NULL);
- g_return_val_if_fail (key != NULL, NULL);
-
- if (!info_dict->lookup ((gchar *)key, &obj)->isString ()) {
- obj.free ();
- return NULL;
- }
-
- value = obj.getString ();
-
- if (has_unicode_marker (value)) {
- result = g_convert (value->getCString () + 2,
- value->getLength () - 2,
- "UTF-8", "UTF-16BE", NULL, NULL, NULL);
- } else {
- result = g_strndup (value->getCString (), value->getLength ());
- }
-
- obj.free ();
-
- return result;
-}
-
-static char *
-pdf_document_get_title (PdfDocument *pdf_document)
-{
- char *title = NULL;
- Object info;
-
- if (pdf_document->doc == NULL)
- return NULL;
- pdf_document->doc->getDocInfo (&info);
-
- if (info.isDict ()) {
- title = pdf_info_dict_get_string (info.getDict(), "Title");
- }
-
- return title;
-}
-
-static char *
-pdf_document_get_text (EvDocument *document, GdkRectangle *rect)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- GooString *sel_text = new GooString;
- const char *text;
- int x1, y1, x2, y2;
-
- x1 = rect->x - pdf_document->page_x_offset;
- y1 = rect->y - pdf_document->page_y_offset;
- x2 = x1 + rect->width;
- y2 = y1 + rect->height;
-
- sel_text = pdf_document->out->getText (x1, y1, x2, y2);
- text = sel_text->getCString ();
-
- return text ? g_strdup (text) : NULL;
-}
-
-static EvLink *
-pdf_document_get_link (EvDocument *document, int x, int y)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
- LinkAction *action;
- double link_x, link_y;
-
- if (pdf_document->links == NULL) {
- return NULL;
- }
-
- /* Offset */
- link_x = x - pdf_document->page_x_offset;
- link_y = y - pdf_document->page_y_offset;
-
- /* Inverse y */
- link_y = pdf_document->out->getBitmapHeight() - link_y;
-
- /* Zoom */
- link_x = link_x / pdf_document->scale;
- link_y = link_y / pdf_document->scale;
-
- action = pdf_document->links->find (link_x, link_y);
-
- if (action) {
- return build_link_from_action (pdf_document, action, "");
- } else {
- return NULL;
- }
-}
-
-static void
-pdf_document_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (object);
- char *title;
-
- switch (prop_id)
- {
- case PROP_TITLE:
- title = pdf_document_get_title (pdf_document);
- g_value_set_string (value, title);
- g_free (title);
- break;
- }
-}
-
-static void
-pdf_document_class_init (PdfDocumentClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->finalize = pdf_document_finalize;
- gobject_class->get_property = pdf_document_get_property;
- gobject_class->set_property = pdf_document_set_property;
-
- g_object_class_override_property (gobject_class, PROP_TITLE, "title");
-}
-
-static void
-pdf_document_document_iface_init (EvDocumentIface *iface)
-{
- iface->load = pdf_document_load;
- iface->save = pdf_document_save;
- iface->get_text = pdf_document_get_text;
- iface->get_link = pdf_document_get_link;
- iface->get_n_pages = pdf_document_get_n_pages;
- iface->set_page = pdf_document_set_page;
- iface->get_page = pdf_document_get_page;
- iface->set_scale = pdf_document_set_scale;
- iface->set_target = pdf_document_set_target;
- iface->set_page_offset = pdf_document_set_page_offset;
- iface->get_page_size = pdf_document_get_page_size;
- iface->render = pdf_document_render;
- iface->render_pixbuf = pdf_document_render_pixbuf;
-}
-
-static void
-pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface)
-{
- iface->begin = pdf_document_ps_export_begin;
- iface->do_page = pdf_document_ps_export_do_page;
- iface->end = pdf_document_ps_export_end;
-}
-
-
-static void
-pdf_document_find_iface_init (EvDocumentFindIface *iface)
-{
- iface->begin = pdf_document_find_begin;
- iface->get_n_results = pdf_document_find_get_n_results;
- iface->get_result = pdf_document_find_get_result;
- iface->page_has_results = pdf_document_find_page_has_results;
- iface->get_progress = pdf_document_find_get_progress;
- iface->cancel = pdf_document_find_cancel;
-}
-
-static void
-pdf_document_security_iface_init (EvDocumentSecurityIface *iface)
-{
- iface->has_document_security = pdf_document_has_document_security;
- iface->set_password = pdf_document_set_password;
-}
-
-static void
-pdf_document_document_links_iface_init (EvDocumentLinksIface *iface)
-{
- iface->has_document_links = pdf_document_links_has_document_links;
- iface->get_links_model = pdf_document_links_get_links_model;
-}
-
-/* Thumbnails */
-
-static GdkPixbuf *
-bitmap_to_pixbuf (SplashBitmap *bitmap,
- GdkPixbuf *target,
- gint x_offset,
- gint y_offset)
-{
- gint width;
- gint height;
- SplashColorPtr dataPtr;
- int x, y;
-
- gboolean target_has_alpha;
- gint target_rowstride;
- guchar *target_data;
-
- width = bitmap->getWidth ();
- height = bitmap->getHeight ();
-
- if (width + x_offset > gdk_pixbuf_get_width (target))
- width = gdk_pixbuf_get_width (target) - x_offset;
- if (height + y_offset > gdk_pixbuf_get_height (target))
- height = gdk_pixbuf_get_height (target) - x_offset;
-
- target_has_alpha = gdk_pixbuf_get_has_alpha (target);
- target_rowstride = gdk_pixbuf_get_rowstride (target);
- target_data = gdk_pixbuf_get_pixels (target);
-
- dataPtr = bitmap->getDataPtr ();
-
- for (y = 0; y < height; y++) {
- SplashRGB8 *p;
- SplashRGB8 rgb;
- guchar *q;
-
- p = dataPtr.rgb8 + y * width;
- q = target_data + ((y + y_offset) * target_rowstride +
- x_offset * (target_has_alpha?4:3));
- for (x = 0; x < width; x++) {
- rgb = *p++;
-
- *q++ = splashRGB8R (rgb);
- *q++ = splashRGB8G (rgb);
- *q++ = splashRGB8B (rgb);
-
- if (target_has_alpha)
- q++;
- }
- }
-
- return target;
-}
-
-
-static GdkPixbuf *
-pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document,
- gdouble scale_factor,
- gint page_num,
- gint width,
- gint height,
- gboolean border)
-{
- SplashOutputDev *output;
- GdkPixbuf *pixbuf;
- SplashColor color;
-
- color.rgb8 = splashMakeRGB8 (255, 255, 255);
-
- output = new SplashOutputDev (splashModeRGB8, gFalse, color);
- output->startDoc (pdf_document->doc->getXRef());
- pdf_document->doc->displayPage (output,
- page_num + 1,
- 72*scale_factor,
- 72*scale_factor,
- 0, gTrue, gFalse);
-
- width = output->getBitmap()->getWidth();
- height = output->getBitmap()->getHeight();
-
- if (border) {
- pixbuf = ev_document_misc_get_thumbnail_frame (width, height, NULL);
- bitmap_to_pixbuf (output->getBitmap(), pixbuf, 1, 1);
- } else {
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
- width, height);
- gdk_pixbuf_fill (pixbuf, 0xffffffff);
- bitmap_to_pixbuf (output->getBitmap(), pixbuf, 0, 0);
- }
-
- delete output;
-
- return pixbuf;
-}
-
-static void
-pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
- gint page,
- gint size,
- gint *width,
- gint *height)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
- Page *the_page;
- Object the_thumb;
- Thumb *thumb = NULL;
-
- the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
- the_page->getThumb (&the_thumb);
-
- if (!(the_thumb.isNull () || the_thumb.isNone())) {
- /* Build the thumbnail object */
- thumb = new Thumb(pdf_document->doc->getXRef (),
- &the_thumb);
-
- *width = thumb->getWidth ();
- *height = thumb->getHeight ();
- } else {
- double page_width, page_height;
-
- page_width = the_page->getWidth ();
- page_height = the_page->getHeight ();
-
- if (page_width > page_height) {
- *width = size;
- *height = (int) (size * page_height / page_width);
- } else {
- *width = (int) (size * page_width / page_height);
- *height = size;
- }
- }
-}
-
-static GdkPixbuf *
-pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
- gint page,
- gint size,
- gboolean border)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
- GdkPixbuf *thumbnail;
- Page *the_page;
- Object the_thumb;
- Thumb *thumb = NULL;
- gboolean have_ethumbs = FALSE;
-
- the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
- the_page->getThumb(&the_thumb);
-
- if (!(the_thumb.isNull () || the_thumb.isNone())) {
- /* Build the thumbnail object */
- thumb = new Thumb(pdf_document->doc->getXRef (),
- &the_thumb);
-
- have_ethumbs = thumb->ok();
- }
-
- if (have_ethumbs) {
- guchar *data;
- GdkPixbuf *tmp_pixbuf;
-
- data = thumb->getPixbufData();
- tmp_pixbuf = gdk_pixbuf_new_from_data (data,
- GDK_COLORSPACE_RGB,
- FALSE,
- 8,
- thumb->getWidth (),
- thumb->getHeight (),
- thumb->getWidth () * 3,
- NULL, NULL);
- /* FIXME: do we want to check that the thumb's size isn't ridiculous?? */
- thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
- g_object_unref (tmp_pixbuf);
- } else {
- int width, height;
- double scale_factor;
-
- pdf_document_thumbnails_get_dimensions (document_thumbnails, page, size,
- &width, &height);
- scale_factor = width / the_page->getWidth ();
- thumbnail = pdf_document_thumbnails_get_page_pixbuf (pdf_document,
- scale_factor,
- page,
- width,
- height,
- border);
- }
-
- return thumbnail;
-}
-static void
-pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
-{
- iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
- iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
-}
-
-
-static void
-pdf_document_init (PdfDocument *pdf_document)
-{
- pdf_document->page = 1;
- pdf_document->page_x_offset = 0;
- pdf_document->page_y_offset = 0;
- pdf_document->scale = 1.;
-
- pdf_document->password = NULL;
-}
-
diff --git a/pdf/pdf-document.h b/pdf/pdf-document.h
deleted file mode 100644
index 5b119b4..0000000
--- a/pdf/pdf-document.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* pdfdocument.h: Implementation of EvDocument for PDF
- * 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 __PDF_DOCUMENT_H__
-#define __PDF_DOCUMENT_H__
-
-#include "ev-document.h"
-
-G_BEGIN_DECLS
-
-#define PDF_TYPE_DOCUMENT (pdf_document_get_type ())
-#define PDF_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDF_TYPE_DOCUMENT, PdfDocument))
-#define PDF_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDF_TYPE_DOCUMENT))
-
-typedef struct _PdfDocument PdfDocument;
-
-PdfDocument *pdf_document_new (void);
-
-GType pdf_document_get_type (void) G_GNUC_CONST;
-
-G_END_DECLS
-
-#endif /* __PDF_DOCUMENT_H__ */
diff --git a/pdf/test-gdk-output-dev.cc b/pdf/test-gdk-output-dev.cc
deleted file mode 100644
index 713cd24..0000000
--- a/pdf/test-gdk-output-dev.cc
+++ /dev/null
@@ -1,174 +0,0 @@
-/**
- * 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;
-}