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 ()
44 gh_define ("security-paranoia", SCM_BOOL_T);
46 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
47 ly_eval_str (s.ch_C ());
50 if (no_timestamps_global_b)
51 creator = gnu_lilypond_str ();
53 creator = gnu_lilypond_version_str ();
56 if (no_timestamps_global_b)
60 generate = _ (", at ");
62 generate += ctime (&t);
63 generate = generate.left_str (generate.length_i () - 1);
67 gh_list (ly_str02scm (creator.ch_l ()),
68 ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
71 SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
76 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
83 for (SCM ptr = gh_cdr (m->atom_list_); ptr != SCM_EOL; ptr = gh_cdr (ptr))
85 Atom * i = unsmob_atom (gh_car (ptr));
87 Offset a_off = i->off_;
96 if (abs(a_off[a]) > 30 CM
97 || isinf (a_off[a]) || isnan (a_off[a]))
99 programming_error ("Improbable offset for object: setting to zero");
107 = gh_list (ly_symbol2scm ("placebox"),
108 gh_double2scm (a_off[X_AXIS]),
109 gh_double2scm (a_off[Y_AXIS]),
113 output_scheme (box_scm);
118 Paper_outputter::output_comment (String str)
120 output_scheme (gh_list (ly_symbol2scm ("comment"),
121 ly_str02scm ((char*)str.ch_C()),
128 Paper_outputter::output_scheme (SCM scm)
130 SCM c = gh_cons (scm,gh_cdr (last_cons_));
131 gh_set_cdr_x(last_cons_, c);
139 if (Atom * a = unsmob_atom (s))
141 return 2 + count_cells (a->func_);
143 else if (gh_pair_p (s))
145 return 2 + count_cells (gh_car (s))+ count_cells (gh_cdr (s));
152 Paper_outputter::dump_onto (Paper_stream *ps)
154 if (String (output_global_ch) == "scm")
155 #if 1 // both are fine
161 if (ofstream* of = dynamic_cast<ofstream*> (ps->os))
162 fd = of->rdbuf ()->fd ();
163 SCM port = scm_fdes_to_port (fd, "a", SCM_EOL);
169 scm_display (gh_str02scm (
170 ";;; Usage: guile -s x.scm > x.tex\n"
171 "(primitive-load-path 'lily.scm)\n"
173 ";(scm-tex-output)\n"
175 "(map (lambda (x) (display (eval x))) '(\n"
178 SCM newline = gh_str02scm ("\n");
179 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
181 scm_write (gh_car (s), port);
182 scm_display (newline, port);
185 scm_display (gh_str02scm ("))"), port);
186 scm_display (newline, port);
188 scm_close_port (port);
196 if (output_global_ch == String ("scm"))
198 ";;; Usage: guile -s x.scm > x.tex\n"
199 "(primitive-load-path 'lily.scm)\n"
202 "(map (lambda (x) (display (eval x))) '(\n"
204 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
206 SCM result = scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
207 ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
209 *ps << ly_scm2string (result);
217 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
219 SCM result = scm_eval (gh_car (s));
220 char *c=gh_scm2newstr (result, NULL);
225 cout << "\nCells in use: " << scm_cells_allocated << endl;
226 cout << "protects " << scm_ilength (scm_protects) << endl;
232 Paper_outputter::output_scope (Scope *scope, String prefix)
234 for (Scope_iter i (*scope); i.ok (); i++)
236 if (dynamic_cast<String_identifier*> (i.val ()))
238 String val = *i.val()->access_content_String (false);
240 output_String_def (prefix + i.key (), val);
242 else if(dynamic_cast<Real_identifier*> (i.val ()))
244 Real val = *i.val ()->access_content_Real (false);
246 output_Real_def (prefix + i.key (), val);
248 else if (dynamic_cast<int_identifier*> (i.val ()))
250 int val = *i.val ()->access_content_int (false);
252 output_int_def (prefix + i.key (), val);
258 Paper_outputter::output_version ()
260 String id_str = "Lily was here";
261 if (no_timestamps_global_b)
264 id_str += String (", ") + version_str ();
266 output_String_def ( "mudelatagline", id_str);
267 output_String_def ( "LilyPondVersion", version_str ());
271 Paper_outputter::start_line (Real height)
275 programming_error ("Improbable system height");
278 SCM scm = gh_list (ly_symbol2scm ("start-line"),
279 gh_double2scm (height),
285 Paper_outputter::output_font_def (int i, String str)
287 SCM scm = gh_list (ly_symbol2scm ("font-def"),
289 ly_str02scm (str.ch_l ()),
296 Paper_outputter::output_Real_def (String k, Real v)
299 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
300 ly_str02scm (k.ch_l ()),
301 ly_str02scm (to_str(v).ch_l ()),
305 // gh_define (k.ch_l (), gh_double2scm (v));
309 Paper_outputter::output_String_def (String k, String v)
312 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
313 ly_str02scm (k.ch_l ()),
314 ly_str02scm (v.ch_l ()),
318 // gh_define (k.ch_l (), ly_str02scm (v.ch_l ()));
322 Paper_outputter::output_int_def (String k, int v)
324 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
325 ly_str02scm (k.ch_l ()),
326 ly_str02scm (to_str (v).ch_l ()),
330 // gh_define (k.ch_l (), gh_int2scm (v));
336 Paper_outputter::stop_line ()
338 SCM scm = gh_list (ly_symbol2scm ("stop-line"), SCM_UNDEFINED);
343 Paper_outputter::stop_last_line ()
345 SCM scm = gh_list (ly_symbol2scm ("stop-last-line"), SCM_UNDEFINED);
347 scm = gh_list (ly_symbol2scm ("end-output"), SCM_UNDEFINED);