#include "ev-document-find.h"
#include "gpdf-g-switch.h"
#include "ev-document-bookmarks.h"
+#include "ev-document-misc.h"
#include "ev-document-thumbnails.h"
#include "GlobalParams.h"
#include "GDKSplashOutputDev.h"
+#include "SplashBitmap.h"
#include "PDFDoc.h"
#include "Outline.h"
#include "UnicodeMap.h"
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) {
+ GString *fname = new GString (filename);
+
+ retval = pdf_document->doc->saveAs (fname);
+ }
+
+ return retval;
+}
+
static int
pdf_document_get_n_pages (EvDocument *document)
{
return (EvDocumentBookmarksIter *) iter;
}
-static gboolean
-pdf_document_bookmarks_get_values (EvDocumentBookmarks *document_bookmarks,
- EvDocumentBookmarksIter *bookmarks_iter,
- char **title,
- EvDocumentBookmarksType *type,
- gint *page)
+static EvBookmark *
+pdf_document_bookmarks_get_bookmark (EvDocumentBookmarks *document_bookmarks,
+ EvDocumentBookmarksIter *bookmarks_iter)
{
PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
+ EvBookmark *bookmark;
BookmarksIter *iter = (BookmarksIter *)bookmarks_iter;
OutlineItem *anItem;
LinkAction *link_action;
GString *named_dest;
Unicode *link_title;
Ref page_ref;
- gint page_num = -1;
+ gint page_num = 0;
+ char *title;
g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (title != NULL, FALSE);
- g_return_val_if_fail (type != NULL, FALSE);
- g_return_val_if_fail (page != NULL, FALSE);
anItem = (OutlineItem *)iter->items->get(iter->index);
link_action = anItem->getAction ();
g_warning ("Unknown link action type: %d", link_action->getKind ());
}
- *title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
+ title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
} else if (link_title) {
- *title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
+ title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
}
- *type = EV_DOCUMENT_BOOKMARKS_TYPE_LINK;
- *page = page_num;
+ bookmark = ev_bookmark_new (title, EV_BOOKMARK_TYPE_LINK, page_num);
- return TRUE;
+ g_free (title);
+
+ return bookmark;
}
static EvDocumentBookmarksIter *
return title;
}
+static char *
+pdf_document_get_text (EvDocument *document, GdkRectangle *rect)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+ GString *sel_text = new GString;
+ const char *text;
+ int x1, y1, x2, y2;
+
+ x1 = rect->x;
+ y1 = rect->y;
+ 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 void
pdf_document_get_property (GObject *object,
guint prop_id,
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_n_pages = pdf_document_get_n_pages;
iface->set_page = pdf_document_set_page;
iface->get_page = pdf_document_get_page;
{
iface->has_document_bookmarks = pdf_document_bookmarks_has_document_bookmarks;
iface->begin_read = pdf_document_bookmarks_begin_read;
- iface->get_values = pdf_document_bookmarks_get_values;
+ iface->get_bookmark = pdf_document_bookmarks_get_bookmark;
iface->get_child = pdf_document_bookmarks_get_child;
iface->next = pdf_document_bookmarks_next;
iface->free_iter = pdf_document_bookmarks_free_iter;
}
/* 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 width,
gint height)
{
- GdkPixmap *pixmap;
- GDKSplashOutputDev *output;
+ SplashOutputDev *output;
GdkPixbuf *pixbuf;
+ SplashColor color;
- pixmap = gdk_pixmap_new (pdf_document->target,
- width, height, -1);
+ color.rgb8 = splashMakeRGB8 (255, 255, 255);
- output = new GDKSplashOutputDev (gdk_drawable_get_screen (pdf_document->target),
- NULL, NULL);
+ 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);
- output->redraw (0, 0,
- pixmap,
- 0, 0,
- width, height);
- pixbuf = gdk_pixbuf_get_from_drawable (NULL,
- pixmap,
- NULL,
- 0, 0,
- 0, 0,
- width, height);
- gdk_drawable_unref (pixmap);
+
+ pixbuf = ev_document_misc_get_thumbnail_frame (output->getBitmap()->getWidth(),
+ output->getBitmap()->getHeight(),
+ NULL);
+ bitmap_to_pixbuf (output->getBitmap(), pixbuf, 1, 1);
delete output;
+
return pixbuf;
}
+static void
+pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
+ gint page,
+ gint suggested_width,
+ gint *width,
+ gint *height)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
+ Page *the_page;
+ Object the_thumb;
+ Thumb *thumb = NULL;
+ gdouble page_ratio;
+
+ /* getPage seems to want page + 1 for some reason; */
+ 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 {
+ page_ratio = the_page->getHeight () / the_page->getWidth ();
+ *width = suggested_width;
+ *height = (gint) (suggested_width * page_ratio);
+ }
+}
+
static GdkPixbuf *
pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
gint page,
Object the_thumb;
Thumb *thumb = NULL;
gboolean have_ethumbs = FALSE;
+ gdouble page_ratio;
+ gint dest_height;
/* getPage seems to want page + 1 for some reason; */
the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
the_page->getThumb(&the_thumb);
+ page_ratio = the_page->getHeight () / the_page->getWidth ();
+ dest_height = (gint) (width * page_ratio);
+
+
if (!(the_thumb.isNull () || the_thumb.isNone())) {
/* Build the thumbnail object */
thumb = new Thumb(pdf_document->doc->getXRef (),
GdkPixbuf *tmp_pixbuf;
data = thumb->getPixbufData();
- /* FISME: scale the image if it's not an appropriate size */
tmp_pixbuf = gdk_pixbuf_new_from_data (data,
GDK_COLORSPACE_RGB,
FALSE,
thumb->getHeight (),
thumb->getWidth () * 3,
NULL, NULL);
-
- thumbnail = tmp_pixbuf;
+ /* 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 {
- gdouble page_ratio;
gdouble scale_factor;
- gint dest_height;
- page_ratio = the_page->getHeight () / the_page->getWidth ();
scale_factor = (gdouble)width / the_page->getWidth ();
- dest_height = (gint) (width * page_ratio);
thumbnail = pdf_document_thumbnails_get_page_pixbuf (pdf_document,
scale_factor,
page,
width,
dest_height);
-
- /* FIXME: Actually get the image... */
}
return thumbnail;
pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
{
iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
+ iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
}