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 (Paper_stream *s)
34 if (output_global_ch == String ("scm"))
35 *outstream_l_->os << ""
36 "(primitive-load-path 'lily.scm)\n"
37 "(eval (tex-scm 'all-definitions))\n"
38 ";(eval (ps-scm 'all-definitions))\n"
39 "(display (map (lambda (x) (string-append (eval x) \"\\n\")) '(\n"
43 Paper_outputter::~Paper_outputter ()
45 SCM scm = gh_list (ly_symbol ("end-output"), SCM_UNDEFINED);
48 if (String (output_global_ch) == "scm")
50 *outstream_l_->os << ")))";
55 Paper_outputter::output_header ()
59 ly_set_scm ("security-paranoia", SCM_BOOL_T);
60 // ly_ch_C_eval_scm ("(set! security-paranoia #t)");
62 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
63 ly_ch_C_eval_scm (s.ch_C ());
66 if (no_timestamps_global_b)
67 creator = gnu_lilypond_str ();
69 creator = gnu_lilypond_version_str ();
72 if (no_timestamps_global_b)
76 generate = _ (", at ");
78 generate += ctime (&t);
83 gh_list (ly_str02scm (creator.ch_l ()),
84 ly_str02scm (generate.ch_l ()), SCM_UNDEFINED);
87 DEBUG_OUT << "output_header\n";
88 if (flower_dstream && !flower_dstream->silent_b ("Guile"))
90 gh_display (args_scm); gh_newline ();
94 SCM scm = gh_cons (gh_symbol2scm ("header"), args_scm);
99 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
102 *outstream_l_ << String ("\n%start: ") << nm << "\n";
111 for (SCM ptr = m->atom_list_; ptr != SCM_EOL; ptr = SCM_CDR(ptr))
113 Atom *i = Atom::atom_l (SCM_CAR(ptr));
115 for (Cons<Atom> *ptr = m->atom_list_; ptr; ptr = ptr->next_)
117 Atom * i = ptr->car_;
122 Offset a_off = i->off_;
128 if (a_off.length () > 100 CM)
130 warning (_f ("improbable offset for object type: `%s'", nm));
134 if (abs(a_off[a]) > 50 CM)
142 output_scheme (gh_list (ly_symbol ("select-font"),
143 ly_str02scm (symbol_to_string (i->font_).ch_C()),
149 = gh_list (gh_symbol2scm ("placebox"),
150 gh_double2scm (a_off.x ()),
151 gh_double2scm (a_off.y ()),
155 output_scheme (box_scm);
160 Paper_outputter::output_comment (String str)
162 if (String (output_global_ch) == "scm")
164 *outstream_l_ << "; " << str << "\n";
168 *outstream_l_ << "% " << str << "\n";
174 Paper_outputter::output_scheme (SCM scm)
176 if (String (output_global_ch) == "scm")
178 SCM result = scm_eval (scm_listify (ly_symbol ("scm->string"), ly_quote_scm (scm), SCM_UNDEFINED));
179 *outstream_l_->os << ly_scm2string (result) << endl;
183 SCM result = scm_eval (scm);
184 char *c=gh_scm2newstr (result, NULL);
192 Paper_outputter::output_scope (Scope *scope, String prefix)
194 for (Scope_iter i (*scope); i.ok (); i++)
196 if (dynamic_cast<String_identifier*> (i.val ()))
198 String val = *i.val()->access_content_String (false);
200 output_String_def (prefix + i.key (), val);
202 else if(dynamic_cast<Real_identifier*> (i.val ()))
204 Real val = *i.val ()->access_content_Real (false);
206 output_Real_def (prefix + i.key (), val);
208 else if (dynamic_cast<int_identifier*> (i.val ()))
210 int val = *i.val ()->access_content_int (false);
212 output_int_def (prefix + i.key (), val);
218 Paper_outputter::output_version ()
220 String id_str = "Lily was here";
221 if (no_timestamps_global_b)
224 id_str += String (", ") + version_str ();
226 output_String_def ( "mudelatagline", id_str);
227 output_String_def ( "LilyPondVersion", version_str ());
231 Paper_outputter::start_line (Real height)
233 SCM scm = gh_list (ly_symbol ("start-line"),
234 gh_double2scm (height),
240 Paper_outputter::output_font_def (int i, String str)
242 SCM scm = gh_list (ly_symbol ("font-def"),
244 ly_str02scm (str.ch_l ()),
251 Paper_outputter::output_Real_def (String k, Real v)
254 SCM scm = gh_list (ly_symbol ("lily-def"),
255 ly_str02scm (k.ch_l ()),
256 ly_str02scm (to_str(v).ch_l ()),
260 gh_define (k.ch_l (), gh_double2scm (v));
264 Paper_outputter::output_String_def (String k, String v)
267 SCM scm = gh_list (ly_symbol ("lily-def"),
268 ly_str02scm (k.ch_l ()),
269 ly_str02scm (v.ch_l ()),
273 gh_define (k.ch_l (), ly_str02scm (v.ch_l ()));
277 Paper_outputter::output_int_def (String k, int v)
279 SCM scm = gh_list (ly_symbol ("lily-def"),
280 ly_str02scm (k.ch_l ()),
281 ly_str02scm (to_str (v).ch_l ()),
285 gh_define (k.ch_l (), gh_int2scm (v));
291 Paper_outputter::stop_line ()
293 SCM scm = gh_list (ly_symbol ("stop-line"), SCM_UNDEFINED);
298 Paper_outputter::stop_last_line ()
300 SCM scm = gh_list (ly_symbol ("stop-last-line"), SCM_UNDEFINED);