]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsConverter.cpp
Fix crash with updateLabels(). I changed the the test in the assertion but endless...
[lyx.git] / src / graphics / GraphicsConverter.cpp
index 6fafbf2679d25ccc0c8c7c87dbfc8e2fe8f4a5fb..67e0421663bc1f2cef440586aabedc9b4e69a627 100644 (file)
@@ -226,8 +226,8 @@ static string const move_file(string const & from_file, string const & to_file)
                return string();
 
        ostringstream command;
-       command << "fromfile = " << from_file << "\n"
-               << "tofile = "   << to_file << "\n\n"
+       command << "fromfile = utf8ToDefaultEncoding(" << from_file << ")\n"
+               << "tofile = utf8ToDefaultEncoding("   << to_file << ")\n\n"
                << "try:\n"
                << "  os.rename(fromfile, tofile)\n"
                << "except:\n"
@@ -257,13 +257,13 @@ static void build_conversion_command(string const & command, ostream & script)
        // If this occurs, move ${outfile}.0 to ${outfile}
        // and delete ${outfile}.? (ignore errors)
        script << "if not os.path.isfile(outfile):\n"
-                 "  if os.path.isfile(outfile + '.0'):\n"
-                 "    os.rename(outfile + '.0', outfile)\n"
-                 "    import glob\n"
-                 "    for file in glob.glob(outfile + '.?'):\n"
-                 "      unlinkNoThrow(file)\n"
-                 "  else:\n"
-                 "    sys.exit(1)\n\n";
+                 "  if os.path.isfile(outfile + '.0'):\n"
+                 "    os.rename(outfile + '.0', outfile)\n"
+                 "    import glob\n"
+                 "    for file in glob.glob(outfile + '.?'):\n"
+                 "      unlinkNoThrow(file)\n"
+                 "  else:\n"
+                 "    sys.exit(1)\n\n";
 
        // Delete the infile
        script << "unlinkNoThrow(infile)\n\n";
@@ -281,23 +281,23 @@ static void build_script(FileName const & from_file,
        typedef Converters::EdgePath EdgePath;
 
        script << "#!/usr/bin/env python\n"
-                 "# -*- coding: utf-8 -*-\n"
-                 "import os, shutil, sys, locale\n\n"
-                 "def unlinkNoThrow(file):\n"
-                 "  ''' remove a file, do not throw if an error occurs '''\n"
-                 "  try:\n"
-                 "    os.unlink(file)\n"
-                 "  except:\n"
-                 "    pass\n\n"
-                 "def utf8ToDefaultEncoding(file):\n"
-                 "  ''' if possible, convert to the default encoding '''\n"
-                 "  try:\n"
-                 "    language, output_encoding = locale.getdefaultlocale()\n"
-                 "    if output_encoding == None:\n"
-                 "      output_encoding = 'latin1'\n"
-                 "    return unicode(file, 'utf8').encode(output_encoding)\n"
-                 "  except:\n"
-                 "    return file\n\n";
+                 "# -*- coding: utf-8 -*-\n"
+                 "import os, shutil, sys, locale\n\n"
+                 "def unlinkNoThrow(file):\n"
+                 "  ''' remove a file, do not throw if an error occurs '''\n"
+                 "  try:\n"
+                 "    os.unlink(file)\n"
+                 "  except:\n"
+                 "    pass\n\n"
+                 "def utf8ToDefaultEncoding(file):\n"
+                 "  ''' if possible, convert to the default encoding '''\n"
+                 "  try:\n"
+                 "    language, output_encoding = locale.getdefaultlocale()\n"
+                 "    if output_encoding == None:\n"
+                 "      output_encoding = 'latin1'\n"
+                 "    return unicode(file, 'utf8').encode(output_encoding)\n"
+                 "  except:\n"
+                 "    return file\n\n";
 
        // we do not use ChangeExtension because this is a basename
        // which may nevertheless contain a '.'
@@ -323,28 +323,30 @@ static void build_script(FileName const & from_file,
        script << "infile = utf8ToDefaultEncoding("
                        << quoteName(from_file.absFilename(), quote_python)
                        << ")\n"
-                 "outfile = " << quoteName(outfile, quote_python) << "\n"
-                 "shutil.copy(infile, outfile)\n";
+                 "outfile = utf8ToDefaultEncoding("
+                       << quoteName(outfile, quote_python) << ")\n"
+                 "shutil.copy(infile, outfile)\n";
 
        // Some converters (e.g. lilypond) can only output files to the
        // current directory, so we need to change the current directory.
        // This has the added benefit that all other files that may be
        // generated by the converter are deleted when LyX closes and do not
        // clutter the real working directory.
-       script << "os.chdir(" << quoteName(onlyPath(outfile)) << ")\n";
+       script << "os.chdir(utf8ToDefaultEncoding("
+              << quoteName(onlyPath(outfile)) << "))\n";
 
        if (edgepath.empty()) {
                // Either from_format is unknown or we don't have a
                // converter path from from_format to to_format, so we use
                // the default converter.
                script << "infile = outfile\n"
-                      << "outfile = " << quoteName(to_file, quote_python)
-                      << '\n';
+                      << "outfile = utf8ToDefaultEncoding("
+                      << quoteName(to_file, quote_python) << ")\n";
 
                ostringstream os;
                os << support::os::python() << ' '
                   << libScriptSearch("$$s/scripts/convertDefault.py",
-                                     quote_python) << ' ';
+                                     quote_python) << ' ';
                if (!from_format.empty())
                        os << from_format << ':';
                // The extra " quotes around infile and outfile are needed
@@ -379,9 +381,12 @@ static void build_script(FileName const & from_file,
                outfile = addExtension(to_base.absFilename(), conv.To->extension());
 
                // Store these names in the python script
-               script << "infile = "      << quoteName(infile, quote_python) << "\n"
-                         "infile_base = " << quoteName(infile_base, quote_python) << "\n"
-                         "outfile = "     << quoteName(outfile, quote_python) << '\n';
+               script << "infile = utf8ToDefaultEncoding("
+                               << quoteName(infile, quote_python) << ")\n"
+                         "infile_base = utf8ToDefaultEncoding("
+                               << quoteName(infile_base, quote_python) << ")\n"
+                         "outfile = utf8ToDefaultEncoding("
+                               << quoteName(outfile, quote_python) << ")\n";
 
                // See comment about extra " quotes above (although that
                // applies only for the first loop run here).