2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
15 #include "dimensions.hh"
16 #include "dictionary-iter.hh"
17 #include "virtual-methods.hh"
18 #include "paper-outputter.hh"
19 #include "paper-stream.hh"
20 #include "molecule.hh"
22 #include "string-convert.hh"
27 #include "identifier.hh"
28 #include "lily-version.hh"
31 Paper_outputter::Paper_outputter ()
33 molecules_ = gh_cons (SCM_EOL, SCM_EOL);
34 last_cons_ = molecules_;
39 Paper_outputter::output_header ()
43 gh_define ("security-paranoia", SCM_BOOL_T);
46 SCM exp = gh_list (ly_symbol2scm ((String (output_global_ch) + "-scm").ch_C()),
47 ly_quote_scm (ly_symbol2scm ("all-definitions")),
53 if (no_timestamps_global_b)
54 creator = gnu_lilypond_str ();
56 creator = gnu_lilypond_version_str ();
59 if (no_timestamps_global_b)
63 generate = _ (", at ");
65 generate += ctime (&t);
66 generate = generate.left_str (generate.length_i () - 1);
70 gh_list (ly_str02scm (creator.ch_l ()),
71 ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
74 SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
79 Paper_outputter::output_molecule (SCM expr, Offset o, char const *nm)
88 SCM offset_sym = ly_symbol2scm ("translate-molecule");
89 SCM combine_sym = ly_symbol2scm ("combine-molecule");
92 if (!gh_pair_p (expr))
95 SCM head =gh_car (expr);
96 if (head == offset_sym)
98 o += ly_scm2offset (gh_cadr (expr));
99 expr = gh_caddr (expr);
102 else if (head == combine_sym)
104 output_molecule (gh_cadr (expr), o, nm);
105 expr = gh_caddr (expr);
106 goto enter; // tail recursion
110 output_scheme (gh_list (ly_symbol2scm ("placebox"),
111 gh_double2scm (o[X_AXIS]),
112 gh_double2scm (o[Y_AXIS]),
120 Paper_outputter::output_comment (String str)
122 output_scheme (gh_list (ly_symbol2scm ("comment"),
123 ly_str02scm ((char*)str.ch_C()),
130 Paper_outputter::output_scheme (SCM scm)
132 SCM c = gh_cons (scm,gh_cdr (last_cons_));
133 gh_set_cdr_x(last_cons_, c);
139 Paper_outputter::dump_onto (Paper_stream *ps)
141 if (String (output_global_ch) == "scm")
142 #if 1 // both are fine
148 if (ofstream* of = dynamic_cast<ofstream*> (ps->os))
149 fd = of->rdbuf ()->fd ();
150 SCM port = scm_fdes_to_port (fd, "a", SCM_EOL);
156 scm_display (gh_str02scm (
157 ";;; Usage: guile -s x.scm > x.tex\n"
158 "(primitive-load-path 'lily.scm)\n"
160 ";(scm-tex-output)\n"
162 "(map (lambda (x) (display (eval x))) '(\n"
165 SCM newline = gh_str02scm ("\n");
166 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
168 scm_write (gh_car (s), port);
169 scm_display (newline, port);
172 scm_display (gh_str02scm ("))"), port);
173 scm_display (newline, port);
175 scm_close_port (port);
183 if (output_global_ch == String ("scm"))
185 ";;; Usage: guile -s x.scm > x.tex\n"
186 "(primitive-load-path 'lily.scm)\n"
189 "(map (lambda (x) (display (eval x))) '(\n"
191 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
193 SCM result = scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
194 ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
196 *ps << ly_scm2string (result);
204 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
206 SCM result = scm_eval (gh_car (s));
207 char *c=gh_scm2newstr (result, NULL);
216 Paper_outputter::output_scope (Scope *scope, String prefix)
218 for (Scope_iter i (*scope); i.ok (); i++)
220 if (dynamic_cast<String_identifier*> (i.val ()))
222 String val = *i.val()->access_content_String (false);
224 output_String_def (prefix + i.key (), val);
226 else if(dynamic_cast<Real_identifier*> (i.val ()))
228 Real val = *i.val ()->access_content_Real (false);
230 output_Real_def (prefix + i.key (), val);
232 else if (dynamic_cast<int_identifier*> (i.val ()))
234 int val = *i.val ()->access_content_int (false);
236 output_int_def (prefix + i.key (), val);
242 Paper_outputter::output_version ()
244 String id_str = "Lily was here";
245 if (no_timestamps_global_b)
248 id_str += String (", ") + version_str ();
250 output_String_def ( "mudelatagline", id_str);
251 output_String_def ( "LilyPondVersion", version_str ());
255 Paper_outputter::start_line (Real height)
259 programming_error ("Improbable system height");
262 SCM scm = gh_list (ly_symbol2scm ("start-line"),
263 gh_double2scm (height),
269 Paper_outputter::output_font_def (int i, String str)
271 SCM scm = gh_list (ly_symbol2scm ("font-def"),
273 ly_str02scm (str.ch_l ()),
280 Paper_outputter::output_Real_def (String k, Real v)
283 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
284 ly_str02scm (k.ch_l ()),
285 ly_str02scm (to_str(v).ch_l ()),
289 // gh_define (k.ch_l (), gh_double2scm (v));
293 Paper_outputter::output_String_def (String k, String v)
296 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
297 ly_str02scm (k.ch_l ()),
298 ly_str02scm (v.ch_l ()),
302 // gh_define (k.ch_l (), ly_str02scm (v.ch_l ()));
306 Paper_outputter::output_int_def (String k, int v)
308 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
309 ly_str02scm (k.ch_l ()),
310 ly_str02scm (to_str (v).ch_l ()),
314 // gh_define (k.ch_l (), gh_int2scm (v));
320 Paper_outputter::stop_line ()
322 SCM scm = gh_list (ly_symbol2scm ("stop-line"), SCM_UNDEFINED);
327 Paper_outputter::stop_last_line ()
329 SCM scm = gh_list (ly_symbol2scm ("stop-last-line"), SCM_UNDEFINED);
331 scm = gh_list (ly_symbol2scm ("end-output"), SCM_UNDEFINED);