lilypond-1.3.31
[lilypond.git] / lily / paper-def.cc
blob2f60f9e14ce2f65295ed3210c2eedc141a736e2b
1 /*
2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
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"
27 Paper_def::Paper_def ()
29 lookup_p_tab_p_ = new Hash_table<int, Lookup*>;
30 lookup_p_tab_p_->hash_func_ = int_hash;
34 Paper_def::~Paper_def ()
36 for (Hash_table_iter<int, Lookup*> ai(*lookup_p_tab_p_); ai.ok (); ai++)
38 delete ai.val ();
41 delete lookup_p_tab_p_;
44 Paper_def::Paper_def (Paper_def const&s)
45 : Music_output_def (s)
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;
51 for (Hash_table_iter<int, Lookup*> ai(*s.lookup_p_tab_p_); ai.ok (); ai++)
53 Lookup * l = new Lookup (*ai.val ());
54 set_lookup (ai.key(), l);
59 Real
60 Paper_def::get_var (String s) const
62 return get_realvar (ly_symbol2scm (s.ch_C()));
65 Real
66 Paper_def::get_realvar (SCM s) const
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)
73 error (_("not a real variable"));
74 return 0.0;
77 return *p;
81 Interval
82 Paper_def::line_dimensions_int (int n) const
84 SCM s = default_properties_.get (ly_symbol2scm ("margin-shape"));
85 if (!gh_pair_p (s))
87 Real lw = get_var ("linewidth");
88 Real ind = n? 0.0:get_var ("indent");
90 return Interval (ind, lw);
94 SCM last = SCM_EOL;
95 while (gh_pair_p (s) && n --)
97 last = s;
98 s = gh_cdr (s);
101 if (s == SCM_EOL)
103 s = last;
106 SCM pair = gh_car (s);
108 return Interval (gh_scm2double (gh_car (pair)),
109 gh_scm2double (gh_cdr (pair)));
112 void
113 Paper_def::set_lookup (int i, Lookup*l)
115 if (lookup_p_tab_p_->elem_b (i))
117 delete lookup_p_tab_p_->elem (i);
119 (*lookup_p_tab_p_)[i] = l;
124 junkme.
126 Real
127 Paper_def::interbeam_f (int multiplicity_i) const
129 if (multiplicity_i <= 3)
130 return get_var ("interbeam");
131 else
132 return get_var ("interbeam4");
136 void
137 Paper_def::print () const
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++)
144 DEBUG_OUT << "Lookup: " << ai.key () << " = " << ai.val ()->font_name_ << '\n';
146 DEBUG_OUT << "}\n";
147 #endif
150 Lookup const *
151 Paper_def::lookup_l (int i) const
153 return (*lookup_p_tab_p_)[i];
158 int Paper_def::default_count_i_ = 0;
161 Paper_def::get_next_default_count () const
163 return default_count_i_ ++;
166 void
167 Paper_def::reset_default_count()
169 default_count_i_ = 0;
173 Paper_stream*
174 Paper_def::paper_stream_p () const
176 String outname = base_output_str ();
178 if (outname != "-")
179 outname += String (".") + output_global_ch;
180 progress_indication (_f ("paper output to %s...",
181 outname == "-" ? String ("<stdout>") : outname));
184 target_str_global_array.push (outname);
185 return new Paper_stream (outname);
189 String
190 Paper_def::base_output_str () const
192 String str = get_default_output ();
194 if (str.empty_b ())
196 str = default_outname_base_global;
197 int def = get_next_default_count ();
198 if (def)
199 str += "-" + to_str (def);
201 return str;