2 crescendo-text-spanner.cc -- implement Text_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Jan Nieuwenhuizen <janneke@gnu.org>
8 Revised over good by Han-Wen.
11 #include "text-item.hh"
12 #include "text-spanner.hh"
13 #include "line-spanner.hh"
15 #include "font-interface.hh"
16 #include "dimensions.hh"
17 #include "output-def.hh"
19 #include "paper-column.hh"
22 class Dynamic_text_spanner
25 DECLARE_SCHEME_CALLBACK (print, (SCM));
26 static bool has_interface (Grob *);
31 This is a partial C&P from text-spanner.cc
33 Dynamic_text_spanner is similar, but
35 * does not require bracket functionality.
37 * should make room for spanning points (mf/f/mp texts).
39 * In the future, we should support
41 cresc - - - - poco - - - a - - - - poco - - -
46 The cut & paste is rather inelegant, but text-spanner was a failed
47 and buggy attempt at being generic.
49 MAKE_SCHEME_CALLBACK (Dynamic_text_spanner, print, 1);
51 Dynamic_text_spanner::print (SCM smob)
53 Grob *me = unsmob_grob (smob);
54 Spanner *spanner = dynamic_cast<Spanner *> (me);
56 Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
57 Output_def *layout = me->get_layout ();
60 Drul_array<bool> broken;
64 Item *b = spanner->get_bound (d);
65 broken[d] = b->break_status_dir () != CENTER;
70 span_points[d] = spanner->get_broken_left_end_align ();
72 span_points[d] = b->relative_coordinate (common, X_AXIS);
78 if (b->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
80 pad = robust_scm2double (me->get_property ("bound-padding"), 0.0);
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);
90 while (flip (&d) != LEFT);
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))
104 SCM text = index_get_cell (edge_text, d);
106 if (Text_interface::markup_p (text))
107 edge[d] = *unsmob_stencil (Text_interface::interpret_markup (layout->self_scm (), properties, text));
109 if (!edge[d].is_empty ())
110 edge[d].align_to (Y_AXIS, CENTER);
112 while (flip (&d) != LEFT);
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 ())
121 edge[d].translate_axis (span_points[d], X_AXIS);
122 m.add_stencil (edge[d]);
123 span_points[d] += -d * (ext[-d] + pad);
126 while (flip (&d) != LEFT);
128 if (!span_points.is_empty ())
130 Stencil l = Line_spanner::line_stencil (me,
131 Offset (span_points[LEFT], 0),
132 Offset (span_points[RIGHT], 0));
135 m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
136 return m.smobbed_copy ();
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");