]> git.donarmstrong.com Git - lilypond.git/blob - lily/ps-lookup.cc
release: 1.0.17
[lilypond.git] / lily / ps-lookup.cc
1 /*
2   ps-lookup.cc -- implement Ps_lookup
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
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"
25
26 Ps_lookup::Ps_lookup ()
27   : Lookup ()
28 {
29 }
30
31 Ps_lookup::Ps_lookup (Lookup const& s)
32   : Lookup (s)
33 {
34 }
35
36 Ps_lookup::Ps_lookup (Symtables const& s)
37   : Lookup (s)
38 {
39 }
40
41 Ps_lookup::~Ps_lookup ()
42 {
43 }
44
45 Atom
46 Ps_lookup::afm_find (String s) const
47 {
48   return Lookup::afm_find (s, String ("(\\%03o) show "));
49 }
50
51 Atom*
52 Ps_lookup::atom_p (String s, int n, Box b) const
53 {
54   for (int i = 0; i < n; i++)
55     s.prepend ("% ");
56   return new Atom (s, b);
57 }
58
59 String
60 Ps_lookup::character_str (int i) const
61 {
62   return to_str (i, "(\\%03o)");
63 }
64
65 Atom
66 Ps_lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
67 {
68   assert (controls.size () == 8);
69
70   String ps;
71   
72   Real dx = controls[3].x () - controls[0].x ();
73   Real dy = controls[3].y () - controls[0].y ();
74
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 ()) + " ";
78
79   ps += String_convert::double_str (controls[0].x ()) + " "
80     + String_convert::double_str (controls[0].y ()) + " ";
81
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 ";
89
90   Atom a;
91   a.str_ = ps;
92   
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;
97 }
98
99 Atom
100 Ps_lookup::hairpin (Real width, bool decresc, bool continued) const
101 {
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;
110
111
112   a.dim_.x () = Interval (0, width);
113   a.dim_.y () = Interval (-2*height, 2*height);
114   a.font_ = font_;
115   return a;
116 }
117
118 Lookup*
119 Ps_lookup::lookup_p (Lookup const& l) const
120 {
121   return new Ps_lookup (l);
122 }
123
124 Lookup*
125 Ps_lookup::lookup_p (Symtables const& s) const
126 {
127   return new Ps_lookup (s);
128 }
129 extern char const *lily_version_number_sz ();
130
131 String
132 header_to_ps_string (Scope *head)
133 {
134   String s;
135   String lily_id_str = "Lily was here, " +
136     String (lily_version_number_sz ());
137   
138   s+= "/lily_id_string\n{" + lily_id_str + "} bind def\n";
139   
140   for (Dictionary_iter<Identifier*> i (*head); i.ok (); i++)
141     {
142       if (!i.val ()->access_String_identifier ())
143         continue;
144       
145       String val = *i.val()->access_String_identifier ()->data_p_;
146       
147       s += "/mudela" + i.key () + "{" + val + "} bind def\n";
148     }
149       
150   return s;
151 }
152
153 Paper_outputter*
154 Ps_lookup::paper_outputter_p (Paper_stream* os_p, Paper_def* paper_l, Header* header_l, String origin_str) const
155 {
156   if (header_global_p)
157     *os_p << header_to_ps_string (header_global_p);
158
159   *os_p << _ ("\n% outputting Score, defined at: ") << origin_str << '\n';
160
161   if (header_l)
162     {
163       *os_p << header_to_ps_string (header_l);
164     }
165
166   *os_p << paper_l->ps_output_settings_str ();
167
168   if (experimental_features_global_b)
169     *os_p << "turnOnExperimentalFeatures\n";
170
171   return new Ps_outputter (os_p);
172 }
173
174 Paper_stream*
175 Ps_lookup::paper_stream_p () const
176 {
177   String outname = base_output_str ();
178
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);
185 }
186
187 Atom
188 Ps_lookup::plet (Real dy , Real dx, Direction dir) const
189 {
190   String ps;
191   
192   ps += String_convert::double_str (dx) + " " 
193     + String_convert::double_str (dy) + " "
194     + String_convert::int_str ( (int)dir) +
195     " draw_plet ";
196
197   Atom s;
198   s.str_ = ps;
199   return s;
200 }
201
202 Atom
203 Ps_lookup::ps_beam (Real slope, Real width, Real thick) const
204 {
205   String ps;
206   ps += to_str (width) + " "+ to_str (slope) + " " + to_str (thick)
207     + " draw_beam ";
208
209   Atom s;
210   s.str_ = ps;
211   return s;
212 }
213
214 Atom
215 Ps_lookup::slur (Array<Offset> controls) const
216 {
217   assert (controls.size () == 8);
218
219   String ps;
220   
221   Real dx = controls[3].x () - controls[0].x ();
222   Real dy = controls[3].y () - controls[0].y ();
223
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 ()) + " ";
227
228   ps += String_convert::double_str (controls[4].x ()) + " "
229     + String_convert::double_str (controls[4].y ()) + " ";
230   
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 ()) + " ";
234
235   ps += String_convert::double_str (controls[0].x ()) + " "
236     + String_convert::double_str (controls[0].y ()) + " ";
237
238   ps += " draw_slur ";
239
240   Atom s;
241   s.str_ = ps;
242   
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;
247 }
248
249 Atom
250 Ps_lookup::stem (Real y1, Real y2) const
251 {
252   return Lookup::stem (y1, y2, "\n% % % % draw_stem ");
253 }
254
255 Atom
256 Ps_lookup::text (String style, String text) const
257 {
258   return Lookup::text (style, "(" + text + ")");
259 }
260
261 String
262 Ps_lookup::unknown_str () const
263 {
264   return "unknown ";
265 }
266
267 Atom
268 Ps_lookup::vbracket (Real &y) const
269 {
270   Atom psbracket;
271   Real min_y = paper_l_->staffheight_f ();
272   if (y < min_y)
273     {
274       warning (_ ("bracket")
275         + " " + _ ("too small") +  " (" + print_dimen (y) + ")");
276 //      y = min_y;
277     }
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;
282 }
283
284
285