X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpaper-def.cc;h=27de71fa443b8f811d97553beebfe015692a1dad;hb=7e72a1e50e94a7f9738d62599de79fe7745f600c;hp=65bf8eac9b092977f5657dda8496cbf4dda080ea;hpb=d3190e49a8f73d44b2e11034323b8f3592f288d6;p=lilypond.git diff --git a/lily/paper-def.cc b/lily/paper-def.cc index 65bf8eac9b..27de71fa44 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -3,144 +3,152 @@ source file of the GNU LilyPond music typesetter - (c) 1997 Han-Wen Nienhuys + (c) 1997--2004 Han-Wen Nienhuys */ + #include + +#include "virtual-font-metric.hh" +#include "all-font-metrics.hh" #include "string.hh" -#include "assoc.hh" #include "misc.hh" #include "paper-def.hh" -#include "debug.hh" -#include "lookup.hh" -#include "dimen.hh" -#include "input-engraver.hh" -#include "engraver-group.hh" -#include "assoc-iter.hh" - -void -Paper_def::set_var(String s, Real r) -{ - real_vars_p_->elem(s) = r; -} +#include "warn.hh" +#include "scaled-font-metric.hh" +#include "main.hh" +#include "scm-hash.hh" +#include "input-file-results.hh" // urg? header_global +#include "paper-outputter.hh" +#include "ly-modules.hh" -Real -Paper_def::get_var(String s)const +/* + This is an almost empty thing. The only substantial thing this class + handles, is scaling up and down to real-world dimensions (internally + dimensions are against global staff-space.) + + */ +Paper_def::Paper_def () { - if(! real_vars_p_->elt_b(s)) - error ( "unknown paper variable `" + s+"'"); - return real_vars_p_->elem(s); } -Real -Paper_def::linewidth_f() const +Paper_def::~Paper_def () { - return get_var("linewidth"); } -Real -Paper_def::duration_to_dist(Moment d) +Paper_def::Paper_def (Paper_def const&src) + : Music_output_def (src) { - if (!d) - return 0; - - return get_var("unitspace") * pow(get_var("geometric"), log_2(d)); } -Paper_def::Paper_def() -{ - igrav_p_ = 0; - lookup_p_ = 0; - real_vars_p_ = new Assoc; - outfile_str_ = "lelie.tex"; -} -Paper_def::~Paper_def() +Real +Paper_def::get_realvar (SCM s) const { - delete igrav_p_; - delete real_vars_p_; - delete lookup_p_; + SCM val = lookup_variable (s); + SCM scale = lookup_variable (ly_symbol2scm ("outputscale")); + + Real sc = gh_scm2double (scale); + return gh_scm2double (val) / sc; } -Paper_def::Paper_def(Paper_def const&s) +/* + FIXME. This is broken until we have a generic way of + putting lists inside the \paper block. + */ +Interval +Paper_def::line_dimensions_int (int n) const { - igrav_p_ = s.igrav_p_ ? new Input_engraver( *s.igrav_p_):0; - lookup_p_ = s.lookup_p_? new Lookup(*s.lookup_p_) : 0; - lookup_p_->paper_l_ = this; - real_vars_p_ = new Assoc (*s.real_vars_p_); - outfile_str_ = s.outfile_str_; -} + Real lw = get_realvar (ly_symbol2scm ("linewidth")); + Real ind = n? 0.0:get_realvar (ly_symbol2scm ("indent")); -void -Paper_def::set(Input_engraver * igrav_p) -{ - delete igrav_p_; - igrav_p_ = igrav_p; + return Interval (ind, lw); } -void -Paper_def::set(Lookup*l) -{ - assert(l != lookup_p_); - delete lookup_p_; - lookup_p_ = l; - lookup_p_->paper_l_ = this; -} -Real -Paper_def::interline_f() const -{ - return get_var("interline"); -} -Real -Paper_def::rule_thickness()const +Paper_outputter* +Paper_def::get_paper_outputter (String outname) const { - return get_var("rule_thickness"); -} + progress_indication (_f ("paper output to `%s'...", + outname == "-" ? String ("") : outname)); -Real -Paper_def::interbeam_f() const -{ - return get_var("interbeam"); -} -Real -Paper_def::internote_f() const -{ - return interline_f() / 2; + global_input_file->target_strings_.push (outname); + Paper_outputter * po = new Paper_outputter (outname); + Path p = split_path (outname); + p.ext = ""; + po->basename_ = p.to_string (); + return po; } -Real -Paper_def::note_width()const -{ - return get_var("notewidth"); -} -void -Paper_def::print() const -{ -#ifndef NPRINT - mtor << "Paper {"; - mtor << "out: " <print(); - for (Assoc_iter i(*real_vars_p_); i.ok(); i++) { - mtor << i.key() << "= " << i.val() << "\n"; +/* + Todo: use symbols and hashtable idx? +*/ +Font_metric * +Paper_def::find_font (SCM fn, Real m) +{ + SCM key = gh_cons (fn, gh_double2scm (m)); + SCM met = scm_assoc (key, scaled_fonts_); + + if (gh_pair_p (met)) + return unsmob_metrics (ly_cdr (met)); + + /* + Hmm. We're chaining font - metrics. Should consider wether to merge + virtual-font and scaled_font. + */ + Font_metric* f=0; + if (gh_list_p (fn)) + { + f = new Virtual_font_metric (fn, m, this); // TODO: GC protection. + + scaled_fonts_ = scm_acons (key, f->self_scm (), scaled_fonts_); + scm_gc_unprotect_object (f->self_scm ()); } - mtor << "}\n"; -#endif + else + { + SCM scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale")); + + m /= gh_scm2double (scm_variable_ref (scale_var)); + + f = all_fonts_global->find_font (ly_scm2string (fn)); + SCM val = Scaled_font_metric::make_scaled_font_metric (f, m); + scaled_fonts_ = scm_acons (key, val, scaled_fonts_); + f = unsmob_metrics (val); + scm_gc_unprotect_object (val); + } + + return f; } -Lookup const * -Paper_def::lookup_l() + +/* + Return alist to translate internally used fonts back to real-world + coordinates. */ +SCM +Paper_def::font_descriptions ()const { - assert( lookup_p_ ); - return lookup_p_; + SCM l = SCM_EOL; + for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s)) + { + SCM desc = ly_caar (s); + if (!gh_string_p (gh_car (desc))) + continue ; + + SCM mdesc = unsmob_metrics (ly_cdar (s))->description_; + + l = gh_cons (gh_cons (mdesc, desc), l); + } + return l; } -Global_translator* -Paper_def::get_global_translator_p() const +Paper_def* +unsmob_paper (SCM x) { - return igrav_p_->get_group_engraver_p()->global_l(); + return dynamic_cast (unsmob_music_output_def (x)); } + +