2006-03-26 03:31:42 +04:00
|
|
|
/*
|
2006-11-27 18:35:18 +03:00
|
|
|
* This file is part of NetSurf, http://netsurf-browser.org/
|
2006-03-26 03:31:42 +04:00
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2006 Rob Kendrick <rjek@rjek.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \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 "netsurf/content/content.h"
|
2006-04-10 03:21:13 +04:00
|
|
|
#include "netsurf/content/urldb.h"
|
2006-03-26 03:31:42 +04:00
|
|
|
#include "netsurf/desktop/plotters.h"
|
|
|
|
#include "netsurf/desktop/browser.h"
|
|
|
|
#include "netsurf/image/bitmap.h"
|
|
|
|
#include "netsurf/render/font.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
2006-11-27 20:13:24 +03:00
|
|
|
#include "netsurf/gtk/gtk_scaffolding.h"
|
2006-03-26 03:31:42 +04:00
|
|
|
#include "netsurf/gtk/gtk_plotters.h"
|
2006-08-09 19:06:14 +04:00
|
|
|
#include "netsurf/gtk/gtk_bitmap.h"
|
2006-03-26 03:31:42 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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(struct content *content, struct bitmap *bitmap,
|
|
|
|
const char *url)
|
|
|
|
{
|
2006-08-09 19:06:14 +04:00
|
|
|
GdkPixbuf *pixbuf = gtk_bitmap_get_primary(bitmap);
|
2006-03-26 03:31:42 +04:00
|
|
|
gint width = gdk_pixbuf_get_width(pixbuf);
|
|
|
|
gint height = gdk_pixbuf_get_height(pixbuf);
|
|
|
|
gint depth = (gdk_screen_get_system_visual(gdk_screen_get_default()))->depth;
|
2006-03-26 05:14:01 +04:00
|
|
|
GdkPixmap *pixmap = gdk_pixmap_new(NULL, content->width, content->width, depth);
|
|
|
|
GdkPixbuf *big;
|
2006-03-26 03:31:42 +04:00
|
|
|
|
|
|
|
assert(content);
|
|
|
|
assert(bitmap);
|
|
|
|
|
|
|
|
gdk_drawable_set_colormap(pixmap, gdk_colormap_get_system());
|
|
|
|
|
|
|
|
/* set the plotting functions up */
|
|
|
|
plot = nsgtk_plotters;
|
|
|
|
|
2006-03-26 05:14:01 +04:00
|
|
|
nsgtk_plot_set_scale(1.0);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
|
|
|
/* 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
|
2006-03-26 05:14:01 +04:00
|
|
|
plot.fill(0, 0, content->width, content->width, 0xffffffff);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
|
|
|
/* render the content */
|
2006-03-26 05:14:01 +04:00
|
|
|
content_redraw(content, 0, 0, content->width, content->width,
|
|
|
|
0, 0, content->width, content->width, 1.0, 0xFFFFFF);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2006-03-26 05:14:01 +04:00
|
|
|
/* resample the large plot down to the size of our thumbnail */
|
|
|
|
big = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0,
|
|
|
|
content->width, content->width);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2006-03-26 05:14:01 +04:00
|
|
|
gdk_pixbuf_scale(big, pixbuf, 0, 0, width, height, 0, 0,
|
2006-04-10 03:21:13 +04:00
|
|
|
(double)width / (double)content->width,
|
2006-03-26 05:14:01 +04:00
|
|
|
(double)height / (double)content->width,
|
2006-03-27 04:51:21 +04:00
|
|
|
GDK_INTERP_TILES);
|
2006-03-26 05:14:01 +04:00
|
|
|
|
|
|
|
/* 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);
|
2006-03-26 03:31:42 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* register the thumbnail with the URL */
|
|
|
|
if (url)
|
2006-04-10 03:21:13 +04:00
|
|
|
urldb_set_thumbnail(url, bitmap);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
|
|
|
bitmap_modified(bitmap);
|
|
|
|
|
|
|
|
g_object_unref(current_gc);
|
|
|
|
#ifdef CAIRO_VERSION
|
|
|
|
cairo_destroy(current_cr);
|
|
|
|
#endif
|
|
|
|
g_object_unref(pixmap);
|
2006-03-26 05:18:00 +04:00
|
|
|
g_object_unref(big);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|