]> git.donarmstrong.com Git - lilypond.git/blob - molecule.cc
release: 0.0.2
[lilypond.git] / molecule.cc
1 #include "glob.hh"
2 #include "string.hh"
3 #include "molecule.hh"
4 #include "symbol.hh"
5
6 Box
7 Atom::extent() const
8 {
9     Box b( sym->dim);
10     b.translate(off);
11     return b;
12 }
13
14 String
15 Atom::TeXstring() const
16 {
17     // whugh.. Hard coded...
18     String s("\\raise");
19     s+= String(off.y * VERT_TO_PT)+"pt\\hbox to 0pt{\\kern ";
20     s+=String(off.x * HOR_TO_PT) + "pt" + sym->tex + "\\hss}";
21     return s;
22 }
23
24 /****************************************************************/
25
26 String
27 Molecule::TeXstring() const
28 {
29     String s;
30     for(Cursor<Atom> c(ats); c.ok(); c++)
31         s+=(*c).TeXstring();
32     return s;
33 }
34
35 Box
36 Molecule::extent() const
37 {
38     Box b;
39     for(Cursor<Atom> c(ats); c.ok(); c++)
40         b.unite((*c).extent());
41     return b;
42 }
43
44 void
45 Molecule::translate(Offset o)
46 {
47     for(Cursor<Atom> c(ats); c.ok(); c++)
48         (*c).translate(o);
49 }
50
51 void
52 Molecule::add(const Molecule &m)
53 {
54     for (Cursor<Atom> c(m.ats); c.ok(); c++) {
55         Atom a(c);
56         ats.bottom().add(a);    
57     }
58 }
59
60 void
61 Molecule::add_right(const Molecule &m)
62 {
63     Real xof=extent().x.max - m.extent().x.min;
64     Molecule toadd(m);
65     toadd.translate(Offset(xof, 0.0));
66     add(toadd);
67 }
68
69 void
70 Molecule::add_left(const Molecule &m)
71 {
72     Real xof=extent().x.min - m.extent().x.max;
73     Molecule toadd(m);
74     toadd.translate(Offset(xof, 0.0));
75         add(toadd);
76 }
77
78
79 void
80 Molecule::add_top(const Molecule &m)
81 {
82     Real yof=extent().y.max - m.extent().y.min;
83     Molecule toadd(m);
84     toadd.translate(Offset(0,yof));
85         add(toadd);
86 }
87
88 void
89 Molecule::add_bot(const Molecule &m)
90 {
91     Real yof=extent().y.min- m.extent().y.max;
92     Molecule toadd(m);
93     toadd.translate(Offset(0,yof));
94     add(toadd);
95 }
96