]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-def.cc
release: 1.0.2
[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@cs.uu.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 "dimension.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   /* TODO: check string for \texcommand
30    */
31
32   Real guess_width_f = text_str_.length_i() * a.dim_.x ().length (); // ugh
33   Interval i (0, guess_width_f);
34   i += - (align_dir_ + 1)* i.center();
35   return i;
36 }
37
38 void
39 Text_def::do_print() const
40 {
41 #ifndef NPRINT
42   DOUT << "align " << align_dir_ << " `" << text_str_ << "'";
43 #endif
44 }
45
46 Text_def::Text_def()
47 {   
48   align_dir_ = RIGHT;
49   style_str_ = "roman";
50 }
51
52 bool
53 Text_def::do_equal_b (General_script_def const *gdef) const
54 {
55   Text_def const *def= (Text_def*)gdef;
56   return align_dir_ == def->align_dir_ && text_str_ == def->text_str_
57         && style_str_ == def->style_str_;
58 }
59
60 Atom
61 Text_def::get_atom (Paper_def *p, Direction) const
62 {
63   Atom a= p->lookup_l(0)->text (style_str_, text_str_);
64
65   Real guess_width_f = text_str_.length_i() * a.dim_.x ().length (); // ugh
66   a.translate_axis (-(align_dir_ + 1)* guess_width_f/ 2, X_AXIS);
67   
68   return a;
69 }
70
71 void
72 Text_def::print() const
73 {
74   DOUT << "Text `" << text_str_ << "\', style " <<
75         style_str_ << "align " << align_dir_ << '\n';
76 }
77
78
79 IMPLEMENT_IS_TYPE_B1(Text_def,General_script_def);