]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
* lily/global-context.cc (run_iterator_on_me): fix grace note
[lilypond.git] / lily / paper-def.cc
1 /*
2   paper-def.cc -- implement Paper_def
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #include <math.h>
11
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"
23 #include "ly-module.hh"
24
25 /*
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.)
29   
30  */
31 Paper_def::Paper_def ()
32 {
33 }
34
35 Paper_def::~Paper_def ()
36 {
37 }
38
39 Paper_def::Paper_def (Paper_def const&src)
40   : Music_output_def (src)
41 {
42 }
43
44 Real
45 Paper_def::get_realvar (SCM s) const
46 {
47   SCM val = lookup_variable (s);
48   SCM scale = lookup_variable (ly_symbol2scm ("outputscale"));
49   
50   Real sc = gh_scm2double (scale);
51   return gh_scm2double (val) / sc;
52 }
53
54 /*
55   FIXME. This is broken until we have a generic way of
56   putting lists inside the \paper block.
57  */
58 Interval
59 Paper_def::line_dimensions_int (int n) const
60 {
61   Real lw =  get_realvar (ly_symbol2scm ("linewidth"));
62   Real ind = n? 0.0:get_realvar (ly_symbol2scm ("indent"));
63
64   return Interval (ind, lw);
65 }
66
67
68
69
70 Paper_outputter*
71 Paper_def::get_paper_outputter (String outname)  const
72 {
73   progress_indication (_f ("paper output to `%s'...",
74                            outname == "-" ? String ("<stdout>") : outname));
75
76   global_input_file->target_strings_.push (outname);
77   Paper_outputter * po = new Paper_outputter (outname);
78   Path p = split_path (outname);
79   p.ext = "";
80   po->basename_ = p.to_string ();
81   return po;
82 }
83
84
85 /*
86   Todo: use symbols and hashtable idx?
87 */
88 Font_metric *
89 Paper_def::find_font (SCM fn, Real m)
90 {
91   SCM key = gh_cons (fn, gh_double2scm (m));
92   SCM met = scm_assoc (key, scaled_fonts_);
93
94   if (gh_pair_p (met))
95     return unsmob_metrics (ly_cdr (met));
96
97   /*
98     Hmm. We're chaining font - metrics. Should consider wether to merge
99     virtual-font and scaled_font.
100    */
101   Font_metric*  f=0;
102   if (gh_list_p (fn))
103     {
104       f = new Virtual_font_metric (fn, m, this); // TODO: GC protection.
105       
106       scaled_fonts_ = scm_acons (key, f->self_scm (), scaled_fonts_);
107       scm_gc_unprotect_object (f->self_scm ());
108     }
109   else
110     {
111       SCM scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale"));
112
113       m /= gh_scm2double (scm_variable_ref (scale_var));
114
115       f = all_fonts_global->find_font (ly_scm2string (fn));
116       SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
117       scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
118       scm_gc_unprotect_object (val);
119       
120       f = unsmob_metrics (val);
121     }
122
123   return f;
124 }
125
126
127 /*
128   Return alist to translate internally used fonts back to real-world
129   coordinates.  */
130 SCM
131 Paper_def::font_descriptions ()const
132 {
133   SCM l = SCM_EOL;
134   for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
135     {
136       SCM desc = ly_caar (s);
137       if (!gh_string_p (gh_car (desc)))
138         continue ;
139
140       SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
141
142       l = gh_cons (gh_cons (mdesc, desc), l);
143     }
144   return l;
145 }
146
147 Paper_def* 
148 unsmob_paper (SCM x)
149 {
150   return dynamic_cast<Paper_def*> (unsmob_music_output_def (x));
151 }
152