]> git.donarmstrong.com Git - lilypond.git/blob - lily/tex-lookup.cc
patch::: 1.0.16.mb1: Re: LilyPond 1.0.16
[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, bool warn) const
46 {
47   return Lookup::afm_find (s, String ("\\char%d"), warn);
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::embed (Atom a) const
68 {
69   a.str_ = "\\embeddedps{\n" + a.str_ + "}";
70   return a;
71 }
72
73 Atom
74 Tex_lookup::hairpin (Real width, bool decresc, bool continued) const
75 {
76   return embed (Ps_lookup::hairpin (width, decresc, continued));
77 }
78
79 Atom
80 Tex_lookup::plet (Real dy , Real dx, Direction dir) const
81 {
82   return embed (Ps_lookup::plet (dy, dx, dir));
83 }
84
85 Lookup*
86 Tex_lookup::lookup_p (Lookup const& l) const
87 {
88   return new Tex_lookup (l);
89 }
90
91 Lookup*
92 Tex_lookup::lookup_p (Symtables const& s) const
93 {
94   return new Tex_lookup (s);
95 }
96
97 extern char const *lily_version_number_sz ();
98
99 String
100 header_to_tex_string (Scope *head)
101 {
102   String s;
103   String lily_id_str = "Lily was here, " +
104     String (lily_version_number_sz ());
105   s+= "\\def\\LilyIdString{"  + lily_id_str + "}\n";
106   
107   for (Dictionary_iter<Identifier*> i(*head); i.ok (); i++)
108     {
109       if (!i.val ()->access_String_identifier ())
110         continue;
111       
112       String val = *i.val()->access_String_identifier ()->data_p_;
113       s += "\\def\\mudela" + i.key () + "{" + val  + "}\n";
114     }
115   return s;
116 }
117
118
119 Paper_outputter*
120 Tex_lookup::paper_outputter_p (Paper_stream* os_p, Paper_def* paper_l, Scope* header_l, String origin_str) const
121 {
122   if (header_global_p)
123     *os_p << header_to_tex_string(header_global_p);
124   
125   *os_p << _ ("\n% outputting Score, defined at: ") << origin_str << '\n';
126
127   if (header_l)
128     *os_p << header_to_tex_string (header_global_p);
129   
130
131   *os_p << paper_l->tex_output_settings_str ();
132   
133   if (experimental_features_global_b)
134     *os_p << "\\turnOnExperimentalFeatures%\n";
135
136   *os_p << "\\turnOnPostScript%\n";
137
138   return new Tex_outputter (os_p);
139 }
140
141 Paper_stream *
142 Tex_lookup::paper_stream_p () const
143 {
144   String outname = base_output_str ();
145
146   Paper_stream* p;
147   if (outname != "-")
148     outname += ".tex";
149   *mlog << _f ("TeX output to %s...", 
150                outname == "-" ? String ("<stdout>") : outname ) << endl;
151   p = new Tex_stream (outname);
152   target_str_global_array.push (outname);
153   return p;
154 }
155
156 String
157 Tex_lookup::print_dimen (Real r) const
158 {
159   String s = to_str (r, "%.3f");
160   if (s.index_i ("NaN") != -1)
161     {
162       warning (_ ("NaN"));
163       s = "0.0";
164     }
165   return Lookup::print_dimen (r) + "pt";
166 }
167
168 Atom
169 Tex_lookup::ps_beam (Real slope, Real width, Real thick) const
170 {
171   return embed (Ps_lookup::ps_beam (slope, width, thick));
172 }
173
174 Atom
175 Tex_lookup::slur (Array<Offset> controls) const
176 {
177   return embed (Ps_lookup::slur (controls));
178 }
179
180 Atom
181 Tex_lookup::stem (Real y1, Real y2) const
182 {
183   return Lookup::stem (y1, y2, "\\kern %\\vrule width % height % depth %");
184 }
185
186 Atom
187 Tex_lookup::text (String style, String text) const
188 {
189   return Lookup::text (style, text);
190 }
191
192 String
193 Tex_lookup::unknown_str () const
194 {
195   return "\\unknown";
196 }
197
198 Atom
199 Tex_lookup::vbracket (Real &y) const
200 {
201   return embed (Ps_lookup::vbracket (y));
202 }
203