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