]> git.donarmstrong.com Git - lilypond.git/blob - lily/dynamic-text-spanner.cc
run cvs up before patching.
[lilypond.git] / lily / dynamic-text-spanner.cc
1 /*
2   dynamic-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-interface.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 class Dynamic_text_spanner
22 {
23 public:
24   DECLARE_SCHEME_CALLBACK (print, (SCM));
25   static bool has_interface (Grob *);
26 };
27
28 /*
29   This is a partial C&P from text-spanner.cc
30
31   Dynamic_text_spanner is similar, but
32
33   * does not require bracket functionality.
34
35   * should make room for spanning points (mf/f/mp texts).
36
37   * In the future, we should  support
38
39   cresc - - - - poco - - - a - - - - poco - - -
40
41   as well
42
43
44   The cut & paste is rather inelegant, but text-spanner was a failed
45   and buggy attempt at being generic.
46 */
47 MAKE_SCHEME_CALLBACK (Dynamic_text_spanner, print, 1);
48 SCM
49 Dynamic_text_spanner::print (SCM smob)
50 {
51   Grob *me = unsmob_grob (smob);
52   Spanner *spanner = dynamic_cast<Spanner *> (me);
53
54   Grob *common = spanner->get_bound (LEFT)
55     ->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
56   Output_def *layout = me->layout ();
57
58   Interval span_points;
59   Drul_array<bool> broken;
60   Direction d = LEFT;
61   do
62     {
63       Item *b = spanner->get_bound (d);
64       broken[d] = b->break_status_dir () != CENTER;
65
66       if (broken[d])
67         {
68           if (d == LEFT)
69             span_points[d] = spanner->get_broken_left_end_align ();
70           else
71             span_points[d] = b->relative_coordinate (common, X_AXIS);
72         }
73       else
74         {
75           Real pad = 0.0;
76           Real encl = d;
77           if (b->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
78             {
79               pad = robust_scm2double (me->get_property ("bound-padding"), 0.0);
80               encl = -d;
81             }
82
83           /*
84             ugh - a special case.
85
86             FIXME: this fixed an issue, but need to have this issue in
87             the issue tracker.
88
89             This fix doesn't quite work: it should only do this if the
90             right bound has a trill too.
91            */
92 #if 0
93           if (d == RIGHT && me->get_property ("style") == ly_symbol2scm ("trill"))
94             {
95               pad = 2.0;
96               encl = LEFT;
97             }
98 #endif
99           
100           Interval ext = b->extent (common, X_AXIS);
101           span_points[d] = -d * pad
102             + robust_relative_extent (b, common, X_AXIS)
103             .linear_combination (encl);
104         }
105     }
106   while (flip (&d) != LEFT);
107
108   SCM properties = Font_interface::text_font_alist_chain (me);
109   SCM edge_text = me->get_property ("edge-text");
110   Drul_array<Stencil> edge;
111   if (scm_is_pair (edge_text))
112     {
113       Direction d = LEFT;
114       do
115         {
116           if (broken[d])
117             continue;
118
119           SCM text = index_get_cell (edge_text, d);
120
121           if (Text_interface::is_markup (text))
122             edge[d] = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (), properties, text));
123
124           if (!edge[d].is_empty ())
125             edge[d].align_to (Y_AXIS, CENTER);
126         }
127       while (flip (&d) != LEFT);
128     }
129
130   Stencil m;
131   do
132     {
133       Interval ext = edge[d].extent (X_AXIS);
134       Real pad = robust_scm2double (me->get_property ("bound-padding"), 0.0);
135       if (!ext.is_empty ())
136         {
137           edge[d].translate_axis (span_points[d], X_AXIS);
138           m.add_stencil (edge[d]);
139           span_points[d] += -d * (ext[-d] + pad);
140         }
141     }
142   while (flip (&d) != LEFT);
143
144   if (!span_points.is_empty ()
145       && span_points.length () > robust_scm2double (me->get_property ("dash-period"), 0.0))
146     {
147       Stencil l = Line_spanner::line_stencil (me,
148                                               Offset (span_points[LEFT], 0),
149                                               Offset (span_points[RIGHT], 0));
150       m.add_stencil (l);
151     }
152   m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
153   return m.smobbed_copy ();
154 }
155
156 ADD_INTERFACE (Dynamic_text_spanner,
157                "dynamic-text-spanner-interface",
158                "A text spanner for crescendo texts",
159                
160                "bound-padding "
161                "dash-period "
162                "dash-fraction "
163                "edge-text "
164                "style "
165                "thickness");
166