Commit 02daae71 authored by John Ellson's avatar John Ellson

Merge branch 'revert-6dcb4f0a' into 'master'

Revert "Merge branch 'cairo-mime-data' into 'master'"

See merge request !1296
parents 2e179ee9 f9b7f421
Pipeline #37875026 passed with stages
in 23 minutes and 12 seconds
...@@ -52,82 +52,31 @@ reader (void *closure, unsigned char *data, unsigned int length) ...@@ -52,82 +52,31 @@ reader (void *closure, unsigned char *data, unsigned int length)
} }
#endif #endif
static void gdk_set_mimedata_from_file (cairo_surface_t *image, const char *mime_type, const char *file)
{
FILE *fp;
unsigned char *data = NULL;
long len;
const char *id_prefix = "gvloadimage_gdk-";
char *unique_id;
size_t unique_id_len;
fp = fopen (file, "rb");
if (fp == NULL)
return;
fseek (fp, 0, SEEK_END);
len = ftell(fp);
fseek (fp, 0, SEEK_SET);
if (len > 0)
data = malloc ((size_t)len);
if (data) {
if (fread(data, (size_t)len, 1, fp) != 1) {
free (data);
data = NULL;
}
}
fclose(fp);
if (data) {
cairo_surface_set_mime_data (image, mime_type, data, (unsigned long)len, free, data);
unique_id_len = strlen(id_prefix) + strlen(file) + 1;
unique_id = malloc (unique_id_len);
snprintf (unique_id, unique_id_len, "%s%s", id_prefix, file);
cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_UNIQUE_ID, (unsigned char *)unique_id, unique_id_len, free, unique_id);
}
}
static void gdk_set_mimedata(cairo_surface_t *image, usershape_t *us)
{
switch (us->type) {
case FT_PNG:
gdk_set_mimedata_from_file (image, CAIRO_MIME_TYPE_PNG, us->name);
break;
case FT_JPEG:
gdk_set_mimedata_from_file (image, CAIRO_MIME_TYPE_JPEG, us->name);
break;
default:
break;
}
}
static void gdk_freeimage(usershape_t *us) static void gdk_freeimage(usershape_t *us)
{ {
cairo_surface_destroy ((cairo_surface_t *)(us->data)); g_object_unref((GdkPixbuf*)(us->data));
} }
static cairo_surface_t* gdk_loadimage(GVJ_t * job, usershape_t *us) static GdkPixbuf* gdk_loadimage(GVJ_t * job, usershape_t *us)
{ {
cairo_t *cr = (cairo_t *) job->context; /* target context */
GdkPixbuf *image = NULL; GdkPixbuf *image = NULL;
cairo_surface_t *cairo_image = NULL;
cairo_pattern_t *pattern;
assert(job); assert(job);
assert(us); assert(us);
assert(us->name); assert(us->name);
if (us->data) { if (us->data) {
if (us->datafree == gdk_freeimage) { if (us->datafree == gdk_freeimage)
cairo_image = cairo_surface_reference ((cairo_surface_t *)(us->data)); /* use cached data */ image = (GdkPixbuf*)(us->data); /* use cached data */
} else { else {
us->datafree(us); /* free incompatible cache data */ us->datafree(us); /* free incompatible cache data */
us->datafree = NULL; us->datafree = NULL;
us->data = NULL; us->data = NULL;
} }
} }
if (!cairo_image) { /* read file into cache */ if (!image) { /* read file into cache */
if (!gvusershape_file_access(us)) if (!gvusershape_file_access(us))
return NULL; return NULL;
switch (us->type) { switch (us->type) {
case FT_PNG: case FT_PNG:
case FT_JPEG: case FT_JPEG:
...@@ -140,38 +89,28 @@ static cairo_surface_t* gdk_loadimage(GVJ_t * job, usershape_t *us) ...@@ -140,38 +89,28 @@ static cairo_surface_t* gdk_loadimage(GVJ_t * job, usershape_t *us)
default: default:
image = NULL; image = NULL;
} }
if (image) { if (image) {
cairo_save (cr); us->data = (void*)image;
gdk_cairo_set_source_pixbuf (cr, image, 0, 0);
pattern = cairo_get_source (cr);
assert(cairo_pattern_get_type (pattern) == CAIRO_PATTERN_TYPE_SURFACE);
cairo_pattern_get_surface (pattern, &cairo_image);
cairo_image = cairo_surface_reference (cairo_image);
cairo_restore (cr);
gdk_set_mimedata (cairo_image, us);
us->data = (void*)cairo_surface_reference (cairo_image);
us->datafree = gdk_freeimage; us->datafree = gdk_freeimage;
} }
gvusershape_file_release(us); gvusershape_file_release(us);
} }
return cairo_image; return image;
} }
static void gdk_loadimage_cairo(GVJ_t * job, usershape_t *us, boxf b, boolean filled) static void gdk_loadimage_cairo(GVJ_t * job, usershape_t *us, boxf b, boolean filled)
{ {
cairo_t *cr = (cairo_t *) job->context; /* target context */ cairo_t *cr = (cairo_t *) job->context; /* target context */
cairo_surface_t *image; GdkPixbuf *image;
image = gdk_loadimage(job, us); image = gdk_loadimage(job, us);
if (image) { if (image) {
cairo_save(cr); cairo_save(cr);
cairo_translate(cr, b.LL.x, -b.UR.y); cairo_translate(cr, b.LL.x, -b.UR.y);
cairo_scale(cr, (b.UR.x - b.LL.x)/(us->w), (b.UR.y - b.LL.y)/(us->h)); cairo_scale(cr, (b.UR.x - b.LL.x)/(us->w), (b.UR.y - b.LL.y)/(us->h));
cairo_set_source_surface (cr, image, 0, 0); gdk_cairo_set_source_pixbuf (cr, image, 0, 0);
cairo_paint (cr); cairo_paint (cr);
cairo_restore(cr); cairo_restore(cr);
cairo_surface_destroy (image);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment