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