]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
*** empty log message ***
[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--2003 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-modules.hh"
24
25
26 /*
27   This is an almost empty thing. The only substantial thing this class
28   handles, is scaling up and down to real-world dimensions (internally
29   dimensions are against global staff-space.)
30   
31  */
32 Paper_def::Paper_def ()
33 {
34 }
35
36 Paper_def::~Paper_def ()
37 {
38 }
39
40 Paper_def::Paper_def (Paper_def const&src)
41   : Music_output_def (src)
42 {
43 }
44
45
46
47 Real
48 Paper_def::get_realvar (SCM s) const
49 {
50   SCM val = lookup_variable (s);
51   SCM scale = lookup_variable (ly_symbol2scm ("outputscale"));
52   
53   Real sc = gh_scm2double (scale);
54   return gh_scm2double (val) / sc;
55 }
56
57 /*
58   FIXME. This is broken until we have a generic way of
59   putting lists inside the \paper block.
60  */
61 Interval
62 Paper_def::line_dimensions_int (int n) const
63 {
64   Real lw =  get_realvar (ly_symbol2scm ("linewidth"));
65   Real ind = n? 0.0:get_realvar (ly_symbol2scm ("indent"));
66
67   return Interval (ind, lw);
68 }
69
70
71 int Paper_def::score_count_ = 0;
72
73 int
74 Paper_def::get_next_score_count () const
75 {
76   return score_count_ ++;
77 }
78
79 void
80 Paper_def::reset_score_count ()
81 {
82   score_count_ = 0;
83 }
84
85
86 Paper_outputter*
87 Paper_def::get_paper_outputter () 
88 {
89   String outname = outname_string (); 
90   progress_indication (_f ("paper output to `%s'...",
91                            outname == "-" ? String ("<stdout>") : outname));
92
93   global_input_file->target_strings_.push (outname);
94   Paper_outputter * po = new Paper_outputter (outname);
95   Path p = split_path (outname);
96   p.ext = "";
97   po->basename_ = p.to_string ();
98   return po;
99 }
100
101
102 /*
103   todo: use symbols and hashtable idx?
104 */
105 Font_metric *
106 Paper_def::find_font (SCM fn, Real m)
107 {
108   SCM key = gh_cons (fn, gh_double2scm (m));
109   SCM met = scm_assoc (key, scaled_fonts_);
110
111   if (gh_pair_p (met))
112     return unsmob_metrics (ly_cdr (met));
113
114   /*
115     Hmm. We're chaining font - metrics. Should consider wether to merge
116     virtual-font and scaled_font.
117    */
118   Font_metric*  f=0;
119   if (gh_list_p (fn))
120     {
121       f = new Virtual_font_metric (fn, m, this);
122     }
123   else
124     {
125       SCM scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale"));
126
127       m /= gh_scm2double (scm_variable_ref (scale_var));
128
129       f = all_fonts_global->find_font (ly_scm2string (fn));
130       SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
131       scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
132       f = unsmob_metrics (val);
133       scm_gc_unprotect_object (val);
134     }
135
136   return f;
137 }
138
139
140 /*
141   Return alist to translate internally used fonts back to real-world
142   coordinates.  */
143 SCM
144 Paper_def::font_descriptions ()const
145 {
146   SCM l = SCM_EOL;
147   for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
148     {
149       SCM desc = ly_caar (s);
150       SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
151
152       l = gh_cons (gh_cons (mdesc, desc), l);
153     }
154   return l;
155 }