]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #include <math.h>
11
12 #include "virtual-font-metric.hh"
13 #include "all-font-metrics.hh"
14 #include "string.hh"
15 #include "misc.hh"
16 #include "paper-def.hh"
17 #include "warn.hh"
18 #include "scaled-font-metric.hh"
19 #include "main.hh"
20 #include "scm-hash.hh"
21 #include "input-file-results.hh" // urg? header_global
22 #include "paper-outputter.hh"
23
24 /*
25   This is an almost empty thing. The only substantial thing this class
26   handles, is scaling up and down to real-world dimensions (internally
27   dimensions are against global staff-space.)
28   
29  */
30 Paper_def::Paper_def ()
31 {
32 }
33
34 Paper_def::~Paper_def ()
35 {
36 }
37
38 Paper_def::Paper_def (Paper_def const&src)
39   : Music_output_def (src)
40 {
41 }
42
43
44 Real
45 Paper_def::get_var (String s) const
46 {
47   return get_realvar (ly_symbol2scm (s.to_str0 ()));
48 }
49
50 SCM
51 Paper_def::get_scmvar (String s) const
52 {
53   return variable_tab_->get (ly_symbol2scm (s.to_str0 ()));
54 }
55
56
57 SCM
58 Paper_def::get_scmvar_scm (SCM sym) const
59 {
60   return  gh_double2scm (get_realvar (sym));
61 }
62
63 Real
64 Paper_def::get_realvar (SCM s) const
65 {
66   SCM val ;
67   if (!variable_tab_->try_retrieve (s, &val))
68     {
69       programming_error ("unknown paper variable: " +  ly_symbol2string (s));
70       return 0.0;
71     }
72
73   Real sc = 1.0;
74   SCM ssc;
75   if (variable_tab_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
76     {
77       sc = gh_scm2double (ssc);
78     }
79   if (gh_number_p (val))
80     {
81       return gh_scm2double (val) / sc;
82     }
83   else
84     {
85       programming_error ("not a real variable");
86       return 0.0;
87     }
88 }
89
90 /*
91   FIXME. This is broken until we have a generic way of
92   putting lists inside the \paper block.
93  */
94 Interval
95 Paper_def::line_dimensions_int (int n) const
96 {
97   Real lw =  get_var ("linewidth");
98   Real ind = n? 0.0:get_var ("indent");
99
100   return Interval (ind, lw);
101 }
102
103
104
105 int Paper_def::score_count_ = 0;
106
107 int
108 Paper_def::get_next_score_count () const
109 {
110   return score_count_ ++;
111 }
112
113 void
114 Paper_def::reset_score_count ()
115 {
116   score_count_ = 0;
117 }
118
119
120 Paper_outputter*
121 Paper_def::get_paper_outputter () 
122 {
123   String outname = outname_string (); 
124   progress_indication (_f ("paper output to `%s'...",
125                            outname == "-" ? String ("<stdout>") : outname));
126
127   global_input_file->target_strings_.push (outname);
128   Paper_outputter * po = new Paper_outputter (outname);
129   Path p = split_path (outname);
130   p.ext = "";
131   po->basename_ = p.string ();
132   return po;
133 }
134
135
136 /*
137   todo: use symbols and hashtable idx?
138
139
140 */
141 Font_metric *
142 Paper_def::find_font (SCM fn, Real m)
143 {
144   SCM key = gh_cons (fn, gh_double2scm (m));
145   SCM met = scm_assoc (key, scaled_fonts_);
146
147   if (gh_pair_p (met))
148     return unsmob_metrics (ly_cdr (met));
149
150   /*
151     Hmm. We're chaining font - metrics. Should consider wether to merge
152     virtual-font and scaled_font.
153    */
154   Font_metric*  f=0;
155   if (gh_list_p (fn))
156     {
157       f = new Virtual_font_metric (fn, m, this);
158     }
159   else
160     {
161       SCM ssc;
162       if (variable_tab_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
163         {
164           m /= gh_scm2double (ssc);
165         }
166
167       f = all_fonts_global->find_font (ly_scm2string (fn));
168       SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
169       scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
170       f = unsmob_metrics (val);
171       scm_gc_unprotect_object (val);
172     }
173
174   return f;
175 }
176
177
178 /*
179   Return alist to translate internally used fonts back to real-world
180   coordinates.  */
181 SCM
182 Paper_def::font_descriptions ()const
183 {
184   SCM l = SCM_EOL;
185   for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
186     {
187       SCM desc = ly_caar (s);
188       SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
189
190       l = gh_cons (gh_cons (mdesc, desc), l);
191     }
192   return l;
193 }