]> git.donarmstrong.com Git - lilypond.git/blob - lily/tex-lookup.cc
release: 1.0.17
[lilypond.git] / lily / tex-lookup.cc
1 /*
2   tex-lookup.cc -- implement Tex_lookup
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
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"
24
25 Tex_lookup::Tex_lookup ()
26   : Ps_lookup ()
27 {
28 }
29
30 Tex_lookup::Tex_lookup (Lookup const& s)
31   : Ps_lookup (s)
32 {
33 }
34
35 Tex_lookup::Tex_lookup (Symtables const& s)
36   : Ps_lookup (s)
37 {
38 }
39
40 Tex_lookup::~Tex_lookup()
41 {
42 }
43
44 Atom
45 Tex_lookup::afm_find (String s) const
46 {
47   return Lookup::afm_find (s, String ("\\char%d"));
48 }
49
50 Atom*
51 Tex_lookup::atom_p (String s, int n, Box b) const
52 {
53   if (s.length_i ())
54     s.prepend ("\\");
55   for (int i = 0; i < n; i++)
56     s += "{%}";
57   return new Atom (s, b);
58 }
59
60 String
61 Tex_lookup::character_str (int i) const
62 {
63   return Lookup::character_str (i);
64 }
65
66 Atom
67 Tex_lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
68 {
69   return embed (Ps_lookup::dashed_slur (controls, thick, dash));
70 }
71
72 Atom
73 Tex_lookup::embed (Atom a) const
74 {
75   a.str_ = "\\embeddedps{\n" + a.str_ + "}";
76   return a;
77 }
78
79 Atom
80 Tex_lookup::hairpin (Real width, bool decresc, bool continued) const
81 {
82   return embed (Ps_lookup::hairpin (width, decresc, continued));
83 }
84
85 Atom
86 Tex_lookup::plet (Real dy , Real dx, Direction dir) const
87 {
88   return embed (Ps_lookup::plet (dy, dx, dir));
89 }
90
91 Lookup*
92 Tex_lookup::lookup_p (Lookup const& l) const
93 {
94   return new Tex_lookup (l);
95 }
96
97 Lookup*
98 Tex_lookup::lookup_p (Symtables const& s) const
99 {
100   return new Tex_lookup (s);
101 }
102
103 extern char const *lily_version_number_sz ();
104
105 String
106 header_to_tex_string (Scope *head)
107 {
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";
112   
113   for (Dictionary_iter<Identifier*> i(*head); i.ok (); i++)
114     {
115       if (!i.val ()->access_String_identifier ())
116         continue;
117       
118       String val = *i.val()->access_String_identifier ()->data_p_;
119       s += "\\def\\mudela" + i.key () + "{" + val  + "}\n";
120     }
121   return s;
122 }
123
124
125 Paper_outputter*
126 Tex_lookup::paper_outputter_p (Paper_stream* os_p, Paper_def* paper_l, Scope* header_l, String origin_str) const
127 {
128   if (header_global_p)
129     *os_p << header_to_tex_string(header_global_p);
130   
131   *os_p << _ ("\n% outputting Score, defined at: ") << origin_str << '\n';
132
133   if (header_l)
134     *os_p << header_to_tex_string (header_global_p);
135   
136
137   *os_p << paper_l->tex_output_settings_str ();
138   
139   if (experimental_features_global_b)
140     *os_p << "\\turnOnExperimentalFeatures%\n";
141
142   *os_p << "\\turnOnPostScript%\n";
143
144   return new Tex_outputter (os_p);
145 }
146
147 Paper_stream *
148 Tex_lookup::paper_stream_p () const
149 {
150   String outname = base_output_str ();
151
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;
160 }
161
162 String
163 Tex_lookup::print_dimen (Real r) const
164 {
165   String s = to_str (r, "%.3f");
166   if (s.index_i ("NaN") != -1)
167     {
168       warning (_ ("NaN"));
169       s = "0.0";
170     }
171   return Lookup::print_dimen (r) + "pt";
172 }
173
174 Atom
175 Tex_lookup::ps_beam (Real slope, Real width, Real thick) const
176 {
177   return embed (Ps_lookup::ps_beam (slope, width, thick));
178 }
179
180 Atom
181 Tex_lookup::slur (Array<Offset> controls) const
182 {
183   return embed (Ps_lookup::slur (controls));
184 }
185
186 Atom
187 Tex_lookup::stem (Real y1, Real y2) const
188 {
189   return Lookup::stem (y1, y2, "\\kern %\\vrule width % height % depth %");
190 }
191
192 Atom
193 Tex_lookup::text (String style, String text) const
194 {
195   return Lookup::text (style, text);
196 }
197
198 String
199 Tex_lookup::unknown_str () const
200 {
201   return "\\unknown";
202 }
203
204 Atom
205 Tex_lookup::vbracket (Real &y) const
206 {
207   return embed (Ps_lookup::vbracket (y));
208 }
209