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