]> git.lyx.org Git - lyx.git/blobdiff - src/converter.C
Remove unused font variable which caused a warning.
[lyx.git] / src / converter.C
index 01fe135b0b2e84756fdffd9c85741d142ca19adb..aa3fbe8d6b06fff52655c32ac1a1638e456591d2 100644 (file)
@@ -4,7 +4,7 @@
  *           LyX, The Document Processor
  *        
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2000 The LyX Team.
+ *           Copyright 1995-2001 The LyX Team.
  *
  * ====================================================== */
 
 #include "bufferview_funcs.h"
 #include "LaTeX.h"
 #include "LyXView.h"
-#include "minibuffer.h"
 #include "lyx_gui_misc.h"
 #include "lyx_cb.h" // ShowMessage()
 #include "support/lyxfunctional.h"
+#include "gettext.h"
+#include "BufferView.h"
 
 using std::vector;
 using std::queue;
@@ -38,13 +39,15 @@ using std::find_if;
 using std::reverse;
 using std::sort;
 
-static string const token_from("$$i");
-static string const token_base("$$b");
-static string const token_to("$$o");
+namespace {
+
+string const token_from("$$i");
+string const token_base("$$b");
+string const token_to("$$o");
 
 //////////////////////////////////////////////////////////////////////////////
 
-static inline
+inline
 string const add_options(string const & command, string const & options)
 {
        string head;
@@ -52,6 +55,8 @@ string const add_options(string const & command, string const & options)
        return head + ' ' + options + ' ' + tail;
 }
 
+} // namespace anon
+
 //////////////////////////////////////////////////////////////////////////////
 
 bool Format::dummy() const
@@ -81,7 +86,7 @@ Format const * Formats::GetFormat(string const & name) const
 {
        FormatList::const_iterator cit =
                find_if(formatlist.begin(), formatlist.end(),
-                       compare_memfun(&Format::name, name));
+                       lyx::compare_memfun(&Format::name, name));
        if (cit != formatlist.end())
                return &(*cit);
        else
@@ -93,7 +98,7 @@ int Formats::GetNumber(string const & name) const
 {
        FormatList::const_iterator cit =
                find_if(formatlist.begin(), formatlist.end(),
-                       compare_memfun(&Format::name, name));
+                       lyx::compare_memfun(&Format::name, name));
        if (cit != formatlist.end())
                return cit - formatlist.begin();
        else
@@ -113,7 +118,7 @@ void Formats::Add(string const & name, string const & extension,
 {
        FormatList::iterator it = 
                find_if(formatlist.begin(), formatlist.end(),
-                       compare_memfun(&Format::name, name));
+                       lyx::compare_memfun(&Format::name, name));
        if (it == formatlist.end())
                formatlist.push_back(Format(name, extension, prettyname,
                                            shortcut, ""));
@@ -128,7 +133,7 @@ void Formats::Delete(string const & name)
 {
        FormatList::iterator it = 
                find_if(formatlist.begin(), formatlist.end(),
-                       compare_memfun(&Format::name, name));
+                       lyx::compare_memfun(&Format::name, name));
        if (it != formatlist.end())
                formatlist.erase(it);
 }
@@ -145,7 +150,7 @@ void Formats::SetViewer(string const & name, string const & command)
        Add(name);
        FormatList::iterator it =
                find_if(formatlist.begin(), formatlist.end(),
-                       compare_memfun(&Format::name, name));
+                       lyx::compare_memfun(&Format::name, name));
        if (it != formatlist.end())
                it->setViewer(command);
 }
@@ -173,7 +178,10 @@ bool Formats::View(Buffer const * buffer, string const & filename,
        if (format_name == "dvi" &&
            !lyxrc.view_dvi_paper_option.empty()) {
                command += " " + lyxrc.view_dvi_paper_option;
-               command += " " + converters.dvi_papersize(buffer);
+               string paper_size = converters.papersize(buffer);
+               if (paper_size == "letter")
+                       paper_size = "us";
+               command += " " + paper_size;
                if (buffer->params.orientation 
                    == BufferParams::ORIENTATION_LANDSCAPE)
                        command += 'r';
@@ -181,7 +189,7 @@ bool Formats::View(Buffer const * buffer, string const & filename,
 
        command += " " + QuoteName(OnlyFilename((filename)));
 
-       lyxerr << "Executing command: " << command << endl;
+       lyxerr[Debug::FILES] << "Executing command: " << command << endl;
        ShowMessage(buffer, _("Executing command:"), command);
 
        Path p(OnlyPath(filename));
@@ -566,7 +574,7 @@ bool Converters::Convert(Buffer const * buffer,
                Converter const & conv = converterlist[*cit];
                bool dummy = conv.To->dummy() && conv.to != "program";
                if (!dummy)
-                       lyxerr << "Converting from  "
+                       lyxerr[Debug::FILES] << "Converting from  "
                               << conv.from << " to " << conv.to << endl;
                infile = outfile;
                outfile = conv.result_dir.empty()
@@ -579,14 +587,15 @@ bool Converters::Convert(Buffer const * buffer,
                if (conv.latex) {
                        run_latex = true;
                        string command = subst(conv.command, token_from, "");
-                       lyxerr << "Running " << command << endl;
+                       lyxerr[Debug::FILES] << "Running " << command << endl;
                        if (!runLaTeX(buffer, command))
                                return false;
                } else {
                        if (conv.need_aux && !run_latex
                            && !latex_command.empty()) {
-                               lyxerr << "Running " << latex_command 
-                                      << " to update aux file"<<  endl;
+                               lyxerr[Debug::FILES] 
+                                       << "Running " << latex_command 
+                                       << " to update aux file"<<  endl;
                                runLaTeX(buffer, latex_command);
                        }
 
@@ -606,8 +615,11 @@ bool Converters::Convert(Buffer const * buffer,
                        if (conv.from == "dvi" && conv.to == "ps")
                                command = add_options(command,
                                                      dvips_options(buffer));
+                       else if (conv.from == "dvi" && prefixIs(conv.to, "pdf"))
+                               command = add_options(command,
+                                                     dvipdfm_options(buffer));
 
-                       lyxerr << "Calling " << command << endl;
+                       lyxerr[Debug::FILES] << "Calling " << command << endl;
                        if (buffer)
                                ShowMessage(buffer, _("Executing command:"), command);
 
@@ -687,9 +699,10 @@ bool Converters::Move(string const & from, string const & to, bool copy)
             it != files.end(); ++it)
                if (prefixIs(*it, base)) {
                        string from2 = path + *it;
-                       string to2 = to_base + (*it).substr(base.length());
+                       string to2 = to_base + it->substr(base.length());
                        to2 = ChangeExtension(to2, to_extension);
-                       lyxerr << "moving " << from2 << " to " << to2 << endl;
+                       lyxerr[Debug::FILES] << "moving " << from2 
+                                            << " to " << to2 << endl;
                        bool moved = (copy)
                                ? lyx::copy(from2, to2)
                                : lyx::rename(from2, to2);
@@ -748,7 +761,7 @@ bool Converters::scanLog(Buffer const * buffer, string const & command,
        BufferView * bv = buffer->getUser();
        bool need_redraw = false;
        if (bv) {
-               ProhibitInput(bv);
+               bv->owner()->prohibitInput();
                // Remove all error insets
                need_redraw = bv->removeAutoInsets();
        }
@@ -766,7 +779,7 @@ bool Converters::scanLog(Buffer const * buffer, string const & command,
                        bv->redraw();
                        bv->fitCursor(bv->text);
                }
-               AllowInput(bv);
+               bv->owner()->allowInput();
        }
 
        if ((result & LaTeX::ERRORS)) {
@@ -806,8 +819,8 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command)
        bool need_redraw = false;
 
        if (bv) {
-               ProhibitInput(bv);
-               bv->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
+               bv->owner()->prohibitInput();
+               bv->owner()->message(_("Running LaTeX..."));
                // Remove all error insets
                need_redraw = bv->removeAutoInsets();
        }
@@ -817,7 +830,7 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command)
        TeXErrors terr;
        LaTeX latex(command, name, buffer->filepath);
        int result = latex.run(terr,
-                              bv ? bv->owner()->getMiniBuffer() : 0);
+                              bv ? bv->owner()->getLyXFunc() : 0);
        
 
        if (bv) {
@@ -860,7 +873,7 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command)
        }
 
        if (bv)
-               AllowInput(bv);
+               bv->owner()->allowInput();
  
        int const ERROR_MASK = 
                        LaTeX::NO_LOGFILE |
@@ -872,7 +885,7 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command)
 }
 
 
-string const Converters::dvi_papersize(Buffer const * buffer)
+string const Converters::papersize(Buffer const * buffer)
 {
        char real_papersize = buffer->params.papersize;
        if (real_papersize == BufferParams::PAPER_DEFAULT)
@@ -893,7 +906,7 @@ string const Converters::dvi_papersize(Buffer const * buffer)
                return "legal";
        case BufferParams::PAPER_USLETTER:
        default:
-               return "us";
+               return "letter";
        }
 }
 
@@ -914,9 +927,7 @@ string const Converters::dvips_options(Buffer const * buffer)
                result += ' ' + buffer->params.paperwidth;
                result += ',' + buffer->params.paperheight;
        } else {
-               string paper_option = dvi_papersize(buffer);
-               if (paper_option == "us")
-                       paper_option = "letter";
+               string paper_option = papersize(buffer);
                if (paper_option != "letter" ||
                    buffer->params.orientation != BufferParams::ORIENTATION_LANDSCAPE) {
                        // dvips won't accept -t letter -t landscape.  In all other
@@ -925,11 +936,32 @@ string const Converters::dvips_options(Buffer const * buffer)
                        result += ' ' + paper_option;
                }
        }
-       if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
+       if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE &&
+           buffer->params.papersize2 != BufferParams::VM_PAPER_CUSTOM)
                result += ' ' + lyxrc.print_landscape_flag;
        return result;
 }
 
+
+string const Converters::dvipdfm_options(Buffer const * buffer)
+{
+       string result;
+       if (!buffer)
+               return result;
+
+       if (buffer->params.papersize2 != BufferParams::VM_PAPER_CUSTOM) {
+               string paper_size = papersize(buffer);
+               if (paper_size != "b5" && paper_size != "foolscap")
+                       result = "-p "+ paper_size;
+
+               if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
+                       result += " -l";
+       }
+
+       return result;
+}
+
+
 vector<Converters::Vertex> Converters::vertices;