]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-def.cc
release: 1.1.1
[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 <ctype.h>
15
16 Direction
17 Text_def::staff_dir () const
18 {
19   if (style_str_ == "finger")
20     return UP;
21   return DOWN;
22 }
23
24 Real
25 Text_def::guess_width_f(Atom& a) const
26 {
27   // Count each TeX command as one character, ugh
28   int index, length=0;
29   int total_length=text_str_.length_i();
30   const char* str=text_str_.ch_C();
31   for (index=0;index<total_length;index++) {
32     length++;
33     if (str[index]=='\\')
34       for (index++;(index < total_length) && isalpha(str[index]);index++)
35         ;
36   }
37   return length * a.dim_.x ().length (); // ugh
38 }
39
40 Interval
41 Text_def::width (Paper_def * p) const
42 {
43   Atom a = get_atom (p,CENTER);
44
45
46   Interval i (0, guess_width_f(a));
47   i += - (align_dir_ + 1)* i.center();
48   return i;
49 }
50
51 void
52 Text_def::do_print() const
53 {
54 #ifndef NPRINT
55   DOUT << "align " << align_dir_ << " `" << text_str_ << "'";
56 #endif
57 }
58
59 Text_def::Text_def()
60 {   
61   align_dir_ = RIGHT;
62   style_str_ = "roman";
63 }
64
65 bool
66 Text_def::do_equal_b (General_script_def const *gdef) const
67 {
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_;
71 }
72
73 Atom
74 Text_def::get_atom (Paper_def *p, Direction) const
75 {
76   Atom a= p->lookup_l(0)->text (style_str_, text_str_);
77
78   a.translate_axis (-(align_dir_ + 1)* guess_width_f (a) / 2, X_AXIS);
79   
80   return a;
81 }
82
83 void
84 Text_def::print() const
85 {
86   DOUT << "Text `" << text_str_ << "\', style " <<
87         style_str_ << "align " << align_dir_ << '\n';
88 }
89
90
91 IMPLEMENT_IS_TYPE_B1(Text_def,General_script_def);