diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-01-16 21:05:23 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-01-16 21:05:23 +0000 |
| commit | d41eb702951c69bfd362e70bd072a869bf73967a (patch) | |
| tree | d96343f52b5a9e230dba24eaab73bfd9656ae867 /src/sp-image.cpp | |
| parent | Fixing edit-clear icon in the star tool (partial fix for Bug #1269698). (diff) | |
| download | inkscape-d41eb702951c69bfd362e70bd072a869bf73967a.tar.gz inkscape-d41eb702951c69bfd362e70bd072a869bf73967a.zip | |
Clean up sp-image's read_image, remove duplicate code
(bzr r12942)
Diffstat (limited to 'src/sp-image.cpp')
| -rw-r--r-- | src/sp-image.cpp | 57 |
1 files changed, 14 insertions, 43 deletions
diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 8f7a60ca6..9044257f4 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -649,56 +649,27 @@ Inkscape::DrawingItem* SPImage::show(Inkscape::Drawing &drawing, unsigned int /* Inkscape::Pixbuf *sp_image_repr_read_image(gchar const *href, gchar const *absref, gchar const *base) { Inkscape::Pixbuf *inkpb = 0; - gchar const *filename = href; - + if (filename != NULL) { if (strncmp (filename,"file:",5) == 0) { - gchar *fullname = g_filename_from_uri(filename, NULL, NULL); - if (fullname) { - inkpb = Inkscape::Pixbuf::create_from_file(fullname); - g_free(fullname); - if (inkpb != NULL) { - return inkpb; - } - } + filename = g_filename_from_uri(filename, NULL, NULL); } else if (strncmp (filename,"data:",5) == 0) { /* data URI - embedded image */ filename += 5; - inkpb = Inkscape::Pixbuf::create_from_data_uri(filename); - if (inkpb != NULL) { - return inkpb; - } - } else { - - if (!g_path_is_absolute (filename)) { - /* try to load from relative pos combined with document base*/ - const gchar *docbase = base; - 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)) { - inkpb = Inkscape::Pixbuf::create_from_file(fullname); - if (inkpb != NULL) { - g_free (fullname); - return inkpb; - } - } - g_free (fullname); - } + } 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); + } + } - /* try filename as absolute */ - if (g_file_test (filename, G_FILE_TEST_EXISTS) && !g_file_test (filename, G_FILE_TEST_IS_DIR)) { - inkpb = Inkscape::Pixbuf::create_from_file(filename); - if (inkpb != NULL) { - return inkpb; - } - } + if (filename && g_file_test(filename, G_FILE_TEST_EXISTS) ) { + inkpb = Inkscape::Pixbuf::create_from_file(filename); + if (inkpb != NULL) { + // g_free filename? + return inkpb; } } |
