2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
15 #include "dimensions.hh"
16 #include "virtual-methods.hh"
17 #include "paper-outputter.hh"
18 #include "molecule.hh"
20 #include "string-convert.hh"
22 #include "font-metric.hh"
24 #include "scm-hash.hh"
25 #include "lily-version.hh"
26 #include "paper-def.hh"
27 #include "file-results.hh"
33 Paper_outputter::Paper_outputter (String name)
37 gh_define ("security-paranoia", SCM_BOOL_T);
40 file_ = scm_open_file (ly_str02scm (name.ch_C()),
43 SCM exp = scm_list_n (ly_symbol2scm ("find-dumper"),
44 ly_str02scm (output_format_global.ch_C()),
47 output_func_ = scm_primitive_eval (exp);
50 Paper_outputter::~Paper_outputter ()
57 Paper_outputter::output_header ()
59 String generate = _ (", at ");
61 generate += ctime (&t);
62 generate = generate.left_str (generate.length_i () - 1);
65 Make fixed length time stamps
67 generate = generate + to_str (' ' * (120 - generate.length_i ())>? 0) ;
68 String creator = "lelie";
70 SCM args_scm = scm_list_n (ly_str02scm (creator.ch_C ()),
71 ly_str02scm (generate.ch_C ()), SCM_UNDEFINED);
74 SCM scm = gh_cons (ly_symbol2scm ("header"), args_scm);
82 Paper_outputter::output_comment (String str)
84 output_scheme (scm_list_n (ly_symbol2scm ("comment"),
85 ly_str02scm ((char*)str.ch_C ()),
91 Paper_outputter::output_scheme (SCM scm)
93 gh_call2 (output_func_, scm, file_);
97 Paper_outputter::output_scope (Scheme_hash_table *scope, String prefix)
99 SCM al = scope->to_alist ();
100 for (SCM s = al ; gh_pair_p (s); s = ly_cdr (s))
104 String s = ly_symbol2string (k);
108 output_String_def (prefix + s, ly_scm2string (v));
110 else if (scm_exact_p (v) == SCM_BOOL_T)
112 output_int_def (prefix + s, gh_scm2int (v));
114 else if (gh_number_p (v))
116 output_Real_def (prefix + s, gh_scm2double (v));
122 Paper_outputter::output_version ()
124 String id_str = "Lily was here";
125 id_str += String_convert::pad_to (String (", ") + version_str (), 40);
127 output_String_def ("lilypondtagline", id_str);
128 output_String_def ("LilyPondVersion", version_str ());
129 output_String_def ("lilypondpaperunit", String (INTERNAL_UNIT));
134 Paper_outputter::output_Real_def (String k, Real v)
137 SCM scm = scm_list_n (ly_symbol2scm ("lily-def"),
138 ly_str02scm (k.ch_l ()),
139 ly_str02scm (to_str (v).ch_l ()),
145 Paper_outputter::output_String_def (String k, String v)
148 SCM scm = scm_list_n (ly_symbol2scm ("lily-def"),
149 ly_str02scm (k.ch_l ()),
150 ly_str02scm (v.ch_l ()),
156 Paper_outputter::output_int_def (String k, int v)
158 SCM scm = scm_list_n (ly_symbol2scm ("lily-def"),
159 ly_str02scm (k.ch_l ()),
160 ly_str02scm (to_str (v).ch_l ()),
166 Paper_outputter::write_header_field_to_file (String filename, SCM key, SCM value)
168 output_scheme (scm_list_n (ly_symbol2scm ("header-to-file"),
169 ly_str02scm (filename.ch_C()),
170 ly_quote_scm (key), value,
175 Paper_outputter::write_header_fields_to_file (Scheme_hash_table * header)
177 if (dump_header_fieldnames_global.size ())
179 SCM fields = header->to_alist ();
180 for (int i = 0; i < dump_header_fieldnames_global.size (); i++)
182 String key = dump_header_fieldnames_global[i];
183 SCM val = gh_assoc (ly_symbol2scm (key.ch_C ()), fields);
185 /* Only write header field to file if it exists */
188 s = ly_scm2string (ly_cdr (val));
189 /* Always write header field file, even if string is empty ... */
190 write_header_field_to_file (basename_ , ly_car (val), ly_cdr (val));