]> www.fi.muni.cz Git - evince.git/blob - backend/ev-document-misc.c
Hungarian translation added by "Last-Translator: \n".
[evince.git] / backend / 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
22         if (source_pixbuf)
23                 g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
24
25         if (source_pixbuf) {
26                 width = gdk_pixbuf_get_width (source_pixbuf);
27                 height = gdk_pixbuf_get_height (source_pixbuf);
28         }
29
30         /* make sure no one is passing us garbage */
31         g_assert (width > 0 && height > 0);
32
33         retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
34                                  TRUE, 8,
35                                  width + 4,
36                                  height + 4);
37
38         /* make it black and fill in the middle */
39         data = gdk_pixbuf_get_pixels (retval);
40         rowstride = gdk_pixbuf_get_rowstride (retval);
41
42         gdk_pixbuf_fill (retval, 0x000000ff);
43         for (i = 1; i < height + 1; i++)
44                 memset (data + (rowstride * i) + 4, 0xffffffff, width * 4);
45
46         /* copy the source pixbuf */
47         if (source_pixbuf)
48                 gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
49                                       width,
50                                       height,
51                                       retval,
52                                       1, 1);
53         /* Add the corner */
54         data [(width + 2) * 4 + 3] = 0;
55         data [(width + 3) * 4 + 3] = 0;
56         data [(width + 2) * 4 + (rowstride * 1) + 3] = 0;
57         data [(width + 3) * 4 + (rowstride * 1) + 3] = 0;
58
59         data [(height + 2) * rowstride + 3] = 0;
60         data [(height + 3) * rowstride + 3] = 0;
61         data [(height + 2) * rowstride + 4 + 3] = 0;
62         data [(height + 3) * rowstride + 4 + 3] = 0;
63
64         return retval;
65 }
66
67 void
68 ev_document_misc_get_page_border_size (gint       page_width,
69                                        gint       page_height,
70                                        GtkBorder *border)
71 {
72         g_assert (border);
73
74         border->left = 1;
75         border->top = 1;
76         if (page_width < 100) {
77                 border->right = 2;
78                 border->bottom = 2;
79         } else if (page_width < 500) {
80                 border->right = 3;
81                 border->bottom = 3;
82         } else {
83                 border->right = 4;
84                 border->bottom = 4;
85         }
86 }
87
88
89 void
90 ev_document_misc_paint_one_page (GdkDrawable  *drawable,
91                                  GtkWidget    *widget,
92                                  GdkRectangle *area,
93                                  GtkBorder    *border)
94 {
95         gdk_draw_rectangle (drawable,
96                             widget->style->black_gc,
97                             TRUE,
98                             area->x,
99                             area->y,
100                             area->width,
101                             area->height);
102         gdk_draw_rectangle (drawable,
103                             widget->style->white_gc,
104                             TRUE,
105                             area->x + border->left,
106                             area->y + border->top,
107                             area->width - (border->left + border->right),
108                             area->height - (border->top + border->bottom));
109         gdk_draw_rectangle (drawable,
110                             widget->style->mid_gc[widget->state],
111                             TRUE,
112                             area->x,
113                             area->y + area->height - (border->bottom - border->top),
114                             border->bottom - border->top,
115                             border->bottom - border->top);
116         gdk_draw_rectangle (drawable,
117                             widget->style->mid_gc[widget->state],
118                             TRUE,
119                             area->x + area->width - (border->right - border->left),
120                             area->y,
121                             border->right - border->left,
122                             border->right - border->left);
123
124 }