]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-def.cc
release: 1.1.5
[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 <ctype.h>
10 #include "debug.hh"
11 #include "lookup.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "text-def.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 Real
25 Text_def::guess_width_f(Atom& a) const
26 {
27   return a.dim_.x ().length ();
28 }
29
30 Interval
31 Text_def::width (Paper_def * p) const
32 {
33   Atom a = get_atom (p,CENTER);
34
35   Interval i (0, guess_width_f (a));
36   i += - (align_dir_ + 1)* i.center ();
37   return i;
38 }
39
40 void
41 Text_def::do_print() const
42 {
43 #ifndef NPRINT
44   DOUT << "align " << align_dir_ << " `" << text_str_ << "'";
45 #endif
46 }
47
48 Text_def::Text_def()
49 {   
50   align_dir_ = RIGHT;
51   style_str_ = "roman";
52 }
53
54 bool
55 Text_def::do_equal_b (General_script_def const *gdef) const
56 {
57   Text_def const *def= dynamic_cast<Text_def const*>(gdef);
58   return def&& align_dir_ == def->align_dir_ && text_str_ == def->text_str_
59         && style_str_ == def->style_str_;
60 }
61
62 Atom
63 Text_def::get_atom (Paper_def *p, Direction) const
64 {
65   Atom a= p->lookup_l(0)->text (style_str_, text_str_);
66
67   a.translate_axis (-(align_dir_ + 1)* guess_width_f (a) / 2, X_AXIS);
68   // urg 1/1 is too much; see input/test/vertical-text.ly
69   a.translate_axis (a.dim_.y ().length () * 9 / 10, Y_AXIS);
70   
71   return a;
72 }
73
74 void
75 Text_def::print() const
76 {
77   DOUT << "Text `" << text_str_ << "\', style " <<
78         style_str_ << "align " << align_dir_ << '\n';
79 }
80
81
82 IMPLEMENT_IS_TYPE_B1(Text_def,General_script_def);