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>
|
2011-03-26 23:56:59 +03:00
|
|
|
#include <gdk/gdk.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-02-20 01:17:54 +03:00
|
|
|
#include "desktop/thumbnail.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)
|
|
|
|
{
|
2011-12-30 04:58:35 +04:00
|
|
|
cairo_surface_t *dsurface = bitmap->surface;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *old_cr;
|
|
|
|
gint dwidth, dheight;
|
2008-08-13 21:16:39 +04:00
|
|
|
int cwidth, cheight;
|
2011-06-30 19:48:07 +04:00
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = false,
|
2011-12-24 02:39:25 +04:00
|
|
|
.background_images = true,
|
2011-06-30 19:48:07 +04:00
|
|
|
.plot = &nsgtk_plotters
|
|
|
|
};
|
|
|
|
|
2008-03-25 14:42:59 +03:00
|
|
|
assert(content);
|
|
|
|
assert(bitmap);
|
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
dwidth = cairo_image_surface_get_width(dsurface);
|
|
|
|
dheight = cairo_image_surface_get_height(dsurface);
|
2008-03-25 14:42:59 +03:00
|
|
|
|
2011-02-16 16:52:29 +03:00
|
|
|
/* Calculate size of buffer to render the content into */
|
2011-02-16 17:35:48 +03:00
|
|
|
/* We get the width from the content width, unless it exceeds 1024,
|
|
|
|
* in which case we use 1024. This means we never create excessively
|
|
|
|
* large render buffers for huge contents, which would eat memory and
|
|
|
|
* cripple performance. */
|
2011-02-16 16:52:29 +03:00
|
|
|
cwidth = min(content_get_width(content), 1024);
|
2011-12-30 04:58:35 +04:00
|
|
|
|
2011-02-16 17:35:48 +03:00
|
|
|
/* The height is set in proportion with the width, according to the
|
|
|
|
* aspect ratio of the required thumbnail. */
|
2011-12-30 04:58:35 +04:00
|
|
|
cheight = ((cwidth * dheight) + (dwidth / 2)) / dwidth;
|
|
|
|
|
|
|
|
/* Create surface to render into */
|
|
|
|
surface = cairo_surface_create_similar(dsurface, CAIRO_CONTENT_COLOR_ALPHA, cwidth, cheight);
|
|
|
|
|
|
|
|
if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
|
|
|
|
cairo_surface_destroy(surface);
|
2008-03-25 14:42:59 +03:00
|
|
|
return false;
|
|
|
|
}
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
old_cr = current_cr;
|
|
|
|
current_cr = cairo_create(surface);
|
2011-02-16 16:52:29 +03:00
|
|
|
|
2006-03-26 03:31:42 +04:00
|
|
|
/* render the content */
|
2011-06-30 19:48:07 +04:00
|
|
|
thumbnail_redraw(content, cwidth, cheight, &ctx);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
cairo_destroy(current_cr);
|
|
|
|
current_cr = old_cr;
|
|
|
|
|
|
|
|
cairo_t *cr = cairo_create(dsurface);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
/* Scale *before* setting the source surface (1) */
|
|
|
|
cairo_scale (cr, (double)dwidth / cwidth, (double)dheight / cheight);
|
|
|
|
cairo_set_source_surface (cr, surface, 0, 0);
|
2006-03-26 05:14:01 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
/* To avoid getting the edge pixels blended with 0 alpha,
|
|
|
|
* which would occur with the default EXTEND_NONE. Use
|
|
|
|
* EXTEND_PAD for 1.2 or newer (2)
|
2006-03-26 03:31:42 +04:00
|
|
|
*/
|
2011-12-30 04:58:35 +04:00
|
|
|
cairo_pattern_set_extend (cairo_get_source(cr), CAIRO_EXTEND_REFLECT);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
/* Replace the destination with the source instead of overlaying */
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
/* Do the actual drawing */
|
|
|
|
cairo_paint(cr);
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
cairo_surface_destroy(surface);
|
2011-09-17 18:58:42 +04:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
/* register the thumbnail with the URL */
|
|
|
|
if (url)
|
|
|
|
urldb_set_thumbnail(url, bitmap);
|
2006-03-26 03:31:42 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-16 17:35:48 +03:00
|
|
|
|