diff options
Diffstat (limited to 'src/sp-image.cpp')
| -rw-r--r-- | src/sp-image.cpp | 89 |
1 files changed, 33 insertions, 56 deletions
diff --git a/src/sp-image.cpp b/src/sp-image.cpp index b08d6f9b0..f1ea737ff 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -76,7 +76,6 @@ static void sp_image_set_curve(SPImage *image); -gchar const *sp_image_repr_read_filename(gchar const *href, gchar const *absref, gchar const *base ); static void sp_image_update_arenaitem (SPImage *img, Inkscape::DrawingImage *ai); static void sp_image_update_canvas_image (SPImage *image); @@ -170,8 +169,7 @@ void SPImage::release() { this->href = NULL; } - delete this->pixbuf; - this->pixbuf = NULL; + this->clear_image(); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) if (this->color_profile) { @@ -329,29 +327,31 @@ void SPImage::update(SPCtx *ctx, unsigned int flags) { SPItem::update(ctx, flags); if (flags & SP_IMAGE_HREF_MODIFIED_FLAG) { - delete this->pixbuf; - this->pixbuf = NULL; + this->clear_image(); if (this->href) { Inkscape::Pixbuf *pixbuf = NULL; + gchar const* uri = this->getRepr()->attribute("xlink:href"); + + if(!uri) { + g_warning("Image tag has no valid href: %s", this->getId()); - gchar const* filename = sp_image_repr_read_filename ( - this->getRepr()->attribute("xlink:href"), - this->getRepr()->attribute("sodipodi:absref"), - doc->getBase()); - - Inkscape::Pixbuf::create_from_data_uri(filename); - if (strncmp (filename,"data:", 5) == 0) { - filename += 5; - pixbuf = Inkscape::Pixbuf::create_from_data_uri(filename); - } else if(filename && g_str_has_suffix(filename, ".svg")) { - // TODO: We want to deal with svg images properly. This - // space allows us to do so later. - g_warning("Including svg images tags is not yet supported."); - } else if (filename) { - pixbuf = Inkscape::Pixbuf::create_from_file(filename); + } else if (strncmp (uri, "data:", 5) == 0) { + uri += 5; + pixbuf = Inkscape::Pixbuf::create_from_data_uri(uri); + + } else if(g_str_has_suffix(uri, ".svg")) { + SPDocument *doc = this->document->createChildDoc(uri); + if(doc) { + this->child = SP_ITEM(doc); + g_warning("Loaded document: %s", uri); + } else { + g_warning("Could not load svg for image tag: %s",this->getId()); + } + } else { + pixbuf = Inkscape::Pixbuf::create_from_file(uri); } - if(!pixbuf) { + if(!pixbuf && !this->child) { /* Nope: We do not find any valid pixmap file :-( */ pixbuf = new Inkscape::Pixbuf( gdk_pixbuf_new_from_xpm_data((const gchar **) brokenimage_xpm)); @@ -527,6 +527,18 @@ void SPImage::update(SPCtx *ctx, unsigned int flags) { sp_image_update_canvas_image ((SPImage *) this); } +// Remove references to image or child objects. +void SPImage::clear_image() { + if(this->pixbuf) { + delete this->pixbuf; + this->pixbuf = NULL; + } + if(this->child) { + this->detach(this->child); + this->child = NULL; + } +} + void SPImage::modified(unsigned int flags) { // SPItem::onModified(flags); @@ -667,41 +679,6 @@ Inkscape::DrawingItem* SPImage::show(Inkscape::Drawing &drawing, unsigned int /* return ai; } -gchar const *sp_image_repr_read_filename(gchar const *href, gchar const *absref, gchar const *base) -{ - gchar const *filename = href; - - if (filename != NULL) { - if (strncmp (filename,"file:",5) == 0) { - filename = g_filename_from_uri(filename, NULL, NULL); - } else if (strncmp (filename,"data:",5) == 0) { - /* data URI - embedded image */ - return filename; - } else if (!g_path_is_absolute (filename)) { - /* try to load from relative pos combined with document base*/ - const gchar *docbase = base; - if (!docbase) docbase = "."; - filename = g_build_filename(docbase, filename, NULL); - } - } - - if (filename && g_file_test(filename, G_FILE_TEST_EXISTS) ) { - return filename; - } - - /* at last try to load from sp absolute path name */ - if (absref != NULL && g_file_test(absref, G_FILE_TEST_EXISTS)) { - // using absref is outside of SVG rules, so we must at least warn the user - if ( base != NULL && href != NULL ) { - g_warning ("<image xlink:href=\"%s\"> did not resolve to a valid image file (base dir is %s), now trying sodipodi:absref=\"%s\"", href, base, absref); - } else { - g_warning ("xlink:href did not resolve to a valid image file, now trying sodipodi:absref=\"%s\"", absref); - } - return absref; - } - return NULL; -} - /* We assert that realpixbuf is either NULL or identical size to pixbuf */ static void sp_image_update_arenaitem (SPImage *image, Inkscape::DrawingImage *ai) |
