]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner.cc
b4668ce37229816299030a612e4a5ba73cd1d4fb
[lilypond.git] / lily / text-spanner.cc
1 /*
2
3   text-spanner.cc -- implement Text_spanner
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 2000--2001 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "molecule.hh"
11 #include "text-item.hh"
12 #include "text-spanner.hh"
13 #include "line-spanner.hh"
14 #include "spanner.hh"
15 #include "font-interface.hh"
16 #include "dimensions.hh"
17 #include "paper-def.hh"
18 #include "debug.hh"
19 #include "paper-column.hh"
20 #include "staff-symbol-referencer.hh"
21
22 /*
23   TODO:
24     - vertical start / vertical end (fixme-name) |
25     - contination types (vert. star, vert. end)  |-> eat volta-spanner
26     - more styles
27     - more texts/positions
28  */
29
30 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
31
32 SCM
33 Text_spanner::brew_molecule (SCM smob) 
34 {
35   Grob *me= unsmob_grob (smob);
36   Spanner *spanner = dynamic_cast<Spanner*> (me);
37
38
39
40   /* Ugh, must be same as Hairpin::brew_molecule.  */
41   Real padding = gh_scm2double (me->get_grob_property ("if-text-padding"));
42   Real broken_left =  spanner->get_broken_left_end_align ();
43   Real width = spanner->spanner_length ();
44   width -= broken_left;
45
46   Drul_array<bool> broken;
47   Drul_array<Real> extra_off;
48   Direction d = LEFT;
49   do
50     {
51       extra_off [d]=0;
52       Item *b = spanner->get_bound (d);
53       broken[d] = b->break_status_dir () != CENTER;
54
55       if (!broken [d])
56         {
57
58           Interval e = b->extent (b, X_AXIS);
59           Real r = 0.0;
60           if (!e.empty_b ())
61             r = e[-d] + padding;
62           /* Text spanners such as ottava, should span from outer limits of
63            noteheads, iso (de)cresc. spanners that span the inner space */
64           if (me->get_grob_property ("outer") != SCM_EOL)
65             // r *= -1; // huh?
66             {
67               width -= d * r;
68             }
69           else
70             {
71               width += d * r;
72               extra_off[d] = r;
73             }
74         }
75     }
76   while (flip (&d) != LEFT);
77
78   // FIXME: ecs tells us -- only for (de)cresc. spanners
79   width += gh_scm2double (me->get_grob_property ("width-correct"));
80   /* /Ugh */
81
82
83   SCM properties = Font_interface::font_alist_chain (me);
84   
85   SCM edge_text = me->get_grob_property ("edge-text");
86   Drul_array<Molecule> edge;
87   if (gh_pair_p (edge_text))
88     {
89       Direction d = LEFT;
90       do
91         {
92           SCM text = index_cell (edge_text, d);
93           edge[d] = Text_item::text2molecule (me, text, properties);
94           if (!edge[d].empty_b ())
95             edge[d].align_to (Y_AXIS, CENTER);
96         }
97       while (flip (&d) != LEFT);
98     }
99   width -= edge[LEFT].extent (X_AXIS).length ()
100     + edge[RIGHT].extent (X_AXIS).length ();
101
102   Drul_array<Real> shorten;
103   shorten[LEFT] = 0;
104   shorten[RIGHT] = 0;
105
106   SCM s = me->get_grob_property ("shorten");
107   if (gh_pair_p (s))
108     {
109       shorten[LEFT] = gh_scm2double (gh_car (s));
110       shorten[RIGHT] = gh_scm2double (gh_cdr (s));
111     }
112
113   width -= shorten[LEFT] + shorten[RIGHT];
114   
115   if (width < 0)
116     {
117       warning (_ ("Text_spanner too small"));
118       width = 0;
119     }
120
121   /* ugh */
122   Real thick = me->paper_l ()->get_var ("stafflinethickness");  
123   
124   Molecule line;
125   SCM list = Line_spanner::line_atom (me, width, 0);
126   if (list != SCM_EOL)
127     {
128       
129       Box b (Interval (0, width), Interval (-thick / 2, thick / 2));
130       line = Molecule (b, list);
131     }
132   
133   Drul_array<Molecule> edge_line;
134   s = me->get_grob_property ("edge-height");
135   if (gh_pair_p (s))
136     {
137       Direction d = LEFT;
138       int dir = to_dir (me->get_grob_property ("direction"));
139       do
140         {
141           Real dy = gh_scm2double (index_cell (s, d)) * - dir;
142           if (dy)
143             {
144               SCM list = Line_spanner::line_atom (me, 0, dy);
145               Box b (Interval (0, thick),
146                      dy > 0
147                      ? Interval (0, dy)
148                      : Interval (dy, 0));
149               edge_line[d] = Molecule (b, list);
150             }
151         }
152       while (flip (&d) != LEFT);
153     }
154   
155   Molecule m;
156   if (!edge[LEFT].empty_b ())
157     m = edge[LEFT];
158
159   if (!edge_line[LEFT].empty_b ())
160     m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0);
161   if (!line.empty_b ())
162     m.add_at_edge (X_AXIS, RIGHT, line, 0);
163   if (!edge_line[RIGHT].empty_b ())
164     m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], 0);
165   if (!edge[RIGHT].empty_b ())
166     m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0);
167   m.translate_axis (broken_left + extra_off[LEFT], X_AXIS);
168
169   return m.smobbed_copy ();
170 }
171
172