3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
19 #include "PrinterParams.h"
21 #include "frontends/LyXView.h"
22 #include "BufferView.h"
25 #include "converter.h"
27 #include "support/LAssert.h"
28 #include "support/lstrings.h"
29 #include "support/filetools.h"
30 #include "support/path.h"
31 #include "support/systemcall.h"
33 #include "debug.h" // for lyxerr
39 PrinterParams getPrinterParams(Buffer * buffer)
41 return PrinterParams(PrinterParams::PRINTER,
43 ChangeExtension(buffer->fileName(),
44 lyxrc.print_file_extension));
48 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
50 string command(lyxrc.print_command + ' ');
52 if (pp.target == PrinterParams::PRINTER
53 && lyxrc.print_adapt_output // dvips wants a printer name
54 && !pp.printer_name.empty()) {// printer name given
55 command += lyxrc.print_to_printer
60 if (!pp.all_pages && pp.from_page) {
61 command += lyxrc.print_pagerange_flag + ' ';
62 command += tostr(pp.from_page);
64 // we have a range "from-to"
66 command += tostr(pp.to_page);
71 // If both are, or both are not selected, then skip the odd/even printing
72 if (pp.odd_pages != pp.even_pages) {
74 command += lyxrc.print_oddpage_flag + ' ';
75 } else if (pp.even_pages) {
76 command += lyxrc.print_evenpage_flag + ' ';
80 if (pp.count_copies > 1) {
81 if (pp.sorted_copies) {
82 command += lyxrc.print_collcopies_flag;
84 command += lyxrc.print_copies_flag;
87 command += tostr(pp.count_copies);
91 if (pp.reverse_order) {
92 command += lyxrc.print_reverse_flag + ' ';
95 if (!lyxrc.print_extra_options.empty()) {
96 command += lyxrc.print_extra_options + ' ';
99 command += converters.dvips_options(buffer) + ' ';
101 if (!Exporter::Export(buffer, "dvi", true))
104 // Push directory path.
105 string path = buffer->filePath();
106 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
107 path = buffer->tmppath;
111 // there are three cases here:
112 // 1. we print to a file
113 // 2. we print direct to a printer
114 // 3. we print using a spool command (print to file first)
117 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
119 case PrinterParams::PRINTER:
120 if (!lyxrc.print_spool_command.empty()) {
122 string psname = ChangeExtension(dviname, ".ps");
123 command += lyxrc.print_to_file
124 + QuoteName(psname) + ' ';
125 command += QuoteName(dviname);
126 string command2 = lyxrc.print_spool_command + ' ';
127 if (!pp.printer_name.empty())
128 command2 += lyxrc.print_spool_printerprefix
129 + pp.printer_name + ' ';
130 command2 += QuoteName(psname);
132 // If successful, then spool command
133 res = one.startscript(Systemcall::Wait, command);
135 res = one.startscript(Systemcall::DontWait,
139 res = one.startscript(Systemcall::DontWait,
140 command + QuoteName(dviname));
143 case PrinterParams::FILE:
145 command += lyxrc.print_to_file
146 + QuoteName(MakeAbsPath(pp.file_name, path));
147 command += ' ' + QuoteName(dviname);
148 res = one.startscript(Systemcall::DontWait, command);
152 lyxerr[Debug::LATEX] << "printBuffer: \"" << command << "\"\n";
157 } // namespace Liason