2 /******************************************************************************
4 * DESCRIPTION: routines for the editor
5 * COPYRIGHT : (C) 1999 Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
12 #include "edit_main.hpp"
13 #include "tm_buffer.hpp"
15 #include "sys_utils.hpp"
16 #include "printer.hpp"
17 #include "convert.hpp"
18 #include "connect.hpp"
19 #include "typesetter.hpp"
20 #include "drd_std.hpp"
21 #include "message.hpp"
24 #include "../../Style/Memorizer/clean_copy.hpp"
28 #include "Ghostscript/gs_utilities.hpp"
31 /******************************************************************************
32 * Constructors and destructor
33 ******************************************************************************/
35 editor_rep::editor_rep ():
37 drd (buf
->abbr
, std_drd
), et (the_et
), rp (buf
->rp
) {}
39 editor_rep::editor_rep (server_rep
* sv2
, tm_buffer buf2
):
41 sv (sv2
), buf (buf2
), drd (buf
->abbr
, std_drd
),
42 et (the_et
), rp (buf2
->rp
) {}
44 edit_main_rep::edit_main_rep (server_rep
* sv
, tm_buffer buf
):
45 editor_rep (sv
, buf
), props (UNKNOWN
), ed_obs (edit_observer (this))
48 cct
= copy (subtree (et
, rp
));
49 copy_ip (subtree (et
, rp
), cct
);
51 attach_observer (subtree (et
, rp
), ed_obs
);
52 notify_change (THE_TREE
);
53 tp
= correct_cursor (et
, rp
* 0);
56 edit_main_rep::~edit_main_rep () {
57 detach_observer (subtree (et
, rp
), ed_obs
);
64 new_editor (server_rep
* sv
, tm_buffer buf
) {
65 return tm_new
<edit_main_rep
> (sv
, buf
);
68 /******************************************************************************
70 ******************************************************************************/
73 edit_main_rep::set_property (scheme_tree what
, scheme_tree val
) {
78 edit_main_rep::set_bool_property (string what
, bool val
) {
79 props (what
)= (val
? string ("true"): string ("false"));
83 edit_main_rep::set_int_property (string what
, int val
) {
84 props (what
)= as_tree (val
);
88 edit_main_rep::set_string_property (string what
, string val
) {
93 edit_main_rep::get_property (scheme_tree what
) {
98 edit_main_rep::get_bool_property (string what
) {
99 return as_bool (props
[what
]);
103 edit_main_rep::get_int_property (string what
) {
104 return as_int (props
[what
]);
108 edit_main_rep::get_string_property (string what
) {
109 return as_string (props
[what
]);
112 /******************************************************************************
114 ******************************************************************************/
117 edit_main_rep::clear_buffer () {
118 assign (rp
, tree (DOCUMENT
, tree ("")));
122 edit_main_rep::new_window () {
126 edit_main_rep::clone_window () {
130 edit_main_rep::tex_buffer () {
134 edit_main_rep::get_name () {
139 edit_main_rep::focus_on_this_editor () {
140 sv
->focus_on_editor (this);
144 edit_main_rep::notify_page_change () {
145 if (is_attached (this)) send_invalidate_all (this);
148 /******************************************************************************
150 ******************************************************************************/
152 string
printing_dpi ("600");
153 string
printing_cmd ("lpr");
154 string
printing_on ("a4");
157 edit_main_rep::print (url name
, bool conform
, int first
, int last
) {
158 bool pdf
= (suffix (name
) == "pdf");
159 url orig
= resolve (name
, "");
161 if (pdf
) name
= url_temp (".ps");
164 string medium
= env
->get_string (PAGE_MEDIUM
);
165 if (conform
&& (medium
!= "paper")) conform
= false;
166 // FIXME: better command for conform printing
168 // Set environment variables for printing
171 env
->write (DPI
, printing_dpi
);
172 env
->write (PAGE_SHOW_HF
, "true");
173 env
->write (PAGE_SCREEN_MARGIN
, "false");
175 env
->write (PAGE_MEDIUM
, "paper");
176 env
->write (PAGE_PRINTED
, "true");
179 // Typeset pages for printing
181 box the_box
= typeset_as_document (env
, subtree (et
, rp
), reverse (rp
));
183 // Determine parameters for printer
185 string page_type
= env
->get_string (PAGE_TYPE
);
186 double w
= env
->page_width
;
187 double h
= env
->page_height
;
188 double cm
= env
->as_length (string ("1cm"));
189 bool landsc
= env
->page_landscape
;
190 int dpi
= as_int (printing_dpi
);
191 int start
= max (0, first
-1);
192 int end
= min (N(the_box
[0]), last
);
193 int pages
= end
-start
;
196 SI bw
= the_box
[0][0]->w();
197 SI bh
= the_box
[0][0]->h();
198 string bws
= as_string (bw
) * "tmpt";
199 string bhs
= as_string (bh
) * "tmpt";
200 w
= env
->as_length (bws
);
201 h
= env
->as_length (bhs
);
208 printer (name
, dpi
, pages
, page_type
, landsc
, w
/cm
, h
/cm
);
209 for (i
=start
; i
<end
; i
++) {
210 tree bg
= env
->read (BG_COLOR
);
211 ren
->set_background_pattern (bg
);
213 ren
->clear_pattern (0, (SI
) -h
, (SI
) w
, 0);
216 the_box
[0]->sx(i
)= 0;
217 the_box
[0]->sy(i
)= 0;
218 the_box
[0][i
]->redraw (ren
, path (0), rs
);
219 if (i
<end
-1) ren
->next_page ();
225 gs_to_pdf (name
, orig
);
232 edit_main_rep::print_to_file (url name
, string first
, string last
) {
233 print (name
, false, as_int (first
), as_int (last
));
237 edit_main_rep::print_buffer (string first
, string last
) {
238 url temp
= url_temp (".ps");
239 print (temp
, false, as_int (first
), as_int (last
));
240 system (printing_cmd
, temp
);
245 edit_main_rep::export_ps (url name
, string first
, string last
) {
246 print (name
, true, as_int (first
), as_int (last
));
250 edit_main_rep::print_snippet (url name
, tree t
) {
251 bool ps
= suffix (name
) == "ps" || suffix (name
) == "eps";
253 int dpi
= as_int (printing_dpi
);
254 //if (!ps) t= tree (WITH, MAGNIFICATION, "2", PAGE_WIDTH, "40cm", t);
255 if (!ps
) t
= tree (WITH
, MAGNIFICATION
, "1.6", PAGE_WIDTH
, "40cm", t
);
256 box b
= typeset_as_box (env
, t
, path ());
257 if (b
->x4
- b
->x3
>= 5*PIXEL
&& b
->y4
- b
->y3
>= 5*PIXEL
) {
258 if (ps
) make_eps (name
, b
, dpi
);
260 url temp
= url_temp ("eps");
261 make_eps (temp
, b
, dpi
);
262 system ("convert", temp
, name
);
267 a
<< b
->x3
<< b
->y3
<< b
->x4
<< b
->y4
;
271 /******************************************************************************
272 * Evaluation of expressions
273 ******************************************************************************/
276 edit_main_rep::footer_eval (string s
) {
277 // s= unslash (s); // FIXME: dirty fix; should not be necessary
278 string r
= object_to_string (eval (s
));
279 set_message (r
, "evaluate expression");
283 edit_main_rep::the_line () {
284 path p
= search_parent_upwards (DOCUMENT
);
285 return copy (subtree (et
, p
));
289 edit_main_rep::the_root () {
294 edit_main_rep::the_buffer () {
295 return subtree (et
, rp
);
299 edit_main_rep::the_subtree (path p
) {
300 return subtree (et
, p
);
304 edit_main_rep::the_buffer_path () {
309 edit_main_rep::the_path () {
313 /******************************************************************************
315 ******************************************************************************/
318 edit_main_rep::show_tree () {
319 stretched_print (et
, true);
320 // cout << et << "\n";
324 edit_main_rep::show_env () {
329 edit_main_rep::show_path () {
334 edit_main_rep::show_cursor () {
335 cout
<< "Principal cursor: "
336 << cu
->ox
<< ", " << cu
->oy
<< " [" << cu
->delta
<< "]\n";
337 cout
<< "Ghost cursor : "
338 << mv
->ox
<< ", " << mv
->oy
<< " [" << mv
->delta
<< "]\n";
342 edit_main_rep::show_selection () {
343 selection sel
; selection_get (sel
);
344 cout
<< "physical selection: " << start_p
<< " --- " << end_p
<< "\n";
345 cout
<< "logical selection: " << sel
->start
<< " --- " << sel
->end
<< "\n";
349 edit_main_rep::show_meminfo () {
354 edit_main_rep::edit_special () {
358 void test_commute ();
363 edit_main_rep::edit_test () {