lilypond-0.0.4
[lilypond.git] / molecule.cc
blob7b8a752423e002148d726345d24031991f254b47
1 #include "glob.hh"
2 #include "dimen.hh"
3 #include "string.hh"
4 #include "molecule.hh"
5 #include "symbol.hh"
7 Box
8 Atom::extent() const
10 Box b( sym.dim);
11 b.translate(off);
12 return b;
15 Atom::Atom(Symbol s)
17 sym=s;
21 String
22 Atom::TeXstring() const
24 // whugh.. Hard coded...
25 String s("\\raise");
26 s+= print_dimen(off.y) +"\\hbox to 0pt{\\kern ";
27 s+= print_dimen(off.x);
28 s+= sym.tex + "\\hss}";
29 return s;
32 /****************************************************************/
34 String
35 Molecule::TeXstring() const
37 String s;
38 for(PCursor<Atom*> c(ats); c.ok(); c++)
39 s+=c->TeXstring();
40 return s;
43 Box
44 Molecule::extent() const
46 Box b;
47 for(PCursor<Atom*> c(ats); c.ok(); c++)
48 b.unite(c->extent());
49 return b;
52 void
53 Molecule::translate(Offset o)
55 for (PCursor<Atom*> c(ats); c.ok(); c++)
56 c->translate(o);
59 void
60 Molecule::add(const Molecule &m)
62 for (PCursor<Atom*> c(m.ats); c.ok(); c++) {
63 add(**c);
67 void
68 Molecule::add_right(const Molecule &m)
70 Real xof=extent().x.max - m.extent().x.min;
71 Molecule toadd(m);
72 toadd.translate(Offset(xof, 0.0));
73 add(toadd);
76 void
77 Molecule::add_left(const Molecule &m)
79 Real xof=extent().x.min - m.extent().x.max;
80 Molecule toadd(m);
81 toadd.translate(Offset(xof, 0.0));
82 add(toadd);
86 void
87 Molecule::add_top(const Molecule &m)
89 Real yof=extent().y.max - m.extent().y.min;
90 Molecule toadd(m);
91 toadd.translate(Offset(0,yof));
92 add(toadd);
95 void
96 Molecule::add_bot(const Molecule &m)
98 Real yof=extent().y.min- m.extent().y.max;
99 Molecule toadd(m);
100 toadd.translate(Offset(0,yof));
101 add(toadd);
104 void
105 Molecule::operator = (const Molecule&)
107 assert(false);
110 Molecule::Molecule(const Molecule&s)
112 add(s);