]> git.donarmstrong.com Git - lilypond.git/blob - lily/molecule.cc
ee4fe5e48527549fa91dd0e7db647b34087fd03a
[lilypond.git] / lily / molecule.cc
1 /*
2   molecule.cc -- implement Molecule
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "interval.hh"
10 #include "dimen.hh"
11 #include "string.hh"
12 #include "molecule.hh"
13 #include "symbol.hh"
14 #include "debug.hh"
15 #include "tex.hh"
16
17
18 /* *************** */
19
20 String
21 Molecule::TeX_string() const
22 {
23     String s;
24     for(iter_top(ats,c); c.ok(); c++)
25         s+=c->TeX_string();
26     return s;
27 }
28
29 Box
30 Molecule::extent() const
31 {
32     Box b;
33     for(iter_top(ats,c); c.ok(); c++)
34         b.unite(c->extent());
35     return b;
36 }
37
38 void
39 Molecule::translate(Offset o)
40 {
41     for (iter_top(ats,c); c.ok(); c++)
42         c->translate(o);
43 }
44
45 void
46 Molecule::translate_x(Real x)
47 {
48     translate(Offset(x,0));
49 }
50
51 void
52 Molecule::translate_y(Real y)
53 {
54     translate(Offset(0,y));
55 }
56
57 void
58 Molecule::add(Molecule const &m)
59 {
60     for (iter_top(m.ats,c); c.ok(); c++) {
61         add(**c);
62     }
63 }
64
65 void
66 Molecule::add_right(Molecule const &m)
67 {
68      if (!ats.size()) {
69         add(m);
70         return;
71     }
72    Real xof=extent().x.right - m.extent().x.left;
73     Molecule toadd(m);
74     toadd.translate(Offset(xof, 0.0));
75     add(toadd);
76 }
77
78 void
79 Molecule::add_left(Molecule const &m)
80 {
81     if (!ats.size()) {
82         add(m);
83         return;
84     }
85     Real xof=extent().x.left - m.extent().x.right;
86     Molecule toadd(m);
87     toadd.translate(Offset(xof, 0.0));
88     add(toadd);
89 }
90
91
92 void
93 Molecule::add_top(Molecule const &m)
94 {
95       if (!ats.size()) {
96         add(m);
97         return;
98     }
99   Real yof=extent().y.right - m.extent().y.left;
100     Molecule toadd(m);
101     toadd.translate_y(yof);
102     add(toadd);
103 }
104
105 void
106 Molecule::add_bottom(Molecule const &m)
107 {
108     if (!ats.size()) {
109         add(m);
110         return;
111     }
112     Real yof=extent().y.left- m.extent().y.right;
113     Molecule toadd(m);
114     toadd.translate_y(yof);
115     add(toadd);
116 }
117
118 void
119 Molecule::operator = (Molecule const &)
120 {
121     assert(false);
122 }
123
124 Molecule::Molecule(Molecule const &s)
125 {
126     add(s);
127 }
128
129 void
130 Molecule::print() const
131 {
132 #ifndef NPRINT
133     if (! check_debug)
134         return;
135     for (iter_top(ats,c); c.ok(); c++)
136         c->print();
137 #endif
138 }
139
140 void
141 Molecule::add(Atom const &a)
142 {
143     ats.bottom().add(new Atom(a)); 
144 }