5 #include "BufferView.h"
8 #include "PrinterParams.h"
9 #include "lyx_gui_misc.h"
10 #include "support/lstrings.h"
11 #include "support/filetools.h"
12 #include "support/path.h"
15 extern bool RunScript(Buffer * buffer, bool wait, string const & command,
16 string const & orgname = string(), bool need_shell=true);
19 #ifdef CXX_WORKING_NAMESPACES
24 PrinterParams getPrinterParams(Buffer * buffer)
26 return PrinterParams(PrinterParams::PRINTER,
28 ChangeExtension(buffer->fileName(),
29 lyxrc.print_file_extension));
33 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
36 string command(lyxrc.print_command + ' ');
38 if (pp.target == PrinterParams::PRINTER
39 && lyxrc.print_adapt_output // dvips wants a printer name
40 && !pp.printer_name.empty()) {// printer name given
41 command += lyxrc.print_to_printer
46 switch (pp.which_pages) {
47 case PrinterParams::EVEN:
48 command += lyxrc.print_evenpage_flag + ' ';
51 case PrinterParams::ODD:
52 command += lyxrc.print_oddpage_flag + ' ';
56 // only option left is print all of them
60 if (!pp.from_page.empty()) {
61 command += lyxrc.print_pagerange_flag + ' ';
62 command += pp.from_page;
64 // we have a range "from-to"
66 command += tostr(pp.to_page);
71 if (pp.reverse_order) {
72 command += lyxrc.print_reverse_flag + ' ';
75 BufferParams params(buffer->params);
76 if (params.orientation
77 == BufferParams::ORIENTATION_LANDSCAPE) {
78 command += lyxrc.print_landscape_flag + ' ';
81 if (1 < pp.count_copies) {
82 if (pp.unsorted_copies) {
83 command += lyxrc.print_copies_flag;
85 command += lyxrc.print_collcopies_flag;
88 command += tostr(pp.count_copies);
92 if (!lyxrc.print_extra_options.empty()) {
93 command += lyxrc.print_extra_options + ' ';
96 char real_papersize = params.papersize;
97 if (real_papersize == BufferParams::PAPER_DEFAULT) {
98 real_papersize = lyxrc.default_papersize;
101 if (params.use_geometry
102 && params.papersize2 == BufferParams::VM_PAPER_CUSTOM
103 && !lyxrc.print_paper_dimension_flag.empty()
104 && !params.paperwidth.empty()
105 && !params.paperheight.empty()) {
106 // using a custom papersize
107 command += lyxrc.print_paper_dimension_flag + ' ';
108 command += params.paperwidth + ',';
109 command += params.paperheight + ' ';
110 } else if (!lyxrc.print_paper_flag.empty()
111 && (real_papersize != BufferParams::PAPER_USLETTER
112 || params.orientation
113 == BufferParams::ORIENTATION_PORTRAIT)) {
114 // There's a problem with US Letter + landscape
116 switch (real_papersize) {
117 case BufferParams::PAPER_USLETTER:
120 case BufferParams::PAPER_A3PAPER:
123 case BufferParams::PAPER_A4PAPER:
126 case BufferParams::PAPER_A5PAPER:
129 case BufferParams::PAPER_B5PAPER:
132 case BufferParams::PAPER_EXECUTIVEPAPER:
135 case BufferParams::PAPER_LEGALPAPER:
138 default: /* If nothing else fits, keep empty value */
141 if (!paper.empty()) {
142 command += lyxrc.print_paper_flag + ' ';
143 command += paper + ' ';
147 // Push directory path if necessary.
148 // PS file should go where the source file is unless it's a
149 // read-only directory in which case we write it to tmpdir.
150 // All temporary files go in tmpdir (like spool files).
151 string path = OnlyPath(buffer->fileName());
152 if ((pp.target != PrinterParams::FILE
153 && lyxrc.use_tempdir)
154 || (IsDirWriteable(path) < 1)) {
155 path = buffer->tmppath;
159 // there are three cases here:
160 // 1. we print to a file
161 // 2. we print direct to a printer
162 // 3. we print using a spool command (print to file first)
164 case PrinterParams::PRINTER:
165 if (!lyxrc.print_spool_command.empty()) {
167 command += lyxrc.print_to_file
168 + QuoteName(pp.file_name);
169 string command2 = lyxrc.print_spool_command
171 if (!pp.printer_name.empty()) {
172 command2 += lyxrc.print_spool_printerprefix
176 // If successful, then spool command
177 if (result = RunScript(buffer, true, command)) {
178 result = RunScript(buffer, false,
180 QuoteName(pp.file_name));
184 result = RunScript(buffer, false, command);
188 case PrinterParams::FILE:
190 command += lyxrc.print_to_file
191 + QuoteName(MakeAbsPath(pp.file_name, path));
192 result = RunScript(buffer, false, command);
198 #ifdef CXX_WORKING_NAMESPACES