1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 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 "minibuffer.h"
30 #include "support/syscall.h"
36 #ifdef CXX_WORKING_NAMESPACES
41 PrinterParams getPrinterParams(Buffer * buffer)
43 return PrinterParams(PrinterParams::PRINTER,
45 ChangeExtension(buffer->fileName(),
46 lyxrc.print_file_extension));
50 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
52 string command(lyxrc.print_command + ' ');
54 if (pp.target == PrinterParams::PRINTER
55 && lyxrc.print_adapt_output // dvips wants a printer name
56 && !pp.printer_name.empty()) {// printer name given
57 command += lyxrc.print_to_printer
62 switch (pp.which_pages) {
63 case PrinterParams::EVEN:
64 command += lyxrc.print_evenpage_flag + ' ';
67 case PrinterParams::ODD:
68 command += lyxrc.print_oddpage_flag + ' ';
72 // only option left is print all of them
76 if (!pp.from_page.empty()) {
77 command += lyxrc.print_pagerange_flag + ' ';
78 command += pp.from_page;
80 // we have a range "from-to"
82 command += tostr(pp.to_page);
87 if (pp.reverse_order) {
88 command += lyxrc.print_reverse_flag + ' ';
91 if (1 < pp.count_copies) {
92 if (pp.unsorted_copies) {
93 command += lyxrc.print_copies_flag;
95 command += lyxrc.print_collcopies_flag;
98 command += tostr(pp.count_copies);
102 if (!lyxrc.print_extra_options.empty()) {
103 command += lyxrc.print_extra_options + ' ';
106 command += converters.dvips_options(buffer) + ' ';
108 if (!Exporter::Export(buffer, "dvi", true))
111 // Push directory path.
112 string path = OnlyPath(buffer->fileName());
113 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
114 path = buffer->tmppath;
118 // there are three cases here:
119 // 1. we print to a file
120 // 2. we print direct to a printer
121 // 3. we print using a spool command (print to file first)
124 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
126 case PrinterParams::PRINTER:
127 if (!lyxrc.print_spool_command.empty()) {
129 string psname = ChangeExtension(dviname, ".ps");
130 command += lyxrc.print_to_file
131 + QuoteName(psname) + ' ';
132 command += QuoteName(dviname);
133 string command2 = lyxrc.print_spool_command + ' ';
134 if (!pp.printer_name.empty())
135 command2 += lyxrc.print_spool_printerprefix
136 + pp.printer_name + ' ';
137 command2 += QuoteName(psname);
139 // If successful, then spool command
140 res = one.startscript(Systemcalls::System, command);
142 res = one.startscript(Systemcalls::SystemDontWait,
146 res = one.startscript(Systemcalls::SystemDontWait, command);
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(Systemcalls::SystemDontWait, command);
160 void setMinibuffer(LyXView * lv, char const * msg)
162 lv->getMiniBuffer()->Set(msg);
165 #ifdef CXX_WORKING_NAMESPACES