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 SCM offset_sym = ly_symbol2scm ("translate-atom");
84 for (SCM ptr = gh_cdr (m->atom_list_); ptr != SCM_EOL; ptr = gh_cdr (ptr))
86 SCM func = gh_car (ptr);
90 while (gh_pair_p (funcptr))
92 if (gh_car (funcptr) == offset_sym)
94 SCM quot = gh_cadr (funcptr);
95 a_off += ly_scm2offset (gh_cadr (quot));
97 funcptr = scm_last_pair (funcptr);
98 if (funcptr != SCM_EOL )
100 funcptr = gh_car (funcptr);
109 if (abs(a_off[a]) > 30 CM
110 || isinf (a_off[a]) || isnan (a_off[a]))
112 programming_error ("Improbable offset for object: setting to zero");
120 = gh_list (ly_symbol2scm ("placebox"),
121 gh_double2scm (a_off[X_AXIS]),
122 gh_double2scm (a_off[Y_AXIS]),
126 output_scheme (box_scm);
131 Paper_outputter::output_comment (String str)
133 output_scheme (gh_list (ly_symbol2scm ("comment"),
134 ly_str02scm ((char*)str.ch_C()),
141 Paper_outputter::output_scheme (SCM scm)
143 SCM c = gh_cons (scm,gh_cdr (last_cons_));
144 gh_set_cdr_x(last_cons_, c);
150 Paper_outputter::dump_onto (Paper_stream *ps)
152 if (String (output_global_ch) == "scm")
153 #if 1 // both are fine
159 if (ofstream* of = dynamic_cast<ofstream*> (ps->os))
160 fd = of->rdbuf ()->fd ();
161 SCM port = scm_fdes_to_port (fd, "a", SCM_EOL);
167 scm_display (gh_str02scm (
168 ";;; Usage: guile -s x.scm > x.tex\n"
169 "(primitive-load-path 'lily.scm)\n"
171 ";(scm-tex-output)\n"
173 "(map (lambda (x) (display (eval x))) '(\n"
176 SCM newline = gh_str02scm ("\n");
177 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
179 scm_write (gh_car (s), port);
180 scm_display (newline, port);
183 scm_display (gh_str02scm ("))"), port);
184 scm_display (newline, port);
186 scm_close_port (port);
194 if (output_global_ch == String ("scm"))
196 ";;; Usage: guile -s x.scm > x.tex\n"
197 "(primitive-load-path 'lily.scm)\n"
200 "(map (lambda (x) (display (eval x))) '(\n"
202 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
204 SCM result = scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
205 ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
207 *ps << ly_scm2string (result);
215 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
217 SCM result = scm_eval (gh_car (s));
218 char *c=gh_scm2newstr (result, NULL);
227 Paper_outputter::output_scope (Scope *scope, String prefix)
229 for (Scope_iter i (*scope); i.ok (); i++)
231 if (dynamic_cast<String_identifier*> (i.val ()))
233 String val = *i.val()->access_content_String (false);
235 output_String_def (prefix + i.key (), val);
237 else if(dynamic_cast<Real_identifier*> (i.val ()))
239 Real val = *i.val ()->access_content_Real (false);
241 output_Real_def (prefix + i.key (), val);
243 else if (dynamic_cast<int_identifier*> (i.val ()))
245 int val = *i.val ()->access_content_int (false);
247 output_int_def (prefix + i.key (), val);
253 Paper_outputter::output_version ()
255 String id_str = "Lily was here";
256 if (no_timestamps_global_b)
259 id_str += String (", ") + version_str ();
261 output_String_def ( "mudelatagline", id_str);
262 output_String_def ( "LilyPondVersion", version_str ());
266 Paper_outputter::start_line (Real height)
270 programming_error ("Improbable system height");
273 SCM scm = gh_list (ly_symbol2scm ("start-line"),
274 gh_double2scm (height),
280 Paper_outputter::output_font_def (int i, String str)
282 SCM scm = gh_list (ly_symbol2scm ("font-def"),
284 ly_str02scm (str.ch_l ()),
291 Paper_outputter::output_Real_def (String k, Real v)
294 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
295 ly_str02scm (k.ch_l ()),
296 ly_str02scm (to_str(v).ch_l ()),
300 // gh_define (k.ch_l (), gh_double2scm (v));
304 Paper_outputter::output_String_def (String k, String v)
307 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
308 ly_str02scm (k.ch_l ()),
309 ly_str02scm (v.ch_l ()),
313 // gh_define (k.ch_l (), ly_str02scm (v.ch_l ()));
317 Paper_outputter::output_int_def (String k, int v)
319 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
320 ly_str02scm (k.ch_l ()),
321 ly_str02scm (to_str (v).ch_l ()),
325 // gh_define (k.ch_l (), gh_int2scm (v));
331 Paper_outputter::stop_line ()
333 SCM scm = gh_list (ly_symbol2scm ("stop-line"), SCM_UNDEFINED);
338 Paper_outputter::stop_last_line ()
340 SCM scm = gh_list (ly_symbol2scm ("stop-last-line"), SCM_UNDEFINED);
342 scm = gh_list (ly_symbol2scm ("end-output"), SCM_UNDEFINED);