]> git.donarmstrong.com Git - lilypond.git/blob - lily/ps-lookup.cc
release: 1.0.14
[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 "header.hh"
19 #include "paper-stream.hh"
20 #include "ps-stream.hh"
21 #include "ps-outputter.hh"
22
23 Ps_lookup::Ps_lookup ()
24   : Lookup ()
25 {
26 }
27
28 Ps_lookup::Ps_lookup (Lookup const& s)
29   : Lookup (s)
30 {
31 }
32
33 Ps_lookup::Ps_lookup (Symtables const& s)
34   : Lookup (s)
35 {
36 }
37
38 Ps_lookup::~Ps_lookup ()
39 {
40 }
41
42 Atom
43 Ps_lookup::afm_find (String s) const
44 {
45   return Lookup::afm_find (s, String ("(\\%03o) show "));
46 }
47
48 Atom*
49 Ps_lookup::atom_p (String s, int n, Box b) const
50 {
51   for (int i = 0; i < n; i++)
52     s.prepend ("% ");
53   return new Atom (s, b);
54 }
55
56 String
57 Ps_lookup::character_str (int i) const
58 {
59   return to_str (i, "(\\%03o)");
60 }
61
62 Atom
63 Ps_lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
64 {
65   assert (controls.size () == 8);
66
67   String ps;
68   
69   Real dx = controls[3].x () - controls[0].x ();
70   Real dy = controls[3].y () - controls[0].y ();
71
72   for (int i = 1; i < 4; i++)
73     ps += String_convert::double_str (controls[i].x ()) + " "
74       + String_convert::double_str (controls[i].y ()) + " ";
75
76   ps += String_convert::double_str (controls[0].x ()) + " "
77     + String_convert::double_str (controls[0].y ()) + " ";
78
79   ps += String_convert::double_str (thick) + " ";
80   Real on = dash > 1? thick * dash - thick : 0;
81   Real off = 2 * thick;
82   ps += "[" + String_convert::double_str (on) + " ";
83   ps += String_convert::double_str (off) + "] ";
84   ps += String_convert::int_str (0) + " ";
85   ps += "draw_dashed_slur ";
86
87   Atom a;
88   a.str_ = ps;
89   
90   a.dim_[X_AXIS] = Interval (0, dx);
91   a.dim_[Y_AXIS] = Interval (0 <? dy,  0 >? dy);
92   a.font_ = font_;
93   return a;
94 }
95
96 Atom
97 Ps_lookup::hairpin (Real width, bool decresc, bool continued) const
98 {
99   Atom a;  
100   Real height = paper_l_->staffheight_f () / 6;
101   String ps;
102   ps += to_str (width) + " " 
103         + to_str (height) + " " 
104     + to_str (continued ? height/2 : 0) + 
105     + " draw_"  + String (decresc ? "de" : "") + "cresc\n";
106   a.str_ = ps;
107
108
109   a.dim_.x () = Interval (0, width);
110   a.dim_.y () = Interval (-2*height, 2*height);
111   a.font_ = font_;
112   return a;
113 }
114
115 Lookup*
116 Ps_lookup::lookup_p (Lookup const& l) const
117 {
118   return new Ps_lookup (l);
119 }
120
121 Lookup*
122 Ps_lookup::lookup_p (Symtables const& s) const
123 {
124   return new Ps_lookup (s);
125 }
126
127 Paper_outputter*
128 Ps_lookup::paper_outputter_p (Paper_stream* os_p, Paper_def* paper_l, Header* header_l, String origin_str) const
129 {
130   if (header_global_p)
131     *os_p << header_global_p->ps_string ();
132   
133   *os_p << _ ("\n% outputting Score, defined at: ") << origin_str << '\n';
134
135   if (header_l)
136     *os_p << header_l->ps_string ();
137   *os_p << paper_l->ps_output_settings_str ();
138
139   if (experimental_features_global_b)
140     *os_p << "turnOnExperimentalFeatures\n";
141
142   return new Ps_outputter (os_p);
143 }
144
145 Paper_stream*
146 Ps_lookup::paper_stream_p () const
147 {
148 #if 1
149   String outname = base_output_str ();
150 #else
151   String outname = "lelie";
152 #endif
153
154   if (outname != "-")
155     outname += ".ps";
156   *mlog << _f ("PostScript output to %s...", 
157                outname == "-" ? String ("<stdout>") : outname ) << endl;
158   target_str_global_array.push (outname);
159   return new Ps_stream (outname);
160 }
161
162 Atom
163 Ps_lookup::plet (Real dy , Real dx, Direction dir) const
164 {
165   String ps;
166   
167   ps += String_convert::double_str (dx) + " " 
168     + String_convert::double_str (dy) + " "
169     + String_convert::int_str ( (int)dir) +
170     " draw_plet ";
171
172   Atom s;
173   s.str_ = ps;
174   return s;
175 }
176
177 Atom
178 Ps_lookup::ps_beam (Real slope, Real width, Real thick) const
179 {
180   String ps;
181   ps += to_str (width) + " "+ to_str (slope) + " " + to_str (thick)
182     + " draw_beam ";
183
184   Atom s;
185   s.str_ = ps;
186   return s;
187 }
188
189 Atom
190 Ps_lookup::slur (Array<Offset> controls) const
191 {
192   assert (controls.size () == 8);
193
194   String ps;
195   
196   Real dx = controls[3].x () - controls[0].x ();
197   Real dy = controls[3].y () - controls[0].y ();
198
199   for (int i = 5; i < 8; i++)
200     ps += String_convert::double_str (controls[i].x ()) + " "
201       + String_convert::double_str (controls[i].y ()) + " ";
202
203   ps += String_convert::double_str (controls[4].x ()) + " "
204     + String_convert::double_str (controls[4].y ()) + " ";
205   
206   for (int i = 1; i < 4; i++)
207     ps += String_convert::double_str (controls[i].x ()) + " "
208       + String_convert::double_str (controls[i].y ()) + " ";
209
210   ps += String_convert::double_str (controls[0].x ()) + " "
211     + String_convert::double_str (controls[0].y ()) + " ";
212
213   ps += " draw_slur ";
214
215   Atom s;
216   s.str_ = ps;
217   
218   s.dim_[X_AXIS] = Interval (0, dx);
219   s.dim_[Y_AXIS] = Interval (0 <? dy,  0 >? dy);
220   s.font_ = font_;
221   return s;
222 }
223
224 Atom
225 Ps_lookup::stem (Real y1, Real y2) const
226 {
227   return Lookup::stem (y1, y2, "\n% % % % draw_stem ");
228 }
229
230 Atom
231 Ps_lookup::text (String style, String text) const
232 {
233   return Lookup::text (style, "(" + text + ")");
234 }
235
236 String
237 Ps_lookup::unknown_str () const
238 {
239   return "unknown ";
240 }
241
242 Atom
243 Ps_lookup::vbracket (Real &y) const
244 {
245   Atom psbracket;
246   Real min_y = paper_l_->staffheight_f ();
247   if (y < min_y)
248     {
249       warning (_ ("bracket")
250         + " " + _ ("too small") +  " (" + print_dimen (y) + ")");
251 //      y = min_y;
252     }
253   psbracket.str_ = to_str (y) + " draw_bracket ";
254   psbracket.dim_[Y_AXIS] = Interval (-y/2,y/2);
255   psbracket.dim_[X_AXIS] = Interval (0,4 PT);
256   return psbracket;
257 }
258
259
260