1 /* 2 This file is part of LilyPond, the GNU music typesetter. 3 4 Copyright (C) 2005--2020 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 @code{port}. @code{alist} should map " 31 "symbols to procedures. See @code{output-ps.scm} for an example. " 32 "If @code{default_callback} is given, it is called for unsupported " 33 "expressions") 34 { 35 LY_ASSERT_TYPE (ly_is_port, port, 1); 36 LY_ASSERT_TYPE (ly_cheap_is_list, alist, 2); 37 if (default_callback != SCM_UNDEFINED && !ly_is_procedure (default_callback)) 38 { 39 scm_wrong_type_arg_msg (mangle_cxx_identifier (__FUNCTION__).c_str (), 3, 40 default_callback, "procedure"); 41 } 42 43 Paper_outputter *po = new Paper_outputter (port, alist, default_callback); 44 45 po->unprotect (); 46 return po->self_scm (); 47 } 48 49 LY_DEFINE (ly_outputter_dump_stencil, "ly:outputter-dump-stencil", 50 2, 0, 0, (SCM outputter, SCM stencil), 51 "Dump stencil @var{expr} onto @var{outputter}.") 52 { 53 54 LY_ASSERT_SMOB (Paper_outputter, outputter, 1); 55 LY_ASSERT_SMOB (Stencil, stencil, 2); 56 57 Paper_outputter *po = unsmob<Paper_outputter> (outputter); 58 Stencil *st = unsmob<Stencil> (stencil); 59 60 po->output_stencil (*st); 61 return SCM_UNSPECIFIED; 62 } 63 64 LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string", 65 2, 0, 0, (SCM outputter, SCM str), 66 "Dump @var{str} onto @var{outputter}.") 67 { 68 LY_ASSERT_SMOB (Paper_outputter, outputter, 1); 69 LY_ASSERT_TYPE (scm_is_string, str, 2); 70 71 Paper_outputter *po = unsmob<Paper_outputter> (outputter); 72 73 return po->dump_string (str); 74 } 75 76 LY_DEFINE (ly_outputter_port, "ly:outputter-port", 77 1, 0, 0, (SCM outputter), 78 "Return output port for @var{outputter}.") 79 { 80 LY_ASSERT_SMOB (Paper_outputter, outputter, 1); 81 Paper_outputter *po = unsmob<Paper_outputter> (outputter); 82 83 return po->file (); 84 } 85 86 LY_DEFINE (ly_outputter_close, "ly:outputter-close", 87 1, 0, 0, (SCM outputter), 88 "Close port of @var{outputter}.") 89 { 90 LY_ASSERT_SMOB (Paper_outputter, outputter, 1); 91 Paper_outputter *po = unsmob<Paper_outputter> (outputter); 92 93 po->close (); 94 return SCM_UNSPECIFIED; 95 } 96 97 LY_DEFINE (ly_outputter_output_scheme, "ly:outputter-output-scheme", 2, 0, 0, 98 (SCM outputter, SCM expr), 99 "Output @var{expr} to the paper outputter.") 100 { 101 LY_ASSERT_SMOB (Paper_outputter, outputter, 1); 102 Paper_outputter *po = unsmob<Paper_outputter> (outputter); 103 104 po->output_scheme (expr); 105 106 return SCM_UNSPECIFIED; 107 } 108