]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 1.3.61
[lilypond.git] / lily / paper-def.cc
1 /*
2   paper-def.cc -- implement Paper_def
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <math.h>
10
11 #include "all-font-metrics.hh"
12 #include "string.hh"
13 #include "misc.hh"
14 #include "paper-def.hh"
15 #include "debug.hh"
16 #include "lookup.hh"
17 #include "score-engraver.hh"
18 #include "paper-score.hh"
19 #include "identifier.hh"
20 #include "main.hh"
21 #include "scope.hh"
22 #include "file-results.hh" // urg? header_global_p
23 #include "paper-outputter.hh"
24 #include "paper-stream.hh"
25
26
27 Paper_def::Paper_def ()
28 {
29   lookup_p_tab_p_ = new map<int, Lookup*>;
30 }
31
32
33 Paper_def::~Paper_def ()
34 {
35   for (map<int,Lookup*>::const_iterator ai = lookup_p_tab_p_->begin();
36        ai != lookup_p_tab_p_->end (); ai++)
37     {
38       delete (*ai).second;
39     }
40   
41   delete lookup_p_tab_p_;
42 }
43
44 Paper_def::Paper_def (Paper_def const&s)
45   : Music_output_def (s)
46 {
47   lookup_p_tab_p_ = new map<int, Lookup*>;
48   
49   for (map<int,Lookup*>::const_iterator ai = s.lookup_p_tab_p_->begin();
50        ai != s.lookup_p_tab_p_->end (); ai++)
51     {
52       Lookup * l = new Lookup (* (*ai).second);
53       set_lookup ((*ai).first, l);      
54     }
55 }
56
57
58 Real
59 Paper_def::get_var (String s) const
60 {
61   return get_realvar (ly_symbol2scm (s.ch_C()));
62 }
63
64 SCM
65 Paper_def::get_scmvar (String s) const
66 {
67   return  scope_p_->scm_elem (ly_symbol2scm (s.ch_C()));
68 }
69
70 Real
71 Paper_def::get_realvar (SCM s) const
72 {
73   if (!scope_p_->elem_b (s))
74     {
75       programming_error ("unknown paper variable: " +  ly_symbol2string (s));
76       return 0.0;
77     }
78   SCM val = scope_p_->scm_elem (s);
79   if (gh_number_p (val))
80     {
81       return gh_scm2double (val);
82     }
83   else
84     {
85       non_fatal_error (_("not a real variable"));
86       return 0.0;
87     }
88 }
89
90 /*
91   FIXME. This is broken until we have a generic way of
92   putting lists inside the \paper block.
93  */
94 Interval
95 Paper_def::line_dimensions_int (int n) const
96 {
97   Real lw =  get_var ("linewidth");
98   Real ind = n? 0.0:get_var ("indent");
99
100   return Interval (ind, lw);
101 }
102
103 void
104 Paper_def::set_lookup (int i, Lookup*l)
105 {
106   map<int,Lookup*> :: const_iterator it (lookup_p_tab_p_->find (i));
107   if (it != lookup_p_tab_p_->end ())
108     {
109       delete (*it).second;
110     }
111   (*lookup_p_tab_p_)[i] = l;
112 }
113
114
115 /*
116   junkme.
117  */
118 Real
119 Paper_def::interbeam_f (int multiplicity_i) const
120 {
121   if (multiplicity_i <= 3)
122     return get_var ("interbeam");
123   else
124     return get_var ("interbeam4");
125 }
126
127
128 void
129 Paper_def::print () const
130 {
131 #ifndef NPRINT
132   Music_output_def::print ();
133   DEBUG_OUT << "Paper {";
134   for (map<int,Lookup*>::const_iterator ai = lookup_p_tab_p_->begin();
135        ai != lookup_p_tab_p_->end (); ai++)
136     {
137       DEBUG_OUT << "Lookup: " << (*ai).first
138                 << " = " << (*ai).second->font_name_ << '\n';
139     }
140   DEBUG_OUT << "}\n";
141 #endif
142 }
143
144 Lookup const *
145 Paper_def::lookup_l (int i) const
146 {
147   return (*lookup_p_tab_p_)[i];
148 }
149
150
151
152 int Paper_def::default_count_i_ = 0;
153
154 int
155 Paper_def::get_next_default_count () const
156 {
157   return default_count_i_ ++;
158 }
159
160 void
161 Paper_def::reset_default_count()
162 {
163   default_count_i_ = 0;
164 }
165
166
167 Paper_stream*
168 Paper_def::paper_stream_p () const
169 {
170   String outname = base_output_str ();
171
172   if (outname != "-")
173     outname += String (".") + output_global_ch;
174   progress_indication (_f ("paper output to %s...",
175                            outname == "-" ? String ("<stdout>") : outname));
176                        
177
178   target_str_global_array.push (outname);
179   return new Paper_stream (outname);
180 }
181
182
183 String
184 Paper_def::base_output_str () const
185 {
186   String str = get_default_output ();
187
188   if (str.empty_b ())
189     {
190       str = default_outname_base_global;
191       int def = get_next_default_count ();
192       if (def)
193         str += "-" + to_str (def);
194     }
195   return str;
196 }
197
198