From 88c274eee745433ba14c571f29834b68b8627a91 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 22 Mar 2015 10:22:31 +0100 Subject: [PATCH] Let imagemagick detect file format (bug #2332) Imagemagick detects the inut file format based on contents. Therefore it does not make sense that we prefix the to be converted file name with the extension (assuming that the file extension matches the imagemagick format name). This breaks formats where the extension used by LyX does not match the imagemagick format name. --- lib/scripts/convertDefault.py | 10 +++++----- src/Converter.cpp | 8 ++++---- src/graphics/GraphicsConverter.cpp | 8 +++++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/scripts/convertDefault.py b/lib/scripts/convertDefault.py index 63d0e09c6a..40bc8b53c8 100644 --- a/lib/scripts/convertDefault.py +++ b/lib/scripts/convertDefault.py @@ -15,7 +15,7 @@ # The user can also redefine this default converter, placing their # replacement in ~/.lyx/scripts -# converts an image from $1 to $2 format +# converts an image $2 (format $1) to $4 (format $3) import os, re, sys # We may need some extra options only supported by recent convert versions @@ -42,15 +42,15 @@ else: opts = "-depth 8" -# If supported, add the -define option for pdf source formats -if sys.argv[1][:4] == 'pdf:' and (version >= 0x060206 or gm): +# If supported, add the -define option for pdf source formats +if sys.argv[1] == 'pdf' and (version >= 0x060206 or gm): opts = '-define pdf:use-cropbox=true ' + opts # If supported, add the -flatten option for ppm target formats (see bug 4749) -if sys.argv[2][:4] == 'ppm:' and (version >= 0x060305 or gm): +if sys.argv[3] == 'ppm' and (version >= 0x060305 or gm): opts = opts + ' -flatten' -if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 0: +if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[2], sys.argv[3] + ':' + sys.argv[4])) != 0: print >> sys.stderr, sys.argv[0], 'ERROR' print >> sys.stderr, 'Execution of "convert" failed.' sys.exit(1) diff --git a/src/Converter.cpp b/src/Converter.cpp index 933e2f673b..0f97b7396e 100644 --- a/src/Converter.cpp +++ b/src/Converter.cpp @@ -299,10 +299,10 @@ bool Converters::convert(Buffer const * buffer, string const command = os::python() + ' ' + quoteName(libFileSearch("scripts", "convertDefault.py").toFilesystemEncoding()) + - ' ' + - quoteName(from_ext + ':' + from_file.toFilesystemEncoding()) + - ' ' + - quoteName(to_ext + ':' + to_file.toFilesystemEncoding()); + ' ' + from_ext + ' ' + + quoteName(from_file.toFilesystemEncoding()) + + ' ' + to_ext + ' ' + + quoteName(to_file.toFilesystemEncoding()); LYXERR(Debug::FILES, "No converter defined! " "I use convertDefault.py:\n\t" << command); Systemcall one; diff --git a/src/graphics/GraphicsConverter.cpp b/src/graphics/GraphicsConverter.cpp index 3201d5d06a..4bd5cf1ef4 100644 --- a/src/graphics/GraphicsConverter.cpp +++ b/src/graphics/GraphicsConverter.cpp @@ -324,13 +324,15 @@ static void build_script(string const & from_file, ostringstream os; os << os::python() << ' ' << commandPrep("$$s/scripts/convertDefault.py") << ' '; - if (!from_format.empty()) - os << strip_digit(from_format) << ':'; + if (from_format.empty()) + os << "unknown "; + else + os << strip_digit(from_format) << ' '; // The extra " quotes around infile and outfile are needed // because the filename may contain spaces and it is used // as argument of os.system(). os << "' + '\"' + infile + '\"' + ' " - << strip_digit(to_format) << ":' + '\"' + outfile + '\"' + '"; + << strip_digit(to_format) << " ' + '\"' + outfile + '\"' + '"; string const command = os.str(); LYXERR(Debug::GRAPHICS, -- 2.39.5