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