2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 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-stream.hh"
22 Paper_def::Paper_def ()
24 style_sheet_ = SCM_EOL;
25 scaled_fonts_ = SCM_EOL;
28 Paper_def::~Paper_def ()
32 Paper_def::Paper_def (Paper_def const&src)
33 : Music_output_def (src)
35 scaled_fonts_ = SCM_EOL;
36 style_sheet_ = src.style_sheet_;
41 Paper_def::get_var (String s) const
43 return get_realvar (ly_symbol2scm (s.ch_C()));
47 Paper_def::get_scmvar (String s) const
49 return scope_p_->scm_elem (ly_symbol2scm (s.ch_C()));
53 Paper_def::get_realvar (SCM s) const
56 if (!scope_p_->try_retrieve (s, &val))
58 programming_error ("unknown paper variable: " + ly_symbol2string (s));
64 if (scope_p_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
66 sc = gh_scm2double (ssc);
68 if (gh_number_p (val))
70 return gh_scm2double (val) / sc;
74 programming_error ("not a real variable");
80 FIXME. This is broken until we have a generic way of
81 putting lists inside the \paper block.
84 Paper_def::line_dimensions_int (int n) const
86 Real lw = get_var ("linewidth");
87 Real ind = n? 0.0:get_var ("indent");
89 return Interval (ind, lw);
94 int Paper_def::default_count_i_ = 0;
97 Paper_def::get_next_default_count () const
99 return default_count_i_ ++;
103 Paper_def::reset_default_count()
105 default_count_i_ = 0;
110 Paper_def::paper_stream_p () const
112 String outname = base_output_str ();
115 outname += String (".") + output_global_ch;
116 progress_indication (_f ("paper output to %s...",
117 outname == "-" ? String ("<stdout>") : outname));
119 target_str_global_array.push (outname);
120 return new Paper_stream (outname);
128 Wat een puinhoop is dit. */
130 Paper_def::base_output_str () const
132 String str = get_default_output ();
136 str = default_outname_base_global;
137 int def = get_next_default_count ();
139 str += "-" + to_str (def);
142 /* Must store value, as this function can be called only once */
143 Paper_def *urg = (Paper_def*)this;
144 urg->current_output_base_ = str;
150 todo: use symbols and hashtable idx?
153 Paper_def::find_font (SCM fn, Real m)
155 SCM key = gh_cons (fn, gh_double2scm (m));
156 SCM met = scm_assoc (key, scaled_fonts_);
159 return unsmob_metrics (gh_cdr (met));
162 if (scope_p_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
164 m /= gh_scm2double (ssc);
167 Font_metric* f = all_fonts_global_p->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_ );
171 scm_unprotect_object (val);
173 return dynamic_cast<Scaled_font_metric*> (unsmob_metrics (val));
178 Return alist to translate internally used fonts back to real-world
181 Paper_def::font_descriptions ()const
186 for (SCM s = scaled_fonts_; gh_pair_p (s); s = gh_cdr(s))
188 SCM desc = gh_caar (s);
189 SCM mdesc = unsmob_metrics (gh_cdar (s))->description_;
191 l = gh_cons (gh_cons (mdesc, desc), l);