]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
Web-ja: update introduction
[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 Paper_outputter::Paper_outputter (SCM port, const string &format)
44 {
45   file_ = port;
46   output_module_ = SCM_EOL;
47   smobify_self ();
48
49   string module_name = "scm output-" + format;
50   output_module_ = scm_c_resolve_module (module_name.c_str ());
51
52   /*
53     Enable errors for undefined stencil routines if
54      -dwarning-as-error is specified; else enable warnings.
55   */
56   Lily::backend_testing (output_module_);
57 }
58
59 Paper_outputter::~Paper_outputter ()
60 {
61 }
62
63
64 SCM
65 Paper_outputter::mark_smob () const
66 {
67   scm_gc_mark (output_module_);
68   return file_;
69 }
70
71 SCM
72 Paper_outputter::file () const
73 {
74   return file_;
75 }
76
77 SCM
78 Paper_outputter::dump_string (SCM scm)
79 {
80   return scm_display (scm, file ());
81 }
82
83 SCM
84 Paper_outputter::scheme_to_string (SCM scm)
85 {
86   return scm_eval (scm, output_module_);
87 }
88
89 SCM
90 Paper_outputter::module () const
91 {
92   return output_module_;
93 }
94
95 SCM
96 Paper_outputter::output_scheme (SCM scm)
97 {
98   SCM str = scheme_to_string (scm);
99   if (scm_is_string (str))
100     dump_string (str);
101   return str;
102 }
103
104 SCM
105 paper_outputter_dump (void *po, SCM x)
106 {
107   Paper_outputter *me = (Paper_outputter *) po;
108   return me->output_scheme (x);
109 }
110
111 void
112 Paper_outputter::output_stencil (Stencil stil)
113 {
114   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
115                                 (void *) this, Offset (0, 0));
116 }
117
118 void
119 Paper_outputter::close ()
120 {
121   if (ly_is_port (file_))
122     {
123       scm_close_port (file_);
124       /*
125         Remove the "warning" definitions for missing stencil
126         expressions so that we start fresh with the next \book
127         block.  --pmccarty
128       */
129       Lily::remove_stencil_warnings (output_module_);
130     }
131 }