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)
35 Paper_outputter::~Paper_outputter ()
37 SCM scm = gh_list (ly_symbol ("end-output"), SCM_UNDEFINED);
42 Paper_outputter::output_header ()
46 {// alloc big chunk of memory.
48 String bigstr = String_convert::char_str (' ', 50);
49 for (int i = gobble; i--; )
51 beg = gh_cons (gh_str02scm (bigstr.ch_C()), beg);
58 ly_set_scm ("security-paranoia", SCM_BOOL_T);
59 // gh_eval_str ("(set! security-paranoia #t)");
61 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
62 gh_eval_str (s.ch_C());
65 if (no_timestamps_global_b)
66 creator = gnu_lilypond_str ();
68 creator = gnu_lilypond_version_str ();
71 if (no_timestamps_global_b)
75 generate = _ (", at ");
77 generate += ctime (&t);
82 gh_list (gh_str02scm (creator.ch_l ()),
83 gh_str02scm (generate.ch_l ()), SCM_UNDEFINED);
86 DOUT << "output_header\n";
87 if (check_debug && !monitor->silent_b ("Guile"))
89 gh_display (args_scm); gh_newline ();
93 SCM scm = gh_cons (ly_symbol ("header"), args_scm);
98 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
101 *outstream_l_ << String ("\n%start: ") << nm << "\n";
110 for (SCM ptr = m->atom_list_; ptr != SCM_EOL; ptr = SCM_CDR(ptr))
112 Atom *i = Atom::atom_l (SCM_CAR(ptr));
114 for (Cons<Atom> *ptr = m->atom_list_; ptr; ptr = ptr->next_)
116 Atom * i = ptr->car_;
118 Offset a_off = i->off_;
124 assert (a_off.length () < 100 CM);
128 output_scheme (gh_list (ly_symbol ("select-font"),
129 gh_str02scm (symbol_to_string (i->font_).ch_C()),
134 = gh_list (ly_symbol ("placebox"),
135 gh_double2scm (a_off.x ()),
136 gh_double2scm (a_off.y ()),
140 output_scheme (box_scm);
145 Paper_outputter::output_comment (String str)
147 if (String (output_global_ch) == "scm")
149 *outstream_l_ << "; " << str << '\n';
153 *outstream_l_ << "% " << str << "\n";
159 Paper_outputter::output_scheme (SCM scm)
161 if (String (output_global_ch) == "scm")
169 ofstream * of = dynamic_cast<ofstream*> (outstream_l_->os);
171 fd = of->rdbuf()->fd();
172 FILE *file = fdopen (fd, "a");
173 port = scm_standard_stream_to_port (file, "a", "");
174 scm_display (gh_str02scm ("(load 'lily.scm)\n"), port);
177 scm_display (gh_str02scm ("("), port);
178 scm_write (scm, port);
179 scm_display (gh_str02scm (")\n"),port);
184 SCM result = scm_eval (scm);
185 char *c=gh_scm2newstr (result, NULL);
193 Paper_outputter::output_scope (Scope *scope, String prefix)
195 for (Scope_iter i (*scope); i.ok (); i++)
197 if (dynamic_cast<String_identifier*> (i.val ()))
199 String val = *i.val()->access_content_String (false);
201 output_String_def (prefix + i.key (), val);
203 else if(dynamic_cast<Real_identifier*> (i.val ()))
205 Real val = *i.val ()->access_content_Real (false);
207 output_Real_def (prefix + i.key (), val);
209 else if (dynamic_cast<int_identifier*> (i.val ()))
211 int val = *i.val ()->access_content_int (false);
213 output_int_def (prefix + i.key (), val);
219 Paper_outputter::output_version ()
221 String id_str = "Lily was here";
222 if (no_timestamps_global_b)
225 id_str += String (", ") + version_str ();
226 output_String_def ( "LilyIdString", id_str);
230 Paper_outputter::start_line ()
232 SCM scm = gh_list (ly_symbol ("start-line"), SCM_UNDEFINED);
237 Paper_outputter::output_font_def (int i, String str)
239 SCM scm = gh_list (ly_symbol ("font-def"),
241 gh_str02scm (str.ch_l ()),
248 Paper_outputter::output_Real_def (String k, Real v)
251 SCM scm = gh_list (ly_symbol ("lily-def"),
252 gh_str02scm (k.ch_l ()),
253 gh_str02scm (to_str(v).ch_l ()),
257 gh_define (k.ch_l (), gh_double2scm (v));
261 Paper_outputter::output_String_def (String k, String v)
264 SCM scm = gh_list (ly_symbol ("lily-def"),
265 gh_str02scm (k.ch_l ()),
266 gh_str02scm (v.ch_l ()),
270 gh_define (k.ch_l (), gh_str02scm (v.ch_l ()));
274 Paper_outputter::output_int_def (String k, int v)
276 SCM scm = gh_list (ly_symbol ("lily-def"),
277 gh_str02scm (k.ch_l ()),
278 gh_str02scm (to_str (v).ch_l ()),
282 gh_define (k.ch_l (), gh_int2scm (v));
288 Paper_outputter::stop_line ()
290 SCM scm = gh_list (ly_symbol ("stop-line"), SCM_UNDEFINED);