]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
* scm/music-functions.scm (def-grace-function): move macros from
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7                  Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include <math.h>
11 #include <time.h>
12
13
14 #include "array.hh"
15 #include "dimensions.hh"
16 #include "font-metric.hh"
17 #include "input-smob.hh"
18 #include "lily-guile.hh"
19 #include "lily-version.hh"
20 #include "ly-module.hh"
21 #include "main.hh"
22 #include "page.hh"
23 #include "paper-book.hh"
24 #include "output-def.hh"
25 #include "paper-line.hh"
26 #include "paper-outputter.hh"
27 #include "file-name.hh"
28 #include "scm-hash.hh"
29 #include "stencil.hh"
30 #include "string-convert.hh"
31 #include "warn.hh"
32
33 #include "ly-smobs.icc"
34
35 // JUNKME
36 extern SCM stencil2line (Stencil* stil, bool is_title = false);
37
38 Paper_outputter::Paper_outputter (String filename, String format)
39 {
40   file_ = SCM_EOL;
41   output_module_ = SCM_EOL;
42   smobify_self ();
43   
44   filename_ = filename;
45   file_ = scm_open_file (scm_makfrom0str (filename.to_str0 ()),
46                          scm_makfrom0str ("w"));
47
48   String module_name = "scm output-" + format;
49   output_module_ = scm_c_resolve_module (module_name.to_str0 ());
50 }
51
52 Paper_outputter::~Paper_outputter ()
53 {
54 }
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, SCM p, scm_print_state*)
66 {
67   scm_puts ("#<Paper_outputter>", p);
68   return 1;
69 }
70
71
72
73 SCM
74 Paper_outputter::dump_string (SCM scm)
75 {
76   return scm_display (scm,file_);
77 }
78
79 SCM
80 Paper_outputter::scheme_to_string (SCM scm)
81 {
82   return scm_eval (scm, output_module_);
83 }
84
85 void
86 Paper_outputter::output_scheme (SCM scm)
87 {
88   dump_string (scheme_to_string (scm));
89 }
90
91 void
92 paper_outputter_dump (void * po, SCM x)
93 {
94   Paper_outputter * me = (Paper_outputter*) po;
95   me->output_scheme (x);
96 }
97
98
99 void
100 Paper_outputter::output_stencil (Stencil stil)
101 {
102   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
103                                 (void*) this, Offset (0,0));
104 }
105
106 Paper_outputter*
107 get_paper_outputter (String outname, String f) 
108 {
109   progress_indication (_f ("paper output to `%s'...",
110                            outname == "-" ? String ("<stdout>") : outname));
111   return new Paper_outputter (outname, f);
112
113 }
114
115 IMPLEMENT_SMOBS(Paper_outputter);
116 IMPLEMENT_DEFAULT_EQUAL_P(Paper_outputter);
117
118 LY_DEFINE(ly_outputter_dump_string, "ly:outputter-dump-stencil",
119           2, 0,0, (SCM outputter, SCM stencil),
120           "Dump stencil @var{expr} onto @var{outputter}."
121           )
122 {
123   Paper_outputter* po = unsmob_outputter  (outputter);
124   Stencil *st = unsmob_stencil (stencil);
125   
126   SCM_ASSERT_TYPE(po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
127   SCM_ASSERT_TYPE(st, stencil, SCM_ARG1, __FUNCTION__, "Paper_outputter");
128
129   po->output_stencil (*st);
130
131   return SCM_UNSPECIFIED;
132 }
133
134
135 LY_DEFINE(ly_outputter_dump_stencil, "ly:outputter-dump-string",
136           2, 0, 0, (SCM outputter, SCM str),
137           "Dump @var{str} onto @var{outputter}.")
138 {
139   Paper_outputter* po = unsmob_outputter  (outputter);
140   SCM_ASSERT_TYPE(po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
141   SCM_ASSERT_TYPE(ly_c_string_p (str), str, SCM_ARG1, __FUNCTION__, "Paper_outputter");
142
143   return po->dump_string (str);
144   return SCM_UNSPECIFIED;
145 }