]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document-misc.c
Use an EvRenderContext for rendering thumbnails instead of a suggested
[evince.git] / libdocument / ev-document-misc.c
1
2 #include "ev-document-misc.h"
3 #include <string.h>
4 #include <gtk/gtk.h>
5
6 /* Returns a new GdkPixbuf that is suitable for placing in the thumbnail view.
7  * It is four pixels wider and taller than the source.  If source_pixbuf is not
8  * NULL, then it will fill the return pixbuf with the contents of
9  * source_pixbuf.
10  */
11
12 GdkPixbuf *
13 ev_document_misc_get_thumbnail_frame (int        width,
14                                       int        height,
15                                       GdkPixbuf *source_pixbuf)
16 {
17         GdkPixbuf *retval;
18         guchar *data;
19         gint rowstride;
20         int i;
21         int width_r, height_r;
22
23         if (source_pixbuf)
24                 g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
25
26         if (source_pixbuf) {
27                 width_r = gdk_pixbuf_get_width (source_pixbuf);
28                 height_r = gdk_pixbuf_get_height (source_pixbuf);
29         } else {
30                 width_r = width;
31                 height_r = height;
32         }
33
34         /* make sure no one is passing us garbage */
35         g_assert (width_r >= 0 && height_r >= 0);
36
37         retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
38                                  TRUE, 8,
39                                  width_r + 4,
40                                  height_r + 4);
41
42         /* make it black and fill in the middle */
43         data = gdk_pixbuf_get_pixels (retval);
44         rowstride = gdk_pixbuf_get_rowstride (retval);
45
46         gdk_pixbuf_fill (retval, 0x000000ff);
47         for (i = 1; i < height_r + 1; i++)
48                 memset (data + (rowstride * i) + 4, 0xffffffff, width_r * 4);
49
50         /* copy the source pixbuf */
51         if (source_pixbuf)
52                 gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
53                                       width_r,
54                                       height_r,
55                                       retval,
56                                       1, 1);
57         /* Add the corner */
58         data [(width_r + 2) * 4 + 3] = 0;
59         data [(width_r + 3) * 4 + 3] = 0;
60         data [(width_r + 2) * 4 + (rowstride * 1) + 3] = 0;
61         data [(width_r + 3) * 4 + (rowstride * 1) + 3] = 0;
62
63         data [(height_r + 2) * rowstride + 3] = 0;
64         data [(height_r + 3) * rowstride + 3] = 0;
65         data [(height_r + 2) * rowstride + 4 + 3] = 0;
66         data [(height_r + 3) * rowstride + 4 + 3] = 0;
67
68         return retval;
69 }
70
71 void
72 ev_document_misc_get_page_border_size (gint       page_width,
73                                        gint       page_height,
74                                        GtkBorder *border)
75 {
76         g_assert (border);
77
78         border->left = 1;
79         border->top = 1;
80         if (page_width < 100) {
81                 border->right = 2;
82                 border->bottom = 2;
83         } else if (page_width < 500) {
84                 border->right = 3;
85                 border->bottom = 3;
86         } else {
87                 border->right = 4;
88                 border->bottom = 4;
89         }
90 }
91
92
93 void
94 ev_document_misc_paint_one_page (GdkDrawable  *drawable,
95                                  GtkWidget    *widget,
96                                  GdkRectangle *area,
97                                  GtkBorder    *border,
98                                  gboolean highlight)
99 {
100         gdk_draw_rectangle (drawable,
101                             highlight ?
102                                     widget->style->text_gc[widget->state] : widget->style->dark_gc[widget->state],
103                             TRUE,
104                             area->x,
105                             area->y,
106                             area->width,
107                             area->height);
108         gdk_draw_rectangle (drawable,
109                             widget->style->white_gc,
110                             TRUE,
111                             area->x + border->left,
112                             area->y + border->top,
113                             area->width - (border->left + border->right),
114                             area->height - (border->top + border->bottom));
115         gdk_draw_rectangle (drawable,
116                             widget->style->mid_gc[widget->state],
117                             TRUE,
118                             area->x,
119                             area->y + area->height - (border->bottom - border->top),
120                             border->bottom - border->top,
121                             border->bottom - border->top);
122         gdk_draw_rectangle (drawable,
123                             widget->style->mid_gc[widget->state],
124                             TRUE,
125                             area->x + area->width - (border->right - border->left),
126                             area->y,
127                             border->right - border->left,
128                             border->right - border->left);
129
130 }