1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
19 #include "PrinterParams.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"
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 switch (pp.which_pages) {
61 case PrinterParams::EVEN:
62 command += lyxrc.print_evenpage_flag + ' ';
65 case PrinterParams::ODD:
66 command += lyxrc.print_oddpage_flag + ' ';
70 // only option left is print all of them
74 if (!pp.from_page.empty()) {
75 command += lyxrc.print_pagerange_flag + ' ';
76 command += pp.from_page;
78 // we have a range "from-to"
80 command += tostr(pp.to_page);
85 if (pp.reverse_order) {
86 command += lyxrc.print_reverse_flag + ' ';
89 if (1 < pp.count_copies) {
90 if (pp.unsorted_copies) {
91 command += lyxrc.print_copies_flag;
93 command += lyxrc.print_collcopies_flag;
96 command += tostr(pp.count_copies);
100 if (!lyxrc.print_extra_options.empty()) {
101 command += lyxrc.print_extra_options + ' ';
104 command += converters.dvips_options(buffer) + ' ';
106 if (!Exporter::Export(buffer, "dvi", true))
109 // Push directory path.
110 string path = buffer->filePath();
111 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
112 path = buffer->tmppath;
116 // there are three cases here:
117 // 1. we print to a file
118 // 2. we print direct to a printer
119 // 3. we print using a spool command (print to file first)
122 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
124 case PrinterParams::PRINTER:
125 if (!lyxrc.print_spool_command.empty()) {
127 string psname = ChangeExtension(dviname, ".ps");
128 command += lyxrc.print_to_file
129 + QuoteName(psname) + ' ';
130 command += QuoteName(dviname);
131 string command2 = lyxrc.print_spool_command + ' ';
132 if (!pp.printer_name.empty())
133 command2 += lyxrc.print_spool_printerprefix
134 + pp.printer_name + ' ';
135 command2 += QuoteName(psname);
137 // If successful, then spool command
138 res = one.startscript(Systemcall::Wait, command);
140 res = one.startscript(Systemcall::DontWait,
144 res = one.startscript(Systemcall::DontWait,
145 command + QuoteName(dviname));
148 case PrinterParams::FILE:
150 command += lyxrc.print_to_file
151 + QuoteName(MakeAbsPath(pp.file_name, path));
152 command += ' ' + QuoteName(dviname);
153 res = one.startscript(Systemcall::DontWait, command);
160 void setMinibuffer(LyXView * lv, string const & msg)
166 } // namespace Liason