]> git.donarmstrong.com Git - lilypond.git/blob - lily/dynamic-text-spanner.cc
* flower
[lilypond.git] / lily / dynamic-text-spanner.cc
1 /*
2   crescendo-text-spanner.cc -- implement Text_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   Revised over good by Han-Wen.
9 */
10
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 "output-def.hh"
18 #include "warn.hh"
19 #include "paper-column.hh"
20
21
22 class Dynamic_text_spanner
23 {
24 public:
25   DECLARE_SCHEME_CALLBACK (print, (SCM));
26   static bool has_interface (Grob *);
27 };
28
29
30 /*
31   This is a partial C&P from text-spanner.cc
32
33   Dynamic_text_spanner is similar, but
34
35   * does not require bracket functionality.
36
37   * should make room for spanning points (mf/f/mp texts).
38
39   * In the future, we should  support
40
41   cresc - - - - poco - - - a - - - - poco - - -
42
43   as well
44
45
46   The cut & paste is rather inelegant, but text-spanner was a failed
47   and buggy attempt at being generic.
48 */
49 MAKE_SCHEME_CALLBACK (Dynamic_text_spanner, print, 1);
50 SCM
51 Dynamic_text_spanner::print (SCM smob)
52 {
53   Grob *me = unsmob_grob (smob);
54   Spanner *spanner = dynamic_cast<Spanner *> (me);
55
56   Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
57   Output_def *layout = me->get_layout ();
58
59   Interval span_points;
60   Drul_array<bool> broken;
61   Direction d = LEFT;
62   do
63     {
64       Item *b = spanner->get_bound (d);
65       broken[d] = b->break_status_dir () != CENTER;
66
67       if (broken[d])
68         {
69           if (d == LEFT)
70             span_points[d] = spanner->get_broken_left_end_align ();
71           else
72             span_points[d] = b->relative_coordinate (common, X_AXIS);
73         }
74       else
75         {
76           Real pad = 0.0;
77           Real encl = d;
78           if (b->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
79             {
80               pad = robust_scm2double (me->get_property ("bound-padding"), 0.0);
81               encl = -d;
82             }
83
84           Interval ext = b->extent (common, X_AXIS);
85           span_points[d] = -d * pad
86             + robust_relative_extent (b, common, X_AXIS)
87             .linear_combination (encl);
88         }
89     }
90   while (flip (&d) != LEFT);
91
92   Stencil m;
93   SCM properties = Font_interface::text_font_alist_chain (me);
94   SCM edge_text = me->get_property ("edge-text");
95   Drul_array<Stencil> edge;
96   if (scm_is_pair (edge_text))
97     {
98       Direction d = LEFT;
99       do
100         {
101           if (broken[d])
102             continue;
103
104           SCM text = index_get_cell (edge_text, d);
105
106           if (Text_interface::markup_p (text))
107             edge[d] = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (), properties, text));
108
109           if (!edge[d].is_empty ())
110             edge[d].align_to (Y_AXIS, CENTER);
111         }
112       while (flip (&d) != LEFT);
113     }
114
115   do
116     {
117       Interval ext = edge[d].extent (X_AXIS);
118       Real pad = robust_scm2double (me->get_property ("bound-padding"), 0.0);
119       if (!ext.is_empty ())
120         {
121           edge[d].translate_axis (span_points[d], X_AXIS);
122           m.add_stencil (edge[d]);
123           span_points[d] += -d * (ext[-d] + pad);
124         }
125     }
126   while (flip (&d) != LEFT);
127
128   if (!span_points.is_empty ())
129     {
130       Stencil l = Line_spanner::line_stencil (me,
131                                               Offset (span_points[LEFT], 0),
132                                               Offset (span_points[RIGHT], 0));
133       m.add_stencil (l);
134     }
135   m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
136   return m.smobbed_copy ();
137 }
138
139 ADD_INTERFACE (Dynamic_text_spanner,
140                "dynamic-text-spanner-interface",
141                "A text spanner for crescendo texts",
142                "bound-padding dash-period dash-fraction edge-text style thickness");
143