2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 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"
25 This is an almost empty thing. The only substantial thing this class
26 handles, is scaling up and down to real-world dimensions (internally
27 dimensions are against global staff-space.)
30 Paper_def::Paper_def ()
34 Paper_def::~Paper_def ()
38 Paper_def::Paper_def (Paper_def
const&src
)
39 : Music_output_def (src
)
45 Paper_def::get_var (String s
) const
47 return get_realvar (ly_symbol2scm (s
.to_str0 ()));
51 Paper_def::get_scmvar (String s
) const
53 return variable_tab_
->get (ly_symbol2scm (s
.to_str0 ()));
58 Paper_def::get_scmvar_scm (SCM sym
) const
60 return gh_double2scm (get_realvar (sym
));
64 Paper_def::get_realvar (SCM s
) const
67 if (!variable_tab_
->try_retrieve (s
, &val
))
69 programming_error ("unknown paper variable: " + ly_symbol2string (s
));
75 if (variable_tab_
->try_retrieve (ly_symbol2scm ("outputscale"), &ssc
))
77 sc
= gh_scm2double (ssc
);
79 if (gh_number_p (val
))
81 return gh_scm2double (val
) / sc
;
85 programming_error ("not a real variable");
91 FIXME. This is broken until we have a generic way of
92 putting lists inside the \paper block.
95 Paper_def::line_dimensions_int (int n
) const
97 Real lw
= get_var ("linewidth");
98 Real ind
= n
? 0.0:get_var ("indent");
100 return Interval (ind
, lw
);
105 int Paper_def::score_count_
= 0;
108 Paper_def::get_next_score_count () const
110 return score_count_
++;
114 Paper_def::reset_score_count ()
121 Paper_def::get_paper_outputter ()
123 String outname
= outname_string ();
124 progress_indication (_f ("paper output to `%s'...",
125 outname
== "-" ? String ("<stdout>") : outname
));
127 global_input_file
->target_strings_
.push (outname
);
128 Paper_outputter
* po
= new Paper_outputter (outname
);
129 Path p
= split_path (outname
);
131 po
->basename_
= p
.string ();
137 todo: use symbols and hashtable idx?
142 Paper_def::find_font (SCM fn
, Real m
)
144 SCM key
= gh_cons (fn
, gh_double2scm (m
));
145 SCM met
= scm_assoc (key
, scaled_fonts_
);
148 return unsmob_metrics (ly_cdr (met
));
151 Hmm. We're chaining font - metrics. Should consider wether to merge
152 virtual-font and scaled_font.
157 f
= new Virtual_font_metric (fn
, m
, this);
162 if (variable_tab_
->try_retrieve (ly_symbol2scm ("outputscale"), &ssc
))
164 m
/= gh_scm2double (ssc
);
167 f
= all_fonts_global
->find_font (ly_scm2string (fn
));
168 SCM val
= Scaled_font_metric::make_scaled_font_metric (f
, m
);
169 scaled_fonts_
= scm_acons (key
, val
, scaled_fonts_
);
170 f
= unsmob_metrics (val
);
171 scm_gc_unprotect_object (val
);
179 Return alist to translate internally used fonts back to real-world
182 Paper_def::font_descriptions ()const
185 for (SCM s
= scaled_fonts_
; gh_pair_p (s
); s
= ly_cdr (s
))
187 SCM desc
= ly_caar (s
);
188 SCM mdesc
= unsmob_metrics (ly_cdar (s
))->description_
;
190 l
= gh_cons (gh_cons (mdesc
, desc
), l
);