]> www.fi.muni.cz Git - evince.git/blob - backend/ev-document-misc.c
New file with some random thoughts.
[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                                        gint *left_border,
71                                        gint *right_border,
72                                        gint *top_border,
73                                        gint *bottom_border)
74 {
75         g_assert (left_border);
76         g_assert (right_border);
77         g_assert (top_border);
78         g_assert (bottom_border);
79
80         *left_border = 1;
81         *top_border = 1;
82         if (page_width < 100) {
83                 *right_border = 2;
84                 *bottom_border = 2;
85         } else if (page_width < 500) {
86                 *right_border = 3;
87                 *left_border = 3;
88         } else {
89                 *right_border = 4;
90                 *bottom_border = 4;
91         }
92 }
93