]> git.donarmstrong.com Git - lilypond.git/blob - lily/molecule.cc
release: 0.1.9
[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     {
54         add (**c);
55     }
56 }
57
58 void
59 Molecule::add_right (Molecule const &m)
60 {
61    if (!ats.size()) 
62      {
63         add (m);
64         return;
65     }
66    Real xof=extent().x ().right - m.extent ().x ().left;
67  
68    
69   Molecule toadd (m);
70   toadd.translate (Offset (xof, 0.0));
71   add (toadd);
72 }
73
74 void
75 Molecule::add_left (Molecule const &m)
76 {
77   if (!ats.size()) 
78     {
79         add (m);
80         return;
81     }
82   Real xof=extent().x ().left - m.extent ().x ().right;
83    
84   Molecule toadd (m);
85   toadd.translate (Offset (xof, 0.0));
86   add (toadd);
87 }
88
89
90 void
91 Molecule::add_top (Molecule const &m)
92 {
93     if (!ats.size()) 
94       {
95         add (m);
96         return;
97     }
98    Real yof=extent().y ().right - m.extent ().y ().left;
99
100   Molecule toadd (m);
101   toadd.translate (yof, Y_AXIS);
102   add (toadd);
103 }
104
105 void
106 Molecule::add_bottom (Molecule const &m)
107 {
108   if (!ats.size()) 
109     {
110         add (m);
111         return;
112     }
113    Real yof=extent().y ().left- m.extent ().y ().right;
114   Molecule toadd (m);
115   toadd.translate (yof, Y_AXIS);
116   add (toadd);
117 }
118
119 void
120 Molecule::operator = (Molecule const &)
121 {
122   assert (false);
123 }
124
125 Molecule::Molecule (Molecule const &s)
126 {
127   add (s);
128 }
129
130 void
131 Molecule::print() const
132 {
133 #ifndef NPRINT
134   if (! check_debug)
135         return;
136   for (iter_top (ats,c); c.ok(); c++)
137         c->print();
138 #endif
139 }
140
141 void
142 Molecule::add (Atom const &a)
143 {
144   ats.bottom().add (new Atom (a)); 
145 }