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>
14 #include "dimensions.hh"
15 #include "file-name.hh"
16 #include "font-metric.hh"
17 #include "input-smob.hh"
18 #include "lily-guile.hh"
19 #include "lily-version.hh"
20 #include "ly-module.hh"
22 #include "output-def.hh"
23 #include "paper-book.hh"
24 #include "paper-outputter.hh"
25 #include "paper-system.hh"
26 #include "scm-hash.hh"
28 #include "string-convert.hh"
31 #include "ly-smobs.icc"
34 Paper_outputter::Paper_outputter (String filename, String format)
37 output_module_ = SCM_EOL;
41 String module_name = "scm output-" + format;
42 output_module_ = scm_c_resolve_module (module_name.to_str0 ());
45 Paper_outputter::~Paper_outputter ()
50 IMPLEMENT_SMOBS (Paper_outputter);
51 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
54 Paper_outputter::mark_smob (SCM x)
56 Paper_outputter *p = (Paper_outputter*) SCM_CELL_WORD_1(x);
57 scm_gc_mark (p->output_module_);
62 Paper_outputter::print_smob (SCM x, SCM p, scm_print_state*)
65 scm_puts ("#<Paper_outputter>", p);
70 Paper_outputter::file ()
74 file_ = scm_current_output_port();
76 file_ = scm_open_file (scm_makfrom0str (filename_.to_str0 ()),
77 scm_makfrom0str ("w"));
82 Paper_outputter::dump_string (SCM scm)
84 return scm_display (scm, file ());
88 Paper_outputter::scheme_to_string (SCM scm)
90 return scm_eval (scm, output_module_);
94 Paper_outputter::output_scheme (SCM scm)
96 dump_string (scheme_to_string (scm));
100 paper_outputter_dump (void *po, SCM x)
102 Paper_outputter *me = (Paper_outputter*) po;
103 me->output_scheme (x);
107 Paper_outputter::output_stencil (Stencil stil)
109 interpret_stencil_expression (stil.expr (), paper_outputter_dump,
110 (void*) this, Offset (0,0));
114 get_paper_outputter (String outname, String f)
116 progress_indication (_f ("paper output to `%s'...",
117 outname == "-" ? String ("<stdout>") : outname));
118 return new Paper_outputter (outname, f);
121 /* FIXME: why is output_* wrapper called dump? */
122 LY_DEFINE (ly_outputter_dump_stencil, "ly:outputter-dump-stencil",
123 2, 0, 0, (SCM outputter, SCM stencil),
124 "Dump stencil @var{expr} onto @var{outputter}.")
126 Paper_outputter *po = unsmob_outputter (outputter);
127 Stencil *st = unsmob_stencil (stencil);
128 SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
129 SCM_ASSERT_TYPE (st, stencil, SCM_ARG1, __FUNCTION__, "Paper_outputter");
130 po->output_stencil (*st);
131 return SCM_UNSPECIFIED;
134 LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string",
135 2, 0, 0, (SCM outputter, SCM str),
136 "Dump @var{str} onto @var{outputter}.")
138 Paper_outputter *po = unsmob_outputter (outputter);
139 SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
140 SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "Paper_outputter");
142 return po->dump_string (str);
146 Paper_outputter::close ()
148 scm_close_port (file_);