_cairo_color_init (&white); _cairo_surface_fill_rectangle (white_surface, CAIRO_OPERATOR_SRC, &white, 0, 0, 1, 1); cairo_surface_set_repeat (white_surface, 1);
_cairo_pattern_init_solid (&white_pattern, 1.0, 1.0, 1.0);
_cairo_ps_surface_copy_page (void *abstract_surface){    cairo_status_t status = CAIRO_STATUS_SUCCESS;    cairo_ps_surface_t *surface = abstract_surface;    int width = surface->image->width;    int height = surface->image->height;    FILE *file = surface->file;    int i, x, y;    cairo_surface_t *white_surface;    char *rgb, *compressed;    long rgb_size, compressed_size;    cairo_color_t white;    rgb_size = 3 * width * height;    rgb = malloc (rgb_size);    if (rgb == NULL) {	status = CAIRO_STATUS_NO_MEMORY;	goto BAIL0;    }    compressed_size = (int) (1.0 + 1.1 * rgb_size);    compressed = malloc (compressed_size);    if (compressed == NULL) {	status = CAIRO_STATUS_NO_MEMORY;	goto BAIL1;    }    /* PostScript can not represent the alpha channel, so we blend the       current image over a white RGB surface to eliminate it. */    white_surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1);    if (white_surface == NULL) {	status = CAIRO_STATUS_NO_MEMORY;	goto BAIL2;    }    _cairo_color_init (&white);    _cairo_surface_fill_rectangle (white_surface,				   CAIRO_OPERATOR_SRC,				   &white,				   0, 0, 1, 1);    cairo_surface_set_repeat (white_surface, 1);    _cairo_surface_composite (CAIRO_OPERATOR_OVER_REVERSE,			      white_surface,			      NULL,			      &surface->image->base,			      0, 0,			      0, 0,			      0, 0,			      width, height);    i = 0;    for (y = 0; y < height; y++) {	pixman_bits_t *pixel = (pixman_bits_t *) (surface->image->data + y * surface->image->stride);	for (x = 0; x < width; x++, pixel++) {	    rgb[i++] = (*pixel & 0x00ff0000) >> 16;	    rgb[i++] = (*pixel & 0x0000ff00) >>  8;	    rgb[i++] = (*pixel & 0x000000ff) >>  0;	}    }    compress (compressed, &compressed_size, rgb, rgb_size);    /* Page header */    fprintf (file, "%%%%Page: %d\n", ++surface->pages);    fprintf (file, "gsave\n");    /* Image header goop */    fprintf (file, "%g %g translate\n", 0.0, surface->height_inches * 72.0);    fprintf (file, "%g %g scale\n", 72.0 / surface->x_ppi, 72.0 / surface->y_ppi);    fprintf (file, "/DeviceRGB setcolorspace\n");    fprintf (file, "<<\n");    fprintf (file, "	/ImageType 1\n");    fprintf (file, "	/Width %d\n", width);    fprintf (file, "	/Height %d\n", height);    fprintf (file, "	/BitsPerComponent 8\n");    fprintf (file, "	/Decode [ 0 1 0 1 0 1 ]\n");    fprintf (file, "	/DataSource currentfile /FlateDecode filter\n");    fprintf (file, "	/ImageMatrix [ 1 0 0 -1 0 1 ]\n");    fprintf (file, ">>\n");    fprintf (file, "image\n");    /* Compressed image data */    fwrite (compressed, 1, compressed_size, file);    fprintf (file, "showpage\n");    fprintf (file, "grestore\n");    /* Page footer */    fprintf (file, "%%%%EndPage\n");    cairo_surface_destroy (white_surface);    BAIL2:    free (compressed);    BAIL1:    free (rgb);    BAIL0:    return status;}