lilypond-1.3.124
[lilypond.git] / lily / tex-lookup.cc
blob4f10886e117fb6b6564d5ea1618df7e1a0cc76fa
1 /*
2 tex-lookup.cc -- implement Tex_lookup
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "tex-lookup.hh"
11 #include "debug.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 "tex-stream.hh"
21 #include "tex-outputter.hh"
22 #include "dictionary-iter.hh"
23 #include "identifier.hh"
25 Tex_lookup::Tex_lookup ()
26 : Ps_lookup ()
30 Tex_lookup::Tex_lookup (Lookup const& s)
31 : Ps_lookup (s)
35 Tex_lookup::Tex_lookup (Symtables const& s)
36 : Ps_lookup (s)
40 Tex_lookup::~Tex_lookup()
44 Atom
45 Tex_lookup::afm_find (String s) const
47 return Lookup::afm_find (s, String ("\\char%d"));
50 Atom*
51 Tex_lookup::atom_p (String s, int n, Box b) const
53 if (s.length_i ())
54 s.prepend ("\\");
55 for (int i = 0; i < n; i++)
56 s += "{%}";
57 return new Atom (s, b);
60 String
61 Tex_lookup::character_str (int i) const
63 return Lookup::character_str (i);
66 Atom
67 Tex_lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
69 return embed (Ps_lookup::dashed_slur (controls, thick, dash));
72 Atom
73 Tex_lookup::embed (Atom a) const
75 a.str_ = "\\embeddedps{\n" + a.str_ + "}";
76 return a;
79 Atom
80 Tex_lookup::hairpin (Real width, bool decresc, bool continued) const
82 return embed (Ps_lookup::hairpin (width, decresc, continued));
85 Atom
86 Tex_lookup::plet (Real dy , Real dx, Direction dir) const
88 return embed (Ps_lookup::plet (dy, dx, dir));
91 Lookup*
92 Tex_lookup::lookup_p (Lookup const& l) const
94 return new Tex_lookup (l);
97 Lookup*
98 Tex_lookup::lookup_p (Symtables const& s) const
100 return new Tex_lookup (s);
103 extern char const *lily_version_number_sz ();
105 String
106 header_to_tex_string (Scope *head)
108 String s;
109 String lily_id_str = "Lily was here, " +
110 String (lily_version_number_sz ());
111 s+= "\\def\\LilyIdString{" + lily_id_str + "}\n";
113 for (Dictionary_iter<Identifier*> i(*head); i.ok (); i++)
115 if (!i.val ()->access_String_identifier ())
116 continue;
118 String val = *i.val()->access_String_identifier ()->data_p_;
119 s += "\\def\\mudela" + i.key () + "{" + val + "}\n";
121 return s;
125 Paper_outputter*
126 Tex_lookup::paper_outputter_p (Paper_stream* os_p, Paper_def* paper_l, Scope* header_l, String origin_str) const
128 if (header_global_p)
129 *os_p << header_to_tex_string(header_global_p);
131 *os_p << _ ("\n% outputting Score, defined at: ") << origin_str << '\n';
133 if (header_l)
134 *os_p << header_to_tex_string (header_global_p);
137 *os_p << paper_l->tex_output_settings_str ();
139 if (experimental_features_global_b)
140 *os_p << "\\turnOnExperimentalFeatures%\n";
142 *os_p << "\\turnOnPostScript%\n";
144 return new Tex_outputter (os_p);
147 Paper_stream *
148 Tex_lookup::paper_stream_p () const
150 String outname = base_output_str ();
152 Paper_stream* p;
153 if (outname != "-")
154 outname += ".tex";
155 *mlog << _f ("TeX output to %s...",
156 outname == "-" ? String ("<stdout>") : outname ) << endl;
157 p = new Tex_stream (outname);
158 target_str_global_array.push (outname);
159 return p;
162 String
163 Tex_lookup::print_dimen (Real r) const
165 String s = to_str (r, "%.3f");
166 if (s.index_i ("NaN") != -1)
168 warning (_ ("NaN"));
169 s = "0.0";
171 return Lookup::print_dimen (r) + "pt";
174 Atom
175 Tex_lookup::ps_beam (Real slope, Real width, Real thick) const
177 return embed (Ps_lookup::ps_beam (slope, width, thick));
180 Atom
181 Tex_lookup::slur (Array<Offset> controls) const
183 return embed (Ps_lookup::slur (controls));
186 Atom
187 Tex_lookup::stem (Real y1, Real y2) const
189 return Lookup::stem (y1, y2, "\\kern %\\vrule width % height % depth %");
192 Atom
193 Tex_lookup::text (String style, String text) const
195 return Lookup::text (style, text);
198 String
199 Tex_lookup::unknown_str () const
201 return "\\unknown";
204 Atom
205 Tex_lookup::vbracket (Real &y) const
207 return embed (Ps_lookup::vbracket (y));