X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2FLiason.C;h=1c962dec523d303d6868d2ebc30581d2758c25b4;hb=ca3ee9394ad7c6cc0a345255b1147628ce9ca991;hp=b528bfe2b15e104ef6b3a46e88d2cf4b96446dcb;hpb=b7a16fc4025bef833d10aa075bd4a23b3ed37f03;p=lyx.git diff --git a/src/frontends/Liason.C b/src/frontends/Liason.C index b528bfe2b1..1c962dec52 100644 --- a/src/frontends/Liason.C +++ b/src/frontends/Liason.C @@ -1,12 +1,12 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. +/** + * \file Liason.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * ====================================================== */ + * \author Allan Rae + * + * Full author contact details are available in file CREDITS + */ #include @@ -15,26 +15,26 @@ #endif #include "Liason.h" -#include "LyXView.h" -#include "BufferView.h" -#include "buffer.h" #include "lyxrc.h" #include "PrinterParams.h" -#include "lyx_gui_misc.h" + +#include "frontends/LyXView.h" +#include "BufferView.h" +#include "buffer.h" +#include "exporter.h" +#include "converter.h" + +#include "support/LAssert.h" #include "support/lstrings.h" #include "support/filetools.h" #include "support/path.h" -#include "minibuffer.h" +#include "support/systemcall.h" -extern LyXRC lyxrc; -extern bool RunScript(Buffer * buffer, bool wait, string const & command, - string const & orgname = string(), bool need_shell=true); +#include "debug.h" // for lyxerr +using std::endl; -#ifdef CXX_WORKING_NAMESPACES -namespace Liason -{ -#endif +namespace Liason { PrinterParams getPrinterParams(Buffer * buffer) { @@ -45,11 +45,10 @@ PrinterParams getPrinterParams(Buffer * buffer) } -bool printBuffer(Buffer * buffer, PrinterParams const & pp) +bool printBuffer(Buffer * buffer, PrinterParams const & pp) { - bool result(false); string command(lyxrc.print_command + ' '); - + if (pp.target == PrinterParams::PRINTER && lyxrc.print_adapt_output // dvips wants a printer name && !pp.printer_name.empty()) {// printer name given @@ -58,115 +57,53 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) + ' '; } - switch (pp.which_pages) { - case PrinterParams::EVEN: - command += lyxrc.print_evenpage_flag + ' '; - break; - - case PrinterParams::ODD: - command += lyxrc.print_oddpage_flag + ' '; - break; - - default: - // only option left is print all of them - break; - } - - if (!pp.from_page.empty()) { + if (!pp.all_pages && pp.from_page) { command += lyxrc.print_pagerange_flag + ' '; - command += pp.from_page; + command += tostr(pp.from_page); if (pp.to_page) { - // we have a range "from-to" + // we have a range "from-to" command += '-'; command += tostr(pp.to_page); } command += ' '; } - if (pp.reverse_order) { - command += lyxrc.print_reverse_flag + ' '; - } - - BufferParams params(buffer->params); - if (params.orientation - == BufferParams::ORIENTATION_LANDSCAPE) { - command += lyxrc.print_landscape_flag + ' '; + // If both are, or both are not selected, then skip the odd/even printing + if (pp.odd_pages != pp.even_pages) { + if (pp.odd_pages) { + command += lyxrc.print_oddpage_flag + ' '; + } else if (pp.even_pages) { + command += lyxrc.print_evenpage_flag + ' '; + } } - if (1 < pp.count_copies) { - if (pp.unsorted_copies) { - command += lyxrc.print_copies_flag; - } else { + if (pp.count_copies > 1) { + if (pp.sorted_copies) { command += lyxrc.print_collcopies_flag; + } else { + command += lyxrc.print_copies_flag; } command += ' '; command += tostr(pp.count_copies); command += ' '; } + + if (pp.reverse_order) { + command += lyxrc.print_reverse_flag + ' '; + } if (!lyxrc.print_extra_options.empty()) { command += lyxrc.print_extra_options + ' '; } - char real_papersize = params.papersize; - if (real_papersize == BufferParams::PAPER_DEFAULT) { - real_papersize = lyxrc.default_papersize; - } + command += converters.dvips_options(buffer) + ' '; - if (params.use_geometry - && params.papersize2 == BufferParams::VM_PAPER_CUSTOM - && !lyxrc.print_paper_dimension_flag.empty() - && !params.paperwidth.empty() - && !params.paperheight.empty()) { - // using a custom papersize - command += lyxrc.print_paper_dimension_flag + ' '; - command += params.paperwidth + ','; - command += params.paperheight + ' '; - } else if (!lyxrc.print_paper_flag.empty() - && (real_papersize != BufferParams::PAPER_USLETTER - || params.orientation - == BufferParams::ORIENTATION_PORTRAIT)) { - // There's a problem with US Letter + landscape - string paper; - switch (real_papersize) { - case BufferParams::PAPER_USLETTER: - paper = "letter"; - break; - case BufferParams::PAPER_A3PAPER: - paper = "a3"; - break; - case BufferParams::PAPER_A4PAPER: - paper = "a4"; - break; - case BufferParams::PAPER_A5PAPER: - paper = "a5"; - break; - case BufferParams::PAPER_B5PAPER: - paper = "b5"; - break; - case BufferParams::PAPER_EXECUTIVEPAPER: - paper = "foolscap"; - break; - case BufferParams::PAPER_LEGALPAPER: - paper = "legal"; - break; - default: /* If nothing else fits, keep empty value */ - break; - } - if (!paper.empty()) { - command += lyxrc.print_paper_flag + ' '; - command += paper + ' '; - } - } + if (!Exporter::Export(buffer, "dvi", true)) + return false; - // Push directory path if necessary. - // PS file should go where the source file is unless it's a - // read-only directory in which case we write it to tmpdir. - // All temporary files go in tmpdir (like spool files). - string path = OnlyPath(buffer->fileName()); - if ((pp.target != PrinterParams::FILE - && lyxrc.use_tempdir) - || (IsDirWriteable(path) < 1)) { + // Push directory path. + string path = buffer->filePath(); + if (lyxrc.use_tempdir || !IsDirWriteable(path)) { path = buffer->tmppath; } Path p(path); @@ -175,47 +112,53 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) // 1. we print to a file // 2. we print direct to a printer // 3. we print using a spool command (print to file first) + Systemcall one; + int res = 0; + string dviname = ChangeExtension(buffer->getLatexName(true), "dvi"); switch (pp.target) { case PrinterParams::PRINTER: if (!lyxrc.print_spool_command.empty()) { - // case 3 + // case 3 + string psname = ChangeExtension(dviname, ".ps"); command += lyxrc.print_to_file - + QuoteName(pp.file_name); - string command2 = lyxrc.print_spool_command - + ' '; - if (!pp.printer_name.empty()) { + + QuoteName(psname) + ' '; + command += QuoteName(dviname); + string command2 = lyxrc.print_spool_command + ' '; + if (!pp.printer_name.empty()) command2 += lyxrc.print_spool_printerprefix - + pp.printer_name; - } - // First run dvips. - // If successful, then spool command - if (result = RunScript(buffer, true, command)) { - result = RunScript(buffer, false, - command2, - QuoteName(pp.file_name)); - } - } else { - // case 2 - result = RunScript(buffer, false, command); - } + + pp.printer_name + ' '; + command2 += QuoteName(psname); + // First run dvips. + // If successful, then spool command + res = one.startscript(Systemcall::Wait, command); + if (res == 0) + res = one.startscript(Systemcall::DontWait, + command2); + } else + // case 2 + res = one.startscript(Systemcall::DontWait, + command + QuoteName(dviname)); break; case PrinterParams::FILE: // case 1 command += lyxrc.print_to_file + QuoteName(MakeAbsPath(pp.file_name, path)); - result = RunScript(buffer, false, command); + command += ' ' + QuoteName(dviname); + res = one.startscript(Systemcall::DontWait, command); break; } - return result; -} -void setMinibuffer(LyXView * lv, char const * msg) -{ - lv->getMiniBuffer()->Set(msg); + lyxerr[Debug::LATEX] << "printBuffer: \"" << command << "\"\n"; + + return res == 0; } -#ifdef CXX_WORKING_NAMESPACES + +void setMinibuffer(LyXView * lv, string const & msg) +{ + lyx::Assert(lv); + lv->message(msg); } -#endif +} // namespace Liason