]> git.donarmstrong.com Git - lilypond.git/blob - lily/tex-outputter.cc
release: 1.0.1
[lilypond.git] / lily / tex-outputter.cc
1 /*
2   tex-outputter.cc -- implement Tex_outputter
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "tex-outputter.hh"
10 #include "tex-stream.hh"
11 #include "molecule.hh"
12 #include "atom.hh"
13 #include "array.hh"
14 #include "dimension.hh"
15 #include "tex.hh"
16 #include "string-convert.hh"
17 #include "debug.hh"
18
19 Tex_outputter::Tex_outputter (Tex_stream *s)
20 {
21   outstream_l_ = s;
22 }
23
24 /*
25    26 fonts ought to be enough for anyone.
26 */
27 static String
28 tex_font_command(int i)
29 {
30   return "\\font"  +String_convert::form_str ("%c",  'A' + i) ;
31 }
32
33 void
34 Tex_outputter::switch_to_font (String fontname)
35 {
36   if (!fontname.length_i () || fontname == current_font_)
37     return;
38
39   current_font_ = fontname;
40   int i=0;
41   for (; i< font_arr_.size (); i++)
42     if (font_arr_[i] == fontname)
43       {
44         *outstream_l_ <<tex_font_command (i) << "\n";
45         return ;
46       }
47
48   
49   font_arr_.push (fontname);
50   *outstream_l_ << "\\font"  + tex_font_command (i) << "=" + fontname << "\n";
51   *outstream_l_<< tex_font_command (i);
52 }
53
54 void
55 Tex_outputter::output_molecule (Molecule const*m, Offset o, char const *nm)
56 {
57   if (check_debug)
58     *outstream_l_ << String ("\n%start: ") << nm << "\n";
59
60   for (PCursor <Atom*> i (m->atoms_); i.ok (); i++)
61     {
62       Offset a_off = i->offset ();
63       a_off += o;
64
65       switch_to_font (i->font_);
66
67       Array<String> a;
68       String r;
69   
70     
71       String s ("\\placebox{%}{%}{%}");
72       a.push (print_dimen (a_off.y()));
73       a.push (print_dimen (a_off.x()));
74       a.push (i->tex_);
75       r += substitute_args (s, a);
76       *outstream_l_ << r;
77     }
78 }
79
80
81 void
82 Tex_outputter::start_line ()
83 {
84   *outstream_l_ << "\\hbox{%\n";
85 }
86
87 void
88 Tex_outputter::stop_line ()
89 {
90   *outstream_l_ << "}";
91   *outstream_l_ << "\\interscoreline";
92   current_font_ = "";
93   font_arr_.clear ();
94 }