]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
release: 1.3.88
[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 "lookup.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   lookup_alist_ = SCM_EOL;
24 }
25
26
27 Paper_def::~Paper_def ()
28 {
29 }
30
31 Paper_def::Paper_def (Paper_def const&src)
32   : Music_output_def (src)
33 {
34   SCM n  = SCM_EOL;
35   for (SCM s = src.lookup_alist_; gh_pair_p(s); s = gh_cdr (s))
36     {
37       n = scm_acons (gh_caar(s), gh_cdar (s), n);
38     }
39
40   lookup_alist_  = n;
41 }
42
43
44 Real
45 Paper_def::get_var (String s) const
46 {
47   return get_realvar (ly_symbol2scm (s.ch_C()));
48 }
49
50 SCM
51 Paper_def::get_scmvar (String s) const
52 {
53   return  scope_p_->scm_elem (ly_symbol2scm (s.ch_C()));
54 }
55
56 Real
57 Paper_def::get_realvar (SCM s) const
58 {
59   if (!scope_p_->elem_b (s))
60     {
61       programming_error ("unknown paper variable: " +  ly_symbol2string (s));
62       return 0.0;
63     }
64   SCM val = scope_p_->scm_elem (s);
65   if (gh_number_p (val))
66     {
67       return gh_scm2double (val);
68     }
69   else
70     {
71       programming_error ("not a real variable");
72       return 0.0;
73     }
74 }
75
76 /*
77   FIXME. This is broken until we have a generic way of
78   putting lists inside the \paper block.
79  */
80 Interval
81 Paper_def::line_dimensions_int (int n) const
82 {
83   Real lw =  get_var ("linewidth");
84   Real ind = n? 0.0:get_var ("indent");
85
86   return Interval (ind, lw);
87 }
88
89 void
90 Paper_def::set_lookup (int i, SCM l)
91 {
92   assert (unsmob_lookup (l));
93   lookup_alist_ = scm_assq_set_x(lookup_alist_, gh_int2scm (i), l);
94 }
95
96
97
98 void
99 Paper_def::print () const
100 {
101 #ifndef NPRINT
102   Music_output_def::print ();
103   if (flower_dstream)
104     gh_display (lookup_alist_);
105 #endif
106 }
107
108 Lookup const *
109 Paper_def::lookup_l (int i) const
110 {
111   SCM l = scm_assq (gh_int2scm(i), lookup_alist_);
112   return l == SCM_BOOL_F ? 0 :  unsmob_lookup (gh_cdr (l));
113 }
114
115 int Paper_def::default_count_i_ = 0;
116
117 int
118 Paper_def::get_next_default_count () const
119 {
120   return default_count_i_ ++;
121 }
122
123 void
124 Paper_def::reset_default_count()
125 {
126   default_count_i_ = 0;
127 }
128
129
130 Paper_stream*
131 Paper_def::paper_stream_p () const
132 {
133   String outname = base_output_str ();
134
135   if (outname != "-")
136     outname += String (".") + output_global_ch;
137   progress_indication (_f ("paper output to %s...",
138                            outname == "-" ? String ("<stdout>") : outname));
139
140   target_str_global_array.push (outname);
141   return new Paper_stream (outname);
142 }
143
144
145 String
146 Paper_def::base_output_str () const
147 {
148   String str = get_default_output ();
149
150   if (str.empty_b ())
151     {
152       str = default_outname_base_global;
153       int def = get_next_default_count ();
154       if (def)
155         str += "-" + to_str (def);
156     }
157   return str;
158 }
159
160