summaryrefslogtreecommitdiff
path: root/gtk/thumbnail.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-01-29 23:40:22 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-01-29 23:40:22 +0000
commit42f89d4e0b35bbe768918305b624e20ef654d619 (patch)
treede555d8fc6dcf8c1ed61c73301552bf0a9e06b8e /gtk/thumbnail.c
parentcd5950936ade8320f3801ed213df41153e573f8b (diff)
downloadnetsurf-42f89d4e0b35bbe768918305b624e20ef654d619.tar.gz
netsurf-42f89d4e0b35bbe768918305b624e20ef654d619.tar.bz2
fixup gtk source file names
svn path=/trunk/netsurf/; revision=11529
Diffstat (limited to 'gtk/thumbnail.c')
-rw-r--r--gtk/thumbnail.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/gtk/thumbnail.c b/gtk/thumbnail.c
new file mode 100644
index 000000000..53d62fe30
--- /dev/null
+++ b/gtk/thumbnail.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2006 Rob Kendrick <rjek@rjek.com>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf 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; version 2 of the License.
+ *
+ * NetSurf 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/** \file
+ * Page thumbnail creation (implementation).
+ *
+ * Thumbnails are created by setting the current drawing contexts to the
+ * bitmap (a gdk pixbuf) we are passed, and plotting the page at a small
+ * scale.
+ */
+
+#include <assert.h>
+#include <gtk/gtk.h>
+#include "content/content.h"
+#include "content/hlcache.h"
+#include "content/urldb.h"
+#include "desktop/plotters.h"
+#include "desktop/browser.h"
+#include "gtk/scaffolding.h"
+#include "gtk/plotters.h"
+#include "gtk/bitmap.h"
+#include "image/bitmap.h"
+#include "render/font.h"
+#include "utils/log.h"
+#include "utils/utils.h"
+
+/**
+ * Create a thumbnail of a page.
+ *
+ * \param content content structure to thumbnail
+ * \param bitmap the bitmap to draw to
+ * \param url the URL the thumnail belongs to, or NULL
+ */
+bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap,
+ const char *url)
+{
+ GdkPixbuf *pixbuf;
+ int cwidth, cheight;
+ gint width;
+ gint height;
+ gint depth;
+ GdkPixmap *pixmap;
+ GdkPixbuf *big;
+
+ assert(content);
+ assert(bitmap);
+
+ cwidth = min(content_get_width(content), 1024);
+ cheight = min(content_get_height(content), 768);
+
+ pixbuf = gtk_bitmap_get_primary(bitmap);
+ width = gdk_pixbuf_get_width(pixbuf);
+ height = gdk_pixbuf_get_height(pixbuf);
+ depth = (gdk_screen_get_system_visual(gdk_screen_get_default()))->depth;
+
+ LOG(("Trying to create a thumbnail pixmap for a content of %dx%d@%d",
+ content_get_width(content), content_get_height(content),
+ depth));
+
+ pixmap = gdk_pixmap_new(NULL, cwidth, cwidth, depth);
+
+ if (pixmap == NULL) {
+ /* the creation failed for some reason: most likely because
+ * we've been asked to create with with at least one dimention
+ * as zero. The RISC OS thumbnail generator returns false
+ * from here when it can't create a bitmap, so we assume it's
+ * safe to do so here too.
+ */
+ return false;
+ }
+
+ gdk_drawable_set_colormap(pixmap, gdk_colormap_get_system());
+
+ /* set the plotting functions up */
+ plot = nsgtk_plotters;
+
+ nsgtk_plot_set_scale((double) cwidth /
+ (double) content_get_width(content));
+
+ /* set to plot to pixmap */
+ current_drawable = pixmap;
+ current_gc = gdk_gc_new(current_drawable);
+#ifdef CAIRO_VERSION
+ current_cr = gdk_cairo_create(current_drawable);
+#endif
+ plot.rectangle(0, 0, cwidth, cwidth, plot_style_fill_white);
+
+ plot.clip(0, 0, content_get_width(content), content_get_width(content));
+
+ /* render the content */
+ content_redraw(content, 0, 0, content_get_width(content),
+ content_get_width(content),
+ 0, 0, content_get_width(content),
+ content_get_width(content), 1.0, 0xFFFFFF);
+
+ /* resample the large plot down to the size of our thumbnail */
+ big = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0,
+ cwidth, cwidth);
+
+ gdk_pixbuf_scale(big, pixbuf, 0, 0, width, height, 0, 0,
+ (double)width / (double)cwidth,
+ (double)height / (double)cwidth,
+ GDK_INTERP_TILES);
+
+ /* As a debugging aid, try this to dump out a copy of the thumbnail as
+ * a PNG: gdk_pixbuf_save(pixbuf, "thumbnail.png", "png", NULL, NULL);
+ */
+
+ /* register the thumbnail with the URL */
+ if (url)
+ urldb_set_thumbnail(url, bitmap);
+
+ bitmap_modified(bitmap);
+
+ g_object_unref(current_gc);
+#ifdef CAIRO_VERSION
+ cairo_destroy(current_cr);
+#endif
+ g_object_unref(pixmap);
+ g_object_unref(big);
+
+ return true;
+}