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/lstrings.h"
25 #include "support/filetools.h"
26 #include "support/path.h"
28 #include "converter.h"
29 #include "support/syscall.h"
37 PrinterParams getPrinterParams(Buffer * buffer)
39 return PrinterParams(PrinterParams::PRINTER,
41 ChangeExtension(buffer->fileName(),
42 lyxrc.print_file_extension));
46 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
48 string command(lyxrc.print_command + ' ');
50 if (pp.target == PrinterParams::PRINTER
51 && lyxrc.print_adapt_output // dvips wants a printer name
52 && !pp.printer_name.empty()) {// printer name given
53 command += lyxrc.print_to_printer
58 switch (pp.which_pages) {
59 case PrinterParams::EVEN:
60 command += lyxrc.print_evenpage_flag + ' ';
63 case PrinterParams::ODD:
64 command += lyxrc.print_oddpage_flag + ' ';
68 // only option left is print all of them
72 if (!pp.from_page.empty()) {
73 command += lyxrc.print_pagerange_flag + ' ';
74 command += pp.from_page;
76 // we have a range "from-to"
78 command += tostr(pp.to_page);
83 if (pp.reverse_order) {
84 command += lyxrc.print_reverse_flag + ' ';
87 if (1 < pp.count_copies) {
88 if (pp.unsorted_copies) {
89 command += lyxrc.print_copies_flag;
91 command += lyxrc.print_collcopies_flag;
94 command += tostr(pp.count_copies);
98 if (!lyxrc.print_extra_options.empty()) {
99 command += lyxrc.print_extra_options + ' ';
102 command += converters.dvips_options(buffer) + ' ';
104 if (!Exporter::Export(buffer, "dvi", true))
107 // Push directory path.
108 string path = OnlyPath(buffer->fileName());
109 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
110 path = buffer->tmppath;
114 // there are three cases here:
115 // 1. we print to a file
116 // 2. we print direct to a printer
117 // 3. we print using a spool command (print to file first)
120 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
122 case PrinterParams::PRINTER:
123 if (!lyxrc.print_spool_command.empty()) {
125 string psname = ChangeExtension(dviname, ".ps");
126 command += lyxrc.print_to_file
127 + QuoteName(psname) + ' ';
128 command += QuoteName(dviname);
129 string command2 = lyxrc.print_spool_command + ' ';
130 if (!pp.printer_name.empty())
131 command2 += lyxrc.print_spool_printerprefix
132 + pp.printer_name + ' ';
133 command2 += QuoteName(psname);
135 // If successful, then spool command
136 res = one.startscript(Systemcalls::System, command);
138 res = one.startscript(Systemcalls::SystemDontWait,
142 res = one.startscript(Systemcalls::SystemDontWait,
143 command + QuoteName(dviname));
146 case PrinterParams::FILE:
148 command += lyxrc.print_to_file
149 + QuoteName(MakeAbsPath(pp.file_name, path));
150 command += ' ' + QuoteName(dviname);
151 res = one.startscript(Systemcalls::SystemDontWait, command);
158 void setMinibuffer(LyXView * lv, string const & msg)
164 } // namespace Liason