lilypond-1.1.21
[lilypond.git] / lily / ps-lookup.cc
blob8d160b1f88a50e98a77d873d832413bc73d9b61b
1 /*
2 ps-lookup.cc -- implement Ps_lookup
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "ps-lookup.hh"
10 #include "debug.hh"
11 #include "dimensions.hh"
12 #include "symtable.hh"
13 #include "scalar.hh"
14 #include "paper-def.hh"
15 #include "string-convert.hh"
16 #include "main.hh"
17 #include "file-results.hh"
18 #include "scope.hh"
19 #include "paper-stream.hh"
20 #include "ps-stream.hh"
21 #include "ps-outputter.hh"
22 #include "scope.hh"
23 #include "dictionary-iter.hh"
24 #include "identifier.hh"
26 Ps_lookup::Ps_lookup ()
27 : Lookup ()
31 Ps_lookup::Ps_lookup (Lookup const& s)
32 : Lookup (s)
36 Ps_lookup::Ps_lookup (Symtables const& s)
37 : Lookup (s)
41 Ps_lookup::~Ps_lookup ()
45 Atom
46 Ps_lookup::afm_find (String s) const
48 return Lookup::afm_find (s, String ("(\\%03o) show "));
51 Atom*
52 Ps_lookup::atom_p (String s, int n, Box b) const
54 for (int i = 0; i < n; i++)
55 s.prepend ("% ");
56 return new Atom (s, b);
59 String
60 Ps_lookup::character_str (int i) const
62 return to_str (i, "(\\%03o)");
65 Atom
66 Ps_lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
68 assert (controls.size () == 8);
70 String ps;
72 Real dx = controls[3].x () - controls[0].x ();
73 Real dy = controls[3].y () - controls[0].y ();
75 for (int i = 1; i < 4; i++)
76 ps += String_convert::double_str (controls[i].x ()) + " "
77 + String_convert::double_str (controls[i].y ()) + " ";
79 ps += String_convert::double_str (controls[0].x ()) + " "
80 + String_convert::double_str (controls[0].y ()) + " ";
82 ps += String_convert::double_str (thick) + " ";
83 Real on = dash > 1? thick * dash - thick : 0;
84 Real off = 2 * thick;
85 ps += "[" + String_convert::double_str (on) + " ";
86 ps += String_convert::double_str (off) + "] ";
87 ps += String_convert::int_str (0) + " ";
88 ps += "draw_dashed_slur ";
90 Atom a;
91 a.str_ = ps;
93 a.dim_[X_AXIS] = Interval (0, dx);
94 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
95 a.font_ = font_;
96 return a;
99 Atom
100 Ps_lookup::hairpin (Real width, bool decresc, bool continued) const
102 Atom a;
103 Real height = paper_l_->staffheight_f () / 6;
104 String ps;
105 ps += to_str (width) + " "
106 + to_str (height) + " "
107 + to_str (continued ? height/2 : 0) +
108 + " draw_" + String (decresc ? "de" : "") + "cresc\n";
109 a.str_ = ps;
112 a.dim_.x () = Interval (0, width);
113 a.dim_.y () = Interval (-2*height, 2*height);
114 a.font_ = font_;
115 return a;
118 Lookup*
119 Ps_lookup::lookup_p (Lookup const& l) const
121 return new Ps_lookup (l);
124 Lookup*
125 Ps_lookup::lookup_p (Symtables const& s) const
127 return new Ps_lookup (s);
129 extern char const *lily_version_number_sz ();
131 String
132 header_to_ps_string (Scope *head)
134 String s;
135 String lily_id_str = "Lily was here, " +
136 String (lily_version_number_sz ());
138 s+= "/lily_id_string\n{" + lily_id_str + "} bind def\n";
140 for (Dictionary_iter<Identifier*> i (*head); i.ok (); i++)
142 if (!i.val ()->access_String_identifier ())
143 continue;
145 String val = *i.val()->access_String_identifier ()->data_p_;
147 s += "/mudela" + i.key () + "{" + val + "} bind def\n";
150 return s;
153 Paper_outputter*
154 Ps_lookup::paper_outputter_p (Paper_stream* os_p, Paper_def* paper_l, Header* header_l, String origin_str) const
156 if (header_global_p)
157 *os_p << header_to_ps_string (header_global_p);
159 *os_p << _ ("\n% outputting Score, defined at: ") << origin_str << '\n';
161 if (header_l)
163 *os_p << header_to_ps_string (header_l);
166 *os_p << paper_l->ps_output_settings_str ();
168 if (experimental_features_global_b)
169 *os_p << "turnOnExperimentalFeatures\n";
171 return new Ps_outputter (os_p);
174 Paper_stream*
175 Ps_lookup::paper_stream_p () const
177 String outname = base_output_str ();
179 if (outname != "-")
180 outname += ".ps";
181 *mlog << _f ("PostScript output to %s...",
182 outname == "-" ? String ("<stdout>") : outname ) << endl;
183 target_str_global_array.push (outname);
184 return new Ps_stream (outname);
187 Atom
188 Ps_lookup::plet (Real dy , Real dx, Direction dir) const
190 String ps;
192 ps += String_convert::double_str (dx) + " "
193 + String_convert::double_str (dy) + " "
194 + String_convert::int_str ( (int)dir) +
195 " draw_plet ";
197 Atom s;
198 s.str_ = ps;
199 return s;
202 Atom
203 Ps_lookup::ps_beam (Real slope, Real width, Real thick) const
205 String ps;
206 ps += to_str (width) + " "+ to_str (slope) + " " + to_str (thick)
207 + " draw_beam ";
209 Atom s;
210 s.str_ = ps;
211 return s;
214 Atom
215 Ps_lookup::slur (Array<Offset> controls) const
217 assert (controls.size () == 8);
219 String ps;
221 Real dx = controls[3].x () - controls[0].x ();
222 Real dy = controls[3].y () - controls[0].y ();
224 for (int i = 5; i < 8; i++)
225 ps += String_convert::double_str (controls[i].x ()) + " "
226 + String_convert::double_str (controls[i].y ()) + " ";
228 ps += String_convert::double_str (controls[4].x ()) + " "
229 + String_convert::double_str (controls[4].y ()) + " ";
231 for (int i = 1; i < 4; i++)
232 ps += String_convert::double_str (controls[i].x ()) + " "
233 + String_convert::double_str (controls[i].y ()) + " ";
235 ps += String_convert::double_str (controls[0].x ()) + " "
236 + String_convert::double_str (controls[0].y ()) + " ";
238 ps += " draw_slur ";
240 Atom s;
241 s.str_ = ps;
243 s.dim_[X_AXIS] = Interval (0, dx);
244 s.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
245 s.font_ = font_;
246 return s;
249 Atom
250 Ps_lookup::stem (Real y1, Real y2) const
252 return Lookup::stem (y1, y2, "\n% % % % draw_stem ");
255 Atom
256 Ps_lookup::text (String style, String text) const
258 return Lookup::text (style, "(" + text + ")");
261 String
262 Ps_lookup::unknown_str () const
264 return "unknown ";
267 Atom
268 Ps_lookup::vbracket (Real &y) const
270 Atom psbracket;
271 Real min_y = paper_l_->staffheight_f ();
272 if (y < min_y)
274 warning (_ ("bracket")
275 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
276 // y = min_y;
278 psbracket.str_ = to_str (y) + " draw_bracket ";
279 psbracket.dim_[Y_AXIS] = Interval (-y/2,y/2);
280 psbracket.dim_[X_AXIS] = Interval (0,4 PT);
281 return psbracket;