]> git.donarmstrong.com Git - lilypond.git/blob - lily/ps-lookup.cc
93299307aa781e5a9b6244cf13915de1bfdb6435
[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, bool warn) const
47 {
48   return Lookup::afm_find (s, String ("(\\%03o) show "), warn);
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::hairpin (Real width, bool decresc, bool continued) const
67 {
68   Atom a;  
69   Real height = paper_l_->staffheight_f () / 6;
70   String ps;
71   ps += to_str (width) + " " 
72         + to_str (height) + " " 
73     + to_str (continued ? height/2 : 0) + 
74     + " draw_"  + String (decresc ? "de" : "") + "cresc\n";
75   a.str_ = ps;
76
77
78   a.dim_.x () = Interval (0, width);
79   a.dim_.y () = Interval (-2*height, 2*height);
80   a.font_ = font_;
81   return a;
82 }
83
84 Lookup*
85 Ps_lookup::lookup_p (Lookup const& l) const
86 {
87   return new Ps_lookup (l);
88 }
89
90 Lookup*
91 Ps_lookup::lookup_p (Symtables const& s) const
92 {
93   return new Ps_lookup (s);
94 }
95 extern char const *lily_version_number_sz ();
96
97 String
98 header_to_ps_string (Scope *head)
99 {
100   String s;
101   String lily_id_str = "Lily was here, " +
102     String (lily_version_number_sz ());
103   
104   s+= "/lily_id_string\n{" + lily_id_str + "} bind def\n";
105   
106   for (Dictionary_iter<Identifier*> i (*head); i.ok (); i++)
107     {
108       if (!i.val ()->access_String_identifier ())
109         continue;
110       
111       String val = *i.val()->access_String_identifier ()->data_p_;
112       
113       s += "/mudela" + i.key () + "{" + val + "} bind def\n";
114     }
115       
116   return s;
117 }
118
119 Paper_outputter*
120 Ps_lookup::paper_outputter_p (Paper_stream* os_p, Paper_def* paper_l, Header* header_l, String origin_str) const
121 {
122   if (header_global_p)
123     *os_p << header_to_ps_string (header_global_p);
124
125   *os_p << _ ("\n% outputting Score, defined at: ") << origin_str << '\n';
126
127   if (header_l)
128     {
129       *os_p << header_to_ps_string (header_l);
130     }
131
132   *os_p << paper_l->ps_output_settings_str ();
133
134   if (experimental_features_global_b)
135     *os_p << "turnOnExperimentalFeatures\n";
136
137   return new Ps_outputter (os_p);
138 }
139
140 Paper_stream*
141 Ps_lookup::paper_stream_p () const
142 {
143   String outname = base_output_str ();
144
145   if (outname != "-")
146     outname += ".ps";
147   *mlog << _f ("PostScript output to %s...", 
148                outname == "-" ? String ("<stdout>") : outname ) << endl;
149   target_str_global_array.push (outname);
150   return new Ps_stream (outname);
151 }
152
153 Atom
154 Ps_lookup::plet (Real dy , Real dx, Direction dir) const
155 {
156   String ps;
157   
158   ps += String_convert::double_str (dx) + " " 
159     + String_convert::double_str (dy) + " "
160     + String_convert::int_str ( (int)dir) +
161     " draw_plet ";
162
163   Atom s;
164   s.str_ = ps;
165   return s;
166 }
167
168 Atom
169 Ps_lookup::ps_beam (Real slope, Real width, Real thick) const
170 {
171   String ps;
172   ps += to_str (width) + " "+ to_str (slope) + " " + to_str (thick)
173     + " draw_beam ";
174
175   Atom s;
176   s.str_ = ps;
177   return s;
178 }
179
180 Atom
181 Ps_lookup::slur (Array<Offset> controls) const
182 {
183   assert (controls.size () == 8);
184
185   String ps;
186   
187   Real dx = controls[3].x () - controls[0].x ();
188   Real dy = controls[3].y () - controls[0].y ();
189
190   for (int i = 5; i < 8; i++)
191     ps += String_convert::double_str (controls[i].x ()) + " "
192       + String_convert::double_str (controls[i].y ()) + " ";
193
194   ps += String_convert::double_str (controls[4].x ()) + " "
195     + String_convert::double_str (controls[4].y ()) + " ";
196   
197   for (int i = 1; i < 4; i++)
198     ps += String_convert::double_str (controls[i].x ()) + " "
199       + String_convert::double_str (controls[i].y ()) + " ";
200
201   ps += String_convert::double_str (controls[0].x ()) + " "
202     + String_convert::double_str (controls[0].y ()) + " ";
203
204   ps += " draw_slur ";
205
206   Atom s;
207   s.str_ = ps;
208   
209   s.dim_[X_AXIS] = Interval (0, dx);
210   s.dim_[Y_AXIS] = Interval (0 <? dy,  0 >? dy);
211   s.font_ = font_;
212   return s;
213 }
214
215 Atom
216 Ps_lookup::stem (Real y1, Real y2) const
217 {
218   return Lookup::stem (y1, y2, "\n% % % % draw_stem ");
219 }
220
221 Atom
222 Ps_lookup::text (String style, String text) const
223 {
224   return Lookup::text (style, "(" + text + ")");
225 }
226
227 String
228 Ps_lookup::unknown_str () const
229 {
230   return "unknown ";
231 }
232
233 Atom
234 Ps_lookup::vbracket (Real &y) const
235 {
236   Atom psbracket;
237   Real min_y = paper_l_->staffheight_f ();
238   if (y < min_y)
239     {
240       warning (_ ("bracket")
241         + " " + _ ("too small") +  " (" + print_dimen (y) + ")");
242 //      y = min_y;
243     }
244   psbracket.str_ = to_str (y) + " draw_bracket ";
245   psbracket.dim_[Y_AXIS] = Interval (-y/2,y/2);
246   psbracket.dim_[X_AXIS] = Interval (0,4 PT);
247   return psbracket;
248 }
249
250
251