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"
26 #include "lyx_gui_misc.h"
28 #include "support/LAssert.h"
29 #include "support/lstrings.h"
30 #include "support/filetools.h"
31 #include "support/path.h"
32 #include "support/systemcall.h"
40 PrinterParams getPrinterParams(Buffer * buffer)
42 return PrinterParams(PrinterParams::PRINTER,
44 ChangeExtension(buffer->fileName(),
45 lyxrc.print_file_extension));
49 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
51 string command(lyxrc.print_command + ' ');
53 if (pp.target == PrinterParams::PRINTER
54 && lyxrc.print_adapt_output // dvips wants a printer name
55 && !pp.printer_name.empty()) {// printer name given
56 command += lyxrc.print_to_printer
61 switch (pp.which_pages) {
62 case PrinterParams::EVEN:
63 command += lyxrc.print_evenpage_flag + ' ';
66 case PrinterParams::ODD:
67 command += lyxrc.print_oddpage_flag + ' ';
71 // only option left is print all of them
75 if (!pp.from_page.empty()) {
76 command += lyxrc.print_pagerange_flag + ' ';
77 command += pp.from_page;
79 // we have a range "from-to"
81 command += tostr(pp.to_page);
86 if (pp.reverse_order) {
87 command += lyxrc.print_reverse_flag + ' ';
90 if (1 < pp.count_copies) {
91 if (pp.unsorted_copies) {
92 command += lyxrc.print_copies_flag;
94 command += lyxrc.print_collcopies_flag;
97 command += tostr(pp.count_copies);
101 if (!lyxrc.print_extra_options.empty()) {
102 command += lyxrc.print_extra_options + ' ';
105 command += converters.dvips_options(buffer) + ' ';
107 if (!Exporter::Export(buffer, "dvi", true))
110 // Push directory path.
111 string path = buffer->filePath();
112 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
113 path = buffer->tmppath;
117 // there are three cases here:
118 // 1. we print to a file
119 // 2. we print direct to a printer
120 // 3. we print using a spool command (print to file first)
123 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
125 case PrinterParams::PRINTER:
126 if (!lyxrc.print_spool_command.empty()) {
128 string psname = ChangeExtension(dviname, ".ps");
129 command += lyxrc.print_to_file
130 + QuoteName(psname) + ' ';
131 command += QuoteName(dviname);
132 string command2 = lyxrc.print_spool_command + ' ';
133 if (!pp.printer_name.empty())
134 command2 += lyxrc.print_spool_printerprefix
135 + pp.printer_name + ' ';
136 command2 += QuoteName(psname);
138 // If successful, then spool command
139 res = one.startscript(Systemcall::Wait, command);
141 res = one.startscript(Systemcall::DontWait,
145 res = one.startscript(Systemcall::DontWait,
146 command + QuoteName(dviname));
149 case PrinterParams::FILE:
151 command += lyxrc.print_to_file
152 + QuoteName(MakeAbsPath(pp.file_name, path));
153 command += ' ' + QuoteName(dviname);
154 res = one.startscript(Systemcall::DontWait, command);
161 void setMinibuffer(LyXView * lv, string const & msg)
167 } // namespace Liason