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