]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 1.3.55
[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   FIXME. This is broken until we have a generic way of
83   putting lists inside the \paper block.
84  */
85 Interval
86 Paper_def::line_dimensions_int (int n) const
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 void
95 Paper_def::set_lookup (int i, Lookup*l)
96 {
97   map<int,Lookup*> :: const_iterator it (lookup_p_tab_p_->find (i));
98   if (it != lookup_p_tab_p_->end ())
99     {
100       delete (*it).second;
101     }
102   (*lookup_p_tab_p_)[i] = l;
103 }
104
105
106 /*
107   junkme.
108  */
109 Real
110 Paper_def::interbeam_f (int multiplicity_i) const
111 {
112   if (multiplicity_i <= 3)
113     return get_var ("interbeam");
114   else
115     return get_var ("interbeam4");
116 }
117
118
119 void
120 Paper_def::print () const
121 {
122 #ifndef NPRINT
123   Music_output_def::print ();
124   DEBUG_OUT << "Paper {";
125   for (map<int,Lookup*>::const_iterator ai = lookup_p_tab_p_->begin();
126        ai != lookup_p_tab_p_->end (); ai++)
127     {
128       DEBUG_OUT << "Lookup: " << (*ai).first
129                 << " = " << (*ai).second->font_name_ << '\n';
130     }
131   DEBUG_OUT << "}\n";
132 #endif
133 }
134
135 Lookup const *
136 Paper_def::lookup_l (int i) const
137 {
138   return (*lookup_p_tab_p_)[i];
139 }
140
141
142
143 int Paper_def::default_count_i_ = 0;
144
145 int
146 Paper_def::get_next_default_count () const
147 {
148   return default_count_i_ ++;
149 }
150
151 void
152 Paper_def::reset_default_count()
153 {
154   default_count_i_ = 0;
155 }
156
157
158 Paper_stream*
159 Paper_def::paper_stream_p () const
160 {
161   String outname = base_output_str ();
162
163   if (outname != "-")
164     outname += String (".") + output_global_ch;
165   progress_indication (_f ("paper output to %s...",
166                            outname == "-" ? String ("<stdout>") : outname));
167                        
168
169   target_str_global_array.push (outname);
170   return new Paper_stream (outname);
171 }
172
173
174 String
175 Paper_def::base_output_str () const
176 {
177   String str = get_default_output ();
178
179   if (str.empty_b ())
180     {
181       str = default_outname_base_global;
182       int def = get_next_default_count ();
183       if (def)
184         str += "-" + to_str (def);
185     }
186   return str;
187 }
188
189