]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
Updates to fret-diagrams
[lilypond.git] / lily / paper-outputter.cc
1 /*
2   paper-outputter.cc -- implement Paper_outputter
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "paper-outputter.hh"
11
12 #include <cmath>
13 #include <ctime>
14
15 using namespace std;
16
17 #include "dimensions.hh"
18 #include "file-name.hh"
19 #include "font-metric.hh"
20 #include "input.hh"
21 #include "lily-version.hh"
22 #include "main.hh"
23 #include "output-def.hh"
24 #include "paper-book.hh"
25 #include "paper-system.hh"
26 #include "scm-hash.hh"
27 #include "string-convert.hh"
28 #include "warn.hh"
29
30 #include "ly-smobs.icc"
31
32 Paper_outputter::Paper_outputter (SCM port, string format)
33 {
34   file_ = port;
35   output_module_ = SCM_EOL;
36   smobify_self ();
37
38   string module_name = "scm output-" + format;
39   output_module_ = scm_c_resolve_module (module_name.c_str ());
40 }
41
42 Paper_outputter::~Paper_outputter ()
43 {
44 }
45
46 IMPLEMENT_SMOBS (Paper_outputter);
47 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
48
49 SCM
50 Paper_outputter::mark_smob (SCM x)
51 {
52   Paper_outputter *p = (Paper_outputter *) SCM_CELL_WORD_1 (x);
53   scm_gc_mark (p->output_module_);
54   return p->file_;
55 }
56
57 int
58 Paper_outputter::print_smob (SCM /* x */,
59                              SCM p,
60                              scm_print_state *)
61 {
62   scm_puts ("#<Paper_outputter>", p);
63   return 1;
64 }
65
66 SCM
67 Paper_outputter::file () const
68 {
69   return file_;
70 }
71
72 SCM
73 Paper_outputter::dump_string (SCM scm)
74 {
75   return scm_display (scm, file ());
76 }
77
78 SCM
79 Paper_outputter::scheme_to_string (SCM scm)
80 {
81   return scm_eval (scm, output_module_);
82 }
83
84 void
85 Paper_outputter::output_scheme (SCM scm)
86 {
87   dump_string (scheme_to_string (scm));
88 }
89
90 void
91 paper_outputter_dump (void *po, SCM x)
92 {
93   Paper_outputter *me = (Paper_outputter *) po;
94   me->output_scheme (x);
95 }
96
97 void
98 Paper_outputter::output_stencil (Stencil stil)
99 {
100   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
101                                 (void *) this, Offset (0, 0));
102 }
103
104 void
105 Paper_outputter::close ()
106 {
107   if (scm_port_p (file_) == SCM_BOOL_T)
108     scm_close_port (file_);
109 }