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