2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
13 #include "virtual-methods.hh"
14 #include "paper-outputter.hh"
15 #include "paper-stream.hh"
16 #include "molecule.hh"
19 #include "string-convert.hh"
24 Paper_outputter::Paper_outputter (Paper_stream *s)
30 Paper_outputter::~Paper_outputter ()
32 SCM scm = gh_list (ly_symbol ("end-output"), SCM_UNDEFINED);
37 Paper_outputter::output_header ()
39 String s = String ("(eval (") + output_global_ch + "-scm 'all-definitions))";
40 gh_eval_str (s.ch_C());
44 if (no_timestamps_global_b)
45 creator = "GNU LilyPond\n";
47 creator = get_version_str ();
49 if (no_timestamps_global_b)
53 generate = _ (", at ");
55 generate += ctime (&t);
60 gh_list (gh_str02scm (creator.ch_l ()),
61 gh_str02scm (generate.ch_l ()), SCM_UNDEFINED);
64 DOUT << "output_header\n";
65 if (check_debug && !monitor->silent_b ("Guile"))
67 gh_display (args_scm); gh_newline ();
71 SCM scm = gh_cons (ly_symbol ("header"), args_scm);
76 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
79 *outstream_l_ << String ("\n%start: ") << nm << "\n";
81 for (PCursor <Atom*> i (m->atoms_); i.ok (); i++)
83 Offset a_off = i->offset ();
91 output_comment (classname (i.ptr ()->origin_l_));
95 switch_to_font (i->font_);
97 SCM args_scm = gh_list (gh_double2scm (a_off.x ()),
98 gh_double2scm (a_off.y ()),
103 SCM box_scm = gh_cons (ly_symbol ("placebox"), args_scm);
105 output_scheme (box_scm);
110 Paper_outputter::output_comment (String str)
112 if (String (output_global_ch) == "scm")
114 *outstream_l_ << "; " << str << '\n';
118 *outstream_l_ << "% " << str << "\n";
124 Paper_outputter::output_scheme (SCM scm)
126 String o = String ("\'") + output_global_ch;
128 if (String (output_global_ch) == "scm")
136 ofstream * of = dynamic_cast<ofstream*> (outstream_l_->os);
138 fd = of->rdbuf()->fd();
139 FILE *file = fdopen (fd, "a");
140 port = scm_standard_stream_to_port (file, "a", "");
141 scm_display (gh_str02scm ("(load 'lily.scm)\n"), port);
144 scm_display (gh_str02scm ("("), port);
145 scm_write (scm, port);
146 scm_display (gh_str02scm (")\n"),port);
151 SCM result = scm_eval (scm);
152 char *c=gh_scm2newstr (result, NULL);
159 Paper_outputter::output_string (String str)
162 *outstream_l_ << str;
166 Paper_outputter::switch_to_font (String fontname)
168 if (fontname.length_i () && fontname != current_font_)
170 current_font_ = fontname;
173 for (; i< font_arr_.size (); i++)
174 if (font_arr_[i] == fontname)
177 if (i == font_arr_.size ())
179 font_arr_.push (fontname);
180 output_font_def (i, fontname);
182 output_font_switch (i);
188 Paper_outputter::start_line ()
190 SCM scm = gh_list (ly_symbol ("start-line"), SCM_UNDEFINED);
195 Paper_outputter::output_font_def (int i, String str)
197 SCM scm =gh_list (ly_symbol ("font-def"),
199 gh_str02scm (str.ch_l ()),
206 Paper_outputter::output_font_switch (int i)
208 SCM scm = gh_list (ly_symbol ("font-switch"),
216 Paper_outputter::stop_line ()
218 SCM scm = gh_list (ly_symbol ("stop-line"), SCM_UNDEFINED);