* stepmake/stepmake/metafont-rules.make: backport 1.7 fixes.
[lilypond.git] / lily / paper-def.cc
blobf6bf6ec19bd404f485e5b6200aed8ed5981942b8
1 /*
2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
10 #include <math.h>
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"
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.)
30 Paper_def::Paper_def ()
34 Paper_def::~Paper_def ()
38 Paper_def::Paper_def (Paper_def const&src)
39 : Music_output_def (src)
44 Real
45 Paper_def::get_var (String s) const
47 return get_realvar (ly_symbol2scm (s.to_str0 ()));
50 SCM
51 Paper_def::get_scmvar (String s) const
53 return variable_tab_->get (ly_symbol2scm (s.to_str0 ()));
57 SCM
58 Paper_def::get_scmvar_scm (SCM sym) const
60 return gh_double2scm (get_realvar (sym));
63 Real
64 Paper_def::get_realvar (SCM s) const
66 SCM val ;
67 if (!variable_tab_->try_retrieve (s, &val))
69 programming_error ("unknown paper variable: " + ly_symbol2string (s));
70 return 0.0;
73 Real sc = 1.0;
74 SCM ssc;
75 if (variable_tab_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
77 sc = gh_scm2double (ssc);
79 if (gh_number_p (val))
81 return gh_scm2double (val) / sc;
83 else
85 programming_error ("not a real variable");
86 return 0.0;
91 FIXME. This is broken until we have a generic way of
92 putting lists inside the \paper block.
94 Interval
95 Paper_def::line_dimensions_int (int n) const
97 Real lw = get_var ("linewidth");
98 Real ind = n? 0.0:get_var ("indent");
100 return Interval (ind, lw);
105 int Paper_def::score_count_ = 0;
108 Paper_def::get_next_score_count () const
110 return score_count_ ++;
113 void
114 Paper_def::reset_score_count ()
116 score_count_ = 0;
120 Paper_outputter*
121 Paper_def::get_paper_outputter ()
123 String outname = outname_string ();
124 progress_indication (_f ("paper output to `%s'...",
125 outname == "-" ? String ("<stdout>") : outname));
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;
137 todo: use symbols and hashtable idx?
141 Font_metric *
142 Paper_def::find_font (SCM fn, Real m)
144 SCM key = gh_cons (fn, gh_double2scm (m));
145 SCM met = scm_assoc (key, scaled_fonts_);
147 if (gh_pair_p (met))
148 return unsmob_metrics (ly_cdr (met));
151 Hmm. We're chaining font - metrics. Should consider wether to merge
152 virtual-font and scaled_font.
154 Font_metric* f=0;
155 if (gh_list_p (fn))
157 f = new Virtual_font_metric (fn, m, this);
159 else
161 SCM ssc;
162 if (variable_tab_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
164 m /= gh_scm2double (ssc);
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);
174 return f;
179 Return alist to translate internally used fonts back to real-world
180 coordinates. */
182 Paper_def::font_descriptions ()const
184 SCM l = SCM_EOL;
185 for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
187 SCM desc = ly_caar (s);
188 SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
190 l = gh_cons (gh_cons (mdesc, desc), l);
192 return l;