]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner.cc
Merge branch 'jneeman' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond into jneeman
[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--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   Revised over good by Han-Wen.
9 */
10
11 #include "text-spanner.hh"
12
13 #include "text-interface.hh"
14 #include "line-spanner.hh"
15 #include "spanner.hh"
16 #include "font-interface.hh"
17 #include "dimensions.hh"
18 #include "output-def.hh"
19 #include "warn.hh"
20 #include "paper-column.hh"
21 #include "staff-symbol-referencer.hh"
22
23 /*
24   TODO:
25   - vertical start / vertical end (fixme-name) |
26   - contination types (vert. star, vert. end)  |-> eat volta-bracket
27   - more styles
28   - more texts/positions
29 */
30
31 MAKE_SCHEME_CALLBACK (Text_spanner, print, 1);
32
33 /*
34   TODO: this function is too long
35 */
36 SCM
37 Text_spanner::print (SCM smob)
38 {
39   Grob *me = unsmob_grob (smob);
40   Spanner *spanner = dynamic_cast<Spanner *> (me);
41
42   /* Ugh, must be same as Hairpin::print.  */
43
44   Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
45   Output_def *layout = me->layout ();
46
47   SCM flare = me->get_property ("bracket-flare");
48   SCM shorten = me->get_property ("shorten-pair");
49
50   Interval span_points;
51   Drul_array<bool> broken;
52   Direction d = LEFT;
53   do
54     {
55       Item *b = spanner->get_bound (d);
56       broken[d] = b->break_status_dir () != CENTER;
57
58       if (broken[d])
59         {
60           if (d == LEFT)
61             span_points[d] = spanner->get_broken_left_end_align ();
62           else
63             span_points[d] = b->relative_coordinate (common, X_AXIS);
64         }
65       else
66         {
67           Real encl = robust_scm2double (me->get_property ("enclose-bounds"), 0.0);
68           Interval ext = b->extent (common, X_AXIS);
69
70           span_points[d]
71             = robust_relative_extent (b, common, X_AXIS).linear_combination (d * encl);
72
73           if (is_number_pair (shorten))
74             span_points -= d * scm_to_double (index_get_cell (shorten, d));
75         }
76
77       if (is_number_pair (flare))
78         span_points -= d * scm_to_double (index_get_cell (flare, d));
79     }
80   while (flip (&d) != LEFT);
81
82   SCM properties = Font_interface::text_font_alist_chain (me);
83   SCM edge_text = me->get_property ("edge-text");
84   Drul_array<Stencil> edge;
85   if (scm_is_pair (edge_text))
86     {
87       Direction d = LEFT;
88       do
89         {
90           if (broken[d])
91             continue;
92
93           SCM text = index_get_cell (edge_text, d);
94
95           if (Text_interface::is_markup (text))
96             edge[d] = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (), properties, text));
97
98           if (!edge[d].is_empty ())
99             edge[d].align_to (Y_AXIS, CENTER);
100         }
101       while (flip (&d) != LEFT);
102     }
103
104   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
105                                                       Interval (0.0, 0.0));
106   Drul_array<Stencil> edge_line;
107   {
108     Direction d = LEFT;
109     int dir = to_dir (me->get_property ("direction"));
110     do
111       {
112         if (broken[d])
113           continue;
114
115         Real dx = 0.0;
116         if (is_number_pair (flare))
117           dx = scm_to_double (index_get_cell (flare, d)) * d;
118
119         Real dy = -dir * edge_height[d];
120         if (dy)
121           edge_line[d] = Line_spanner::line_stencil (me, Offset (0, 0), Offset (dx, dy));
122       }
123     while (flip (&d) != LEFT);
124   }
125
126   Stencil m;
127   do
128     {
129       Interval ext = edge[d].extent (X_AXIS);
130       if (!ext.is_empty ())
131         {
132           Real pad = robust_scm2double (me->get_property ("bound-padding"), 0.0);
133           edge[d].translate_axis (span_points[d], X_AXIS);
134           m.add_stencil (edge[d]);
135           span_points[d] += -d * (ext[-d] + pad);
136         }
137     }
138   while (flip (&d) != LEFT);
139
140   do
141     {
142       if (d * span_points[d] > d * edge[-d].extent (X_AXIS)[d])
143         {
144           edge_line[d].translate_axis (span_points[d], X_AXIS);
145           m.add_stencil (edge_line[d]);
146         }
147     }
148   while (flip (&d) != LEFT);
149
150   
151   if (!span_points.is_empty ()
152       && span_points.length () > robust_scm2double (me->get_property ("dash-period"), 0.0))
153     {
154       Stencil l = Line_spanner::line_stencil (me,
155                                               Offset (span_points[LEFT], 0),
156                                               Offset (span_points[RIGHT], 0));
157       m.add_stencil (l);
158     }
159   m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
160   return m.smobbed_copy ();
161 }
162
163 ADD_INTERFACE (Text_spanner,
164
165                "generic text spanner",
166
167                "bound-padding "
168                "bracket-flare "
169                "dash-fraction "
170                "dash-period "
171                "edge-height "
172                "edge-text "
173                "enclose-bounds "
174                "shorten-pair "
175                "style "
176                "thickness "
177                );
178