]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
* mf/parmesan-clefs.mf: use # quantities for char_box
[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   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
45
46 Real
47 Paper_def::get_realvar (SCM s) const
48 {
49   SCM val = lookup_variable (s);
50   SCM scale = lookup_variable (ly_symbol2scm ("outputscale"));
51   
52   Real sc = gh_scm2double (scale);
53   return gh_scm2double (val) / sc;
54 }
55
56 /*
57   FIXME. This is broken until we have a generic way of
58   putting lists inside the \paper block.
59  */
60 Interval
61 Paper_def::line_dimensions_int (int n) const
62 {
63   Real lw =  get_realvar (ly_symbol2scm ("linewidth"));
64   Real ind = n? 0.0:get_realvar (ly_symbol2scm ("indent"));
65
66   return Interval (ind, lw);
67 }
68
69
70 int Paper_def::score_count_ = 0;
71
72 int
73 Paper_def::get_next_score_count () const
74 {
75   return score_count_ ++;
76 }
77
78 void
79 Paper_def::reset_score_count ()
80 {
81   score_count_ = 0;
82 }
83
84
85 Paper_outputter*
86 Paper_def::get_paper_outputter () 
87 {
88   String outname = outname_string (); 
89   progress_indication (_f ("paper output to `%s'...",
90                            outname == "-" ? String ("<stdout>") : outname));
91
92   global_input_file->target_strings_.push (outname);
93   Paper_outputter * po = new Paper_outputter (outname);
94   Path p = split_path (outname);
95   p.ext = "";
96   po->basename_ = p.to_string ();
97   return po;
98 }
99
100
101 /*
102   todo: use symbols and hashtable idx?
103 */
104 Font_metric *
105 Paper_def::find_font (SCM fn, Real m)
106 {
107   SCM key = gh_cons (fn, gh_double2scm (m));
108   SCM met = scm_assoc (key, scaled_fonts_);
109
110   if (gh_pair_p (met))
111     return unsmob_metrics (ly_cdr (met));
112
113   /*
114     Hmm. We're chaining font - metrics. Should consider wether to merge
115     virtual-font and scaled_font.
116    */
117   Font_metric*  f=0;
118   if (gh_list_p (fn))
119     {
120       f = new Virtual_font_metric (fn, m, this);
121     }
122   else
123     {
124       SCM scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale"));
125
126       m /= gh_scm2double (scm_variable_ref (scale_var));
127
128       f = all_fonts_global->find_font (ly_scm2string (fn));
129       SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
130       scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
131       f = unsmob_metrics (val);
132       scm_gc_unprotect_object (val);
133     }
134
135   return f;
136 }
137
138
139 /*
140   Return alist to translate internally used fonts back to real-world
141   coordinates.  */
142 SCM
143 Paper_def::font_descriptions ()const
144 {
145   SCM l = SCM_EOL;
146   for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
147     {
148       SCM desc = ly_caar (s);
149       SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
150
151       l = gh_cons (gh_cons (mdesc, desc), l);
152     }
153   return l;
154 }
155
156 /*
157   Font_interface should be reorganised?
158 */
159 #include "font-interface.hh"
160
161
162 LY_DEFINE(ly_paper_get_font,"ly:paper-get-font", 2, 0, 0,
163           (SCM paper, SCM chain),
164           "Return a font metric satisfying the font-qualifiers in the alist chain @var{chain}.\n"
165 "\n"
166 "The font object represents the metric information of a font. Every font\n"
167 "that is loaded into LilyPond can be accessed via Scheme. \n"
168 "\n"
169 "LilyPond only needs to know the dimension of glyph to be able to process\n"
170 "them. This information is stored in font metric files. LilyPond can read\n"
171 "two types of font-metrics: @TeX{} Font Metric files (TFM files) and\n"
172 "Adobe Font Metric files (AFM files).  LilyPond will always try to load\n"
173 "AFM files first since they are more versatile.\n"
174 "\n"
175 "An alist chain is a list of alists, containing grob properties.\n")
176 {
177   Paper_def *pap = unsmob_paper (paper);
178   SCM_ASSERT_TYPE(pap, paper, SCM_ARG1, __FUNCTION__, "paper definition");
179   
180   Font_metric*fm = Font_interface::get_font (pap, chain);
181   return fm->self_scm();
182 }
183
184 Paper_def* 
185 unsmob_paper (SCM x)
186 {
187   return dynamic_cast<Paper_def*> (unsmob_music_output_def (x));
188 }
189
190