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