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 *os)
137 if (output_global_ch == String ("scm"))
139 "(primitive-load-path 'lily.scm)\n"
140 "(eval (tex-scm 'all-definitions))\n"
141 ";(eval (ps-scm 'all-definitions))\n"
142 "(display (map (lambda (x) (string-append (eval x) \"\\n\")) '(\n"
145 for (SCM s = gh_cdr (molecules_); gh_pair_p (s); s = gh_cdr (s))
147 if (String (output_global_ch) == "scm")
149 SCM result = scm_eval (scm_listify (ly_symbol2scm ("scm->string"),
150 ly_quote_scm (gh_car (s)), SCM_UNDEFINED));
152 *os << ly_scm2string (result);
156 SCM result = scm_eval (gh_car (s));
157 char *c=gh_scm2newstr (result, NULL);
166 if (String (output_global_ch) == "scm")
173 Paper_outputter::output_scope (Scope *scope, String prefix)
175 for (Scope_iter i (*scope); i.ok (); i++)
177 if (dynamic_cast<String_identifier*> (i.val ()))
179 String val = *i.val()->access_content_String (false);
181 output_String_def (prefix + i.key (), val);
183 else if(dynamic_cast<Real_identifier*> (i.val ()))
185 Real val = *i.val ()->access_content_Real (false);
187 output_Real_def (prefix + i.key (), val);
189 else if (dynamic_cast<int_identifier*> (i.val ()))
191 int val = *i.val ()->access_content_int (false);
193 output_int_def (prefix + i.key (), val);
199 Paper_outputter::output_version ()
201 String id_str = "Lily was here";
202 if (no_timestamps_global_b)
205 id_str += String (", ") + version_str ();
207 output_String_def ( "mudelatagline", id_str);
208 output_String_def ( "LilyPondVersion", version_str ());
212 Paper_outputter::start_line (Real height)
216 programming_error ("Improbable system height");
219 SCM scm = gh_list (ly_symbol2scm ("start-line"),
220 gh_double2scm (height),
226 Paper_outputter::output_font_def (int i, String str)
228 SCM scm = gh_list (ly_symbol2scm ("font-def"),
230 ly_str02scm (str.ch_l ()),
237 Paper_outputter::output_Real_def (String k, Real v)
240 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
241 ly_str02scm (k.ch_l ()),
242 ly_str02scm (to_str(v).ch_l ()),
246 gh_define (k.ch_l (), gh_double2scm (v));
250 Paper_outputter::output_String_def (String k, String v)
253 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
254 ly_str02scm (k.ch_l ()),
255 ly_str02scm (v.ch_l ()),
259 gh_define (k.ch_l (), ly_str02scm (v.ch_l ()));
263 Paper_outputter::output_int_def (String k, int v)
265 SCM scm = gh_list (ly_symbol2scm ("lily-def"),
266 ly_str02scm (k.ch_l ()),
267 ly_str02scm (to_str (v).ch_l ()),
271 gh_define (k.ch_l (), gh_int2scm (v));
277 Paper_outputter::stop_line ()
279 SCM scm = gh_list (ly_symbol2scm ("stop-line"), SCM_UNDEFINED);
284 Paper_outputter::stop_last_line ()
286 SCM scm = gh_list (ly_symbol2scm ("stop-last-line"), SCM_UNDEFINED);
288 scm = gh_list (ly_symbol2scm ("end-output"), SCM_UNDEFINED);