24 #include <libspectre/spectre.h>
53 cairo_surface_t *surface;
59 isbox = (glyph->
data == NULL ||
63 x = - glyph->
x + x0 + cairo_device->
xmargin;
64 y = - glyph->
y + y0 + cairo_device->
ymargin;
68 surface = cairo_get_target (cairo_device->
cr);
70 || x + w > cairo_image_surface_get_width (surface)
71 || y + h > cairo_image_surface_get_height (surface))
74 cairo_save (cairo_device->
cr);
76 cairo_rectangle (cairo_device->
cr,
80 cairo_stroke (cairo_device->
cr);
82 cairo_translate (cairo_device->
cr, x, y);
83 cairo_set_source_surface (cairo_device->
cr,
84 (cairo_surface_t *) glyph->
data,
86 cairo_paint (cairo_device->
cr);
89 cairo_restore (cairo_device->
cr);
105 color = cairo_device->
fg;
107 cairo_save (cairo_device->
cr);
108 cairo_scale (cairo_device->
cr, cairo_device->
xscale, cairo_device->
yscale);
110 cairo_set_source_rgb (cairo_device->
cr,
111 ((color >> 16) & 0xff) / 255.,
112 ((color >> 8) & 0xff) / 255.,
113 ((color >> 0) & 0xff) / 255.);
115 cairo_rectangle (cairo_device->
cr,
118 width / cairo_device->
xscale, height / cairo_device->
yscale);
120 cairo_stroke (cairo_device->
cr);
122 cairo_fill (cairo_device->
cr);
125 cairo_restore (cairo_device->
cr);
131 const char *filename,
138 unsigned char *data = NULL;
140 SpectreDocument *psdoc;
141 SpectreRenderContext *rc;
143 SpectreStatus status;
144 cairo_surface_t *image;
148 psdoc = spectre_document_new ();
149 spectre_document_load (psdoc, filename);
150 if (spectre_document_status (psdoc)) {
151 spectre_document_free (psdoc);
155 spectre_document_get_page_size (psdoc, &w, &h);
157 rc = spectre_render_context_new ();
158 spectre_render_context_set_scale (rc,
161 spectre_document_render_full (psdoc, rc, &data, &row_length);
162 status = spectre_document_status (psdoc);
164 spectre_render_context_free (rc);
165 spectre_document_free (psdoc);
168 g_warning (
"Error rendering PS document %s: %s\n",
169 filename, spectre_status_to_string (status));
175 image = cairo_image_surface_create_for_data ((
unsigned char *)data,
180 cairo_save (cairo_device->
cr);
182 cairo_translate (cairo_device->
cr,
185 cairo_set_source_surface (cairo_device->
cr, image, 0, 0);
186 cairo_paint (cairo_device->
cr);
188 cairo_restore (cairo_device->
cr);
190 cairo_surface_destroy (image);
205 GdkColor color, color_fg;
209 color_fg.red = (fg >> 16) & 0xff;
210 color_fg.green = (fg >> 8) & 0xff;
211 color_fg.blue = (fg >> 0) & 0xff;
214 for (i = 0; i < npixels; i++) {
216 pow ((
double)i / n, 1 / gamma) :
217 1 - pow ((
double)(n - i) / n, -gamma);
219 color.red = frac * color_fg.red;
220 color.green = frac * color_fg.green;
221 color.blue = frac * color_fg.blue;
224 pixels[i] = (alpha << 24) + (color.red << 16) + (color.green << 8) + color.blue;
236 return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
242 cairo_surface_destroy ((cairo_surface_t *)ptr);
248 cairo_surface_t *surface;
252 surface = (cairo_surface_t *) image;
254 rowstride = cairo_image_surface_get_stride (surface);
255 p = (guint32*) (cairo_image_surface_get_data (surface) + y * rowstride + x * 4);
258 cairo_surface_flush(surface);
265 cairo_surface_mark_dirty((cairo_surface_t *)ptr);
273 cairo_device->
fg = fg;
274 cairo_device->
bg = bg;
292 device->
draw_ps = dvi_cairo_draw_ps;
306 if (cairo_device->
cr)
307 cairo_destroy (cairo_device->
cr);
309 g_free (cairo_device);
319 return cairo_surface_reference (cairo_get_target (cairo_device->
cr));
328 cairo_surface_t *surface;
332 if (cairo_device->
cr)
333 cairo_destroy (cairo_device->
cr);
338 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
339 page_width, page_height);
341 cairo_device->
cr = cairo_create (surface);
342 cairo_surface_destroy (surface);
344 cairo_set_source_rgb (cairo_device->
cr, 1., 1., 1.);
345 cairo_paint (cairo_device->
cr);
359 cairo_device->
xmargin = xmargin;
360 cairo_device->
ymargin = ymargin;
372 cairo_device->
xscale = xscale;
373 cairo_device->
yscale = yscale;