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>
9 #include "ps-lookup.hh"
11 #include "dimensions.hh"
12 #include "symtable.hh"
14 #include "paper-def.hh"
15 #include "string-convert.hh"
17 #include "file-results.hh"
19 #include "paper-stream.hh"
20 #include "ps-stream.hh"
21 #include "ps-outputter.hh"
23 #include "dictionary-iter.hh"
24 #include "identifier.hh"
26 Ps_lookup::Ps_lookup ()
31 Ps_lookup::Ps_lookup (Lookup
const& s
)
36 Ps_lookup::Ps_lookup (Symtables
const& s
)
41 Ps_lookup::~Ps_lookup ()
46 Ps_lookup::afm_find (String s
) const
48 return Lookup::afm_find (s
, String ("(\\%03o) show "));
52 Ps_lookup::atom_p (String s
, int n
, Box b
) const
54 for (int i
= 0; i
< n
; i
++)
56 return new Atom (s
, b
);
60 Ps_lookup::character_str (int i
) const
62 return to_str (i
, "(\\%03o)");
66 Ps_lookup::dashed_slur (Array
<Offset
> controls
, Real thick
, Real dash
) const
68 assert (controls
.size () == 8);
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;
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 ";
93 a
.dim_
[X_AXIS
] = Interval (0, dx
);
94 a
.dim_
[Y_AXIS
] = Interval (0 <? dy
, 0 >? dy
);
100 Ps_lookup::hairpin (Real width
, bool decresc
, bool continued
) const
103 Real height
= paper_l_
->staffheight_f () / 6;
105 ps
+= to_str (width
) + " "
106 + to_str (height
) + " "
107 + to_str (continued
? height
/2 : 0) +
108 + " draw_" + String (decresc
? "de" : "") + "cresc\n";
112 a
.dim_
.x () = Interval (0, width
);
113 a
.dim_
.y () = Interval (-2*height
, 2*height
);
119 Ps_lookup::lookup_p (Lookup
const& l
) const
121 return new Ps_lookup (l
);
125 Ps_lookup::lookup_p (Symtables
const& s
) const
127 return new Ps_lookup (s
);
129 extern char const *lily_version_number_sz ();
132 header_to_ps_string (Scope
*head
)
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 ())
145 String val
= *i
.val()->access_String_identifier ()->data_p_
;
147 s
+= "/mudela" + i
.key () + "{" + val
+ "} bind def\n";
154 Ps_lookup::paper_outputter_p (Paper_stream
* os_p
, Paper_def
* paper_l
, Header
* header_l
, String origin_str
) const
157 *os_p
<< header_to_ps_string (header_global_p
);
159 *os_p
<< _ ("\n% outputting Score, defined at: ") << origin_str
<< '\n';
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
);
175 Ps_lookup::paper_stream_p () const
177 String outname
= base_output_str ();
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
);
188 Ps_lookup::plet (Real dy
, Real dx
, Direction dir
) const
192 ps
+= String_convert::double_str (dx
) + " "
193 + String_convert::double_str (dy
) + " "
194 + String_convert::int_str ( (int)dir
) +
203 Ps_lookup::ps_beam (Real slope
, Real width
, Real thick
) const
206 ps
+= to_str (width
) + " "+ to_str (slope
) + " " + to_str (thick
)
215 Ps_lookup::slur (Array
<Offset
> controls
) const
217 assert (controls
.size () == 8);
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 ()) + " ";
243 s
.dim_
[X_AXIS
] = Interval (0, dx
);
244 s
.dim_
[Y_AXIS
] = Interval (0 <? dy
, 0 >? dy
);
250 Ps_lookup::stem (Real y1
, Real y2
) const
252 return Lookup::stem (y1
, y2
, "\n% % % % draw_stem ");
256 Ps_lookup::text (String style
, String text
) const
258 return Lookup::text (style
, "(" + text
+ ")");
262 Ps_lookup::unknown_str () const
268 Ps_lookup::vbracket (Real
&y
) const
271 Real min_y
= paper_l_
->staffheight_f ();
274 warning (_ ("bracket")
275 + " " + _ ("too small") + " (" + print_dimen (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
);