2006-03-26 03:31:42 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Rob Kendrick <rjek@rjek.com>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2006-03-26 03:31:42 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \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>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/content.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "desktop/browser.h"
|
2011-01-30 02:40:22 +03:00
|
|
|
#include "gtk/scaffolding.h"
|
|
|
|
#include "gtk/plotters.h"
|
|
|
|
#include "gtk/bitmap.h"
|
2008-08-13 21:16:39 +04:00
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "render/font.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utils.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
|
|
|
|
*/
|
2010-03-28 16:56:39 +04:00
|
|
|
bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap,
|
2006-03-26 03:31:42 +04:00
|
|
|
const char *url)
|
|
|
|
{
|
2008-03-25 14:42:59 +03:00
|
|
|
GdkPixbuf *pixbuf;
|
2008-08-13 21:16:39 +04:00
|
|
|
int cwidth, cheight;
|
2011-02-14 01:25:11 +03:00
|
|
|
struct rect clip;
|
2008-03-25 14:42:59 +03:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint depth;
|
|
|
|
GdkPixmap *pixmap;
|
2006-03-26 05:14:01 +04:00
|
|
|
GdkPixbuf *big;
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2008-03-25 14:42:59 +03:00
|
|
|
assert(content);
|
|
|
|
assert(bitmap);
|
|
|
|
|
2011-02-14 01:25:11 +03:00
|
|
|
clip.x0 = 0;
|
|
|
|
clip.y0 = 0;
|
|
|
|
clip.x1 = content_get_width(content);
|
|
|
|
clip.y1 = content_get_width(content);
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
cwidth = min(content_get_width(content), 1024);
|
|
|
|
cheight = min(content_get_height(content), 768);
|
2008-08-13 21:16:39 +04:00
|
|
|
|
2008-03-25 14:42:59 +03:00
|
|
|
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;
|
|
|
|
|
2008-03-20 22:12:17 +03:00
|
|
|
LOG(("Trying to create a thumbnail pixmap for a content of %dx%d@%d",
|
2010-03-28 16:56:39 +04:00
|
|
|
content_get_width(content), content_get_height(content),
|
|
|
|
depth));
|
2008-03-20 22:12:17 +03:00
|
|
|
|
2008-08-13 21:16:39 +04:00
|
|
|
pixmap = gdk_pixmap_new(NULL, cwidth, cwidth, depth);
|
2008-03-25 14:42:59 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2006-03-26 03:31:42 +04:00
|
|
|
|
|
|
|
gdk_drawable_set_colormap(pixmap, gdk_colormap_get_system());
|
|
|
|
|
|
|
|
/* set the plotting functions up */
|
|
|
|
plot = nsgtk_plotters;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
nsgtk_plot_set_scale((double) cwidth /
|
|
|
|
(double) content_get_width(content));
|
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
|
2009-07-09 02:04:40 +04:00
|
|
|
plot.rectangle(0, 0, cwidth, cwidth, plot_style_fill_white);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2011-02-14 01:25:11 +03:00
|
|
|
plot.clip(clip.x0, clip.y0, clip.x1, clip.y1);
|
2010-09-10 17:08:05 +04:00
|
|
|
|
2006-03-26 03:31:42 +04:00
|
|
|
/* render the content */
|
2010-03-28 16:56:39 +04:00
|
|
|
content_redraw(content, 0, 0, content_get_width(content),
|
|
|
|
content_get_width(content),
|
2011-02-14 01:25:11 +03:00
|
|
|
&clip, 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,
|
2008-08-13 21:16:39 +04:00
|
|
|
cwidth, cwidth);
|
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,
|
2008-08-13 21:16:39 +04:00
|
|
|
(double)width / (double)cwidth,
|
|
|
|
(double)height / (double)cwidth,
|
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;
|
|
|
|
}
|