]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
* lily/paper-book.cc: remove copyright & tagline. Remove
[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 #include "array.hh"
14 #include "dimensions.hh"
15 #include "font-metric.hh"
16 #include "input-smob.hh"
17 #include "lily-guile.hh"
18 #include "lily-version.hh"
19 #include "ly-module.hh"
20 #include "main.hh"
21 #include "paper-book.hh"
22 #include "output-def.hh"
23 #include "paper-line.hh"
24 #include "paper-outputter.hh"
25 #include "file-name.hh"
26 #include "scm-hash.hh"
27 #include "stencil.hh"
28 #include "string-convert.hh"
29 #include "warn.hh"
30
31 // JUNKME
32 extern SCM stencil2line (Stencil *stil, bool is_title = false);
33
34 Paper_outputter::Paper_outputter (String filename, String format)
35 {
36   file_ = SCM_EOL;
37   output_module_ = SCM_EOL;
38   smobify_self ();
39   
40   filename_ = filename;
41   file_ = scm_open_file (scm_makfrom0str (filename.to_str0 ()),
42                          scm_makfrom0str ("w"));
43
44   String module_name = "scm output-" + format;
45   output_module_ = scm_c_resolve_module (module_name.to_str0 ());
46 }
47
48 Paper_outputter::~Paper_outputter ()
49 {
50 }
51
52 #include "ly-smobs.icc"
53
54 IMPLEMENT_SMOBS (Paper_outputter);
55 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
56
57 SCM
58 Paper_outputter::mark_smob (SCM x)
59 {
60   Paper_outputter *p = (Paper_outputter*) SCM_CELL_WORD_1(x);
61   scm_gc_mark (p->output_module_);
62   return p->file_;
63 }
64
65 int
66 Paper_outputter::print_smob (SCM x, SCM p, scm_print_state*)
67 {
68   scm_puts ("#<Paper_outputter>", p);
69   return 1;
70 }
71
72 SCM
73 Paper_outputter::dump_string (SCM scm)
74 {
75   return scm_display (scm, file_);
76 }
77
78 SCM
79 Paper_outputter::scheme_to_string (SCM scm)
80 {
81   return scm_eval (scm, output_module_);
82 }
83
84 void
85 Paper_outputter::output_scheme (SCM scm)
86 {
87   dump_string (scheme_to_string (scm));
88 }
89
90 void
91 paper_outputter_dump (void *po, SCM x)
92 {
93   Paper_outputter *me = (Paper_outputter*) po;
94   me->output_scheme (x);
95 }
96
97 void
98 Paper_outputter::output_stencil (Stencil stil)
99 {
100   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
101                                 (void*) this, Offset (0,0));
102 }
103
104 Paper_outputter *
105 get_paper_outputter (String outname, String f) 
106 {
107   progress_indication (_f ("paper output to `%s'...",
108                            outname == "-" ? String ("<stdout>") : outname));
109   return new Paper_outputter (outname, f);
110
111 }
112
113 /* FIXME: why is output_* wrapper called dump?  */
114 LY_DEFINE (ly_outputter_dump_stencil, "ly:outputter-dump-stencil",
115            2, 0, 0, (SCM outputter, SCM stencil),
116            "Dump stencil @var{expr} onto @var{outputter}.")
117 {
118   Paper_outputter *po = unsmob_outputter  (outputter);
119   Stencil *st = unsmob_stencil (stencil);
120   
121   SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
122   SCM_ASSERT_TYPE (st, stencil, SCM_ARG1, __FUNCTION__, "Paper_outputter");
123
124   po->output_stencil (*st);
125
126   return SCM_UNSPECIFIED;
127 }
128
129 LY_DEFINE (ly_outputter_dump_string, "ly:outputter-dump-string",
130            2, 0, 0, (SCM outputter, SCM str),
131            "Dump @var{str} onto @var{outputter}.")
132 {
133   Paper_outputter *po = unsmob_outputter  (outputter);
134   SCM_ASSERT_TYPE (po, outputter, SCM_ARG1, __FUNCTION__, "Paper_outputter");
135   SCM_ASSERT_TYPE (ly_c_string_p (str), str, SCM_ARG1, __FUNCTION__, "Paper_outputter");
136   
137   return po->dump_string (str);
138 }