]> git.donarmstrong.com Git - lilypond.git/blob - src/molecule.cc
c52fdc7b329b324a974f625bc2fce765b85095bc
[lilypond.git] / src / 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     // whugh.. Hard coded...
34     String s("\\placebox{%}{%}{%}");
35     Array<String> a;
36     a.push(print_dimen(off.y));
37     a.push(print_dimen(off.x));
38     a.push(sym.tex);
39     return substitute_args(s, a);
40 }
41
42 /* *************** */
43
44 String
45 Molecule::TeXstring() const
46 {
47     String s;
48     for(iter_top(ats,c); c.ok(); c++)
49         s+=c->TeXstring();
50     return s;
51 }
52
53 Box
54 Molecule::extent() const
55 {
56     Box b;
57     for(iter_top(ats,c); c.ok(); c++)
58         b.unite(c->extent());
59     return b;
60 }
61
62 void
63 Molecule::translate(Offset o)
64 {
65     for (iter_top(ats,c); c.ok(); c++)
66         c->translate(o);
67 }
68
69 void
70 Molecule::add(const Molecule &m)
71 {
72     for (iter_top(m.ats,c); c.ok(); c++) {
73         add(**c);
74     }
75 }
76
77 void
78 Molecule::add_right(const Molecule &m)
79 {
80      if (!ats.size()) {
81         add(m);
82         return;
83     }
84    Real xof=extent().x.right - m.extent().x.left;
85     Molecule toadd(m);
86     toadd.translate(Offset(xof, 0.0));
87     add(toadd);
88 }
89
90 void
91 Molecule::add_left(const Molecule &m)
92 {
93     if (!ats.size()) {
94         add(m);
95         return;
96     }
97     Real xof=extent().x.left - m.extent().x.right;
98     Molecule toadd(m);
99     toadd.translate(Offset(xof, 0.0));
100     add(toadd);
101 }
102
103
104 void
105 Molecule::add_top(const Molecule &m)
106 {
107       if (!ats.size()) {
108         add(m);
109         return;
110     }
111   Real yof=extent().y.right - m.extent().y.left;
112     Molecule toadd(m);
113     toadd.translate(Offset(0,yof));
114     add(toadd);
115 }
116
117 void
118 Molecule::add_bottom(const Molecule &m)
119 {
120     if (!ats.size()) {
121         add(m);
122         return;
123     }
124     Real yof=extent().y.left- m.extent().y.right;
125     Molecule toadd(m);
126     toadd.translate(Offset(0,yof));
127     add(toadd);
128 }
129
130 void
131 Molecule::operator = (const Molecule&)
132 {
133     assert(false);
134 }
135
136 Molecule::Molecule(const Molecule&s)
137 {
138     add(s);
139 }
140
141 void
142 Molecule::print() const
143 {
144     for (iter_top(ats,c); c.ok(); c++)
145         c->print();
146 }