38 GdkPixbuf *source_pixbuf,
45 int width_r, height_r;
48 g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
51 width_r = gdk_pixbuf_get_width (source_pixbuf);
52 height_r = gdk_pixbuf_get_height (source_pixbuf);
59 g_return_val_if_fail (width_r >= 0 && height_r >= 0, NULL);
61 retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
67 data = gdk_pixbuf_get_pixels (retval);
68 rowstride = gdk_pixbuf_get_rowstride (retval);
70 gdk_pixbuf_fill (retval, 0x000000ff);
72 for (i = 1; i < height_r + 1; i++)
73 memset (data + (rowstride * i) + 4, 0xffffffff, width_r * 4);
78 gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
84 data [(width_r + 2) * 4 + 3] = 0;
85 data [(width_r + 3) * 4 + 3] = 0;
86 data [(width_r + 2) * 4 + (rowstride * 1) + 3] = 0;
87 data [(width_r + 3) * 4 + (rowstride * 1) + 3] = 0;
89 data [(height_r + 2) * rowstride + 3] = 0;
90 data [(height_r + 3) * rowstride + 3] = 0;
91 data [(height_r + 2) * rowstride + 4 + 3] = 0;
92 data [(height_r + 3) * rowstride + 4 + 3] = 0;
108 GdkPixbuf *source_pixbuf)
124 gboolean inverted_colors)
129 static cairo_surface_t *
133 gboolean inverted_colors,
134 GdkPixbuf *source_pixbuf,
135 cairo_surface_t *source_surface)
137 GtkStyleContext *context = gtk_widget_get_style_context (widget);
138 GtkStateFlags state = gtk_widget_get_state_flags (widget);
139 double width_r, height_r;
140 double width_f, height_f;
141 cairo_surface_t *surface;
143 double device_scale_x = 1;
144 double device_scale_y = 1;
145 GtkBorder border = {0, };
147 if (source_surface) {
148 width_r = cairo_image_surface_get_width (source_surface);
149 height_r = cairo_image_surface_get_height (source_surface);
150 #ifdef HAVE_HIDPI_SUPPORT
151 cairo_surface_get_device_scale (source_surface, &device_scale_x, &device_scale_y);
153 }
else if (source_pixbuf) {
154 g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
156 width_r = gdk_pixbuf_get_width (source_pixbuf);
157 height_r = gdk_pixbuf_get_height (source_pixbuf);
158 #ifdef HAVE_HIDPI_SUPPORT
159 device_scale_x = device_scale_y = gtk_widget_get_scale_factor (widget);
164 #ifdef HAVE_HIDPI_SUPPORT
165 device_scale_x = device_scale_y = gtk_widget_get_scale_factor (widget);
169 width_r /= device_scale_x;
170 height_r /= device_scale_y;
172 gtk_style_context_save (context);
174 gtk_style_context_add_class (context,
"page-thumbnail");
176 gtk_style_context_add_class (context,
"inverted");
178 gtk_style_context_get_border (context, state, &border);
179 width_f = width_r + border.left + border.right;
180 height_f = height_r + border.top + border.bottom;
182 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
183 device_scale_x * width_f,
184 device_scale_y * height_f);
186 #ifdef HAVE_HIDPI_SUPPORT
187 cairo_surface_set_device_scale (surface, device_scale_x, device_scale_y);
190 cr = cairo_create (surface);
191 if (source_surface) {
192 cairo_set_source_surface (cr, source_surface, border.left, border.top);
194 }
else if (source_pixbuf) {
195 gdk_cairo_set_source_pixbuf (cr, source_pixbuf, border.left, border.top);
198 gtk_render_background (context, cr, 0, 0, width_f, height_f);
200 gtk_render_frame (context, cr, 0, 0, width_f, height_f);
203 gtk_style_context_restore (context);
223 gboolean inverted_colors)
226 cairo_surface_t *surface;
229 retval = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
230 cairo_surface_destroy (surface);
250 gboolean inverted_colors)
266 GdkPixbuf *source_pixbuf)
269 cairo_surface_t *surface;
272 retval = gdk_pixbuf_get_from_surface (surface, 0, 0,
273 cairo_image_surface_get_width (surface),
274 cairo_image_surface_get_height (surface));
275 cairo_surface_destroy (surface);
293 cairo_surface_t *source_surface,
309 if (page_width < 100) {
312 }
else if (page_width < 500) {
328 gboolean inverted_colors)
330 GtkStyleContext *context = gtk_widget_get_style_context (widget);
331 GtkStateFlags state = gtk_widget_get_state_flags (widget);
332 GdkRGBA fg, bg, shade_bg;
334 gtk_style_context_get_background_color (context, state, &bg);
335 gtk_style_context_get_color (context, state, &fg);
336 gtk_style_context_get_color (context, GTK_STATE_FLAG_INSENSITIVE, &shade_bg);
338 gdk_cairo_set_source_rgba (cr, highlight ? &fg : &shade_bg);
339 gdk_cairo_rectangle (cr, area);
343 cairo_set_source_rgb (cr, 0, 0, 0);
345 cairo_set_source_rgb (cr, 1, 1, 1);
347 area->x + border->left,
348 area->y + border->top,
349 area->width - (border->left + border->right),
350 area->height - (border->top + border->bottom));
353 gdk_cairo_set_source_rgba (cr, &bg);
356 area->y + area->height - (border->bottom - border->top),
357 border->bottom - border->top,
358 border->bottom - border->top);
362 area->x + area->width - (border->right - border->left),
364 border->right - border->left,
365 border->right - border->left);
372 cairo_surface_t *surface;
375 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
377 surface = cairo_image_surface_create (gdk_pixbuf_get_has_alpha (pixbuf) ?
378 CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24,
379 gdk_pixbuf_get_width (pixbuf),
380 gdk_pixbuf_get_height (pixbuf));
381 cr = cairo_create (surface);
382 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
398 g_return_val_if_fail (surface, NULL);
400 return gdk_pixbuf_get_from_surface (surface,
402 cairo_image_surface_get_width (surface),
403 cairo_image_surface_get_height (surface));
412 cairo_surface_t *new_surface;
415 gint new_width = dest_width;
416 gint new_height = dest_height;
418 width = cairo_image_surface_get_width (surface);
419 height = cairo_image_surface_get_height (surface);
421 if (dest_width == width &&
422 dest_height == height &&
423 dest_rotation == 0) {
424 return cairo_surface_reference (surface);
427 if (dest_rotation == 90 || dest_rotation == 270) {
428 new_width = dest_height;
429 new_height = dest_width;
432 new_surface = cairo_surface_create_similar (surface,
433 cairo_surface_get_content (surface),
434 new_width, new_height);
436 cr = cairo_create (new_surface);
437 switch (dest_rotation) {
439 cairo_translate (cr, new_width, 0);
442 cairo_translate (cr, new_width, new_height);
445 cairo_translate (cr, 0, new_height);
448 cairo_translate (cr, 0, 0);
450 cairo_rotate (cr, dest_rotation * G_PI / 180.0);
452 if (dest_width != width || dest_height != height) {
453 cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
455 (gdouble)dest_width / width,
456 (gdouble)dest_height / height);
459 cairo_set_source_surface (cr, surface, 0, 0);
470 cr = cairo_create (surface);
473 cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
474 cairo_set_source_rgb (cr, 1., 1., 1.);
483 guint width, height, x, y, rowstride, n_channels;
485 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
486 g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
487 g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
490 data = gdk_pixbuf_get_pixels (pixbuf);
493 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
495 width = gdk_pixbuf_get_width (pixbuf);
496 height = gdk_pixbuf_get_height (pixbuf);
497 for (x = 0; x < width; x++) {
498 for (y = 0; y < height; y++) {
500 p = data + x * n_channels + y * rowstride;
515 dp = hypot (gdk_screen_get_width (screen), gdk_screen_get_height (screen));
518 di = hypot (gdk_screen_get_width_mm(screen), gdk_screen_get_height_mm (screen)) / 25.4;
527 time_t time = (time_t) utime;
529 const char fmt_hack[] =
"%c";
531 #pragma GCC diagnostic push
532 #pragma GCC diagnostic ignored "-Wformat-y2k"
533 #ifdef HAVE_LOCALTIME_R
535 if (time == 0 || !localtime_r (&time, &t))
return NULL;
536 len = strftime (s,
sizeof (s), fmt_hack, &t);
539 if (time == 0 || !(t = localtime (&time)) )
return NULL;
540 len = strftime (s,
sizeof (s), fmt_hack, t);
542 #pragma GCC diagnostic pop
544 if (len == 0 || s[0] ==
'\0')
return NULL;
546 return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
554 GdkDeviceManager *device_manager;
555 GdkDevice *device_pointer;
556 GdkRectangle allocation;
563 if (!gtk_widget_get_realized (widget))
566 device_manager = gdk_display_get_device_manager (gtk_widget_get_display (widget));
567 device_pointer = gdk_device_manager_get_client_pointer (device_manager);
568 gdk_window_get_device_position (gtk_widget_get_window (widget),
572 if (gtk_widget_get_has_window (widget))
575 gtk_widget_get_allocation (widget, &allocation);