Skip to content

Commit 2bd08e3

Browse files
Piiitclefebvre
authored andcommitted
Change border of pages to a realistic shadow, make thumbnails styleable via CSS (#248)
* ev-view: Update EvView style to use CSS node name based on commit f1d24b0a6b799abc4ff948286c121b6a5bb7a909 * EVINCE BACKPORTS: libdocument: Allow sidebar thumbnails to be styled with CSS commit 30d1c3f4d71d5f53603076c7c93a5999e65eec5a Author: William Jon McCann <jmccann@redhat.com> Date: Sun Dec 23 13:18:49 2012 +0100 libdocument: Allow sidebar thumbnails to be styled with CSS https://bugzilla.gnome.org/show_bug.cgi?id=653294 ...this commit includes also: commit 16bbee9df797c9498b0be983d1bcde309e281824 Author: Trinh Anh Ngoc <atw1990@gmail.com> Date: Sun Nov 29 09:28:29 2015 +0700 shell: Update sidebar thumbnails CSS nodes Fixes frameless thumbnails with GTK+ 3.20 https://bugzilla.gnome.org/show_bug.cgi?id=758793 * EVINCE BACKPORTS: view: Use a rendered frame instead of custom border commit 7a6b53a1b4083cf6a3d9660dfc7978bb37c3d9e7 Author: William Jon McCann <jmccann@redhat.com> Date: Sun Dec 23 10:49:58 2012 +0100 view: Use a rendered frame instead of custom border So it can be styled with CSS. https://bugzilla.gnome.org/show_bug.cgi?id=653294 * EVINCE BACKPORTS: view: Fix page background rendering while loading commit 38528f9f1e225f4d661a1d813c5fae45fd6707d4 Author: Carlos Garcia Campos <carlosgc@gnome.org> Date: Sun Dec 23 11:28:46 2012 +0100 view: Fix page background rendering while loading * EVINCE BACKPORTS: previewer: Add CSS file for EvView styling commit 48110cb41681d8babe94cc8ee3fb26a533d16671 Author: Carlos Garcia Campos <cgarcia@igalia.com> Date: Mon Aug 4 12:50:41 2014 +0200 previewer: Add CSS file for EvView styling EvView CSS used to be shared in adwaita theme, but now that adwaita has been merged into GTK+ and app specific CSS has been removed, we need to add the EvView CSS to all of its users. * libdocument: Do not hardcode thumbnail frames Always draw thumbnail frames styled by CSS (see .page-thumbnail inside shell/xreader.css), and not through hard-coded pixbuf manipulations. * Improve ratio calculations of sidebar thumbnails The old calculation caused sometimes rounding errors, which could cut off the lower border line.
1 parent 10ac353 commit 2bd08e3

14 files changed

Lines changed: 232 additions & 89 deletions

data/thumbnail-frame.png

832 Bytes
Loading

help/reference/libdocument/libxreaderdocument-docs.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
<xi:include href="xml/ev-document-misc.xml"/>
8989
<xi:include href="xml/ev-document-print.xml"/>
9090
<xi:include href="xml/ev-document-security.xml"/>
91-
<xi:include href="xml/ev-document-thumbnails.xml"/>
9291
<xi:include href="xml/ev-document-transition.xml"/>
9392
<xi:include href="xml/ev-selection.xml"/>
9493
<xi:include href="xml/ev-file-exporter.xml"/>

libdocument/ev-document-misc.c

Lines changed: 85 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
#include "ev-document-misc.h"
2929

30-
/* Returns a new GdkPixbuf that is suitable for placing in the thumbnail view.
31-
* It is four pixels wider and taller than the source. If source_pixbuf is not
32-
* NULL, then it will fill the return pixbuf with the contents of
33-
* source_pixbuf.
30+
/**
31+
* Returns a new GdkPixbuf that is suitable for placing in the thumbnail view.
32+
* If source_pixbuf is not NULL, then it will fill the return pixbuf with the
33+
* contents of source_pixbuf.
3434
*/
3535
static GdkPixbuf *
3636
create_thumbnail_frame (int width,
@@ -39,57 +39,31 @@ create_thumbnail_frame (int width,
3939
gboolean fill_bg)
4040
{
4141
GdkPixbuf *retval;
42-
guchar *data;
43-
gint rowstride;
4442
int i;
4543
int width_r, height_r;
4644

4745
if (source_pixbuf)
4846
g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
4947

50-
if (source_pixbuf) {
51-
width_r = gdk_pixbuf_get_width (source_pixbuf);
52-
height_r = gdk_pixbuf_get_height (source_pixbuf);
53-
} else {
54-
width_r = width;
55-
height_r = height;
56-
}
48+
width_r = gdk_pixbuf_get_width (source_pixbuf);
49+
height_r = gdk_pixbuf_get_height (source_pixbuf);
5750

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

6154
retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
6255
TRUE, 8,
63-
width_r + 4,
64-
height_r + 4);
65-
66-
/* make it black and fill in the middle */
67-
data = gdk_pixbuf_get_pixels (retval);
68-
rowstride = gdk_pixbuf_get_rowstride (retval);
56+
width_r,
57+
height_r);
6958

7059
gdk_pixbuf_fill (retval, 0x000000ff);
71-
if (fill_bg) {
72-
for (i = 1; i < height_r + 1; i++)
73-
memset (data + (rowstride * i) + 4, 0xffffffff, width_r * 4);
74-
}
7560

7661
/* copy the source pixbuf */
77-
if (source_pixbuf)
78-
gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
79-
width_r,
80-
height_r,
81-
retval,
82-
1, 1);
83-
/* Add the corner */
84-
data [(width_r + 2) * 4 + 3] = 0;
85-
data [(width_r + 3) * 4 + 3] = 0;
86-
data [(width_r + 2) * 4 + (rowstride * 1) + 3] = 0;
87-
data [(width_r + 3) * 4 + (rowstride * 1) + 3] = 0;
88-
89-
data [(height_r + 2) * rowstride + 3] = 0;
90-
data [(height_r + 3) * rowstride + 3] = 0;
91-
data [(height_r + 2) * rowstride + 4 + 3] = 0;
92-
data [(height_r + 3) * rowstride + 4 + 3] = 0;
62+
gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
63+
width_r,
64+
height_r,
65+
retval,
66+
0, 0);
9367

9468
return retval;
9569
}
@@ -110,6 +84,78 @@ ev_document_misc_get_loading_thumbnail (int width,
11084
return create_thumbnail_frame (width, height, NULL, !inverted_colors);
11185
}
11286

87+
static GdkPixbuf *
88+
ev_document_misc_render_thumbnail_frame (GtkWidget *widget,
89+
int width,
90+
int height,
91+
gboolean inverted_colors,
92+
GdkPixbuf *source_pixbuf)
93+
{
94+
GtkStyleContext *context = gtk_widget_get_style_context (widget);
95+
GtkStateFlags state = gtk_widget_get_state_flags (widget);
96+
int width_r, height_r;
97+
int width_f, height_f;
98+
cairo_surface_t *surface;
99+
cairo_t *cr;
100+
GtkBorder border = {0, };
101+
GdkPixbuf *retval;
102+
103+
if (source_pixbuf) {
104+
g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
105+
106+
width_r = gdk_pixbuf_get_width (source_pixbuf);
107+
height_r = gdk_pixbuf_get_height (source_pixbuf);
108+
} else {
109+
width_r = width;
110+
height_r = height;
111+
}
112+
113+
gtk_style_context_save (context);
114+
115+
gtk_style_context_add_class (context, "page-thumbnail");
116+
if (inverted_colors)
117+
gtk_style_context_add_class (context, "inverted");
118+
119+
gtk_style_context_get_border (context, state, &border);
120+
width_f = width_r + border.left + border.right;
121+
height_f = height_r + border.top + border.bottom;
122+
123+
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
124+
width_f, height_f);
125+
cr = cairo_create (surface);
126+
if (source_pixbuf) {
127+
gdk_cairo_set_source_pixbuf (cr, source_pixbuf, border.left, border.top);
128+
cairo_paint (cr);
129+
} else {
130+
gtk_render_background (context, cr, 0, 0, width_f, height_f);
131+
}
132+
gtk_render_frame (context, cr, 0, 0, width_f, height_f);
133+
cairo_destroy (cr);
134+
135+
gtk_style_context_restore (context);
136+
137+
retval = gdk_pixbuf_get_from_surface (surface, 0, 0, width_f, height_f);
138+
cairo_surface_destroy (surface);
139+
140+
return retval;
141+
}
142+
143+
GdkPixbuf *
144+
ev_document_misc_render_loading_thumbnail (GtkWidget *widget,
145+
int width,
146+
int height,
147+
gboolean inverted_colors)
148+
{
149+
return ev_document_misc_render_thumbnail_frame (widget, width, height, inverted_colors, NULL);
150+
}
151+
152+
GdkPixbuf *
153+
ev_document_misc_render_thumbnail_with_frame (GtkWidget *widget,
154+
GdkPixbuf *source_pixbuf)
155+
{
156+
return ev_document_misc_render_thumbnail_frame (widget, -1, -1, FALSE, source_pixbuf);
157+
}
158+
113159
void
114160
ev_document_misc_get_page_border_size (gint page_width,
115161
gint page_height,

libdocument/ev-document-misc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,27 @@
3030

3131
#include <gdk-pixbuf/gdk-pixbuf.h>
3232
#include <gtk/gtk.h>
33+
#include "ev-macros.h"
3334

3435
G_BEGIN_DECLS
3536

37+
EV_DEPRECATED
3638
GdkPixbuf *ev_document_misc_get_thumbnail_frame (int width,
3739
int height,
3840
GdkPixbuf *source_pixbuf);
41+
EV_DEPRECATED
3942
GdkPixbuf *ev_document_misc_get_loading_thumbnail (int width,
4043
int height,
4144
gboolean inverted_colors);
45+
46+
GdkPixbuf *ev_document_misc_render_loading_thumbnail (GtkWidget *widget,
47+
int width,
48+
int height,
49+
gboolean inverted_colors);
50+
GdkPixbuf *ev_document_misc_render_thumbnail_with_frame (GtkWidget *widget,
51+
GdkPixbuf *source_pixbuf);
52+
53+
EV_DEPRECATED
4254
void ev_document_misc_get_page_border_size (gint page_width,
4355
gint page_height,
4456
GtkBorder *border);

libview/ev-view.c

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2-
/* this file is part of xreader, a mate document viewer
2+
/* this file is part of xreader, a generic document viewer
33
*
44
* Copyright (C) 2004 Red Hat, Inc
55
*
@@ -101,6 +101,9 @@ typedef struct {
101101

102102
#define SCROLL_TIME 150
103103

104+
#define EV_STYLE_CLASS_DOCUMENT_PAGE "document-page"
105+
#define EV_STYLE_CLASS_INVERTED "inverted"
106+
104107
/*** Scrolling ***/
105108
static void view_update_range_and_current_page (EvView *view);
106109
static void add_scroll_binding_keypad (GtkBindingSet *binding_set,
@@ -113,8 +116,6 @@ static void ensure_rectangle_is_visible (EvView
113116

114117
/*** Geometry computations ***/
115118
static void compute_border (EvView *view,
116-
int width,
117-
int height,
118119
GtkBorder *border);
119120
static void get_page_y_offset (EvView *view,
120121
int page,
@@ -1035,9 +1036,16 @@ ensure_rectangle_is_visible (EvView *view, GdkRectangle *rect)
10351036
/*** Geometry computations ***/
10361037

10371038
static void
1038-
compute_border (EvView *view, int width, int height, GtkBorder *border)
1039+
compute_border (EvView *view, GtkBorder *border)
10391040
{
1040-
ev_document_misc_get_page_border_size (width, height, border);
1041+
GtkWidget *widget = GTK_WIDGET (view);
1042+
GtkStyleContext *context = gtk_widget_get_style_context (widget);
1043+
GtkStateFlags state = gtk_widget_get_state_flags (widget);
1044+
1045+
gtk_style_context_save (context);
1046+
gtk_style_context_add_class (context, EV_STYLE_CLASS_DOCUMENT_PAGE);
1047+
gtk_style_context_get_border (context, state, border);
1048+
gtk_style_context_restore (context);
10411049
}
10421050

10431051
void
@@ -1098,13 +1106,12 @@ ev_view_get_max_page_size (EvView *view,
10981106
static void
10991107
get_page_y_offset (EvView *view, int page, int *y_offset)
11001108
{
1101-
int max_width, offset = 0;
1109+
int offset = 0;
11021110
GtkBorder border;
11031111

11041112
g_return_if_fail (y_offset != NULL);
11051113

1106-
ev_view_get_max_page_size (view, &max_width, NULL);
1107-
compute_border (view, max_width, max_width, &border);
1114+
compute_border (view, &border);
11081115

11091116
if (view->dual_page) {
11101117
ev_view_get_height_to_page (view, page, NULL, &offset);
@@ -1134,7 +1141,7 @@ ev_view_get_page_extents (EvView *view,
11341141

11351142
/* Get the size of the page */
11361143
ev_view_get_page_size (view, page, &width, &height);
1137-
compute_border (view, width, height, border);
1144+
compute_border (view, border);
11381145
page_area->width = width + border->left + border->right;
11391146
page_area->height = height + border->top + border->bottom;
11401147

@@ -1180,7 +1187,7 @@ ev_view_get_page_extents (EvView *view,
11801187
if (height_2 > height)
11811188
max_height = height_2;
11821189
}
1183-
compute_border (view, max_width, max_height, &overall_border);
1190+
compute_border (view, &overall_border);
11841191

11851192
/* Find the offsets */
11861193
x = view->spacing;
@@ -3186,7 +3193,7 @@ ev_view_size_request_continuous_dual_page (EvView *view,
31863193
GtkBorder border;
31873194

31883195
ev_view_get_max_page_size (view, &max_width, NULL);
3189-
compute_border (view, max_width, max_width, &border);
3196+
compute_border (view, &border);
31903197
requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
31913198
}
31923199
break;
@@ -3215,7 +3222,7 @@ ev_view_size_request_continuous (EvView *view,
32153222
GtkBorder border;
32163223

32173224
ev_view_get_max_page_size (view, &max_width, NULL);
3218-
compute_border (view, max_width, max_width, &border);
3225+
compute_border (view, &border);
32193226
requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
32203227
}
32213228
break;
@@ -3252,7 +3259,7 @@ ev_view_size_request_dual_page (EvView *view,
32523259
height = height_2;
32533260
}
32543261
}
3255-
compute_border (view, width, height, &border);
3262+
compute_border (view, &border);
32563263

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

32763283
ev_view_get_page_size (view, view->current_page, &width, &height);
3277-
compute_border (view, width, height, &border);
3284+
compute_border (view, &border);
32783285

32793286
requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
32803287
width + border.left + border.right + (2 * view->spacing);
@@ -4589,10 +4596,10 @@ draw_one_page (EvView *view,
45894596
GdkRectangle *expose_area,
45904597
gboolean *page_ready)
45914598
{
4592-
GdkRectangle overlap;
4593-
GdkRectangle real_page_area;
4594-
gint current_page;
4595-
gboolean inverted_colors;
4599+
GtkStyleContext *context;
4600+
GdkRectangle overlap;
4601+
GdkRectangle real_page_area;
4602+
gint current_page;
45964603

45974604
g_assert (view->document);
45984605

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

4618+
context = gtk_widget_get_style_context (GTK_WIDGET (view));
46114619
current_page = ev_document_model_get_page (view->model);
4612-
inverted_colors = ev_document_model_get_inverted_colors (view->model);
4613-
ev_document_misc_paint_one_page (cr,
4614-
GTK_WIDGET (view),
4615-
page_area, border,
4616-
page == current_page,
4617-
inverted_colors);
4620+
4621+
gtk_style_context_save (context);
4622+
gtk_style_context_add_class (context, EV_STYLE_CLASS_DOCUMENT_PAGE);
4623+
if (ev_document_model_get_inverted_colors (view->model))
4624+
gtk_style_context_add_class (context, EV_STYLE_CLASS_INVERTED);
4625+
4626+
if (view->continuous && page == current_page)
4627+
gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
4628+
4629+
gtk_render_background (context, cr, page_area->x, page_area->y, page_area->width, page_area->height);
4630+
gtk_render_frame (context, cr, page_area->x, page_area->y, page_area->width, page_area->height);
4631+
gtk_style_context_restore (context);
46184632

46194633
if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) {
46204634
gint width, height;
@@ -6003,7 +6017,7 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
60036017
doc_height = tmp;
60046018
}
60056019

6006-
compute_border (view, doc_width, doc_height, &border);
6020+
compute_border (view, &border);
60076021

60086022
doc_width *= 2;
60096023
width -= (2 * (border.left + border.right) + 3 * view->spacing);
@@ -6040,7 +6054,7 @@ ev_view_zoom_for_size_continuous (EvView *view,
60406054
doc_height = tmp;
60416055
}
60426056

6043-
compute_border (view, doc_width, doc_height, &border);
6057+
compute_border (view, &border);
60446058

60456059
width -= (border.left + border.right + 2 * view->spacing);
60466060
height -= (border.top + border.bottom + 2 * view->spacing - 1);
@@ -6080,7 +6094,7 @@ ev_view_zoom_for_size_dual_page (EvView *view,
60806094
if (height_2 > doc_height)
60816095
doc_height = height_2;
60826096
}
6083-
compute_border (view, width, height, &border);
6097+
compute_border (view, &border);
60846098

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

61136127
/* Get an approximate border */
6114-
compute_border (view, width, height, &border);
6128+
compute_border (view, &border);
61156129

61166130
width -= (border.left + border.right + 2 * view->spacing);
61176131
height -= (border.top + border.bottom + 2 * view->spacing);

0 commit comments

Comments
 (0)