3 * See the file COPYING.
7 * Full author contact details are available in file CREDITS
13 #pragma implementation
18 #include "PrinterParams.h"
20 #include "frontends/LyXView.h"
21 #include "BufferView.h"
24 #include "converter.h"
26 #include "support/LAssert.h"
27 #include "support/lstrings.h"
28 #include "support/filetools.h"
29 #include "support/path.h"
30 #include "support/systemcall.h"
36 PrinterParams getPrinterParams(Buffer * buffer)
38 return PrinterParams(PrinterParams::PRINTER,
40 ChangeExtension(buffer->fileName(),
41 lyxrc.print_file_extension));
45 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
47 string command(lyxrc.print_command + ' ');
49 if (pp.target == PrinterParams::PRINTER
50 && lyxrc.print_adapt_output // dvips wants a printer name
51 && !pp.printer_name.empty()) {// printer name given
52 command += lyxrc.print_to_printer
57 switch (pp.which_pages) {
58 case PrinterParams::EVEN:
59 command += lyxrc.print_evenpage_flag + ' ';
62 case PrinterParams::ODD:
63 command += lyxrc.print_oddpage_flag + ' ';
67 // only option left is print all of them
71 if (!pp.from_page.empty()) {
72 command += lyxrc.print_pagerange_flag + ' ';
73 command += pp.from_page;
75 // we have a range "from-to"
77 command += tostr(pp.to_page);
82 if (pp.reverse_order) {
83 command += lyxrc.print_reverse_flag + ' ';
86 if (1 < pp.count_copies) {
87 if (pp.unsorted_copies) {
88 command += lyxrc.print_copies_flag;
90 command += lyxrc.print_collcopies_flag;
93 command += tostr(pp.count_copies);
97 if (!lyxrc.print_extra_options.empty()) {
98 command += lyxrc.print_extra_options + ' ';
101 command += converters.dvips_options(buffer) + ' ';
103 if (!Exporter::Export(buffer, "dvi", true))
106 // Push directory path.
107 string path = buffer->filePath();
108 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
109 path = buffer->tmppath;
113 // there are three cases here:
114 // 1. we print to a file
115 // 2. we print direct to a printer
116 // 3. we print using a spool command (print to file first)
119 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
121 case PrinterParams::PRINTER:
122 if (!lyxrc.print_spool_command.empty()) {
124 string psname = ChangeExtension(dviname, ".ps");
125 command += lyxrc.print_to_file
126 + QuoteName(psname) + ' ';
127 command += QuoteName(dviname);
128 string command2 = lyxrc.print_spool_command + ' ';
129 if (!pp.printer_name.empty())
130 command2 += lyxrc.print_spool_printerprefix
131 + pp.printer_name + ' ';
132 command2 += QuoteName(psname);
134 // If successful, then spool command
135 res = one.startscript(Systemcall::Wait, command);
137 res = one.startscript(Systemcall::DontWait,
141 res = one.startscript(Systemcall::DontWait,
142 command + QuoteName(dviname));
145 case PrinterParams::FILE:
147 command += lyxrc.print_to_file
148 + QuoteName(MakeAbsPath(pp.file_name, path));
149 command += ' ' + QuoteName(dviname);
150 res = one.startscript(Systemcall::DontWait, command);
157 void setMinibuffer(LyXView * lv, string const & msg)
163 } // namespace Liason