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