]> git.donarmstrong.com Git - lilypond.git/blob - src/script.cc
release: 0.0.21
[lilypond.git] / src / script.cc
1 #include "request.hh"
2 #include "paper.hh"
3 #include "script.hh"
4 #include "stem.hh"
5 #include "molecule.hh"
6 #include "lookup.hh"
7
8 Script::Script(Script_req* rq, Item*i , int staflen, Stem*st_p)
9 {
10     dependencies.add(st_p);
11     dependencies.add(i);
12     
13     staffsize =staflen;
14     specs = rq->scriptdef;
15     support= i;
16     stem_ = st_p;
17     pos = 0;
18     symdir=1;
19     dir =rq->dir;
20 }
21
22 void
23 Script::set_symdir()
24 {
25     if (specs->invertsym)
26         symdir = (dir < 0) ? -1:1;
27 }
28
29 void
30 Script::set_default_dir()
31 {
32     if (specs->stemdir) {
33         if (!stem_)
34             dir = 1;
35         else
36             dir = stem_->dir * specs->stemdir;
37     }
38 }
39
40 void
41 Script::set_default_pos()
42 {
43     assert(dir);
44     Real y;
45     Real inter= paper()->internote();
46
47     int d = specs->staffdir;
48     if (!d) {
49         Interval v= support->height();
50         pos = rint(v[dir]/inter) + dir* 2;
51     } else {
52         y  = (d > 0) ? staffsize + 2: -2; // ug
53         y *=inter;
54         Interval v= support->height();
55
56         if (dir > 0) {
57             y = y >? v.max();
58         }else if (dir < 0) {
59             y = y <? v.min();
60         }
61         pos = int(rint(Real(y)/inter));
62     }
63 }
64
65 Interval
66 Script::width() const
67 {
68     return paper()->lookup_->script(specs->symidx).dim.x;
69 }
70
71 void
72 Script::do_pre_processing()
73 {
74     set_default_dir();
75     set_symdir();
76 }
77
78 void
79 Script::do_post_processing()
80 {
81     set_default_pos();
82 }
83 Molecule*
84 Script::brew_molecule() const
85 {
86     Paperdef *p =paper();
87
88     Real dy = p->internote();
89     String preidx = (symdir < 0) ?"-" :"";
90     Symbol ss =p->lookup_->script(preidx+specs->symidx);
91     Molecule*out = new Molecule(Atom(ss));
92     out->translate(Offset(0,dy * pos));
93     return
94         out;
95 }