2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
12 #include "paper-outputter.hh"
13 #include "paper-stream.hh"
14 #include "molecule.hh"
17 #include "string-convert.hh"
22 Paper_outputter::Paper_outputter (Paper_stream *s)
28 Paper_outputter::~Paper_outputter ()
31 ly_append (ly_lambda_o (),
32 ly_list1 (ly_append (ly_func_o ("end-output"), SCM_EOL)));
38 Paper_outputter::output_header ()
41 if (no_timestamps_global_b)
42 creator = "GNU LilyPond\n";
44 creator = get_version_str ();
46 if (no_timestamps_global_b)
50 generate = _ (", at ");
52 generate += ctime (&t);
57 gh_cons (gh_str02scm (creator.ch_l ()),
58 gh_cons (gh_str02scm (generate.ch_l ()), SCM_EOL));
61 DOUT << "output_header\n";
62 if (check_debug && !monitor->silent_b ("Guile"))
64 gh_display (args_scm); gh_newline ();
69 ly_append (ly_lambda_o (),
70 ly_list1 (ly_append (ly_func_o ("header"), args_scm)));
76 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
79 *outstream_l_ << String ("\n%start: ") << nm << "\n";
81 for (PCursor <Atom*> i (m->atoms_); i.ok (); i++)
83 Offset a_off = i->offset ();
89 i->lambda_ = ly_append (ly_lambda_o (),
90 ly_list1 (ly_func_o ("empty")));
93 switch_to_font (i->font_);
96 if (check_debug && !monitor->silent_b ("Guile"))
98 DOUT << i->str_ << "\n";
99 gh_display (i->lambda_); gh_newline ();
104 gh_cons (gh_double2scm (a_off.x ()),
105 gh_cons (gh_double2scm (a_off.y ()),
106 gh_cons (i->lambda_, SCM_EOL)));
109 if (check_debug && !monitor->silent_b ("Guile"))
111 gh_display (args_scm); gh_newline ();
116 ly_append (ly_lambda_o (),
117 ly_list1 (ly_append (ly_func_o ("placebox"), args_scm)));
119 output_scheme (box_scm);
124 Paper_outputter::output_comment (String str)
127 *outstream_l_ << "% " << str << "\n";
132 Paper_outputter::output_scheme (SCM scm)
134 String o = String ("\'") + output_global_ch;
136 if (String (output_global_ch) == "scm")
143 ofstream * of = dynamic_cast <ofstream*> (outstream_l_->os);
145 fd = of->rdbuf()->fd();
146 FILE *file = fdopen (fd, "a");
147 port = scm_standard_stream_to_port (file, "a", "");
148 scm_display (gh_str02scm ("(load 'lily.scm)\n"), port);
151 scm_display (gh_str02scm ("(display ((eval "), port);
152 scm_write (scm, port);
153 scm_display (gh_str02scm (") 'tex))\n"), port);
161 SCM str_scm = gh_call1 (ly_eval (scm), gh_eval_str (o.ch_l ()));
162 char* c = gh_scm2newstr (str_scm, NULL);
168 Paper_outputter::output_string (String str)
171 *outstream_l_ << str;
175 Paper_outputter::switch_to_font (String fontname)
177 if (fontname.length_i () && (fontname != current_font_))
179 current_font_ = fontname;
182 for (; i< font_arr_.size (); i++)
183 if (font_arr_[i] == fontname)
191 font_arr_.push (fontname);
192 output_font_def (i, fontname);
194 output_font_switch (i);
200 Paper_outputter::start_line ()
203 gh_append2 (ly_lambda_o (),
204 gh_list (ly_func_o ("start-line"), SCM_UNDEFINED));;
210 26 fonts ought to be enough for anyone.
213 Paper_outputter::output_font_def (int i, String str)
215 //urg, broken with guile-1.3
218 ly_append (ly_lambda_o (),
219 ly_list1 (ly_append (ly_func_o ("font-def"),
220 gh_cons (gh_int2scm (i), gh_cons (gh_str02scm (str.ch_l ()), SCM_EOL)))));
226 Paper_outputter::output_font_switch (int i)
228 //urg, broken with guile-1.2, 1.3
231 ly_append (ly_lambda_o (),
232 ly_list1 (ly_append (ly_func_o ("font-switch"),
233 gh_cons (gh_int2scm (i), SCM_EOL))));
239 Paper_outputter::stop_line ()
242 ly_append (ly_lambda_o (),
243 ly_list1 (ly_append (ly_func_o ("stop-line"), SCM_EOL)));