Code

Fix self-snapping when dragging the transformation center of a selection containing...
[inkscape.git] / src / main.cpp
index c50ba7311b652e00c9344199cefe963a5901100f..78b66d8478766b185c65473e63c70a39e01e919c 100644 (file)
@@ -487,7 +487,6 @@ static void _win32_set_inkscape_env(gchar const *exe)
     gchar *perl = g_build_filename(exe, "python", NULL);
     gchar *pythonlib = g_build_filename(exe, "python", "Lib", NULL);
     gchar *pythondll = g_build_filename(exe, "python", "DLLs", NULL);
-    gchar *extdir = g_build_filename(exe, "share", "extensions", NULL);
     
     // Python 2.x needs short paths in PYTHONPATH.
     // Otherwise it doesn't work when Inkscape is installed in Unicode directories.
@@ -496,7 +495,6 @@ static void _win32_set_inkscape_env(gchar const *exe)
     gchar *python_s = g_win32_locale_filename_from_utf8(python);
     gchar *pythonlib_s = g_win32_locale_filename_from_utf8(pythonlib);
     gchar *pythondll_s = g_win32_locale_filename_from_utf8(pythondll);
-    gchar *extdir_s = g_win32_locale_filename_from_utf8(extdir);
 
     gchar *new_path;
     gchar *new_pythonpath;
@@ -506,11 +504,11 @@ static void _win32_set_inkscape_env(gchar const *exe)
         new_path = g_strdup_printf("%s;%s;%s;%s", exe, python, scripts, perl);
     }
     if (pythonpath) {
-        new_pythonpath = g_strdup_printf("%s;%s;%s;%s;%s",
-            extdir_s, python_s, pythonlib_s, pythondll_s, pythonpath);
-    } else {
         new_pythonpath = g_strdup_printf("%s;%s;%s;%s",
-            extdir_s, python_s, pythonlib_s, pythondll_s);
+             python_s, pythonlib_s, pythondll_s, pythonpath);
+    } else {
+        new_pythonpath = g_strdup_printf("%s;%s;%s",
+            python_s, pythonlib_s, pythondll_s);
     }
 
     g_setenv("PATH", new_path, TRUE);
@@ -543,6 +541,43 @@ static void _win32_set_inkscape_env(gchar const *exe)
 }
 #endif
 
+static void set_extensions_env()
+{
+    gchar const *pythonpath = g_getenv("PYTHONPATH");
+    gchar *extdir;
+    gchar *new_pythonpath;
+    
+#ifdef WIN32
+    extdir = g_win32_locale_filename_from_utf8(INKSCAPE_EXTENSIONDIR);
+#else
+    extdir = g_strdup(INKSCAPE_EXTENSIONDIR);
+#endif
+
+    // On some platforms, INKSCAPE_EXTENSIONDIR is not absolute,
+    // but relative to the directory that contains the Inkscape executable.
+    // Since we spawn Python chdir'ed into the script's directory,
+    // we need to obtain the absolute path here.
+    if (!g_path_is_absolute(extdir)) {
+        gchar *curdir = g_get_current_dir();
+        gchar *extdir_new = g_build_filename(curdir, extdir, NULL);
+        g_free(extdir);
+        g_free(curdir);
+        extdir = extdir_new;
+    }
+
+    if (pythonpath) {
+        new_pythonpath = g_strdup_printf("%s" G_SEARCHPATH_SEPARATOR_S "%s",
+                                         extdir, pythonpath);
+        g_free(extdir);
+    } else {
+        new_pythonpath = extdir;
+    }
+
+    g_setenv("PYTHONPATH", new_pythonpath, TRUE);
+    g_free(new_pythonpath);
+    //printf("PYTHONPATH = %s\n", g_getenv("PYTHONPATH"));
+}
+
 /**
  * This is the classic main() entry point of the program, though on some
  * architectures it might be called by something else.
@@ -558,23 +593,7 @@ main(int argc, char **argv)
 #endif
 
 #ifdef WIN32
-    /*
-      Set the current directory to the directory of the
-      executable.  This seems redundant, but is needed for
-      when inkscape.exe is executed from another directory.
-      We use relative paths on win32.
-      HKCR\svgfile\shell\open\command is a good example
-
-      TODO: this breaks the CLI on Windows, see LP #167455
-      However, the CLI is broken anyway, because we are a GUI app
-    */
-    const int pathbuf = 2048;
-    gunichar2 *path = g_new(gunichar2, pathbuf);
-    GetModuleFileNameW(NULL, (WCHAR*) path, pathbuf);
-    gchar *inkscape = g_utf16_to_utf8(path, -1, NULL, NULL, NULL);
-    gchar *exedir = g_path_get_dirname(inkscape);
-    gunichar2 *dirw = g_utf8_to_utf16(exedir, -1, NULL, NULL, NULL);
-    SetCurrentDirectoryW((WCHAR*) dirw);
+    gchar *exedir = g_strdup(win32_getExePath().data());
     _win32_set_inkscape_env(exedir);
 
 # ifdef ENABLE_NLS
@@ -586,11 +605,7 @@ main(int argc, char **argv)
     g_free(shortexedir);
     g_free(localepath);
 # endif
-    
-    g_free(path);
-    g_free(inkscape);
     g_free(exedir);
-    g_free(dirw);
 
     // Don't touch the registry (works fine without it) for Inkscape Portable
     gchar const *val = g_getenv("INKSCAPE_PORTABLE_PROFILE_DIR");
@@ -620,6 +635,8 @@ main(int argc, char **argv)
     textdomain(GETTEXT_PACKAGE);
 #endif
 
+    set_extensions_env();
+
     // Prevents errors like "Unable to wrap GdkPixbuf..." (in nr-filter-image.cpp for example)
     Gtk::Main::init_gtkmm_internals();
 
@@ -1328,7 +1345,7 @@ sp_do_export_png(SPDocument *doc)
     if (sp_export_area) {
         /* Try to parse area (given in SVG pixels) */
         gdouble x0,y0,x1,y1;
-        if (!sscanf(sp_export_area, "%lg:%lg:%lg:%lg", &x0, &y0, &x1, &y1) == 4) {
+        if (sscanf(sp_export_area, "%lg:%lg:%lg:%lg", &x0, &y0, &x1, &y1) != 4) {
             g_warning("Cannot parse export area '%s'; use 'x0:y0:x1:y1'. Nothing exported.", sp_export_area);
             return;
         }