Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/thumbnail-frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion help/reference/libdocument/libxreaderdocument-docs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
<xi:include href="xml/ev-document-misc.xml"/>
<xi:include href="xml/ev-document-print.xml"/>
<xi:include href="xml/ev-document-security.xml"/>
<xi:include href="xml/ev-document-thumbnails.xml"/>
<xi:include href="xml/ev-document-transition.xml"/>
<xi:include href="xml/ev-selection.xml"/>
<xi:include href="xml/ev-file-exporter.xml"/>
Expand Down
124 changes: 85 additions & 39 deletions libdocument/ev-document-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

#include "ev-document-misc.h"

/* Returns a new GdkPixbuf that is suitable for placing in the thumbnail view.
* It is four pixels wider and taller than the source. If source_pixbuf is not
* NULL, then it will fill the return pixbuf with the contents of
* source_pixbuf.
/**
* Returns a new GdkPixbuf that is suitable for placing in the thumbnail view.
* If source_pixbuf is not NULL, then it will fill the return pixbuf with the
* contents of source_pixbuf.
*/
static GdkPixbuf *
create_thumbnail_frame (int width,
Expand All @@ -39,57 +39,31 @@ create_thumbnail_frame (int width,
gboolean fill_bg)
{
GdkPixbuf *retval;
guchar *data;
gint rowstride;
int i;
int width_r, height_r;

if (source_pixbuf)
g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);

if (source_pixbuf) {
width_r = gdk_pixbuf_get_width (source_pixbuf);
height_r = gdk_pixbuf_get_height (source_pixbuf);
} else {
width_r = width;
height_r = height;
}
width_r = gdk_pixbuf_get_width (source_pixbuf);
height_r = gdk_pixbuf_get_height (source_pixbuf);

/* make sure no one is passing us garbage */
g_return_val_if_fail (width_r >= 0 && height_r >= 0, NULL);

retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
TRUE, 8,
width_r + 4,
height_r + 4);

/* make it black and fill in the middle */
data = gdk_pixbuf_get_pixels (retval);
rowstride = gdk_pixbuf_get_rowstride (retval);
width_r,
height_r);

gdk_pixbuf_fill (retval, 0x000000ff);
if (fill_bg) {
for (i = 1; i < height_r + 1; i++)
memset (data + (rowstride * i) + 4, 0xffffffff, width_r * 4);
}

/* copy the source pixbuf */
if (source_pixbuf)
gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
width_r,
height_r,
retval,
1, 1);
/* Add the corner */
data [(width_r + 2) * 4 + 3] = 0;
data [(width_r + 3) * 4 + 3] = 0;
data [(width_r + 2) * 4 + (rowstride * 1) + 3] = 0;
data [(width_r + 3) * 4 + (rowstride * 1) + 3] = 0;

data [(height_r + 2) * rowstride + 3] = 0;
data [(height_r + 3) * rowstride + 3] = 0;
data [(height_r + 2) * rowstride + 4 + 3] = 0;
data [(height_r + 3) * rowstride + 4 + 3] = 0;
gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
width_r,
height_r,
retval,
0, 0);

return retval;
}
Expand All @@ -110,6 +84,78 @@ ev_document_misc_get_loading_thumbnail (int width,
return create_thumbnail_frame (width, height, NULL, !inverted_colors);
}

static GdkPixbuf *
ev_document_misc_render_thumbnail_frame (GtkWidget *widget,
int width,
int height,
gboolean inverted_colors,
GdkPixbuf *source_pixbuf)
{
GtkStyleContext *context = gtk_widget_get_style_context (widget);
GtkStateFlags state = gtk_widget_get_state_flags (widget);
int width_r, height_r;
int width_f, height_f;
cairo_surface_t *surface;
cairo_t *cr;
GtkBorder border = {0, };
GdkPixbuf *retval;

if (source_pixbuf) {
g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);

width_r = gdk_pixbuf_get_width (source_pixbuf);
height_r = gdk_pixbuf_get_height (source_pixbuf);
} else {
width_r = width;
height_r = height;
}

gtk_style_context_save (context);

gtk_style_context_add_class (context, "page-thumbnail");
if (inverted_colors)
gtk_style_context_add_class (context, "inverted");

gtk_style_context_get_border (context, state, &border);
width_f = width_r + border.left + border.right;
height_f = height_r + border.top + border.bottom;

surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
width_f, height_f);
cr = cairo_create (surface);
if (source_pixbuf) {
gdk_cairo_set_source_pixbuf (cr, source_pixbuf, border.left, border.top);
cairo_paint (cr);
} else {
gtk_render_background (context, cr, 0, 0, width_f, height_f);
}
gtk_render_frame (context, cr, 0, 0, width_f, height_f);
cairo_destroy (cr);

gtk_style_context_restore (context);

retval = gdk_pixbuf_get_from_surface (surface, 0, 0, width_f, height_f);
cairo_surface_destroy (surface);

return retval;
}

GdkPixbuf *
ev_document_misc_render_loading_thumbnail (GtkWidget *widget,
int width,
int height,
gboolean inverted_colors)
{
return ev_document_misc_render_thumbnail_frame (widget, width, height, inverted_colors, NULL);
}

GdkPixbuf *
ev_document_misc_render_thumbnail_with_frame (GtkWidget *widget,
GdkPixbuf *source_pixbuf)
{
return ev_document_misc_render_thumbnail_frame (widget, -1, -1, FALSE, source_pixbuf);
}

void
ev_document_misc_get_page_border_size (gint page_width,
gint page_height,
Expand Down
12 changes: 12 additions & 0 deletions libdocument/ev-document-misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,27 @@

#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
#include "ev-macros.h"

G_BEGIN_DECLS

EV_DEPRECATED
GdkPixbuf *ev_document_misc_get_thumbnail_frame (int width,
int height,
GdkPixbuf *source_pixbuf);
EV_DEPRECATED
GdkPixbuf *ev_document_misc_get_loading_thumbnail (int width,
int height,
gboolean inverted_colors);

GdkPixbuf *ev_document_misc_render_loading_thumbnail (GtkWidget *widget,
int width,
int height,
gboolean inverted_colors);
GdkPixbuf *ev_document_misc_render_thumbnail_with_frame (GtkWidget *widget,
GdkPixbuf *source_pixbuf);

EV_DEPRECATED
void ev_document_misc_get_page_border_size (gint page_width,
gint page_height,
GtkBorder *border);
Expand Down
70 changes: 42 additions & 28 deletions libview/ev-view.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* this file is part of xreader, a mate document viewer
/* this file is part of xreader, a generic document viewer
*
* Copyright (C) 2004 Red Hat, Inc
*
Expand Down Expand Up @@ -101,6 +101,9 @@ typedef struct {

#define SCROLL_TIME 150

#define EV_STYLE_CLASS_DOCUMENT_PAGE "document-page"
#define EV_STYLE_CLASS_INVERTED "inverted"

/*** Scrolling ***/
static void view_update_range_and_current_page (EvView *view);
static void add_scroll_binding_keypad (GtkBindingSet *binding_set,
Expand All @@ -113,8 +116,6 @@ static void ensure_rectangle_is_visible (EvView

/*** Geometry computations ***/
static void compute_border (EvView *view,
int width,
int height,
GtkBorder *border);
static void get_page_y_offset (EvView *view,
int page,
Expand Down Expand Up @@ -1035,9 +1036,16 @@ ensure_rectangle_is_visible (EvView *view, GdkRectangle *rect)
/*** Geometry computations ***/

static void
compute_border (EvView *view, int width, int height, GtkBorder *border)
compute_border (EvView *view, GtkBorder *border)
{
ev_document_misc_get_page_border_size (width, height, border);
GtkWidget *widget = GTK_WIDGET (view);
GtkStyleContext *context = gtk_widget_get_style_context (widget);
GtkStateFlags state = gtk_widget_get_state_flags (widget);

gtk_style_context_save (context);
gtk_style_context_add_class (context, EV_STYLE_CLASS_DOCUMENT_PAGE);
gtk_style_context_get_border (context, state, border);
gtk_style_context_restore (context);
}

void
Expand Down Expand Up @@ -1098,13 +1106,12 @@ ev_view_get_max_page_size (EvView *view,
static void
get_page_y_offset (EvView *view, int page, int *y_offset)
{
int max_width, offset = 0;
int offset = 0;
GtkBorder border;

g_return_if_fail (y_offset != NULL);

ev_view_get_max_page_size (view, &max_width, NULL);
compute_border (view, max_width, max_width, &border);
compute_border (view, &border);

if (view->dual_page) {
ev_view_get_height_to_page (view, page, NULL, &offset);
Expand Down Expand Up @@ -1134,7 +1141,7 @@ ev_view_get_page_extents (EvView *view,

/* Get the size of the page */
ev_view_get_page_size (view, page, &width, &height);
compute_border (view, width, height, border);
compute_border (view, border);
page_area->width = width + border->left + border->right;
page_area->height = height + border->top + border->bottom;

Expand Down Expand Up @@ -1180,7 +1187,7 @@ ev_view_get_page_extents (EvView *view,
if (height_2 > height)
max_height = height_2;
}
compute_border (view, max_width, max_height, &overall_border);
compute_border (view, &overall_border);

/* Find the offsets */
x = view->spacing;
Expand Down Expand Up @@ -3186,7 +3193,7 @@ ev_view_size_request_continuous_dual_page (EvView *view,
GtkBorder border;

ev_view_get_max_page_size (view, &max_width, NULL);
compute_border (view, max_width, max_width, &border);
compute_border (view, &border);
requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
}
break;
Expand Down Expand Up @@ -3215,7 +3222,7 @@ ev_view_size_request_continuous (EvView *view,
GtkBorder border;

ev_view_get_max_page_size (view, &max_width, NULL);
compute_border (view, max_width, max_width, &border);
compute_border (view, &border);
requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
}
break;
Expand Down Expand Up @@ -3252,7 +3259,7 @@ ev_view_size_request_dual_page (EvView *view,
height = height_2;
}
}
compute_border (view, width, height, &border);
compute_border (view, &border);

requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
((width + border.left + border.right) * 2) + (view->spacing * 3);
Expand All @@ -3274,7 +3281,7 @@ ev_view_size_request_single_page (EvView *view,
}

ev_view_get_page_size (view, view->current_page, &width, &height);
compute_border (view, width, height, &border);
compute_border (view, &border);

requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
width + border.left + border.right + (2 * view->spacing);
Expand Down Expand Up @@ -4589,10 +4596,10 @@ draw_one_page (EvView *view,
GdkRectangle *expose_area,
gboolean *page_ready)
{
GdkRectangle overlap;
GdkRectangle real_page_area;
gint current_page;
gboolean inverted_colors;
GtkStyleContext *context;
GdkRectangle overlap;
GdkRectangle real_page_area;
gint current_page;

g_assert (view->document);

Expand All @@ -4608,13 +4615,20 @@ draw_one_page (EvView *view,
real_page_area.height -= (border->top + border->bottom);
*page_ready = TRUE;

context = gtk_widget_get_style_context (GTK_WIDGET (view));
current_page = ev_document_model_get_page (view->model);
inverted_colors = ev_document_model_get_inverted_colors (view->model);
ev_document_misc_paint_one_page (cr,
GTK_WIDGET (view),
page_area, border,
page == current_page,
inverted_colors);

gtk_style_context_save (context);
gtk_style_context_add_class (context, EV_STYLE_CLASS_DOCUMENT_PAGE);
if (ev_document_model_get_inverted_colors (view->model))
gtk_style_context_add_class (context, EV_STYLE_CLASS_INVERTED);

if (view->continuous && page == current_page)
gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);

gtk_render_background (context, cr, page_area->x, page_area->y, page_area->width, page_area->height);
gtk_render_frame (context, cr, page_area->x, page_area->y, page_area->width, page_area->height);
gtk_style_context_restore (context);

if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) {
gint width, height;
Expand Down Expand Up @@ -6003,7 +6017,7 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
doc_height = tmp;
}

compute_border (view, doc_width, doc_height, &border);
compute_border (view, &border);

doc_width *= 2;
width -= (2 * (border.left + border.right) + 3 * view->spacing);
Expand Down Expand Up @@ -6040,7 +6054,7 @@ ev_view_zoom_for_size_continuous (EvView *view,
doc_height = tmp;
}

compute_border (view, doc_width, doc_height, &border);
compute_border (view, &border);

width -= (border.left + border.right + 2 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing - 1);
Expand Down Expand Up @@ -6080,7 +6094,7 @@ ev_view_zoom_for_size_dual_page (EvView *view,
if (height_2 > doc_height)
doc_height = height_2;
}
compute_border (view, width, height, &border);
compute_border (view, &border);

doc_width = doc_width * 2;
width -= ((border.left + border.right)* 2 + 3 * view->spacing);
Expand Down Expand Up @@ -6111,7 +6125,7 @@ ev_view_zoom_for_size_single_page (EvView *view,
get_doc_page_size (view, view->current_page, &doc_width, &doc_height);

/* Get an approximate border */
compute_border (view, width, height, &border);
compute_border (view, &border);

width -= (border.left + border.right + 2 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing);
Expand Down
Loading