Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2011 Michael Drake <tlsa@netsurf-browser.org>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. /** \file
  20.  * Core thumbnail handling (implementation).
  21.  */
  22.  
  23. #include <assert.h>
  24. #include <stdbool.h>
  25.  
  26. #include "content/content.h"
  27. #include "content/hlcache.h"
  28. #include "desktop/browser.h"
  29. #include "desktop/knockout.h"
  30. #include "desktop/options.h"
  31. #include "desktop/plotters.h"
  32. #include "desktop/thumbnail.h"
  33. #include "utils/log.h"
  34.  
  35.  
  36. /**
  37.  * Get scale at which thumbnail will be rendered for a given content and
  38.  * thumbnail size.
  39.  *
  40.  * \param  content  The content to redraw for thumbnail
  41.  * \param  width    The thumbnail width
  42.  * \return scale thumbnail will be rendered at
  43.  *
  44.  * Units for width and height are pixels.
  45.  */
  46. static float thumbnail_get_redraw_scale(struct hlcache_handle *content,
  47.                 int width)
  48. {
  49.         assert(content);
  50.  
  51.         if (content_get_width(content))
  52.                 return (float)width / (float)content_get_width(content);
  53.         else
  54.                 return 1.0;    
  55. }
  56.  
  57.  
  58. /* exported interface, documented in thumbnail.h */
  59. bool thumbnail_redraw(struct hlcache_handle *content,
  60.                 int width, int height, const struct redraw_context *ctx)
  61. {
  62.         struct redraw_context new_ctx = *ctx;
  63.         struct rect clip;
  64.         struct content_redraw_data data;
  65.         float scale;
  66.         bool plot_ok = true;
  67.  
  68.         assert(content);
  69.  
  70.         if (ctx->plot->option_knockout)
  71.                 knockout_plot_start(ctx, &new_ctx);
  72.  
  73.         /* Set clip rectangle to required thumbnail size */
  74.         clip.x0 = 0;
  75.         clip.y0 = 0;
  76.         clip.x1 = width;
  77.         clip.y1 = height;
  78.  
  79.         new_ctx.plot->clip(&clip);
  80.  
  81.         /* Plot white background */
  82.         plot_ok &= new_ctx.plot->rectangle(clip.x0, clip.y0, clip.x1, clip.y1,
  83.                         plot_style_fill_white);
  84.  
  85.         /* Find the scale we're using */
  86.         scale = thumbnail_get_redraw_scale(content, width);
  87.  
  88.         /* Set up content redraw data */
  89.         data.x = 0;
  90.         data.y = 0;
  91.         data.width = width;
  92.         data.height = height;
  93.  
  94.         data.background_colour = 0xFFFFFF;
  95.         data.scale = scale;
  96.         data.repeat_x = false;
  97.         data.repeat_y = false;
  98.  
  99.         /* Render the content */
  100.         plot_ok &= content_redraw(content, &data, &clip, &new_ctx);
  101.        
  102.         if (ctx->plot->option_knockout)
  103.                 knockout_plot_end();
  104.  
  105.         return plot_ok;
  106. }
  107.