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>
10 #include "paper-outputter.hh"
15 #include "dimensions.hh"
16 #include "file-name.hh"
17 #include "font-metric.hh"
18 #include "input-smob.hh"
19 #include "lily-version.hh"
20 #include "ly-module.hh"
22 #include "output-def.hh"
23 #include "paper-book.hh"
24 #include "paper-system.hh"
25 #include "scm-hash.hh"
26 #include "string-convert.hh"
29 #include "ly-smobs.icc"
31 Paper_outputter::Paper_outputter (String file_name, String format)
34 output_module_ = SCM_EOL;
37 file_name_ = file_name;
38 String module_name = "scm output-" + format;
39 output_module_ = scm_c_resolve_module (module_name.to_str0 ());
42 Paper_outputter::~Paper_outputter ()
47 IMPLEMENT_SMOBS (Paper_outputter);
48 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
51 Paper_outputter::mark_smob (SCM x)
53 Paper_outputter *p = (Paper_outputter*) SCM_CELL_WORD_1(x);
54 scm_gc_mark (p->output_module_);
59 Paper_outputter::print_smob (SCM x, SCM p, scm_print_state*)
62 scm_puts ("#<Paper_outputter>", p);
67 Paper_outputter::file ()
70 if (file_name_ == "-")
71 file_ = scm_current_output_port();
73 file_ = scm_open_file (scm_makfrom0str (file_name_.to_str0 ()),
74 scm_makfrom0str ("w"));
79 Paper_outputter::dump_string (SCM scm)
81 return scm_display (scm, file ());
85 Paper_outputter::scheme_to_string (SCM scm)
87 return scm_eval (scm, output_module_);
91 Paper_outputter::output_scheme (SCM scm)
93 dump_string (scheme_to_string (scm));
97 paper_outputter_dump (void *po, SCM x)
99 Paper_outputter *me = (Paper_outputter*) po;
100 me->output_scheme (x);
104 Paper_outputter::output_stencil (Stencil stil)
106 interpret_stencil_expression (stil.expr (), paper_outputter_dump,
107 (void*) this, Offset (0,0));
111 get_paper_outputter (String outname, String f)
113 progress_indication (_f ("Layout output to `%s'...",
114 outname == "-" ? String ("<stdout>") : outname));
115 progress_indication ("\n");
116 return new Paper_outputter (outname, f);
119 /* FIXME: why is output_* wrapper called dump? */
120 LY_DEFINE (ly_outputter_dump_stencil, "ly:outputter-dump-stencil",
121 2, 0, 0, (SCM outputter, SCM stencil),
122 "Dump stencil @var{expr} onto @var{outputter}.")
124 Paper_outputter *po = unsmob_outputter (outputter);
125 Stencil *st = unsmob_stencil (stencil);
126 SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
127 SCM_ASSERT_TYPE (st, stencil, SCM_ARG1, __FUNCTION__, "Paper_outputter");
128 po->output_stencil (*st);
129 return SCM_UNSPECIFIED;
132 LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string",
133 2, 0, 0, (SCM outputter, SCM str),
134 "Dump @var{str} onto @var{outputter}.")
136 Paper_outputter *po = unsmob_outputter (outputter);
137 SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
138 SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "Paper_outputter");
140 return po->dump_string (str);
144 Paper_outputter::close ()
146 if (scm_port_p (file_) == SCM_BOOL_T)
147 scm_close_port (file_);