Angus Leeming wrote:
> Georg Baum wrote:
>> Yes. I knew that, but did not remember that _this_ could be your problem.
>> I don't know why it is like that, but if desired it would not be
>> difficult to call convertDefault.sh. Angus, do we want that?
>
> Sure. I must have forgotten it.
This patch implements that. Jürgen, this should finally fix your problem.
I moved the default converter into Converters::convert() (where it belongs
IMO). Since I don't think that we want to try to convert from latex -> ps
with ImageMagick, I introduced a new parameter try_default that controls
wether the default converter is tried at all.
A side effect of this move is that Converters::convert() now always pops up
an error message if something goes wrong. Before, this was not done if no
converter was available.
OK to go in?
Georg
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2082
diff -u -p -r1.2082 ChangeLog
--- src/ChangeLog 13 Jan 2005 10:10:14 -0000 1.2082
+++ src/ChangeLog 14 Jan 2005 15:23:28 -0000
@@ -1,3 +1,8 @@
+2005-01-14 Georg Baum <[EMAIL PROTECTED]>
+
+ * converter.[Ch] (convert): take a new parameter try_default. Use
+ a default converter (imagemagick) if try_default is true.
+
2005-01-12 Angus Leeming <[EMAIL PROTECTED]>
* lyx_main.C (init): set the PATH variable to include the
Index: src/converter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/converter.C,v
retrieving revision 1.103
diff -u -p -r1.103 converter.C
--- src/converter.C 5 Jan 2005 20:21:24 -0000 1.103
+++ src/converter.C 14 Jan 2005 15:23:42 -0000
@@ -36,6 +38,8 @@ using lyx::support::compare_ascii_no_cas
using lyx::support::contains;
using lyx::support::DirList;
using lyx::support::GetExtension;
+using lyx::support::IsFileReadable;
+using lyx::support::LibFileSearch;
using lyx::support::LibScriptSearch;
using lyx::support::MakeRelPath;
using lyx::support::OnlyFilename;
@@ -279,16 +284,39 @@ OutputParams::FLAVOR Converters::getFlav
bool Converters::convert(Buffer const * buffer,
string const & from_file, string const & to_file_base,
string const & from_format, string const & to_format,
- string & to_file)
+ string & to_file, bool try_default)
{
- to_file = ChangeExtension(to_file_base,
- formats.extension(to_format));
+ string const to_ext = formats.extension(to_format);
+ to_file = ChangeExtension(to_file_base, to_ext);
if (from_format == to_format)
return move(from_format, from_file, to_file, false);
Graph::EdgePath edgepath = getPath(from_format, to_format);
if (edgepath.empty()) {
+ if (try_default) {
+ // if no special converter defined, then we take the
+ // default one from ImageMagic.
+ string const from_ext = formats.extension(from_format);
+ string const command = "sh " +
+ LibFileSearch("scripts", "convertDefault.sh") +
+ ' ' + from_ext + ':' + from_file +
+ ' ' + to_ext + ':' + to_file;
+ lyxerr[Debug::FILES]
+ << "No converter defined! "
+ "I use convertDefault.sh:\n\t"
+ << command << endl;
+ Systemcall one;
+ one.startscript(Systemcall::Wait, command);
+ if (IsFileReadable(to_file)) {
+ return true;
+ }
+ }
+ Alert::error(_("Cannot convert file"),
+ bformat(_("No information for converting %1$s "
+ "format files to %2$s.\n"
+ "Try defining a convertor in the preferences."),
+ from_format, to_format));
return false;
}
OutputParams runparams;
@@ -481,11 +527,12 @@ bool Converters::move(string const & fmt
bool Converters::convert(Buffer const * buffer,
string const & from_file, string const & to_file_base,
- string const & from_format, string const & to_format)
+ string const & from_format, string const & to_format,
+ bool try_default)
{
string to_file;
return convert(buffer, from_file, to_file_base, from_format, to_format,
- to_file);
+ to_file, try_default);
}
Index: src/converter.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/converter.h,v
retrieving revision 1.39
diff -u -p -r1.39 converter.h
--- src/converter.h 8 Nov 2004 08:22:03 -0000 1.39
+++ src/converter.h 14 Jan 2005 15:23:42 -0000
@@ -107,11 +109,12 @@ public:
bool convert(Buffer const * buffer,
std::string const & from_file, std::string const & to_file_base,
std::string const & from_format, std::string const & to_format,
- std::string & to_file);
+ std::string & to_file, bool try_default = false);
///
bool convert(Buffer const * buffer,
std::string const & from_file, std::string const & to_file_base,
- std::string const & from_format, std::string const & to_format);
+ std::string const & from_format, std::string const & to_format,
+ bool try_default = false);
///
void update(Formats const & formats);
///
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1098
diff -u -p -r1.1098 ChangeLog
--- src/insets/ChangeLog 14 Jan 2005 08:52:35 -0000 1.1098
+++ src/insets/ChangeLog 14 Jan 2005 15:25:39 -0000
@@ -1,9 +1,16 @@
+2005-01-14 Georg Baum <[EMAIL PROTECTED]>
+
+ * insetgraphics.C (prepareFile): move the invocation of the default
+ converter to ../converter.C
+ * insetgraphics.C (prepareFile), ExternalSupport.C (updateExternal):
+ call convert with try_default == true
+
2005-01-11 Georg Baum <[EMAIL PROTECTED]>
* insetgraphics.C (prepareFile): add missing calls to addExternalFile
- * updateExternal.[Ch] (doSubstitution): take a new parameter that
+ * ExternalSupport.[Ch] (doSubstitution): take a new parameter that
determines what variables are substituted
- * updateExternal.C (updateExternal): fix substitution of
+ * ExternalSupport.C (updateExternal): fix substitution of
ReferencedFiles
2005-01-10 Angus Leeming <[EMAIL PROTECTED]>
Index: src/insets/ExternalSupport.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ExternalSupport.C,v
retrieving revision 1.15
diff -u -p -r1.15 ExternalSupport.C
--- src/insets/ExternalSupport.C 14 Jan 2005 08:52:35 -0000 1.15
+++ src/insets/ExternalSupport.C 14 Jan 2005 15:25:40 -0000
@@ -273,7 +276,7 @@ void updateExternal(InsetExternalParams
support::ChangeExtension(to_file, string());
/* bool const success = */
converters.convert(&buffer, temp_file, to_file_base,
- from_format, to_format);
+ from_format, to_format, true);
// return success
}
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.270
diff -u -p -r1.270 insetgraphics.C
--- src/insets/insetgraphics.C 14 Jan 2005 08:52:35 -0000 1.270
+++ src/insets/insetgraphics.C 14 Jan 2005 15:25:47 -0000
@@ -97,7 +97,6 @@ using lyx::support::FileName;
using lyx::support::float_equal;
using lyx::support::GetExtension;
using lyx::support::IsFileReadable;
-using lyx::support::LibFileSearch;
using lyx::support::OnlyFilename;
using lyx::support::rtrim;
using lyx::support::strToDbl;
@@ -672,34 +670,11 @@ string const InsetGraphics::prepareFile(
<< "\tfile to convert = " << temp_file << '\n'
<< "\t from " << from << " to " << to << '\n';
- // if no special converter defined, then we take the default one
- // from ImageMagic: convert from:inname.from to:outname.to
- if (converters.convert(&buf, temp_file, temp_file, from, to)) {
+ if (converters.convert(&buf, temp_file, temp_file, from, to, true)) {
runparams.exportdata->addExternalFile("latex",
to_file, output_to_file);
runparams.exportdata->addExternalFile("dvi",
to_file, output_to_file);
- } else {
- string const command =
- "sh " + LibFileSearch("scripts", "convertDefault.sh") +
- ' ' + formats.extension(from) + ':' + temp_file +
- ' ' + ext + ':' + to_file;
- lyxerr[Debug::GRAPHICS]
- << "No converter defined! I use convertDefault.sh:\n\t"
- << command << endl;
- Systemcall one;
- one.startscript(Systemcall::Wait, command);
- if (IsFileReadable(to_file)) {
- runparams.exportdata->addExternalFile("latex",
- to_file, output_to_file);
- runparams.exportdata->addExternalFile("dvi",
- to_file, output_to_file);
- } else {
- string str = bformat(_("No information for converting %1$s "
- "format files to %2$s.\n"
- "Try defining a convertor in the preferences."), from, to);
- Alert::error(_("Could not convert image"), str);
- }
}
return stripExtension(output_file);