]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
patch::: 1.3.99.jcn2
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include <math.h>
10
11 #include "string.hh"
12 #include "misc.hh"
13 #include "paper-def.hh"
14 #include "debug.hh"
15 #include "font-metric.hh"
16 #include "main.hh"
17 #include "scope.hh"
18 #include "file-results.hh" // urg? header_global_p
19 #include "paper-stream.hh"
20
21 Paper_def::Paper_def ()
22 {
23   style_sheet_ = SCM_EOL;
24 }
25
26 Paper_def::~Paper_def ()
27 {
28 }
29
30 Paper_def::Paper_def (Paper_def const&src)
31   : Music_output_def (src)
32 {
33   style_sheet_ = src.style_sheet_;
34 }
35
36
37 Real
38 Paper_def::get_var (String s) const
39 {
40   return get_realvar (ly_symbol2scm (s.ch_C()));
41 }
42
43 SCM
44 Paper_def::get_scmvar (String s) const
45 {
46   return  scope_p_->scm_elem (ly_symbol2scm (s.ch_C()));
47 }
48
49 Real
50 Paper_def::get_realvar (SCM s) const
51 {
52   SCM val ;
53   if (!scope_p_->try_retrieve (s, &val))
54     {
55       programming_error ("unknown paper variable: " +  ly_symbol2string (s));
56       return 0.0;
57     }
58
59   if (gh_number_p (val))
60     {
61       return gh_scm2double (val);
62     }
63   else
64     {
65       programming_error ("not a real variable");
66       return 0.0;
67     }
68 }
69
70 /*
71   FIXME. This is broken until we have a generic way of
72   putting lists inside the \paper block.
73  */
74 Interval
75 Paper_def::line_dimensions_int (int n) const
76 {
77   Real lw =  get_var ("linewidth");
78   Real ind = n? 0.0:get_var ("indent");
79
80   return Interval (ind, lw);
81 }
82
83
84
85 int Paper_def::default_count_i_ = 0;
86
87 int
88 Paper_def::get_next_default_count () const
89 {
90   return default_count_i_ ++;
91 }
92
93 void
94 Paper_def::reset_default_count()
95 {
96   default_count_i_ = 0;
97 }
98
99
100 Paper_stream*
101 Paper_def::paper_stream_p () const
102 {
103   String outname = base_output_str ();
104
105   if (outname != "-")
106     outname += String (".") + output_global_ch;
107   progress_indication (_f ("paper output to %s...",
108                            outname == "-" ? String ("<stdout>") : outname));
109
110   target_str_global_array.push (outname);
111   return new Paper_stream (outname);
112 }
113
114
115 String
116 Paper_def::base_output_str () const
117 {
118   String str = get_default_output ();
119
120   if (str.empty_b ())
121     {
122       str = default_outname_base_global;
123       int def = get_next_default_count ();
124       if (def)
125         str += "-" + to_str (def);
126     }
127   return str;
128 }
129
130