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