]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
Merge commit 'origin/lilypond/translation'
[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--2009 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     Enable errors for undefined stencil routines if
43      -dwarning-as-error is specified; else enable warnings.
44   */
45   SCM proc = ly_lily_module_constant ("backend-testing");
46   scm_call_1 (proc, output_module_);
47 }
48
49 Paper_outputter::~Paper_outputter ()
50 {
51 }
52
53 IMPLEMENT_SMOBS (Paper_outputter);
54 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
55
56 SCM
57 Paper_outputter::mark_smob (SCM x)
58 {
59   Paper_outputter *p = (Paper_outputter *) SCM_CELL_WORD_1 (x);
60   scm_gc_mark (p->output_module_);
61   return p->file_;
62 }
63
64 int
65 Paper_outputter::print_smob (SCM /* x */,
66                              SCM p,
67                              scm_print_state *)
68 {
69   scm_puts ("#<Paper_outputter>", p);
70   return 1;
71 }
72
73 SCM
74 Paper_outputter::file () const
75 {
76   return file_;
77 }
78
79 SCM
80 Paper_outputter::dump_string (SCM scm)
81 {
82   return scm_display (scm, file ());
83 }
84
85 SCM
86 Paper_outputter::scheme_to_string (SCM scm)
87 {
88   return scm_eval (scm, output_module_);
89 }
90
91 void
92 Paper_outputter::output_scheme (SCM scm)
93 {
94   dump_string (scheme_to_string (scm));
95 }
96
97 void
98 paper_outputter_dump (void *po, SCM x)
99 {
100   Paper_outputter *me = (Paper_outputter *) po;
101   me->output_scheme (x);
102 }
103
104 void
105 Paper_outputter::output_stencil (Stencil stil)
106 {
107   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
108                                 (void *) this, Offset (0, 0));
109 }
110
111 void
112 Paper_outputter::close ()
113 {
114   if (scm_port_p (file_) == SCM_BOOL_T)
115     {
116       scm_close_port (file_);
117       /*
118         Remove the "warning" definitions for missing stencil
119         expressions so that we start fresh with the next \book
120         block.  --pmccarty
121       */
122       SCM proc = ly_lily_module_constant ("remove-stencil-warnings");
123       scm_call_1 (proc, output_module_);
124     }
125 }