2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "all-font-metrics.hh"
13 #include "paper-def.hh"
16 #include "score-engraver.hh"
17 #include "paper-score.hh"
18 #include "identifier.hh"
21 #include "dictionary-iter.hh"
22 #include "file-results.hh" // urg? header_global_p
23 #include "paper-outputter.hh"
24 #include "paper-stream.hh"
27 Paper_def::Paper_def ()
29 lookup_p_tab_p_
= new Hash_table
<int, Lookup
*>;
30 lookup_p_tab_p_
->hash_func_
= int_hash
;
34 Paper_def::~Paper_def ()
36 for (Hash_table_iter
<int, Lookup
*> ai(*lookup_p_tab_p_
); ai
.ok (); ai
++)
41 delete lookup_p_tab_p_
;
44 Paper_def::Paper_def (Paper_def
const&s
)
45 : Music_output_def (s
)
47 shape_int_a_
= s
.shape_int_a_
;
48 lookup_p_tab_p_
= new Hash_table
<int, Lookup
*>;
49 lookup_p_tab_p_
->hash_func_
= int_hash
;
51 for (Hash_table_iter
<int, Lookup
*> ai(*s
.lookup_p_tab_p_
); ai
.ok (); ai
++)
53 Lookup
* l
= new Lookup (*ai
.val ());
54 set_lookup (ai
.key(), l
);
60 Paper_def::get_var (String s
) const
62 return get_realvar (ly_symbol2scm (s
.ch_C()));
66 Paper_def::get_realvar (SCM s
) const
68 if (!scope_p_
->elem_b (s
))
69 error (_f ("unknown paper variable: `%s'", ly_symbol2string (s
)));
70 Real
* p
= scope_p_
->elem (s
)->access_content_Real (false);
73 error (_("not a real variable"));
82 Paper_def::line_dimensions_int (int n
) const
84 SCM s
= default_properties_
.get (ly_symbol2scm ("margin-shape"));
87 Real lw
= get_var ("linewidth");
88 Real ind
= n
? 0.0:get_var ("indent");
90 return Interval (ind
, lw
);
95 while (gh_pair_p (s
) && n
--)
106 SCM pair
= gh_car (s
);
108 return Interval (gh_scm2double (gh_car (pair
)),
109 gh_scm2double (gh_cdr (pair
)));
113 Paper_def::set_lookup (int i
, Lookup
*l
)
115 if (lookup_p_tab_p_
->elem_b (i
))
117 delete lookup_p_tab_p_
->elem (i
);
119 (*lookup_p_tab_p_
)[i
] = l
;
127 Paper_def::interbeam_f (int multiplicity_i
) const
129 if (multiplicity_i
<= 3)
130 return get_var ("interbeam");
132 return get_var ("interbeam4");
137 Paper_def::print () const
140 Music_output_def::print ();
141 DEBUG_OUT
<< "Paper {";
142 for (Hash_table_iter
<int, Lookup
*> ai(*lookup_p_tab_p_
); ai
.ok (); ai
++)
144 DEBUG_OUT
<< "Lookup: " << ai
.key () << " = " << ai
.val ()->font_name_
<< '\n';
151 Paper_def::lookup_l (int i
) const
153 return (*lookup_p_tab_p_
)[i
];
158 int Paper_def::default_count_i_
= 0;
161 Paper_def::get_next_default_count () const
163 return default_count_i_
++;
167 Paper_def::reset_default_count()
169 default_count_i_
= 0;
174 Paper_def::paper_stream_p () const
176 String outname
= base_output_str ();
179 outname
+= String (".") + output_global_ch
;
180 progress_indication (_f ("paper output to %s...",
181 outname
== "-" ? String ("<stdout>") : outname
));
184 target_str_global_array
.push (outname
);
185 return new Paper_stream (outname
);
190 Paper_def::base_output_str () const
192 String str
= get_default_output ();
196 str
= default_outname_base_global
;
197 int def
= get_next_default_count ();
199 str
+= "-" + to_str (def
);