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 "BufferView.h"
22 #include "PrinterParams.h"
23 #include "lyx_gui_misc.h"
24 #include "support/LAssert.h"
25 #include "support/lstrings.h"
26 #include "support/filetools.h"
27 #include "support/path.h"
29 #include "converter.h"
30 #include "support/syscall.h"
38 PrinterParams getPrinterParams(Buffer * buffer)
40 return PrinterParams(PrinterParams::PRINTER,
42 ChangeExtension(buffer->fileName(),
43 lyxrc.print_file_extension));
47 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
49 string command(lyxrc.print_command + ' ');
51 if (pp.target == PrinterParams::PRINTER
52 && lyxrc.print_adapt_output // dvips wants a printer name
53 && !pp.printer_name.empty()) {// printer name given
54 command += lyxrc.print_to_printer
59 switch (pp.which_pages) {
60 case PrinterParams::EVEN:
61 command += lyxrc.print_evenpage_flag + ' ';
64 case PrinterParams::ODD:
65 command += lyxrc.print_oddpage_flag + ' ';
69 // only option left is print all of them
73 if (!pp.from_page.empty()) {
74 command += lyxrc.print_pagerange_flag + ' ';
75 command += pp.from_page;
77 // we have a range "from-to"
79 command += tostr(pp.to_page);
84 if (pp.reverse_order) {
85 command += lyxrc.print_reverse_flag + ' ';
88 if (1 < pp.count_copies) {
89 if (pp.unsorted_copies) {
90 command += lyxrc.print_copies_flag;
92 command += lyxrc.print_collcopies_flag;
95 command += tostr(pp.count_copies);
99 if (!lyxrc.print_extra_options.empty()) {
100 command += lyxrc.print_extra_options + ' ';
103 command += converters.dvips_options(buffer) + ' ';
105 if (!Exporter::Export(buffer, "dvi", true))
108 // Push directory path.
109 string path = OnlyPath(buffer->fileName());
110 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
111 path = buffer->tmppath;
115 // there are three cases here:
116 // 1. we print to a file
117 // 2. we print direct to a printer
118 // 3. we print using a spool command (print to file first)
121 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
123 case PrinterParams::PRINTER:
124 if (!lyxrc.print_spool_command.empty()) {
126 string psname = ChangeExtension(dviname, ".ps");
127 command += lyxrc.print_to_file
128 + QuoteName(psname) + ' ';
129 command += QuoteName(dviname);
130 string command2 = lyxrc.print_spool_command + ' ';
131 if (!pp.printer_name.empty())
132 command2 += lyxrc.print_spool_printerprefix
133 + pp.printer_name + ' ';
134 command2 += QuoteName(psname);
136 // If successful, then spool command
137 res = one.startscript(Systemcalls::System, command);
139 res = one.startscript(Systemcalls::SystemDontWait,
143 res = one.startscript(Systemcalls::SystemDontWait,
144 command + QuoteName(dviname));
147 case PrinterParams::FILE:
149 command += lyxrc.print_to_file
150 + QuoteName(MakeAbsPath(pp.file_name, path));
151 command += ' ' + QuoteName(dviname);
152 res = one.startscript(Systemcalls::SystemDontWait, command);
159 void setMinibuffer(LyXView * lv, string const & msg)
165 } // namespace Liason