Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-document-misc.h File Reference
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
#include "ev-macros.h"
+ Include dependency graph for ev-document-misc.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

G_BEGIN_DECLS EV_DEPRECATED
GdkPixbuf * 
ev_document_misc_get_thumbnail_frame (int width, int height, GdkPixbuf *source_pixbuf)
 
EV_DEPRECATED GdkPixbuf * ev_document_misc_get_loading_thumbnail (int width, int height, gboolean inverted_colors)
 
GdkPixbuf * ev_document_misc_render_loading_thumbnail (GtkWidget *widget, int width, int height, gboolean inverted_colors)
 
GdkPixbuf * ev_document_misc_render_thumbnail_with_frame (GtkWidget *widget, GdkPixbuf *source_pixbuf)
 
cairo_surface_t * ev_document_misc_render_loading_thumbnail_surface (GtkWidget *widget, int width, int height, gboolean inverted_colors)
 
cairo_surface_t * ev_document_misc_render_thumbnail_surface_with_frame (GtkWidget *widget, cairo_surface_t *source_surface, int width, int height)
 
EV_DEPRECATED void ev_document_misc_get_page_border_size (gint page_width, gint page_height, GtkBorder *border)
 
EV_DEPRECATED void ev_document_misc_paint_one_page (cairo_t *cr, GtkWidget *widget, GdkRectangle *area, GtkBorder *border, gboolean highlight, gboolean inverted_colors)
 
cairo_surface_t * ev_document_misc_surface_from_pixbuf (GdkPixbuf *pixbuf)
 
GdkPixbuf * ev_document_misc_pixbuf_from_surface (cairo_surface_t *surface)
 
cairo_surface_t * ev_document_misc_surface_rotate_and_scale (cairo_surface_t *surface, gint dest_width, gint dest_height, gint dest_rotation)
 
void ev_document_misc_invert_surface (cairo_surface_t *surface)
 
void ev_document_misc_invert_pixbuf (GdkPixbuf *pixbuf)
 
gdouble ev_document_misc_get_screen_dpi (GdkScreen *screen)
 
gchar * ev_document_misc_format_date (GTime utime)
 
void ev_document_misc_get_pointer_position (GtkWidget *widget, gint *x, gint *y)
 

Function Documentation

gchar* ev_document_misc_format_date ( GTime  utime)

Definition at line 525 of file ev-document-misc.c.

526 {
527  time_t time = (time_t) utime;
528  char s[256];
529  const char fmt_hack[] = "%c";
530  size_t len;
531 #pragma GCC diagnostic push
532 #pragma GCC diagnostic ignored "-Wformat-y2k"
533 #ifdef HAVE_LOCALTIME_R
534  struct tm t;
535  if (time == 0 || !localtime_r (&time, &t)) return NULL;
536  len = strftime (s, sizeof (s), fmt_hack, &t);
537 #else
538  struct tm *t;
539  if (time == 0 || !(t = localtime (&time)) ) return NULL;
540  len = strftime (s, sizeof (s), fmt_hack, t);
541 #endif
542 #pragma GCC diagnostic pop
543 
544  if (len == 0 || s[0] == '\0') return NULL;
545 
546  return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
547 }

+ Here is the caller graph for this function:

EV_DEPRECATED GdkPixbuf* ev_document_misc_get_loading_thumbnail ( int  width,
int  height,
gboolean  inverted_colors 
)

ev_document_misc_get_loading_thumbnail: : the desired width : the desired height : whether to invert colors

Returns: (transfer full): a #GdkPixbuf

Definition at line 122 of file ev-document-misc.c.

125 {
126  return create_thumbnail_frame (width, height, NULL, !inverted_colors);
127 }
EV_DEPRECATED void ev_document_misc_get_page_border_size ( gint  page_width,
gint  page_height,
GtkBorder *  border 
)

Definition at line 301 of file ev-document-misc.c.

304 {
305  g_assert (border);
306 
307  border->left = 1;
308  border->top = 1;
309  if (page_width < 100) {
310  border->right = 2;
311  border->bottom = 2;
312  } else if (page_width < 500) {
313  border->right = 3;
314  border->bottom = 3;
315  } else {
316  border->right = 4;
317  border->bottom = 4;
318  }
319 }
void ev_document_misc_get_pointer_position ( GtkWidget *  widget,
gint *  x,
gint *  y 
)

Definition at line 550 of file ev-document-misc.c.

553 {
554  GdkDeviceManager *device_manager;
555  GdkDevice *device_pointer;
556  GdkRectangle allocation;
557 
558  if (x)
559  *x = -1;
560  if (y)
561  *y = -1;
562 
563  if (!gtk_widget_get_realized (widget))
564  return;
565 
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),
569  device_pointer,
570  x, y, NULL);
571 
572  if (gtk_widget_get_has_window (widget))
573  return;
574 
575  gtk_widget_get_allocation (widget, &allocation);
576  if (x)
577  *x -= allocation.x;
578  if (y)
579  *y -= allocation.y;
580 }

+ Here is the caller graph for this function:

gdouble ev_document_misc_get_screen_dpi ( GdkScreen *  screen)

Definition at line 510 of file ev-document-misc.c.

511 {
512  gdouble dp, di;
513 
514  /*diagonal in pixels*/
515  dp = hypot (gdk_screen_get_width (screen), gdk_screen_get_height (screen));
516 
517  /*diagonal in inches*/
518  di = hypot (gdk_screen_get_width_mm(screen), gdk_screen_get_height_mm (screen)) / 25.4;
519 
520  return (dp / di);
521 }

+ Here is the caller graph for this function:

G_BEGIN_DECLS EV_DEPRECATED GdkPixbuf* ev_document_misc_get_thumbnail_frame ( int  width,
int  height,
GdkPixbuf *  source_pixbuf 
)

ev_document_misc_get_thumbnail_frame: : the desired width : the desired height : a #GdkPixbuf

Returns: (transfer full): a #GdkPixbuf

Definition at line 106 of file ev-document-misc.c.

109 {
110  return create_thumbnail_frame (width, height, source_pixbuf, TRUE);
111 }

+ Here is the caller graph for this function:

void ev_document_misc_invert_pixbuf ( GdkPixbuf *  pixbuf)

Definition at line 480 of file ev-document-misc.c.

481 {
482  guchar *data, *p;
483  guint width, height, x, y, rowstride, n_channels;
484 
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);
488 
489  /* First grab a pointer to the raw pixel data. */
490  data = gdk_pixbuf_get_pixels (pixbuf);
491 
492  /* Find the number of bytes per row (could be padded). */
493  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
494 
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++) {
499  /* Calculate pixel's offset into the data array. */
500  p = data + x * n_channels + y * rowstride;
501  /* Change the RGB values*/
502  p[0] = 255 - p[0];
503  p[1] = 255 - p[1];
504  p[2] = 255 - p[2];
505  }
506  }
507 }
void ev_document_misc_invert_surface ( cairo_surface_t *  surface)

Definition at line 467 of file ev-document-misc.c.

467  {
468  cairo_t *cr;
469 
470  cr = cairo_create (surface);
471 
472  /* white + DIFFERENCE -> invert */
473  cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
474  cairo_set_source_rgb (cr, 1., 1., 1.);
475  cairo_paint(cr);
476  cairo_destroy (cr);
477 }

+ Here is the caller graph for this function:

EV_DEPRECATED void ev_document_misc_paint_one_page ( cairo_t *  cr,
GtkWidget *  widget,
GdkRectangle *  area,
GtkBorder *  border,
gboolean  highlight,
gboolean  inverted_colors 
)

Definition at line 323 of file ev-document-misc.c.

329 {
330  GtkStyleContext *context = gtk_widget_get_style_context (widget);
331  GtkStateFlags state = gtk_widget_get_state_flags (widget);
332  GdkRGBA fg, bg, shade_bg;
333 
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);
337 
338  gdk_cairo_set_source_rgba (cr, highlight ? &fg : &shade_bg);
339  gdk_cairo_rectangle (cr, area);
340  cairo_fill (cr);
341 
342  if (inverted_colors)
343  cairo_set_source_rgb (cr, 0, 0, 0);
344  else
345  cairo_set_source_rgb (cr, 1, 1, 1);
346  cairo_rectangle (cr,
347  area->x + border->left,
348  area->y + border->top,
349  area->width - (border->left + border->right),
350  area->height - (border->top + border->bottom));
351  cairo_fill (cr);
352 
353  gdk_cairo_set_source_rgba (cr, &bg);
354  cairo_rectangle (cr,
355  area->x,
356  area->y + area->height - (border->bottom - border->top),
357  border->bottom - border->top,
358  border->bottom - border->top);
359  cairo_fill (cr);
360 
361  cairo_rectangle (cr,
362  area->x + area->width - (border->right - border->left),
363  area->y,
364  border->right - border->left,
365  border->right - border->left);
366  cairo_fill (cr);
367 }
GdkPixbuf* ev_document_misc_pixbuf_from_surface ( cairo_surface_t *  surface)

ev_document_misc_pixbuf_from_surface: : a #cairo_surface_t

Returns: (transfer full): a #GdkPixbuf

Definition at line 396 of file ev-document-misc.c.

397 {
398  g_return_val_if_fail (surface, NULL);
399 
400  return gdk_pixbuf_get_from_surface (surface,
401  0, 0,
402  cairo_image_surface_get_width (surface),
403  cairo_image_surface_get_height (surface));
404 }

+ Here is the caller graph for this function:

GdkPixbuf* ev_document_misc_render_loading_thumbnail ( GtkWidget *  widget,
int  width,
int  height,
gboolean  inverted_colors 
)

ev_document_misc_render_loading_thumbnail: : a #GtkWidget to use for style information : the desired width : the desired height : whether to invert colors

Returns: (transfer full): a #GdkPixbuf

Since: 3.8

Definition at line 220 of file ev-document-misc.c.

224 {
225  GdkPixbuf *retval;
226  cairo_surface_t *surface;
227 
228  surface = ev_document_misc_render_thumbnail_frame (widget, width, height, inverted_colors, NULL, NULL);
229  retval = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
230  cairo_surface_destroy (surface);
231 
232  return retval;
233 }
cairo_surface_t* ev_document_misc_render_loading_thumbnail_surface ( GtkWidget *  widget,
int  width,
int  height,
gboolean  inverted_colors 
)

ev_document_misc_render_loading_thumbnail_surface: : a #GtkWidget to use for style information : the desired width : the desired height : whether to invert colors

Returns: (transfer full): a #cairo_surface_t

Since: 3.14

Definition at line 247 of file ev-document-misc.c.

251 {
252  return ev_document_misc_render_thumbnail_frame (widget, width, height, inverted_colors, NULL, NULL);
253 }

+ Here is the caller graph for this function:

cairo_surface_t* ev_document_misc_render_thumbnail_surface_with_frame ( GtkWidget *  widget,
cairo_surface_t *  source_surface,
int  width,
int  height 
)

ev_document_misc_render_thumbnail_surface_with_frame: : a #GtkWidget to use for style information : a #cairo_surface_t : the desired width : the desired height

Returns: (transfer full): a #cairo_surface_t

Since: 3.14

Definition at line 292 of file ev-document-misc.c.

296 {
297  return ev_document_misc_render_thumbnail_frame (widget, width, height, FALSE, NULL, source_surface);
298 }

+ Here is the caller graph for this function:

GdkPixbuf* ev_document_misc_render_thumbnail_with_frame ( GtkWidget *  widget,
GdkPixbuf *  source_pixbuf 
)

ev_document_misc_render_thumbnail_with_frame: : a #GtkWidget to use for style information : a #GdkPixbuf

Returns: (transfer full): a #GdkPixbuf

Since: 3.8

Definition at line 265 of file ev-document-misc.c.

267 {
268  GdkPixbuf *retval;
269  cairo_surface_t *surface;
270 
271  surface = ev_document_misc_render_thumbnail_frame (widget, -1, -1, FALSE, source_pixbuf, NULL);
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);
276 
277  return retval;
278 }
cairo_surface_t* ev_document_misc_surface_from_pixbuf ( GdkPixbuf *  pixbuf)

Definition at line 370 of file ev-document-misc.c.

371 {
372  cairo_surface_t *surface;
373  cairo_t *cr;
374 
375  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
376 
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);
383  cairo_paint (cr);
384  cairo_destroy (cr);
385 
386  return surface;
387 }

+ Here is the caller graph for this function:

cairo_surface_t* ev_document_misc_surface_rotate_and_scale ( cairo_surface_t *  surface,
gint  dest_width,
gint  dest_height,
gint  dest_rotation 
)

Definition at line 407 of file ev-document-misc.c.

411 {
412  cairo_surface_t *new_surface;
413  cairo_t *cr;
414  gint width, height;
415  gint new_width = dest_width;
416  gint new_height = dest_height;
417 
418  width = cairo_image_surface_get_width (surface);
419  height = cairo_image_surface_get_height (surface);
420 
421  if (dest_width == width &&
422  dest_height == height &&
423  dest_rotation == 0) {
424  return cairo_surface_reference (surface);
425  }
426 
427  if (dest_rotation == 90 || dest_rotation == 270) {
428  new_width = dest_height;
429  new_height = dest_width;
430  }
431 
432  new_surface = cairo_surface_create_similar (surface,
433  cairo_surface_get_content (surface),
434  new_width, new_height);
435 
436  cr = cairo_create (new_surface);
437  switch (dest_rotation) {
438  case 90:
439  cairo_translate (cr, new_width, 0);
440  break;
441  case 180:
442  cairo_translate (cr, new_width, new_height);
443  break;
444  case 270:
445  cairo_translate (cr, 0, new_height);
446  break;
447  default:
448  cairo_translate (cr, 0, 0);
449  }
450  cairo_rotate (cr, dest_rotation * G_PI / 180.0);
451 
452  if (dest_width != width || dest_height != height) {
453  cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
454  cairo_scale (cr,
455  (gdouble)dest_width / width,
456  (gdouble)dest_height / height);
457  }
458 
459  cairo_set_source_surface (cr, surface, 0, 0);
460  cairo_paint (cr);
461  cairo_destroy (cr);
462 
463  return new_surface;
464 }

+ Here is the caller graph for this function: