2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
13 #include "dimensions.hh"
14 #include "virtual-methods.hh"
15 #include "paper-outputter.hh"
16 #include "molecule.hh"
18 #include "string-convert.hh"
20 #include "font-metric.hh"
22 #include "scm-hash.hh"
23 #include "lily-version.hh"
24 #include "paper-def.hh"
25 #include "input-file-results.hh"
26 #include "ly-modules.hh"
33 Paper_outputter::Paper_outputter (String name
)
37 gh_define ("security-paranoia", SCM_BOOL_T
);
40 file_
= scm_open_file (scm_makfrom0str (name
.to_str0 ()),
41 scm_makfrom0str ("w"));
46 SCM exp
= scm_list_n (ly_symbol2scm ("find-dumper"),
47 scm_makfrom0str (output_format_global
.to_str0 ()),
50 output_func_
= scm_primitive_eval (exp
);
53 Paper_outputter::~Paper_outputter ()
55 scm_close_port (file_
);
61 Paper_outputter::output_header ()
64 String generate
= ctime (&t
);
65 generate
= generate
.left_string (generate
.length () - 1) + " " + *tzname
;
67 /* Fixed length time stamp */
68 generate
= generate
+ to_string (' ', (50 - generate
.length ()) >? 0);
70 /* Fixed length creator string */
71 String creator
= gnu_lilypond_version_string ();
72 creator
+= " (http://lilypond.org)";
73 creator
= creator
+ to_string (' ', (50 - creator
.length ()) >? 0);
75 SCM args_scm
= scm_list_n (scm_makfrom0str (creator
.to_str0 ()),
76 scm_makfrom0str (generate
.to_str0 ()),
80 SCM scm
= gh_cons (ly_symbol2scm ("header"), args_scm
);
88 Paper_outputter::output_comment (String str
)
90 output_scheme (scm_list_n (ly_symbol2scm ("comment"),
91 scm_makfrom0str ((char*)str
.to_str0 ()),
97 Paper_outputter::output_scheme (SCM scm
)
99 gh_call2 (output_func_
, scm
, file_
);
103 Paper_outputter::output_scope (SCM mod
, String prefix
)
105 if (!SCM_MODULEP (mod
))
108 SCM al
= ly_module_to_alist (mod
);
109 for (SCM s
= al
; gh_pair_p (s
); s
= ly_cdr (s
))
113 String s
= ly_symbol2string (k
);
117 output_String_def (prefix
+ s
, ly_scm2string (v
));
119 else if (scm_exact_p (v
) == SCM_BOOL_T
)
121 output_int_def (prefix
+ s
, gh_scm2int (v
));
123 else if (gh_number_p (v
))
125 output_Real_def (prefix
+ s
, gh_scm2double (v
));
131 Paper_outputter::output_version ()
133 String id_string
= "Lily was here";
134 id_string
+= String_convert::pad_to (String (", ") + version_string (), 40);
136 output_String_def ("lilypondtagline", id_string
);
137 output_String_def ("LilyPondVersion", version_string ());
138 output_String_def ("lilypondpaperunit", String (INTERNAL_UNIT
));
143 Paper_outputter::output_Real_def (String k
, Real v
)
146 SCM scm
= scm_list_n (ly_symbol2scm ("lily-def"),
147 scm_makfrom0str (k
.get_str0 ()),
148 scm_makfrom0str (to_string (v
).get_str0 ()),
154 Paper_outputter::output_String_def (String k
, String v
)
157 SCM scm
= scm_list_n (ly_symbol2scm ("lily-def"),
158 scm_makfrom0str (k
.get_str0 ()),
159 scm_makfrom0str (v
.get_str0 ()),
165 Paper_outputter::output_int_def (String k
, int v
)
167 SCM scm
= scm_list_n (ly_symbol2scm ("lily-def"),
168 scm_makfrom0str (k
.get_str0 ()),
169 scm_makfrom0str (to_string (v
).get_str0 ()),
175 Paper_outputter::write_header_field_to_file (String filename
, SCM key
, SCM value
)
177 output_scheme (scm_list_n (ly_symbol2scm ("header-to-file"),
178 scm_makfrom0str (filename
.to_str0 ()),
179 ly_quote_scm (key
), value
,
184 Paper_outputter::write_header_fields_to_file (SCM mod
)
186 if (ly_module_p (mod
)&&
187 dump_header_fieldnames_global
.size ())
189 SCM fields
= ly_module_to_alist (mod
);
190 for (int i
= 0; i
< dump_header_fieldnames_global
.size (); i
++)
192 String key
= dump_header_fieldnames_global
[i
];
193 SCM val
= gh_assoc (ly_symbol2scm (key
.to_str0 ()), fields
);
195 /* Only write header field to file if it exists */
198 s
= ly_scm2string (ly_cdr (val
));
199 /* Always write header field file, even if string is empty ... */
200 write_header_field_to_file (basename_
, ly_car (val
), ly_cdr (val
));