Beispiel #1
0
cairo_surface_t *
cairo_boilerplate_convert_to_image (const char *filename, int page)
{
    FILE *file;
    unsigned int flags = 0;
    cairo_surface_t *image;

  RETRY:
    file = cairo_boilerplate_open_any2ppm (filename, page, flags);
    if (file == NULL)
	return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);

    image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
    fclose (file);

    if (cairo_surface_status (image) == CAIRO_STATUS_READ_ERROR) {
	if (flags == 0) {
	    /* Try again in process, e.g. to propagate a CRASH. */
	    cairo_surface_destroy (image);
	    flags = CAIRO_BOILERPLATE_OPEN_NO_DAEMON;
	    goto RETRY;
	}
    }

    return image;
}
Beispiel #2
0
static cairo_surface_t *
_cairo_boilerplate_svg_convert_to_image (cairo_surface_t *surface)
{
    svg_target_closure_t *ptc = cairo_surface_get_user_data (surface,
							     &svg_closure_key);
    FILE *file;
    cairo_surface_t *image;

    file = cairo_boilerplate_open_any2ppm (ptc->filename, 0);
    if (file == NULL)
	return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);

    image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
    fclose (file);

    return image;
}
Beispiel #3
0
cairo_surface_t *
cairo_boilerplate_convert_to_image (const char *filename,
				    int 	page)
{
    FILE *file;
    unsigned int flags = 0;
    cairo_surface_t *image;
    int (*close_cb) (FILE *);
    int ret;

  RETRY:
    file = cairo_boilerplate_open_any2ppm (filename, page, flags, &close_cb);
    if (file == NULL) {
	switch (errno) {
	case ENOMEM:
	    return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
	default:
	    return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
	}
    }

    image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
    ret = close_cb (file);
    /* check for fatal errors from the interpreter */
    if (ret) { /* any2pmm should never die... */
	cairo_surface_destroy (image);
	return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_INVALID_STATUS);
    }

    if (ret == 0 && cairo_surface_status (image) == CAIRO_STATUS_READ_ERROR) {
	if (flags == 0) {
	    /* Try again in a standalone process. */
	    cairo_surface_destroy (image);
	    flags = CAIRO_BOILERPLATE_OPEN_NO_DAEMON;
	    goto RETRY;
	}
    }

    return image;
}