]> git.donarmstrong.com Git - lilypond.git/blob - lily/molecule.cc
release: 0.1.7
[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 String
18 Molecule::TeX_string() const
19 {
20     String s;
21     for(iter_top(ats,c); c.ok(); c++)
22         s+=c->TeX_string();
23     return s;
24 }
25
26 Box
27 Molecule::extent() const
28 {
29     Box b;
30     for(iter_top(ats,c); c.ok(); c++)
31         b.unite(c->extent());
32     return b;
33 }
34
35 void
36 Molecule::translate(Offset o)
37 {
38     for (iter_top(ats,c); c.ok(); c++)
39         c->translate(o);
40 }
41
42 void
43 Molecule::translate(Real x,Axis a)
44 {
45     for (iter_top(ats,c); c.ok(); c++)
46         c->translate(x,a);
47 }
48
49 void
50 Molecule::add(Molecule const &m)
51 {
52     for (iter_top(m.ats,c); c.ok(); c++) {
53         add(**c);
54     }
55 }
56
57 void
58 Molecule::add_right(Molecule const &m)
59 {
60      if (!ats.size()) {
61         add(m);
62         return;
63     }
64      Real xof=extent().x().right - m.extent().x().left;
65  
66      
67     Molecule toadd(m);
68     toadd.translate(Offset(xof, 0.0));
69     add(toadd);
70 }
71
72 void
73 Molecule::add_left(Molecule const &m)
74 {
75     if (!ats.size()) {
76         add(m);
77         return;
78     }
79   Real xof=extent().x().left - m.extent().x().right;
80    
81     Molecule toadd(m);
82     toadd.translate(Offset(xof, 0.0));
83     add(toadd);
84 }
85
86
87 void
88 Molecule::add_top(Molecule const &m)
89 {
90       if (!ats.size()) {
91         add(m);
92         return;
93     }
94    Real yof=extent().y().right - m.extent().y().left;
95
96     Molecule toadd(m);
97     toadd.translate(yof, Y_AXIS);
98     add(toadd);
99 }
100
101 void
102 Molecule::add_bottom(Molecule const &m)
103 {
104     if (!ats.size()) {
105         add(m);
106         return;
107     }
108      Real yof=extent().y().left- m.extent().y().right;
109     Molecule toadd(m);
110     toadd.translate(yof, Y_AXIS);
111     add(toadd);
112 }
113
114 void
115 Molecule::operator = (Molecule const &)
116 {
117     assert(false);
118 }
119
120 Molecule::Molecule(Molecule const &s)
121 {
122     add(s);
123 }
124
125 void
126 Molecule::print() const
127 {
128 #ifndef NPRINT
129     if (! check_debug)
130         return;
131     for (iter_top(ats,c); c.ok(); c++)
132         c->print();
133 #endif
134 }
135
136 void
137 Molecule::add(Atom const &a)
138 {
139     ats.bottom().add(new Atom(a)); 
140 }