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>
11 #include "all-font-metrics.hh"
14 #include "paper-def.hh"
16 #include "scaled-font-metric.hh"
19 #include "file-results.hh" // urg? header_global_p
20 #include "paper-outputter.hh"
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.)
28 Paper_def::Paper_def ()
32 Paper_def::~Paper_def ()
36 Paper_def::Paper_def (Paper_def const&src)
37 : Music_output_def (src)
43 Paper_def::get_var (String s) const
45 return get_realvar (ly_symbol2scm (s.ch_C ()));
49 Paper_def::get_scmvar (String s) const
51 return scope_p_->scm_elem (ly_symbol2scm (s.ch_C ()));
56 Paper_def::get_scmvar_scm (SCM sym) const
58 return gh_double2scm (get_realvar (sym));
62 Paper_def::get_realvar (SCM s) const
65 if (!scope_p_->try_retrieve (s, &val))
67 programming_error ("unknown paper variable: " + ly_symbol2string (s));
73 if (scope_p_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
75 sc = gh_scm2double (ssc);
77 if (gh_number_p (val))
79 return gh_scm2double (val) / sc;
83 programming_error ("not a real variable");
89 FIXME. This is broken until we have a generic way of
90 putting lists inside the \paper block.
93 Paper_def::line_dimensions_int (int n) const
95 Real lw = get_var ("linewidth");
96 Real ind = n? 0.0:get_var ("indent");
98 return Interval (ind, lw);
103 int Paper_def::score_count_i_ = 0;
106 Paper_def::get_next_score_count () const
108 return score_count_i_ ++;
112 Paper_def::reset_score_count ()
119 Paper_def::paper_outputter_p ()
121 String outname = outname_str ();
122 progress_indication (_f ("paper output to `%s'...",
123 outname == "-" ? String ("<stdout>") : outname));
125 target_str_global_array.push (outname);
126 Paper_outputter * po = new Paper_outputter (outname);
127 Path p = split_path (outname);
129 po->basename_ = p.str ();
135 todo: use symbols and hashtable idx?
138 Paper_def::find_font (SCM fn, Real m)
140 SCM key = gh_cons (fn, gh_double2scm (m));
141 SCM met = scm_assoc (key, scaled_fonts_);
144 return unsmob_metrics (ly_cdr (met));
147 if (scope_p_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
149 m /= gh_scm2double (ssc);
152 Font_metric* f = all_fonts_global_p->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_);
156 scm_gc_unprotect_object (val);
158 return dynamic_cast<Scaled_font_metric*> (unsmob_metrics (val));
163 Return alist to translate internally used fonts back to real-world
166 Paper_def::font_descriptions ()const
171 for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
173 SCM desc = ly_caar (s);
174 SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
176 l = gh_cons (gh_cons (mdesc, desc), l);