From 55ded55ccfede99816c92de009d82c245ab69514 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 14 Jan 2005 19:13:17 +0000 Subject: [PATCH] use the default converter for insetexternal, too git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9479 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++++ src/converter.C | 36 +++++++++++++++++++++++++++++++----- src/converter.h | 5 +++-- src/insets/ChangeLog | 11 +++++++++-- src/insets/ExternalSupport.C | 2 +- src/insets/insetgraphics.C | 26 +------------------------- 6 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d4a60b771b..d5b171f48b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2005-01-14 Georg Baum + + * converter.[Ch] (convert): take a new parameter try_default. Use + a default converter (imagemagick) if try_default is true. + 2005-01-13 Angus Leeming * lyxrc.C (read): use LyXRC::cygwin_path_fix to set the value of diff --git a/src/converter.C b/src/converter.C index 693ba8e444..1784d915cd 100644 --- a/src/converter.C +++ b/src/converter.C @@ -36,6 +36,8 @@ using lyx::support::compare_ascii_no_case; 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 +281,39 @@ OutputParams::FLAVOR Converters::getFlavor(Graph::EdgePath const & path) 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 +506,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); } diff --git a/src/converter.h b/src/converter.h index bfdb26f788..f5f66ed810 100644 --- a/src/converter.h +++ b/src/converter.h @@ -107,11 +107,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); /// diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index c44d432e24..3bc294dd05 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,9 +1,16 @@ +2005-01-14 Georg Baum + + * 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 * 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 diff --git a/src/insets/ExternalSupport.C b/src/insets/ExternalSupport.C index a1068f9d11..5caa740762 100644 --- a/src/insets/ExternalSupport.C +++ b/src/insets/ExternalSupport.C @@ -273,7 +273,7 @@ void updateExternal(InsetExternalParams const & params, 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 } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 9450a7b2f7..0ef5fcc870 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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 +671,11 @@ string const InsetGraphics::prepareFile(Buffer const & buf, << "\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); -- 2.39.2