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