]> git.donarmstrong.com Git - lilypond.git/blob - molecule.cc
release: 0.0.6
[lilypond.git] / 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
8 void
9 Atom::print() const
10 {
11     mtor << "texstring: " <<sym.tex<<"\n";    
12 }
13
14 Box
15 Atom::extent() const
16 {
17     Box b( sym.dim);
18     b.translate(off);
19     return b;
20 }
21
22 Atom::Atom(Symbol s)
23 {
24     sym=s;
25 }
26
27
28 String
29 Atom::TeXstring() const
30 {
31     // whugh.. Hard coded...
32     String s("\\raise");
33     s+= print_dimen(off.y) +"\\hbox to 0pt{\\kern ";
34     s+= print_dimen(off.x);
35     s+= sym.tex + "\\hss}";
36     return s;
37 }
38
39
40 String
41 Molecule::TeXstring() const
42 {
43     String s;
44     for(PCursor<Atom*> c(ats); c.ok(); c++)
45         s+=c->TeXstring();
46     return s;
47 }
48
49 Box
50 Molecule::extent() const
51 {
52     Box b;
53     for(PCursor<Atom*> c(ats); c.ok(); c++)
54         b.unite(c->extent());
55     return b;
56 }
57
58 void
59 Molecule::translate(Offset o)
60 {
61     for (PCursor<Atom*> c(ats); c.ok(); c++)
62         c->translate(o);
63 }
64
65 void
66 Molecule::add(const Molecule &m)
67 {
68     for (PCursor<Atom*> c(m.ats); c.ok(); c++) {
69         add(**c);
70     }
71 }
72
73 void
74 Molecule::add_right(const Molecule &m)
75 {
76     Real xof=extent().x.max - m.extent().x.min;
77     Molecule toadd(m);
78     toadd.translate(Offset(xof, 0.0));
79     add(toadd);
80 }
81
82 void
83 Molecule::add_left(const Molecule &m)
84 {
85     Real xof=extent().x.min - m.extent().x.max;
86     Molecule toadd(m);
87     toadd.translate(Offset(xof, 0.0));
88     add(toadd);
89 }
90
91
92 void
93 Molecule::add_top(const Molecule &m)
94 {
95     Real yof=extent().y.max - m.extent().y.min;
96     Molecule toadd(m);
97     toadd.translate(Offset(0,yof));
98     add(toadd);
99 }
100
101 void
102 Molecule::add_bot(const Molecule &m)
103 {
104     Real yof=extent().y.min- m.extent().y.max;
105     Molecule toadd(m);
106     toadd.translate(Offset(0,yof));
107     add(toadd);
108 }
109
110 void
111 Molecule::operator = (const Molecule&)
112 {
113     assert(false);
114 }
115
116 Molecule::Molecule(const Molecule&s)
117 {
118     add(s);
119 }
120
121 void
122 Molecule::print() const
123 {
124     for (PCursor<Atom*> c(ats); c.ok(); c++)
125         c->print();
126 }