]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 1.3.36
[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 "dictionary-iter.hh"
23 #include "file-results.hh" // urg? header_global_p
24 #include "paper-outputter.hh"
25 #include "paper-stream.hh"
26
27
28 Paper_def::Paper_def ()
29 {
30   lookup_p_tab_p_ = new map<int, Lookup*>;
31 }
32
33
34 Paper_def::~Paper_def ()
35 {
36   for (map<int,Lookup*>::const_iterator ai = lookup_p_tab_p_->begin();
37        ai != lookup_p_tab_p_->end (); ai++)
38     {
39       delete (*ai).second;
40     }
41   
42   delete lookup_p_tab_p_;
43 }
44
45 Paper_def::Paper_def (Paper_def const&s)
46   : Music_output_def (s)
47 {
48   shape_int_a_ = s.shape_int_a_;
49   lookup_p_tab_p_ = new map<int, Lookup*>;
50   
51   for (map<int,Lookup*>::const_iterator ai = s.lookup_p_tab_p_->begin();
52        ai != s.lookup_p_tab_p_->end (); ai++)
53     {
54       Lookup * l = new Lookup (* (*ai).second);
55       set_lookup ((*ai).first, l);      
56     }
57 }
58
59
60 Real
61 Paper_def::get_var (String s) const
62 {
63   return get_realvar (ly_symbol2scm (s.ch_C()));
64 }
65
66 Real
67 Paper_def::get_realvar (SCM s) const
68 {
69   if (!scope_p_->elem_b (s))
70     error (_f ("unknown paper variable: `%s'", ly_symbol2string (s)));
71   Real * p = scope_p_->elem (s)->access_content_Real (false);
72   if (!p)
73     {
74       error (_("not a real variable"));
75       return 0.0;
76     }
77
78   return *p;
79 }
80
81
82 Interval
83 Paper_def::line_dimensions_int (int n) const
84 {
85   SCM s = default_properties_.get (ly_symbol2scm ("margin-shape"));
86   if (!gh_pair_p (s))
87     {
88       Real lw =  get_var ("linewidth");
89       Real ind = n? 0.0:get_var ("indent");
90
91       return Interval (ind, lw);
92     }
93
94  
95   SCM last = SCM_EOL;
96   while (gh_pair_p (s) && n --)
97     {
98       last = s;
99       s = gh_cdr (s);
100     }
101
102   if (s == SCM_EOL)
103     {
104       s = last;
105     }
106
107   SCM pair = gh_car (s);
108   
109   return Interval (gh_scm2double (gh_car (pair)),
110                    gh_scm2double (gh_cdr (pair)));
111 }
112
113 void
114 Paper_def::set_lookup (int i, Lookup*l)
115 {
116   map<int,Lookup*> :: const_iterator it (lookup_p_tab_p_->find (i));
117   if (it != lookup_p_tab_p_->end ())
118     {
119       delete (*it).second;
120     }
121   (*lookup_p_tab_p_)[i] = l;
122 }
123
124
125 /*
126   junkme.
127  */
128 Real
129 Paper_def::interbeam_f (int multiplicity_i) const
130 {
131   if (multiplicity_i <= 3)
132     return get_var ("interbeam");
133   else
134     return get_var ("interbeam4");
135 }
136
137
138 void
139 Paper_def::print () const
140 {
141 #ifndef NPRINT
142   Music_output_def::print ();
143   DEBUG_OUT << "Paper {";
144   for (map<int,Lookup*>::const_iterator ai = lookup_p_tab_p_->begin();
145        ai != lookup_p_tab_p_->end (); ai++)
146     {
147       DEBUG_OUT << "Lookup: " << (*ai).first
148                 << " = " << (*ai).second->font_name_ << '\n';
149     }
150   DEBUG_OUT << "}\n";
151 #endif
152 }
153
154 Lookup const *
155 Paper_def::lookup_l (int i) const
156 {
157   return (*lookup_p_tab_p_)[i];
158 }
159
160
161
162 int Paper_def::default_count_i_ = 0;
163
164 int
165 Paper_def::get_next_default_count () const
166 {
167   return default_count_i_ ++;
168 }
169
170 void
171 Paper_def::reset_default_count()
172 {
173   default_count_i_ = 0;
174 }
175
176
177 Paper_stream*
178 Paper_def::paper_stream_p () const
179 {
180   String outname = base_output_str ();
181
182   if (outname != "-")
183     outname += String (".") + output_global_ch;
184   progress_indication (_f ("paper output to %s...",
185                            outname == "-" ? String ("<stdout>") : outname));
186                        
187
188   target_str_global_array.push (outname);
189   return new Paper_stream (outname);
190 }
191
192
193 String
194 Paper_def::base_output_str () const
195 {
196   String str = get_default_output ();
197
198   if (str.empty_b ())
199     {
200       str = default_outname_base_global;
201       int def = get_next_default_count ();
202       if (def)
203         str += "-" + to_str (def);
204     }
205   return str;
206 }
207
208