]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
use SCM module in stead of
[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 Real
51 Paper_def::get_realvar (SCM s) const
52 {
53   SCM val = lookup_variable (s);
54   SCM scale = lookup_variable (ly_symbol2scm ("outputscale"));
55   
56   Real sc = gh_scm2double (scale);
57   return gh_scm2double (val) / sc;
58 }
59
60 /*
61   FIXME. This is broken until we have a generic way of
62   putting lists inside the \paper block.
63  */
64 Interval
65 Paper_def::line_dimensions_int (int n) const
66 {
67   Real lw =  get_var ("linewidth");
68   Real ind = n? 0.0:get_var ("indent");
69
70   return Interval (ind, lw);
71 }
72
73
74
75 int Paper_def::score_count_ = 0;
76
77 int
78 Paper_def::get_next_score_count () const
79 {
80   return score_count_ ++;
81 }
82
83 void
84 Paper_def::reset_score_count ()
85 {
86   score_count_ = 0;
87 }
88
89
90 Paper_outputter*
91 Paper_def::get_paper_outputter () 
92 {
93   String outname = outname_string (); 
94   progress_indication (_f ("paper output to `%s'...",
95                            outname == "-" ? String ("<stdout>") : outname));
96
97   global_input_file->target_strings_.push (outname);
98   Paper_outputter * po = new Paper_outputter (outname);
99   Path p = split_path (outname);
100   p.ext = "";
101   po->basename_ = p.string ();
102   return po;
103 }
104
105
106 /*
107   todo: use symbols and hashtable idx?
108
109
110 */
111 Font_metric *
112 Paper_def::find_font (SCM fn, Real m)
113 {
114   SCM key = gh_cons (fn, gh_double2scm (m));
115   SCM met = scm_assoc (key, scaled_fonts_);
116
117   if (gh_pair_p (met))
118     return unsmob_metrics (ly_cdr (met));
119
120   /*
121     Hmm. We're chaining font - metrics. Should consider wether to merge
122     virtual-font and scaled_font.
123    */
124   Font_metric*  f=0;
125   if (gh_list_p (fn))
126     {
127       f = new Virtual_font_metric (fn, m, this);
128     }
129   else
130     {
131       SCM var =  scm_module_lookup (scope_, ly_symbol2scm ("outputscale"));
132       m /= gh_scm2double (scm_variable_ref (var));
133
134       f = all_fonts_global->find_font (ly_scm2string (fn));
135       SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
136       scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
137       f = unsmob_metrics (val);
138       scm_gc_unprotect_object (val);
139     }
140
141   return f;
142 }
143
144
145 /*
146   Return alist to translate internally used fonts back to real-world
147   coordinates.  */
148 SCM
149 Paper_def::font_descriptions ()const
150 {
151   SCM l = SCM_EOL;
152   for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
153     {
154       SCM desc = ly_caar (s);
155       SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
156
157       l = gh_cons (gh_cons (mdesc, desc), l);
158     }
159   return l;
160 }