=== modified file 'src/extension/internal/cairo-render-context.cpp'
--- src/extension/internal/cairo-render-context.cpp	2013-04-29 00:51:29 +0000
+++ src/extension/internal/cairo-render-context.cpp	2013-06-13 14:26:20 +0000
@@ -1400,8 +1400,151 @@
     return true;
 }
 
+
+int CairoRenderContext::dumpImageFile(const gchar *filename,
+                                      guchar **data, unsigned int *len)
+{
+    FILE *f = Inkscape::IO::fopen_utf8name(filename, "rb");
+    if (f == NULL)
+    {
+        g_warning ("Unable to open linked file: %s", filename);
+        *data = NULL;
+        return -1; // -1 means file opening fail
+    }
+    fseek(f, 0, SEEK_END);
+    *len = ftell(f);
+    fseek(f, 0, SEEK_SET);
+    *data = (guchar*)g_malloc(*len);
+    if (1 != fread(*data, *len, 1, f))
+    {
+        g_warning ("Unable to read linked file: %s", filename);
+        g_free(*data);
+        return -2; // -2 means file reading fail
+    }
+    fclose(f);
+    return 1;
+}
+
+bool CairoRenderContext::renderImage(SPImage *image,
+                                     Geom::Affine const &image_transform,
+                                     SPStyle const *style)
+{
+    SPDocument *doc = image->document;
+    
+    g_assert( _is_valid );
+
+    if (_render_mode == RENDER_MODE_CLIP) {
+        return true;
+    }
+
+    int w = gdk_pixbuf_get_width (image->pixbuf);
+    int h = gdk_pixbuf_get_height (image->pixbuf);
+
+    // TODO: reenable merge_opacity if useful
+    float opacity = _state->opacity;
+
+    cairo_surface_t *image_surface = \
+        ink_cairo_surface_create_for_argb32_pixbuf(image->pixbuf);
+    
+    guchar *rawdata;
+    unsigned int len;
+
+    /* Copied and modified from sp-image code */
+    const gchar *filename = image->href;
+    if (filename != NULL && strncmp (filename,"data:",5) != 0) {
+        //if (strncmp (filename,"data:",5) == 0) {
+            /* data URI – embedded image, use stored pixbuf */
+            
+            // FIXME convert base64 data back to binay
+            //       and store them with the correct mime
+            //       type. Else embedded images will be exported
+            //       to bitmap file in the PDF file from a cairo pixbuf
+
+        //} else if
+        if (strncmp (filename,"file:",5) == 0) {
+            /* external file with absolute path */
+            gchar *fullname = g_filename_from_uri(filename, NULL, NULL);
+            if (fullname) {
+                dumpImageFile(fullname, &rawdata, &len);
+                g_free(fullname);
+                if (rawdata == NULL) {
+                    g_warning("data is NULL");
+                    return false;
+                }
+            }
+        } else {
+            if (!g_path_is_absolute(filename)) {
+                /* try to load from relative pos combined with document base*/
+                const gchar *docbase = doc->getBase();
+                g_warning("Docbase = %s", docbase);
+                if (!docbase) {
+                    docbase = ".";
+                }
+                gchar *fullname = g_build_filename(docbase, filename, NULL);
+
+                // document base can be wrong (on the temporary doc when
+                // importing bitmap from a
+                // different dir) or unset (when doc is not saved yet), so we
+                // check for base+href existence first,
+                // and if it fails, we also try to use bare href regardless of
+                // its g_path_is_absolute
+                if (g_file_test (fullname, G_FILE_TEST_EXISTS) &&
+                   !g_file_test (fullname, G_FILE_TEST_IS_DIR)) {
+                    dumpImageFile(fullname, &rawdata, &len);
+                    g_free (fullname);
+                    if (rawdata == NULL) {
+                        g_warning("data is NULL");
+                        return false;
+                    }
+                }
+            } else if (g_file_test (filename, G_FILE_TEST_EXISTS) &&
+                       !g_file_test (filename, G_FILE_TEST_IS_DIR)) {
+                /* try filename as absolute */
+                dumpImageFile(filename, &rawdata, &len);
+                if (rawdata == NULL) {
+                    g_warning("data is NULL");
+                    return false;
+                }
+            }
+        }
+
+        /* FIXME We need to deal with specific MIME types
+         * the data could be PNG or other supported format
+         */
+         cairo_surface_set_mime_data (image_surface, CAIRO_MIME_TYPE_JPEG,
+                         rawdata, len, (cairo_destroy_func_t)g_free, rawdata);
+    }
+
+    if (cairo_surface_status(image_surface)) {
+        TRACE(("Image surface creation failed:\n%s\n",
+               cairo_status_to_string(cairo_surface_status(image_surface))));
+        return false;
+    }
+
+    cairo_save(_cr);
+
+    // scaling by width & height is not needed because it will be done by Cairo
+    transform(image_transform);
+
+    cairo_set_source_surface(_cr, image_surface, 0.0, 0.0);
+
+    // set clip region so that the pattern will not be repeated
+    // (bug in Cairo-PDF)
+    if (_vector_based_target) {
+        cairo_new_path(_cr);
+        cairo_rectangle(_cr, 0, 0, w, h);
+        cairo_clip(_cr);
+    }
+    cairo_paint_with_alpha(_cr, opacity);
+    
+    cairo_restore(_cr);
+    cairo_surface_destroy(image_surface);
+    return true;
+}
+
 bool CairoRenderContext::renderImage(GdkPixbuf *pb,
-                                     Geom::Affine const &image_transform, SPStyle const * /*style*/)
+                                     Geom::Affine const &image_transform,
+                                     SPStyle const *style)
 {
     g_assert( _is_valid );
 

=== modified file 'src/extension/internal/cairo-render-context.h'
--- src/extension/internal/cairo-render-context.h	2013-03-15 00:39:02 +0000
+++ src/extension/internal/cairo-render-context.h	2013-06-12 18:43:25 +0000
@@ -26,6 +26,10 @@
 
 #include "style.h"
 
+#include "sp-item.h"
+#include "sp-image.h"
+#include "document.h"
+
 #include <cairo.h>
 
 class SPClipPath;
@@ -139,6 +143,10 @@
 
     /* Rendering methods */
     bool renderPathVector(Geom::PathVector const &pathv, SPStyle const *style, Geom::OptRect const &pbox);
+    int dumpImageFile(const gchar *filename, guchar **data,
+                      unsigned int *len);
+    bool renderImage(SPImage *image,
+                     Geom::Affine const &image_transform, SPStyle const *style);
     bool renderImage(GdkPixbuf *pb,
                      Geom::Affine const &image_transform, SPStyle const *style);
     bool renderGlyphtext(PangoFont *font, Geom::Affine const &font_matrix,

=== modified file 'src/extension/internal/cairo-renderer.cpp'
--- src/extension/internal/cairo-renderer.cpp	2012-10-28 18:19:43 +0000
+++ src/extension/internal/cairo-renderer.cpp	2013-06-13 11:12:56 +0000
@@ -369,7 +369,7 @@
     Geom::Scale s(width / (double)w, height / (double)h);
     Geom::Affine t(s * tp);
 
-    ctx->renderImage (image->pixbuf, t, item->style);
+    ctx->renderImage (image, t, item->style);
 }
 
 static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx)

=== modified file 'src/sp-image.h'
--- src/sp-image.h	2013-03-14 23:24:17 +0000
+++ src/sp-image.h	2013-06-12 12:28:41 +0000
@@ -26,6 +26,7 @@
 #include <glibmm/ustring.h>
 #include "svg/svg-length.h"
 #include "sp-item.h"
+#include "sp-path.h"
 
 #define SP_IMAGE_HREF_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A
 

