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
cairo-device.c File Reference
#include <config.h>
#include <stdlib.h>
#include <gdk/gdk.h>
#include "cairo-device.h"
+ Include dependency graph for cairo-device.c:

Go to the source code of this file.

Data Structures

struct  DviCairoDevice
 

Functions

static void dvi_cairo_draw_glyph (DviContext *dvi, DviFontChar *ch, int x0, int y0)
 
static void dvi_cairo_draw_rule (DviContext *dvi, int x, int y, Uint width, Uint height, int fill)
 
static int dvi_cairo_alloc_colors (void *device_data, Ulong *pixels, int npixels, Ulong fg, Ulong bg, double gamma, int density)
 
static void * dvi_cairo_create_image (void *device_data, Uint width, Uint height, Uint bpp)
 
static void dvi_cairo_free_image (void *ptr)
 
static void dvi_cairo_put_pixel (void *image, int x, int y, Ulong color)
 
static void dvi_cairo_image_done (void *ptr)
 
static void dvi_cairo_set_color (void *device_data, Ulong fg, Ulong bg)
 
void mdvi_cairo_device_init (DviDevice *device)
 
void mdvi_cairo_device_free (DviDevice *device)
 
cairo_surface_t * mdvi_cairo_device_get_surface (DviDevice *device)
 
void mdvi_cairo_device_render (DviContext *dvi)
 
void mdvi_cairo_device_set_margins (DviDevice *device, gint xmargin, gint ymargin)
 
void mdvi_cairo_device_set_scale (DviDevice *device, gdouble xscale, gdouble yscale)
 

Function Documentation

static int dvi_cairo_alloc_colors ( void *  device_data,
Ulong pixels,
int  npixels,
Ulong  fg,
Ulong  bg,
double  gamma,
int  density 
)
static

Definition at line 196 of file cairo-device.c.

203 {
204  double frac;
205  GdkColor color, color_fg;
206  int i, n;
207  unsigned int alpha;
208 
209  color_fg.red = (fg >> 16) & 0xff;
210  color_fg.green = (fg >> 8) & 0xff;
211  color_fg.blue = (fg >> 0) & 0xff;
212 
213  n = npixels - 1;
214  for (i = 0; i < npixels; i++) {
215  frac = (gamma > 0) ?
216  pow ((double)i / n, 1 / gamma) :
217  1 - pow ((double)(n - i) / n, -gamma);
218 
219  color.red = frac * color_fg.red;
220  color.green = frac * color_fg.green;
221  color.blue = frac * color_fg.blue;
222  alpha = frac * 0xFF;
223 
224  pixels[i] = (alpha << 24) + (color.red << 16) + (color.green << 8) + color.blue;
225  }
226 
227  return npixels;
228 }

+ Here is the caller graph for this function:

static void* dvi_cairo_create_image ( void *  device_data,
Uint  width,
Uint  height,
Uint  bpp 
)
static

Definition at line 231 of file cairo-device.c.

235 {
236  return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
237 }

+ Here is the caller graph for this function:

static void dvi_cairo_draw_glyph ( DviContext dvi,
DviFontChar ch,
int  x0,
int  y0 
)
static

Definition at line 44 of file cairo-device.c.

48 {
49  DviCairoDevice *cairo_device;
50  int x, y, w, h;
51  gboolean isbox;
52  DviGlyph *glyph;
53  cairo_surface_t *surface;
54 
55  cairo_device = (DviCairoDevice *) dvi->device.device_data;
56 
57  glyph = &ch->grey;
58 
59  isbox = (glyph->data == NULL ||
61  MDVI_GLYPH_ISEMPTY (glyph->data));
62 
63  x = - glyph->x + x0 + cairo_device->xmargin;
64  y = - glyph->y + y0 + cairo_device->ymargin;
65  w = glyph->w;
66  h = glyph->h;
67 
68  surface = cairo_get_target (cairo_device->cr);
69  if (x < 0 || y < 0
70  || x + w > cairo_image_surface_get_width (surface)
71  || y + h > cairo_image_surface_get_height (surface))
72  return;
73 
74  cairo_save (cairo_device->cr);
75  if (isbox) {
76  cairo_rectangle (cairo_device->cr,
77  x - cairo_device->xmargin,
78  y - cairo_device->ymargin,
79  w, h);
80  cairo_stroke (cairo_device->cr);
81  } else {
82  cairo_translate (cairo_device->cr, x, y);
83  cairo_set_source_surface (cairo_device->cr,
84  (cairo_surface_t *) glyph->data,
85  0, 0);
86  cairo_paint (cairo_device->cr);
87  }
88 
89  cairo_restore (cairo_device->cr);
90 }

+ Here is the caller graph for this function:

static void dvi_cairo_draw_rule ( DviContext dvi,
int  x,
int  y,
Uint  width,
Uint  height,
int  fill 
)
static

Definition at line 93 of file cairo-device.c.

99 {
100  DviCairoDevice *cairo_device;
101  Ulong color;
102 
103  cairo_device = (DviCairoDevice *) dvi->device.device_data;
104 
105  color = cairo_device->fg;
106 
107  cairo_save (cairo_device->cr);
108  cairo_scale (cairo_device->cr, cairo_device->xscale, cairo_device->yscale);
109 
110  cairo_set_source_rgb (cairo_device->cr,
111  ((color >> 16) & 0xff) / 255.,
112  ((color >> 8) & 0xff) / 255.,
113  ((color >> 0) & 0xff) / 255.);
114 
115  cairo_rectangle (cairo_device->cr,
116  (x + cairo_device->xmargin) / cairo_device->xscale,
117  (y + cairo_device->ymargin) / cairo_device->yscale,
118  width / cairo_device->xscale, height / cairo_device->yscale);
119  if (fill == 0) {
120  cairo_stroke (cairo_device->cr);
121  } else {
122  cairo_fill (cairo_device->cr);
123  }
124 
125  cairo_restore (cairo_device->cr);
126 }

+ Here is the caller graph for this function:

static void dvi_cairo_free_image ( void *  ptr)
static

Definition at line 240 of file cairo-device.c.

241 {
242  cairo_surface_destroy ((cairo_surface_t *)ptr);
243 }

+ Here is the caller graph for this function:

static void dvi_cairo_image_done ( void *  ptr)
static

Definition at line 263 of file cairo-device.c.

264 {
265  cairo_surface_mark_dirty((cairo_surface_t *)ptr);
266 }

+ Here is the caller graph for this function:

static void dvi_cairo_put_pixel ( void *  image,
int  x,
int  y,
Ulong  color 
)
static

Definition at line 246 of file cairo-device.c.

247 {
248  cairo_surface_t *surface;
249  gint rowstride;
250  guint32 *p;
251 
252  surface = (cairo_surface_t *) image;
253 
254  rowstride = cairo_image_surface_get_stride (surface);
255  p = (guint32*) (cairo_image_surface_get_data (surface) + y * rowstride + x * 4);
256 
257  /* per cairo docs, must flush before modifying outside of cairo */
258  cairo_surface_flush(surface);
259  *p = color;
260 }

+ Here is the caller graph for this function:

static void dvi_cairo_set_color ( void *  device_data,
Ulong  fg,
Ulong  bg 
)
static

Definition at line 269 of file cairo-device.c.

270 {
271  DviCairoDevice *cairo_device = (DviCairoDevice *) device_data;
272 
273  cairo_device->fg = fg;
274  cairo_device->bg = bg;
275 }

+ Here is the caller graph for this function:

void mdvi_cairo_device_free ( DviDevice device)

Definition at line 300 of file cairo-device.c.

301 {
302  DviCairoDevice *cairo_device;
303 
304  cairo_device = (DviCairoDevice *) device->device_data;
305 
306  if (cairo_device->cr)
307  cairo_destroy (cairo_device->cr);
308 
309  g_free (cairo_device);
310 }

+ Here is the caller graph for this function:

cairo_surface_t* mdvi_cairo_device_get_surface ( DviDevice device)

Definition at line 313 of file cairo-device.c.

314 {
315  DviCairoDevice *cairo_device;
316 
317  cairo_device = (DviCairoDevice *) device->device_data;
318 
319  return cairo_surface_reference (cairo_get_target (cairo_device->cr));
320 }

+ Here is the caller graph for this function:

void mdvi_cairo_device_init ( DviDevice device)

Definition at line 279 of file cairo-device.c.

280 {
281  device->device_data = g_new0 (DviCairoDevice, 1);
282 
284  device->draw_rule = dvi_cairo_draw_rule;
288  device->put_pixel = dvi_cairo_put_pixel;
290  device->set_color = dvi_cairo_set_color;
291 #ifdef HAVE_SPECTRE
292  device->draw_ps = dvi_cairo_draw_ps;
293 #else
294  device->draw_ps = NULL;
295 #endif
296  device->refresh = NULL;
297 }

+ Here is the caller graph for this function:

void mdvi_cairo_device_render ( DviContext dvi)

Definition at line 323 of file cairo-device.c.

324 {
325  DviCairoDevice *cairo_device;
326  gint page_width;
327  gint page_height;
328  cairo_surface_t *surface;
329 
330  cairo_device = (DviCairoDevice *) dvi->device.device_data;
331 
332  if (cairo_device->cr)
333  cairo_destroy (cairo_device->cr);
334 
335  page_width = dvi->dvi_page_w * dvi->params.conv + 2 * cairo_device->xmargin;
336  page_height = dvi->dvi_page_h * dvi->params.vconv + 2 * cairo_device->ymargin;
337 
338  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
339  page_width, page_height);
340 
341  cairo_device->cr = cairo_create (surface);
342  cairo_surface_destroy (surface);
343 
344  cairo_set_source_rgb (cairo_device->cr, 1., 1., 1.);
345  cairo_paint (cairo_device->cr);
346 
347  mdvi_dopage (dvi, dvi->currpage);
348 }

+ Here is the caller graph for this function:

void mdvi_cairo_device_set_margins ( DviDevice device,
gint  xmargin,
gint  ymargin 
)

Definition at line 351 of file cairo-device.c.

354 {
355  DviCairoDevice *cairo_device;
356 
357  cairo_device = (DviCairoDevice *) device->device_data;
358 
359  cairo_device->xmargin = xmargin;
360  cairo_device->ymargin = ymargin;
361 }

+ Here is the caller graph for this function:

void mdvi_cairo_device_set_scale ( DviDevice device,
gdouble  xscale,
gdouble  yscale 
)

Definition at line 364 of file cairo-device.c.

367 {
368  DviCairoDevice *cairo_device;
369 
370  cairo_device = (DviCairoDevice *) device->device_data;
371 
372  cairo_device->xscale = xscale;
373  cairo_device->yscale = yscale;
374 }

+ Here is the caller graph for this function: