Code

Fix Bug #675309 - crash when unlinking an orphaned clone
[inkscape.git] / src / helper / png-write.cpp
index 753b0df45ee1a684ad07e283663ee00cf9e93016..754372f23b35e40b22d22c2d2961c0a96090dac4 100644 (file)
@@ -31,7 +31,7 @@
 #include <sp-root.h>
 #include <sp-defs.h>
 #include "preferences.h"
-#include "dialogs/rdf.h"
+#include "rdf.h"
 
 /* This is an example of how to use libpng to read and write PNG files.
  * The file libpng.txt is much more verbose then this.  If you have not
@@ -133,6 +133,7 @@ sp_png_write_rgba_striped(SPDocument *doc,
     png_uint_32 r;
 
     g_return_val_if_fail(filename != NULL, false);
+    g_return_val_if_fail(data != NULL, false);
 
     /* open the file */
 
@@ -413,20 +414,7 @@ sp_export_png_file(SPDocument *doc, gchar const *filename,
     g_return_val_if_fail(height >= 1, false);
     g_return_val_if_fail(!area.hasZeroArea(), false);
 
-    //Make relative paths absolute, if possible:
-    gchar *path = 0;
-    if (!g_path_is_absolute(filename) && doc->uri) {
-        gchar *dirname = g_path_get_dirname(doc->uri);
-        if (dirname) {
-            path = g_build_filename(dirname, filename, NULL);
-            g_free(dirname);
-        }
-    }
-    if (!path) {
-        path = g_strdup(filename);
-    }
-
-    if (!force_overwrite && !sp_ui_overwrite_file(path)) {
+    if (!force_overwrite && !sp_ui_overwrite_file(filename)) {
         /* Remark: We return true so as not to invoke an error dialog in case export is cancelled
            by the user; currently this is safe because the callers only act when false is returned.
            If this changes in the future we need better distinction of return types (e.g., use int)
@@ -434,13 +422,6 @@ sp_export_png_file(SPDocument *doc, gchar const *filename,
         return true;
     }
 
-    // export with maximum blur rendering quality
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    int saved_quality = prefs->getInt("/options/blurquality/value", 0);
-    prefs->setInt("/options/blurquality/value", 2);
-    int saved_filter_quality = prefs->getInt("/options/filterquality/value", 0);
-    prefs->setInt("/options/filterquality/value", 2);
-
     sp_document_ensure_up_to_date(doc);
 
     /* Calculate translation by transforming to document coordinates (flipping Y)*/
@@ -478,6 +459,8 @@ sp_export_png_file(SPDocument *doc, gchar const *filename,
 
     /* Create new arena */
     NRArena *const arena = NRArena::create();
+    // export with maximum blur rendering quality
+    nr_arena_set_renderoffscreen(arena);
     unsigned const dkey = sp_item_display_key_new(1);
 
     /* Create ArenaItems and set transform */
@@ -497,12 +480,12 @@ sp_export_png_file(SPDocument *doc, gchar const *filename,
     if ((width < 256) || ((width * height) < 32768)) {
         ebp.px = nr_pixelstore_64K_new(FALSE, 0);
         ebp.sheight = 65536 / (4 * width);
-        write_status = sp_png_write_rgba_striped(doc, path, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
+        write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
         nr_pixelstore_64K_free(ebp.px);
     } else {
         ebp.sheight = 64;
-        ebp.px = g_new(guchar, 4 * ebp.sheight * width);
-        write_status = sp_png_write_rgba_striped(doc, path, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
+        ebp.px = g_try_new(guchar, 4 * ebp.sheight * width);
+        write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
         g_free(ebp.px);
     }
 
@@ -512,12 +495,6 @@ sp_export_png_file(SPDocument *doc, gchar const *filename,
     /* Free arena */
     nr_object_unref((NRObject *) arena);
 
-    // restore saved blur and filter quality
-    prefs->setInt("/options/blurquality/value", saved_quality);
-    prefs->setInt("/options/filterquality/value", saved_filter_quality);
-
-    g_free(path);
-
     return write_status;
 }
 
@@ -531,4 +508,4 @@ sp_export_png_file(SPDocument *doc, gchar const *filename,
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :