X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fconverter.C;h=1d5b67c19700e6184a836709c0ff96499763cabf;hb=b9963e1a57135c3e2ab128a9ec4300f0e4886992;hp=693ba8e444d765778a71451049da390386ed552d;hpb=46756fd9e4087fd30d9de504684d83803cd4b4c5;p=lyx.git diff --git a/src/converter.C b/src/converter.C index 693ba8e444..1d5b67c197 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; @@ -75,7 +77,7 @@ string const dvipdfm_options(BufferParams const & bp) { string result; - if (bp.papersize2 != VM_PAPER_CUSTOM) { + if (bp.papersize != PAPER_CUSTOM) { string const paper_size = bp.paperSizeName(); if (paper_size != "b5" && paper_size != "foolscap") result = "-p "+ paper_size; @@ -279,16 +281,44 @@ 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 = from_format.empty() ? + GetExtension(from_file) : + formats.extension(from_format); + string const command = + "sh " + + QuoteName(LibFileSearch("scripts", "convertDefault.sh")) + + ' ' + + QuoteName(from_ext + ':' + from_file) + + ' ' + + QuoteName(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; @@ -384,6 +414,9 @@ bool Converters::convert(Buffer const * buffer, << "renaming file " << outfile << " to " << real_outfile << endl; + // Finally, don't forget to tell any future + // converters to use the renamed file... + outfile = real_outfile; } if (!conv.parselog.empty()) { @@ -481,11 +514,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); }