2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "virtual-font-metric.hh"
13 #include "all-font-metrics.hh"
16 #include "paper-def.hh"
18 #include "scaled-font-metric.hh"
20 #include "scm-hash.hh"
21 #include "input-file-results.hh" // urg? header_global
22 #include "paper-outputter.hh"
23 #include "ly-modules.hh"
26 This is an almost empty thing. The only substantial thing this class
27 handles, is scaling up and down to real-world dimensions (internally
28 dimensions are against global staff-space.)
31 Paper_def::Paper_def ()
35 Paper_def::~Paper_def ()
39 Paper_def::Paper_def (Paper_def const&src)
40 : Music_output_def (src)
47 Paper_def::get_realvar (SCM s) const
49 SCM val = lookup_variable (s);
50 SCM scale = lookup_variable (ly_symbol2scm ("outputscale"));
52 Real sc = gh_scm2double (scale);
53 return gh_scm2double (val) / sc;
57 FIXME. This is broken until we have a generic way of
58 putting lists inside the \paper block.
61 Paper_def::line_dimensions_int (int n) const
63 Real lw = get_realvar (ly_symbol2scm ("linewidth"));
64 Real ind = n? 0.0:get_realvar (ly_symbol2scm ("indent"));
66 return Interval (ind, lw);
73 Paper_def::get_paper_outputter (String outname) const
75 progress_indication (_f ("paper output to `%s'...",
76 outname == "-" ? String ("<stdout>") : outname));
78 global_input_file->target_strings_.push (outname);
79 Paper_outputter * po = new Paper_outputter (outname);
80 Path p = split_path (outname);
82 po->basename_ = p.to_string ();
88 Todo: use symbols and hashtable idx?
91 Paper_def::find_font (SCM fn, Real m)
93 SCM key = gh_cons (fn, gh_double2scm (m));
94 SCM met = scm_assoc (key, scaled_fonts_);
97 return unsmob_metrics (ly_cdr (met));
100 Hmm. We're chaining font - metrics. Should consider wether to merge
101 virtual-font and scaled_font.
106 f = new Virtual_font_metric (fn, m, this); // TODO: GC protection.
108 scaled_fonts_ = scm_acons (key, f->self_scm (), scaled_fonts_);
109 scm_gc_unprotect_object (f->self_scm ());
113 SCM scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale"));
115 m /= gh_scm2double (scm_variable_ref (scale_var));
117 f = all_fonts_global->find_font (ly_scm2string (fn));
118 SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
119 scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
120 scm_gc_unprotect_object (val);
122 f = unsmob_metrics (val);
130 Return alist to translate internally used fonts back to real-world
133 Paper_def::font_descriptions ()const
136 for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
138 SCM desc = ly_caar (s);
139 if (!gh_string_p (gh_car (desc)))
142 SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
144 l = gh_cons (gh_cons (mdesc, desc), l);
152 return dynamic_cast<Paper_def*> (unsmob_music_output_def (x));