]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
Doc: CG - Re-organize information about 'Patches'
[lilypond.git] / lily / paper-outputter.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5   Jan Nieuwenhuizen <janneke@gnu.org>
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "paper-outputter.hh"
22
23 #include <cmath>
24 #include <ctime>
25
26 using namespace std;
27
28 #include "dimensions.hh"
29 #include "file-name.hh"
30 #include "font-metric.hh"
31 #include "input.hh"
32 #include "lily-version.hh"
33 #include "main.hh"
34 #include "output-def.hh"
35 #include "paper-book.hh"
36 #include "paper-system.hh"
37 #include "scm-hash.hh"
38 #include "string-convert.hh"
39 #include "warn.hh"
40 #include "lily-imports.hh"
41
42
43 const char * const Paper_outputter::type_p_name_ = 0;
44
45 Paper_outputter::Paper_outputter (SCM port, const string &format)
46 {
47   file_ = port;
48   output_module_ = SCM_EOL;
49   smobify_self ();
50
51   string module_name = "scm output-" + format;
52   output_module_ = scm_c_resolve_module (module_name.c_str ());
53
54   /*
55     Enable errors for undefined stencil routines if
56      -dwarning-as-error is specified; else enable warnings.
57   */
58   Lily::backend_testing (output_module_);
59 }
60
61 Paper_outputter::~Paper_outputter ()
62 {
63 }
64
65
66 SCM
67 Paper_outputter::mark_smob () const
68 {
69   scm_gc_mark (output_module_);
70   return file_;
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 SCM
92 Paper_outputter::module () const
93 {
94   return output_module_;
95 }
96
97 SCM
98 Paper_outputter::output_scheme (SCM scm)
99 {
100   SCM str = scheme_to_string (scm);
101   if (scm_is_string (str))
102     dump_string (str);
103   return str;
104 }
105
106 SCM
107 paper_outputter_dump (void *po, SCM x)
108 {
109   Paper_outputter *me = (Paper_outputter *) po;
110   return me->output_scheme (x);
111 }
112
113 void
114 Paper_outputter::output_stencil (Stencil stil)
115 {
116   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
117                                 (void *) this, Offset (0, 0));
118 }
119
120 void
121 Paper_outputter::close ()
122 {
123   if (ly_is_port (file_))
124     {
125       scm_close_port (file_);
126       /*
127         Remove the "warning" definitions for missing stencil
128         expressions so that we start fresh with the next \book
129         block.  --pmccarty
130       */
131       Lily::remove_stencil_warnings (output_module_);
132     }
133 }