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