2 paper-outputter.cc -- implement Paper_outputter
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 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"
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-module.hh"
29 #include "input-smob.hh" // output_expr
32 Paper_outputter::Paper_outputter (String name)
36 gh_define ("security-paranoia", SCM_BOOL_T);
39 file_ = scm_open_file (scm_makfrom0str (name.to_str0 ()),
40 scm_makfrom0str ("w"));
42 static SCM find_dumper;
44 find_dumper = scm_c_eval_string ("find-dumper");
47 output_func_ = scm_call_1 (find_dumper,scm_makfrom0str (output_format_global.to_str0 ()));
48 output_scheme (gh_cons (ly_symbol2scm ("top-of-file"), SCM_EOL));
51 Paper_outputter::~Paper_outputter ()
53 scm_close_port (file_);
58 Paper_outputter::output_scheme (SCM scm)
60 gh_call2 (output_func_, scm, file_);
64 Paper_outputter::output_metadata (SCM scopes, Paper_def *paper)
67 for (int i = dump_header_fieldnames_global.size (); i--; )
69 = gh_cons (ly_symbol2scm (dump_header_fieldnames_global[i].to_str0 ()),
71 output_scheme (scm_list_n (ly_symbol2scm ("output-scopes"),
73 scm_list_n (ly_symbol2scm ("quote"),
74 scopes, SCM_UNDEFINED),
75 scm_list_n (ly_symbol2scm ("quote"),
76 fields, SCM_UNDEFINED),
77 scm_makfrom0str (basename_.to_str0 ()),
82 Paper_outputter::output_header (Paper_def *paper)
84 output_music_output_def (paper);
85 output_scheme (scm_list_1 (ly_symbol2scm ("header-end")));
86 output_scheme (scm_list_2 (ly_symbol2scm ("define-fonts"),
87 ly_quote_scm (paper->font_descriptions ())));
91 Paper_outputter::output_line (SCM line, bool is_last)
93 Offset dim = ly_scm2offset (ly_car (line));
94 Real width = dim[X_AXIS];
95 Real height = dim[Y_AXIS];
99 programming_error ("Improbable system height.");
103 output_scheme (scm_list_3 (ly_symbol2scm ("start-system"),
104 gh_double2scm (width), gh_double2scm (height)));
106 for (SCM s = ly_cdr (line); gh_pair_p (s); s = ly_cdr (s))
108 Stencil *stil = unsmob_stencil (ly_cdar (s));
109 output_expr (stil->get_expr (), ly_scm2offset (ly_caar (s)));
113 output_scheme (scm_list_1 (ly_symbol2scm ("stop-last-system")));
115 output_scheme (scm_list_1 (ly_symbol2scm ("stop-system")));
119 Paper_outputter::output_music_output_def (Music_output_def* odef)
121 output_scheme (scm_list_n (ly_symbol2scm ("output-paper-def"),
122 odef->self_scm (), SCM_UNDEFINED));
125 /* TODO: replaceme/rewriteme, see output-ps.scm: output-stencil */
127 Paper_outputter::output_expr (SCM expr, Offset o)
131 if (!gh_pair_p (expr))
134 SCM head =ly_car (expr);
135 if (unsmob_input (head))
137 Input * ip = unsmob_input (head);
139 output_scheme (scm_list_n (ly_symbol2scm ("define-origin"),
140 scm_makfrom0str (ip->file_string ().to_str0 ()),
141 gh_int2scm (ip->line_number ()),
142 gh_int2scm (ip->column_number ()),
144 expr = ly_cadr (expr);
146 else if (head == ly_symbol2scm ("no-origin"))
148 output_scheme (scm_list_n (head, SCM_UNDEFINED));
149 expr = ly_cadr (expr);
151 else if (head == ly_symbol2scm ("translate-stencil"))
153 o += ly_scm2offset (ly_cadr (expr));
154 expr = ly_caddr (expr);
156 else if (head == ly_symbol2scm ("combine-stencil"))
158 output_expr (ly_cadr (expr), o);
159 expr = ly_caddr (expr);
163 output_scheme (scm_list_n (ly_symbol2scm ("placebox"),
164 gh_double2scm (o[X_AXIS]),
165 gh_double2scm (o[Y_AXIS]),