]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrint.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / controllers / ControlPrint.C
1 /**
2  * \file ControlPrint.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlPrint.h"
14
15 #include "ButtonController.h"
16 #include "helper_funcs.h"
17
18 #include "buffer.h"
19 #include "bufferparams.h"
20 #include "funcrequest.h"
21 #include "gettext.h"
22 #include "PrinterParams.h"
23
24 #include "support/convert.h"
25 #include "support/filefilterlist.h"
26 #include "support/filetools.h"
27
28 using std::string;
29
30 namespace lyx {
31
32 using support::changeExtension;
33 using support::FileFilterList;
34
35 namespace frontend {
36
37
38 ControlPrint::ControlPrint(Dialog & parent)
39         : Dialog::Controller(parent),
40           params_(0)
41 {}
42
43
44 bool ControlPrint::initialiseParams(std::string const &)
45 {
46         /// get global printer parameters
47         string const name =  changeExtension(kernel().buffer().fileName(),
48                                         lyxrc.print_file_extension);
49         params_.reset(new PrinterParams(PrinterParams::PRINTER,
50                                         lyxrc.printer, name));
51
52         dialog().bc().valid(); // so that the user can press Ok
53         return true;
54 }
55
56
57 void ControlPrint::clearParams()
58 {
59         params_.reset();
60 }
61
62
63 PrinterParams & ControlPrint::params() const
64 {
65         BOOST_ASSERT(params_.get());
66         return *params_;
67 }
68
69
70 string const ControlPrint::browse(string const & in_name) const
71 {
72         // FIXME UNICODE
73         return browseRelFile(in_name, kernel().buffer().filePath(),
74                              lyx::to_utf8(_("Print to file")),
75                              FileFilterList(lyx::to_utf8(_("PostScript files (*.ps)"))),
76                              true);
77 }
78
79
80 /// print the current buffer
81 void ControlPrint::dispatchParams()
82 {
83         PrinterParams const pp = params();
84         string command(lyxrc.print_command + ' ');
85
86         if (pp.target == PrinterParams::PRINTER
87             && lyxrc.print_adapt_output  // dvips wants a printer name
88             && !pp.printer_name.empty()) {// printer name given
89                 command += lyxrc.print_to_printer
90                         + pp.printer_name
91                         + ' ';
92         }
93
94         if (!pp.all_pages && pp.from_page) {
95                 command += lyxrc.print_pagerange_flag + ' ';
96                 command += convert<string>(pp.from_page);
97                 if (pp.to_page) {
98                         // we have a range "from-to"
99                         command += '-'
100                                 + convert<string>(pp.to_page);
101                 }
102                 command += ' ';
103         }
104
105         // If both are, or both are not selected, then skip the odd/even printing
106         if (pp.odd_pages != pp.even_pages) {
107                 if (pp.odd_pages) {
108                         command += lyxrc.print_oddpage_flag + ' ';
109                 } else if (pp.even_pages) {
110                         command += lyxrc.print_evenpage_flag + ' ';
111                 }
112         }
113
114         if (pp.count_copies > 1) {
115                 if (pp.sorted_copies) {
116                         command += lyxrc.print_collcopies_flag;
117                 } else {
118                         command += lyxrc.print_copies_flag;
119                 }
120                 command += ' '
121                         + convert<string>(pp.count_copies)
122                         + ' ';
123         }
124
125         if (pp.reverse_order) {
126                 command += lyxrc.print_reverse_flag + ' ';
127         }
128
129         if (!lyxrc.print_extra_options.empty()) {
130                 command += lyxrc.print_extra_options + ' ';
131         }
132
133         command += kernel().buffer().params().dvips_options() + ' ';
134
135         string const target = (pp.target == PrinterParams::PRINTER) ?
136                 "printer" : "file";
137
138         string const target_name = (pp.target == PrinterParams::PRINTER) ?
139                 (pp.printer_name.empty() ? "default" : pp.printer_name) :
140                 pp.file_name;
141
142         string const data = target + " " + target_name + " " + command;
143         kernel().dispatch(FuncRequest(getLfun(), data));
144 }
145
146 } // namespace frontend
147 } // namespace lyx