2 text-def.cc -- implement Text_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "paper-def.hh"
12 #include "molecule.hh"
13 #include "text-def.hh"
17 Text_def::staff_dir () const
19 if (style_str_ == "finger")
25 Text_def::guess_width_f(Atom& a) const
27 // Count each TeX command as one character, ugh
29 int total_length=text_str_.length_i();
30 const char* str=text_str_.ch_C();
31 for (index=0;index<total_length;index++) {
34 for (index++;(index < total_length) && isalpha(str[index]);index++)
37 return length * a.dim_.x ().length (); // ugh
41 Text_def::width (Paper_def * p) const
43 Atom a = get_atom (p,CENTER);
46 Interval i (0, guess_width_f(a));
47 i += - (align_dir_ + 1)* i.center();
52 Text_def::do_print() const
55 DOUT << "align " << align_dir_ << " `" << text_str_ << "'";
66 Text_def::do_equal_b (General_script_def const *gdef) const
68 Text_def const *def= dynamic_cast<Text_def const*>(gdef);
69 return def&& align_dir_ == def->align_dir_ && text_str_ == def->text_str_
70 && style_str_ == def->style_str_;
74 Text_def::get_atom (Paper_def *p, Direction) const
76 Atom a= p->lookup_l(0)->text (style_str_, text_str_);
78 a.translate_axis (-(align_dir_ + 1)* guess_width_f (a) / 2, X_AXIS);
84 Text_def::print() const
86 DOUT << "Text `" << text_str_ << "\', style " <<
87 style_str_ << "align " << align_dir_ << '\n';
91 IMPLEMENT_IS_TYPE_B1(Text_def,General_script_def);