void data_add_pixbuf (AttributeNode attr, GdkPixbuf *pixbuf) { ObjectNode composite = data_add_composite(attr, "pixbuf"); AttributeNode comp_attr = composite_add_attribute (composite, "data"); gchar *b64; b64 = pixbuf_encode_base64 (pixbuf); if (b64) (void)xmlNewChild (comp_attr, NULL, (const xmlChar *)"data", (xmlChar *)b64); g_free (b64); }
static void draw_image(DiaRenderer *self, Point *point, real width, real height, DiaImage *image) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); xmlNodePtr node; gchar d_buf[DTOSTR_BUF_SIZE]; gchar *uri = NULL; node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"image", NULL); dia_svg_dtostr(d_buf, point->x); xmlSetProp(node, (const xmlChar *)"x", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, point->y); xmlSetProp(node, (const xmlChar *)"y", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, width); xmlSetProp(node, (const xmlChar *)"width", (xmlChar *) d_buf); dia_svg_dtostr(d_buf, height); xmlSetProp(node, (const xmlChar *)"height", (xmlChar *) d_buf); /* if the image file location is relative to the SVG file's store * a relative path - if it does not have a path: inline it */ if (strcmp (dia_image_filename(image), "(null)") == 0) { gchar *b64 = pixbuf_encode_base64 (dia_image_pixbuf (image)); gchar *uri; if (b64) uri = g_strdup_printf ("data:image/png;base64,%s", b64); else uri = g_strdup ("(null)"); xmlSetProp(node, (const xmlChar *)"xlink:href", (xmlChar *) uri); g_free (b64); } else if ((uri = dia_relativize_filename (renderer->filename, dia_image_filename(image))) != NULL) xmlSetProp(node, (const xmlChar *)"xlink:href", (xmlChar *) uri); else if ((uri = g_filename_to_uri(dia_image_filename(image), NULL, NULL)) != NULL) xmlSetProp(node, (const xmlChar *)"xlink:href", (xmlChar *) uri); else /* not sure if this fallback is better than nothing */ xmlSetProp(node, (const xmlChar *)"xlink:href", (xmlChar *) dia_image_filename(image)); g_free (uri); }