2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
13 #include "dimensions.hh"
14 #include "dictionary-iter.hh"
15 #include "virtual-methods.hh"
16 #include "paper-outputter.hh"
17 #include "paper-stream.hh"
18 #include "molecule.hh"
20 #include "string-convert.hh"
25 #include "identifier.hh"
26 #include "lily-version.hh"
29 Paper_outputter::Paper_outputter ()
31 molecules_ = gh_cons (SCM_EOL, SCM_EOL);
32 last_cons_ = molecules_;
37 Paper_outputter::output_header ()
41 // ly_set_x ("security-paranoia", SCM_BOOL_T);
42 gh_define ("security-paranoia", SCM_BOOL_T);
44 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
45 ly_eval_str (s.ch_C ());
48 if (no_timestamps_global_b)
49 creator = gnu_lilypond_str ();
51 creator = gnu_lilypond_version_str ();
54 if (no_timestamps_global_b)
58 generate = _ (", at ");
60 generate += ctime (&t);
65 gh_list (ly_str02scm (creator.ch_l ()),
66 ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
69 SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
74 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
81 for (Cons<Atom> *ptr = m->atom_list_; ptr; ptr = ptr->next_)
85 Offset a_off = i->off_;
91 if (a_off.length () > 100 CM)
93 programming_error ("improbable offset for object");
97 if (abs(a_off[a]) > 30 CM)
104 = gh_list (ly_symbol2scm ("placebox"),
105 gh_double2scm (a_off.x ()),
106 gh_double2scm (a_off.y ()),
110 output_scheme (box_scm);
115 Paper_outputter::output_comment (String str)
117 output_scheme (gh_list (ly_symbol2scm ("comment"),
118 ly_str02scm ((char*)str.ch_C()),
125 Paper_outputter::output_scheme (SCM scm)
127 SCM c = gh_cons (scm,gh_cdr (last_cons_));
128 gh_set_cdr_x(last_cons_, c);
134 Paper_outputter::dump_onto (Paper_stream *ps)
136 if (String (output_global_ch) == "scm")
137 #if 1 // both are fine
143 if (ofstream* of = dynamic_cast<ofstream*> (ps->os))
144 fd = of->rdbuf ()->fd ();
145 SCM port = scm_fdes_to_port (fd, "a", SCM_EOL);
151 scm_display (gh_str02scm (
152 ";;; Usage: guile -s x.scm > x.tex\n"
153 "(primitive-load-path 'lily.scm)\n"
156 "(map (lambda (x) (display (eval x))) '(\n"
159 SCM newline = gh_str02scm ("\n");
160 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
162 scm_write (gh_car (s), port);
163 scm_display (newline, port);
166 scm_display (gh_str02scm (")))"), port);
167 scm_display (newline, port);
169 scm_close_port (port);
177 if (output_global_ch == String ("scm"))
179 ";;; Usage: guile -s x.scm > x.tex\n"
180 "(primitive-load-path 'lily.scm)\n"
183 "(map (lambda (x) (display (eval x))) '(\n"
185 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
187 SCM result = scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
188 ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
190 *ps << ly_scm2string (result);
198 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
200 SCM result = scm_eval (gh_car (s));
201 char *c=gh_scm2newstr (result, NULL);
210 Paper_outputter::output_scope (Scope *scope, String prefix)
212 for (Scope_iter i (*scope); i.ok (); i++)
214 if (dynamic_cast<String_identifier*> (i.val ()))
216 String val = *i.val()->access_content_String (false);
218 output_String_def (prefix + i.key (), val);
220 else if(dynamic_cast<Real_identifier*> (i.val ()))
222 Real val = *i.val ()->access_content_Real (false);
224 output_Real_def (prefix + i.key (), val);
226 else if (dynamic_cast<int_identifier*> (i.val ()))
228 int val = *i.val ()->access_content_int (false);
230 output_int_def (prefix + i.key (), val);
236 Paper_outputter::output_version ()
238 String id_str = "Lily was here";
239 if (no_timestamps_global_b)
242 id_str += String (", ") + version_str ();
244 output_String_def ( "mudelatagline", id_str);
245 output_String_def ( "LilyPondVersion", version_str ());
249 Paper_outputter::start_line (Real height)
253 programming_error ("Improbable system height");
256 SCM scm = gh_list (ly_symbol2scm ("start-line"),
257 gh_double2scm (height),
263 Paper_outputter::output_font_def (int i, String str)
265 SCM scm = gh_list (ly_symbol2scm ("font-def"),
267 ly_str02scm (str.ch_l ()),
274 Paper_outputter::output_Real_def (String k, Real v)
277 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
278 ly_str02scm (k.ch_l ()),
279 ly_str02scm (to_str(v).ch_l ()),
283 gh_define (k.ch_l (), gh_double2scm (v));
287 Paper_outputter::output_String_def (String k, String v)
290 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
291 ly_str02scm (k.ch_l ()),
292 ly_str02scm (v.ch_l ()),
296 gh_define (k.ch_l (), ly_str02scm (v.ch_l ()));
300 Paper_outputter::output_int_def (String k, int v)
302 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
303 ly_str02scm (k.ch_l ()),
304 ly_str02scm (to_str (v).ch_l ()),
308 gh_define (k.ch_l (), gh_int2scm (v));
314 Paper_outputter::stop_line ()
316 SCM scm = gh_list (ly_symbol2scm ("stop-line"), SCM_UNDEFINED);
321 Paper_outputter::stop_last_line ()
323 SCM scm = gh_list (ly_symbol2scm ("stop-last-line"), SCM_UNDEFINED);
325 scm = gh_list (ly_symbol2scm ("end-output"), SCM_UNDEFINED);