]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
release: 1.1.1
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include <time.h>
11 #include "paper-outputter.hh"
12 #include "paper-stream.hh"
13 #include "molecule.hh"
14 #include "atom.hh"
15 #include "array.hh"
16 #include "string-convert.hh"
17 #include "debug.hh"
18 #include "lookup.hh"
19 #include "main.hh"
20
21 Paper_outputter::Paper_outputter (Paper_stream *s)
22 {
23   outstream_l_ = s;
24   output_header ();
25 }
26
27 Paper_outputter::~Paper_outputter ()
28 {
29   SCM scm =
30     ly_append (ly_lambda_o (),
31     ly_list1 (ly_append (ly_func_o ("end-output"), SCM_EOL)));
32
33   output_scheme (scm);
34 }
35
36 void
37 Paper_outputter::output_header ()
38 {
39   String creator;
40   if (no_timestamps_global_b)
41     creator = "GNU LilyPond\n";
42   else
43     creator = get_version_str ();
44   String generate;
45   if (no_timestamps_global_b)
46     generate = ".";
47   else
48     {
49       generate = _ (", at ");
50       time_t t (time (0));
51       generate += ctime (&t);
52       //urg
53     }
54
55   SCM args_scm = 
56     gh_cons (gh_str02scm (creator.ch_l ()),
57     gh_cons (gh_str02scm (generate.ch_l ()), SCM_EOL));
58
59 #ifndef NPRINT
60   DOUT << "output_header\n";
61   if (check_debug && !monitor->silent_b ("Guile"))
62     {
63       gh_display (args_scm); gh_newline ();
64     }
65 #endif
66
67   SCM scm =
68     ly_append (ly_lambda_o (),
69     ly_list1 (ly_append (ly_func_o ("header"), args_scm)));
70
71   output_scheme (scm);
72 }
73
74 void
75 Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
76 {
77   if (check_debug)
78     *outstream_l_ << String ("\n%start: ") << nm << "\n";
79
80   for (PCursor <Atom*> i (m->atoms_); i.ok (); i++)
81     {
82       Offset a_off = i->offset ();
83       a_off += o;
84
85       if (!i->lambda_)
86         {
87           // urg
88           i->lambda_ = ly_append (ly_lambda_o (), 
89             ly_list1 (ly_func_o ("empty")));
90         }
91
92       switch_to_font (i->font_);
93
94 #ifndef NPRINT
95       if (check_debug && !monitor->silent_b ("Guile"))
96         {
97           gh_display (i->lambda_); gh_newline ();
98         }
99 #endif
100
101       SCM args_scm = 
102         gh_cons (gh_double2scm (a_off.x ()), 
103         gh_cons (gh_double2scm (a_off.y ()), 
104         gh_cons (i->lambda_, SCM_EOL)));
105
106 #ifndef NPRINT
107       if (check_debug && !monitor->silent_b ("Guile"))
108         {
109           gh_display (args_scm); gh_newline ();
110         }
111 #endif
112
113       SCM box_scm =
114         ly_append (ly_lambda_o (),
115         ly_list1 (ly_append (ly_func_o ("placebox"), args_scm)));
116
117       output_scheme (box_scm);
118     }
119 }
120
121 void
122 Paper_outputter::output_comment (String str)
123 {
124   // urg
125   *outstream_l_ << "% " << str << "\n";
126 }
127
128
129 void
130 Paper_outputter::output_scheme (SCM scm)
131 {
132   String o = String ("\'") + output_global_ch;
133 #ifndef NPRINT
134   if (check_debug && !monitor->silent_b ("Guile"))
135     {
136       gh_display (scm); gh_newline ();
137     }
138 #endif
139   // urg; temporary hack to debug scheme error #unknown
140   if (String (output_global_ch) == "scm")
141     {
142 //      char* c = gh_scm2newstr (scm, NULL);
143 //      *outstream_l_ << c << "\n";
144 //      free (c);
145         gh_display (scm); gh_newline ();
146       return;
147     }
148   SCM str_scm = gh_call1 (ly_eval (scm), gh_eval_str (o.ch_l ()));
149   char* c = gh_scm2newstr (str_scm, NULL);
150 #ifndef NPRINT
151   if (check_debug && !monitor->silent_b ("Guile"))
152     {
153       gh_display (str_scm); gh_newline ();
154     }
155 #endif
156   *outstream_l_ << c;
157   free (c);
158 }
159
160 void
161 Paper_outputter::output_string (String str)
162 {
163   // urg
164   *outstream_l_ << str;
165 }
166
167 void
168 Paper_outputter::switch_to_font (String fontname)
169 {
170   if (fontname.length_i () && (fontname != current_font_))
171     {
172       current_font_ = fontname;
173       int i=0;
174       bool new_b = false;
175       for (; i< font_arr_.size (); i++)
176         if (font_arr_[i] == fontname)
177           {
178             new_b = true;
179             break;
180           }
181
182       if (new_b)
183         {
184           font_arr_.push (fontname);
185           output_font_def (i, fontname);
186         }
187       output_font_switch (i);
188     }
189   return;
190 }
191
192 void
193 Paper_outputter::start_line ()
194 {
195   SCM scm =
196     ly_append (ly_lambda_o (),
197     ly_list1 (ly_append (ly_func_o ("start-line"), SCM_EOL)));
198
199   output_scheme (scm);
200 }
201
202 /*
203    26 fonts ought to be enough for anyone.
204 */
205 void
206 Paper_outputter::output_font_def (int i, String str)
207 {
208   //urg, broken with guile-1.3
209   //return;
210   SCM scm =
211     ly_append (ly_lambda_o (),
212     ly_list1 (ly_append (ly_func_o ("font-def"), 
213     gh_cons (gh_int2scm (i), gh_cons (gh_str02scm (str.ch_l ()), SCM_EOL)))));
214
215   output_scheme (scm);
216 }
217
218 void
219 Paper_outputter::output_font_switch (int i)
220 {
221   //urg, broken with guile-1.2, 1.3
222   //return;
223   SCM scm =
224     ly_append (ly_lambda_o (),
225     ly_list1 (ly_append (ly_func_o ("font-switch"), 
226     gh_cons (gh_int2scm (i), SCM_EOL))));
227
228   output_scheme (scm);
229 }
230
231 void
232 Paper_outputter::stop_line ()
233 {
234   SCM scm =
235     ly_append (ly_lambda_o (),
236     ly_list1 (ly_append (ly_func_o ("stop-line"), SCM_EOL)));
237
238   output_scheme (scm);
239
240   current_font_ = "";
241   font_arr_.clear ();
242 }