]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-def.cc
release: 0.1.61
[lilypond.git] / lily / text-def.cc
1 /*
2   text-def.cc -- implement Text_def
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "debug.hh"
10 #include "lookup.hh"
11 #include "paper-def.hh"
12 #include "molecule.hh"
13 #include "text-def.hh"
14 #include "dimen.hh"
15
16 Direction
17 Text_def::staff_dir () const
18 {
19   if (style_str_ == "finger")
20     return UP;
21   return DOWN;
22 }
23
24 Interval
25 Text_def::width (Paper_def * p) const
26 {
27   Atom a = get_atom (p,CENTER);
28
29   Real guess_width_f = text_str_.length_i() * a.dim_.x ().length (); // ugh
30   Interval i (0, guess_width_f);
31   i += - (align_i_ + 1)* i.center();
32   return i;
33 }
34
35 void
36 Text_def::do_print() const
37 {
38 #ifndef NPRINT
39   DOUT << "align " <<align_i_ << " `" << text_str_ << "'";
40 #endif
41 }
42
43 Text_def::Text_def()
44 {   
45   align_i_ = RIGHT;
46   style_str_ = "roman";
47 }
48
49 bool
50 Text_def::do_equal_b (General_script_def const *gdef) const
51 {
52   Text_def const *def= (Text_def*)gdef;
53   return align_i_ == def->align_i_ && text_str_ == def->text_str_
54         && style_str_ == def->style_str_;
55 }
56
57 Atom
58 Text_def::get_atom (Paper_def *p, Direction) const
59 {
60   return p->lookup_l()->text (style_str_, text_str_, -align_i_);
61 }
62
63 void
64 Text_def::print() const
65 {
66   DOUT << "Text `" << text_str_ << "\', style " <<
67         style_str_ << "align " << align_i_ << '\n';
68 }
69
70
71 IMPLEMENT_IS_TYPE_B1(Text_def,General_script_def);