* python/lilylib.py (setup_temp): temporary directories are mode 700.
[lilypond.git] / lily / paper-def.cc
blobe96afc33d10266921c946245b2c3aa9eb3751aea
1 /*
2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
10 #include <math.h>
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"
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.)
32 Paper_def::Paper_def ()
36 Paper_def::~Paper_def ()
40 Paper_def::Paper_def (Paper_def const&src)
41 : Music_output_def (src)
46 Real
47 Paper_def::get_var (String s) const
49 return get_realvar (ly_symbol2scm (s.to_str0 ()));
52 Real
53 Paper_def::get_realvar (SCM s) const
55 SCM val = lookup_variable (s);
56 SCM scale = lookup_variable (ly_symbol2scm ("outputscale"));
58 Real sc = gh_scm2double (scale);
59 return gh_scm2double (val) / sc;
63 FIXME. This is broken until we have a generic way of
64 putting lists inside the \paper block.
66 Interval
67 Paper_def::line_dimensions_int (int n) const
69 Real lw = get_var ("linewidth");
70 Real ind = n? 0.0:get_var ("indent");
72 return Interval (ind, lw);
77 int Paper_def::score_count_ = 0;
79 int
80 Paper_def::get_next_score_count () const
82 return score_count_ ++;
85 void
86 Paper_def::reset_score_count ()
88 score_count_ = 0;
92 Paper_outputter*
93 Paper_def::get_paper_outputter ()
95 String outname = outname_string ();
96 progress_indication (_f ("paper output to `%s'...",
97 outname == "-" ? String ("<stdout>") : outname));
99 global_input_file->target_strings_.push (outname);
100 Paper_outputter * po = new Paper_outputter (outname);
101 Path p = split_path (outname);
102 p.ext = "";
103 po->basename_ = p.to_string ();
104 return po;
109 todo: use symbols and hashtable idx?
113 Font_metric *
114 Paper_def::find_font (SCM fn, Real m)
116 SCM key = gh_cons (fn, gh_double2scm (m));
117 SCM met = scm_assoc (key, scaled_fonts_);
119 if (gh_pair_p (met))
120 return unsmob_metrics (ly_cdr (met));
123 Hmm. We're chaining font - metrics. Should consider wether to merge
124 virtual-font and scaled_font.
126 Font_metric* f=0;
127 if (gh_list_p (fn))
129 f = new Virtual_font_metric (fn, m, this);
131 else
133 SCM var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale"));
134 m /= gh_scm2double (scm_variable_ref (var));
136 f = all_fonts_global->find_font (ly_scm2string (fn));
137 SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
138 scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
139 f = unsmob_metrics (val);
140 scm_gc_unprotect_object (val);
143 return f;
148 Return alist to translate internally used fonts back to real-world
149 coordinates. */
151 Paper_def::font_descriptions ()const
153 SCM l = SCM_EOL;
154 for (SCM s = scaled_fonts_; gh_pair_p (s); s = ly_cdr (s))
156 SCM desc = ly_caar (s);
157 SCM mdesc = unsmob_metrics (ly_cdar (s))->description_;
159 l = gh_cons (gh_cons (mdesc, desc), l);
161 return l;