]> git.donarmstrong.com Git - lilypond.git/blob - lily/molecule.cc
release: 0.0.42.pre3
[lilypond.git] / lily / molecule.cc
1 #include "varray.hh"
2 #include "interval.hh"
3 #include "dimen.hh"
4 #include "string.hh"
5 #include "molecule.hh"
6 #include "symbol.hh"
7 #include "debug.hh"
8 #include "tex.hh"
9
10 void
11 Atom::print() const
12 {
13     mtor << "texstring: " <<sym.tex<<"\n";    
14 }
15
16 Box
17 Atom::extent() const
18 {
19     Box b( sym.dim);
20     b.translate(off);
21     return b;
22 }
23
24 Atom::Atom(Symbol s)
25 {
26     sym=s;
27 }
28
29
30 String
31 Atom::TeXstring() const
32 {
33     /* infinity checks. */
34     assert( abs(off.x) < 100 CM);
35     assert( abs(off.y) < 100 CM);
36     
37     // whugh.. Hard coded...
38     String s("\\placebox{%}{%}{%}");
39     Array<String> a;
40     a.push(print_dimen(off.y));
41     a.push(print_dimen(off.x));
42     a.push(sym.tex);
43     return substitute_args(s, a);
44 }
45
46 /* *************** */
47
48 String
49 Molecule::TeXstring() const
50 {
51     String s;
52     for(iter_top(ats,c); c.ok(); c++)
53         s+=c->TeXstring();
54     return s;
55 }
56
57 Box
58 Molecule::extent() const
59 {
60     Box b;
61     for(iter_top(ats,c); c.ok(); c++)
62         b.unite(c->extent());
63     return b;
64 }
65
66 void
67 Molecule::translate(Offset o)
68 {
69     for (iter_top(ats,c); c.ok(); c++)
70         c->translate(o);
71 }
72
73 void
74 Molecule::add(Molecule const &m)
75 {
76     for (iter_top(m.ats,c); c.ok(); c++) {
77         add(**c);
78     }
79 }
80
81 void
82 Molecule::add_right(Molecule const &m)
83 {
84      if (!ats.size()) {
85         add(m);
86         return;
87     }
88    Real xof=extent().x.right - m.extent().x.left;
89     Molecule toadd(m);
90     toadd.translate(Offset(xof, 0.0));
91     add(toadd);
92 }
93
94 void
95 Molecule::add_left(Molecule const &m)
96 {
97     if (!ats.size()) {
98         add(m);
99         return;
100     }
101     Real xof=extent().x.left - m.extent().x.right;
102     Molecule toadd(m);
103     toadd.translate(Offset(xof, 0.0));
104     add(toadd);
105 }
106
107
108 void
109 Molecule::add_top(Molecule const &m)
110 {
111       if (!ats.size()) {
112         add(m);
113         return;
114     }
115   Real yof=extent().y.right - m.extent().y.left;
116     Molecule toadd(m);
117     toadd.translate(Offset(0,yof));
118     add(toadd);
119 }
120
121 void
122 Molecule::add_bottom(Molecule const &m)
123 {
124     if (!ats.size()) {
125         add(m);
126         return;
127     }
128     Real yof=extent().y.left- m.extent().y.right;
129     Molecule toadd(m);
130     toadd.translate(Offset(0,yof));
131     add(toadd);
132 }
133
134 void
135 Molecule::operator = (Molecule const &)
136 {
137     assert(false);
138 }
139
140 Molecule::Molecule(Molecule const &s)
141 {
142     add(s);
143 }
144
145 void
146 Molecule::print() const
147 {
148     for (iter_top(ats,c); c.ok(); c++)
149         c->print();
150 }