Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/backend/ev-document-misc.c
blob: 0626e1372567de9cf71fba781a1dc001661907d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

#include "ev-document-misc.h"
#include <string.h>
#include <gtk/gtk.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.
 */

GdkPixbuf *
ev_document_misc_get_thumbnail_frame (int        width,
				      int        height,
				      GdkPixbuf *source_pixbuf)
{
	GdkPixbuf *retval;
	guchar *data;
	gint rowstride;
	int i;

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

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

	/* make sure no one is passing us garbage */
	g_assert (width >= 0 && height >= 0);

	retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
				 TRUE, 8,
				 width + 4,
				 height + 4);

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

	gdk_pixbuf_fill (retval, 0x000000ff);
	for (i = 1; i < height + 1; i++)
		memset (data + (rowstride * i) + 4, 0xffffffff, width * 4);

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

	data [(height + 2) * rowstride + 3] = 0;
	data [(height + 3) * rowstride + 3] = 0;
	data [(height + 2) * rowstride + 4 + 3] = 0;
	data [(height + 3) * rowstride + 4 + 3] = 0;

	return retval;
}

void
ev_document_misc_get_page_border_size (gint       page_width,
				       gint       page_height,
				       GtkBorder *border)
{
	g_assert (border);

	border->left = 1;
	border->top = 1;
	if (page_width < 100) {
		border->right = 2;
		border->bottom = 2;
	} else if (page_width < 500) {
		border->right = 3;
		border->bottom = 3;
	} else {
		border->right = 4;
		border->bottom = 4;
	}
}


void
ev_document_misc_paint_one_page (GdkDrawable  *drawable,
				 GtkWidget    *widget,
				 GdkRectangle *area,
				 GtkBorder    *border)
{
	gdk_draw_rectangle (drawable,
			    widget->style->black_gc,
			    TRUE,
			    area->x,
			    area->y,
			    area->width,
			    area->height);
	gdk_draw_rectangle (drawable,
			    widget->style->white_gc,
			    TRUE,
			    area->x + border->left,
			    area->y + border->top,
			    area->width - (border->left + border->right),
			    area->height - (border->top + border->bottom));
	gdk_draw_rectangle (drawable,
			    widget->style->mid_gc[widget->state],
			    TRUE,
			    area->x,
			    area->y + area->height - (border->bottom - border->top),
			    border->bottom - border->top,
			    border->bottom - border->top);
	gdk_draw_rectangle (drawable,
			    widget->style->mid_gc[widget->state],
			    TRUE,
			    area->x + area->width - (border->right - border->left),
			    area->y,
			    border->right - border->left,
			    border->right - border->left);

}