1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3 
4   Copyright (C) 2005--2021 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10 
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15 
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "paper-outputter.hh"
21 
22 #include "international.hh"
23 #include "stencil.hh"
24 #include "warn.hh"
25 
26 using std::string;
27 
28 LY_DEFINE (ly_make_paper_outputter, "ly:make-paper-outputter", 2, 1, 0,
29            (SCM port, SCM alist, SCM default_callback),
30            "Create an outputter dumping to @var{port}.  @var{alist} should map"
31            " symbols to procedures.  See file @file{output-ps.scm} for an"
32            " example.  If @var{default-callback} is given, it is called for"
33            " unsupported expressions.")
34 {
35   LY_ASSERT_TYPE (ly_is_port, port, 1);
36   LY_ASSERT_TYPE (ly_cheap_is_list, alist, 2);
37   if (!SCM_UNBNDP (default_callback))
38     LY_ASSERT_TYPE (ly_is_procedure, default_callback, 3);
39 
40   Paper_outputter *po = new Paper_outputter (port, alist, default_callback);
41 
42   po->unprotect ();
43   return po->self_scm ();
44 }
45 
46 LY_DEFINE (ly_outputter_dump_stencil, "ly:outputter-dump-stencil",
47            2, 0, 0, (SCM outputter, SCM stencil),
48            "Dump stencil @var{expr} onto @var{outputter}.")
49 {
50 
51   auto *const po = LY_ASSERT_SMOB (Paper_outputter, outputter, 1);
52   auto *const st = LY_ASSERT_SMOB (const Stencil, stencil, 2);
53 
54   po->output_stencil (*st);
55   return SCM_UNSPECIFIED;
56 }
57 
58 LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string",
59            2, 0, 0, (SCM outputter, SCM str),
60            "Dump @var{str} onto @var{outputter}.")
61 {
62   auto *const po = LY_ASSERT_SMOB (Paper_outputter, outputter, 1);
63   LY_ASSERT_TYPE (scm_is_string, str, 2);
64 
65   return po->dump_string (str);
66 }
67 
68 LY_DEFINE (ly_outputter_port, "ly:outputter-port",
69            1, 0, 0, (SCM outputter),
70            "Return output port for @var{outputter}.")
71 {
72   auto *const po = LY_ASSERT_SMOB (Paper_outputter, outputter, 1);
73 
74   return po->file ();
75 }
76 
77 LY_DEFINE (ly_outputter_close, "ly:outputter-close",
78            1, 0, 0, (SCM outputter),
79            "Close port of @var{outputter}.")
80 {
81   auto *const po = LY_ASSERT_SMOB (Paper_outputter, outputter, 1);
82 
83   po->close ();
84   return SCM_UNSPECIFIED;
85 }
86 
87 LY_DEFINE (ly_outputter_output_scheme, "ly:outputter-output-scheme", 2, 0, 0,
88            (SCM outputter, SCM expr),
89            "Output @var{expr} to the paper outputter.")
90 {
91   auto *const po = LY_ASSERT_SMOB (Paper_outputter, outputter, 1);
92 
93   po->output_scheme (expr);
94 
95   return SCM_UNSPECIFIED;
96 }
97